Update PR

* Update PR
This commit is contained in:
abraunegg 2024-04-26 07:00:43 +10:00
parent 080a44b9d7
commit c775ce6a69
4 changed files with 32 additions and 23 deletions

View file

@ -161,7 +161,7 @@ class CurlResponse {
class CurlEngine { class CurlEngine {
__gshared static CurlEngine[] curlEnginePool; // __gshared is used for thread-shared static variables __gshared static CurlEngine[] curlEnginePool; // __gshared is used for thread-shared static variables
HTTP http; HTTP http;
bool keepAlive; bool keepAlive;
ulong dnsTimeout; ulong dnsTimeout;
@ -211,8 +211,8 @@ class CurlEngine {
} }
} }
} }
static void releaseAllCurlInstances() { static void releaseAllCurlInstances() {
synchronized (CurlEngine.classinfo) { synchronized (CurlEngine.classinfo) {
// Safely iterate and clean up each CurlEngine instance // Safely iterate and clean up each CurlEngine instance
foreach (CurlEngine curlEngine; curlEnginePool) { foreach (CurlEngine curlEngine; curlEnginePool) {
@ -230,7 +230,12 @@ class CurlEngine {
// Clear the array after all instances have been handled // Clear the array after all instances have been handled
curlEnginePool.length = 0; // More explicit than curlEnginePool = []; curlEnginePool.length = 0; // More explicit than curlEnginePool = [];
} }
// Destroy curlEnginePool, set to null }
static void destroyAllCurlInstances() {
// Release all 'curl' instances
releaseAllCurlInstances();
// Destroy curlEnginePool, set to null
object.destroy(curlEnginePool); object.destroy(curlEnginePool);
curlEnginePool = null; curlEnginePool = null;
} }

View file

@ -107,8 +107,9 @@ class LogBuffer {
// Use dnotify's functionality for GUI notifications, if GUI notifications is enabled // Use dnotify's functionality for GUI notifications, if GUI notifications is enabled
version(Notifications) { version(Notifications) {
try { try {
auto n = new Notification("OneDrive Client for Linux", message, "IGNORED"); auto n = new Notification("OneDrive Client", message, "IGNORED");
//n.timeout = 5; // Show notification for 10 seconds
n.timeout = 10;
n.show(); n.show();
} catch (NotificationError e) { } catch (NotificationError e) {
sendGUINotification = false; sendGUINotification = false;

View file

@ -994,13 +994,17 @@ int main(string[] cliArgs) {
addLogEntry("End Monitor Loop Time: " ~ to!string(endFunctionProcessingTime), ["debug"]); addLogEntry("End Monitor Loop Time: " ~ to!string(endFunctionProcessingTime), ["debug"]);
addLogEntry("Elapsed Monitor Loop Processing Time: " ~ to!string((endFunctionProcessingTime - startFunctionProcessingTime)), ["debug"]); addLogEntry("Elapsed Monitor Loop Processing Time: " ~ to!string((endFunctionProcessingTime - startFunctionProcessingTime)), ["debug"]);
// Display memory details before cleanup // Release all the curl instances used during this loop
// New curl instances will be established on next loop
CurlEngine.releaseAllCurlInstances();
// Display memory details before garbage collection
if (displayMemoryUsage) displayMemoryUsagePreGC(); if (displayMemoryUsage) displayMemoryUsagePreGC();
// Perform Garbage Cleanup // Perform Garbage Collection
GC.collect(); GC.collect();
// Return free memory to the OS // Return free memory to the OS
GC.minimize(); GC.minimize();
// Display memory details after cleanup // Display memory details after garbage collection
if (displayMemoryUsage) displayMemoryUsagePostGC(); if (displayMemoryUsage) displayMemoryUsagePostGC();
// Log that this loop is complete // Log that this loop is complete
@ -1405,8 +1409,8 @@ void performSynchronisedExitProcess(string scopeCaller = null) {
shutdownFilesystemMonitor(); shutdownFilesystemMonitor();
// Shutdown the database // Shutdown the database
shutdownDatabase(); shutdownDatabase();
// Shutdown 'curl' instances // Destroy all 'curl' instances
shutdownCurlInstances(); destroyCurlInstances();
// Shutdown the application configuration objects // Shutdown the application configuration objects
shutdownAppConfig(); shutdownAppConfig();
@ -1481,8 +1485,8 @@ void shutdownAppConfig() {
} }
} }
void shutdownCurlInstances() { void destroyCurlInstances() {
CurlEngine.releaseAllCurlInstances(); CurlEngine.destroyAllCurlInstances();
} }
void shutdownApplicationLogging() { void shutdownApplicationLogging() {

View file

@ -202,7 +202,7 @@ Regex!char wild2regex(const(char)[] pattern) {
} }
// Test Internet access to Microsoft OneDrive // Test Internet access to Microsoft OneDrive
bool testInternetReachability(ApplicationConfig appConfig) { bool testInternetReachabilityCurlPool(ApplicationConfig appConfig) {
CurlEngine curlEngine; CurlEngine curlEngine;
bool result = false; bool result = false;
try { try {
@ -240,7 +240,7 @@ bool testInternetReachability(ApplicationConfig appConfig) {
} }
// Test Internet access to Microsoft OneDrive using a simple HTTP HEAD request // Test Internet access to Microsoft OneDrive using a simple HTTP HEAD request
bool testInternetReachabilityAlternate(ApplicationConfig appConfig) { bool testInternetReachability(ApplicationConfig appConfig) {
auto http = HTTP(); auto http = HTTP();
http.url = "https://login.microsoftonline.com"; http.url = "https://login.microsoftonline.com";
@ -1114,26 +1114,25 @@ string generateAlphanumericString(size_t length = 16) {
void displayMemoryUsagePreGC() { void displayMemoryUsagePreGC() {
// Display memory usage // Display memory usage
writeln(); writeln();
writeln("Memory Usage pre GC (KB)"); writeln("Memory Usage PRE Garbage Collection (KB)");
writeln("------------------------"); writeln("-----------------------------------------");
writeMemoryStats(); writeMemoryStats();
writeln(); writeln();
} }
void displayMemoryUsagePostGC() { void displayMemoryUsagePostGC() {
// Display memory usage // Display memory usage
writeln(); writeln("Memory Usage POST Garbage Collection (KB)");
writeln("Memory Usage post GC (KB)"); writeln("-----------------------------------------");
writeln("-------------------------");
writeMemoryStats(); writeMemoryStats();
writeln(); writeln();
} }
void writeMemoryStats() { void writeMemoryStats() {
// write memory stats // write memory stats
writeln("memory usedSize = ", (GC.stats.usedSize/1024)); writeln("memory usedSize = ", (GC.stats.usedSize/1024)); // number of used bytes on the GC heap (might only get updated after a collection)
writeln("memory freeSize = ", (GC.stats.freeSize/1024)); writeln("memory freeSize = ", (GC.stats.freeSize/1024)); // number of free bytes on the GC heap (might only get updated after a collection)
writeln("memory allocatedInCurrentThread = ", (GC.stats.allocatedInCurrentThread/1024)); writeln("memory allocatedInCurrentThread = ", (GC.stats.allocatedInCurrentThread/1024)); // number of bytes allocated for current thread since program start
} }
// Return the username of the UID running the 'onedrive' process // Return the username of the UID running the 'onedrive' process