From d77940d22f1d0a537591d6a5ad37d8b60cdd7367 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 12 Mar 2025 10:00:07 +0000 Subject: [PATCH 1/3] Feat: calculate and log time taken for each project --- src/Appwrite/Platform/Workers/StatsResources.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Appwrite/Platform/Workers/StatsResources.php b/src/Appwrite/Platform/Workers/StatsResources.php index 969d43e895..420aeb5f77 100644 --- a/src/Appwrite/Platform/Workers/StatsResources.php +++ b/src/Appwrite/Platform/Workers/StatsResources.php @@ -77,7 +77,21 @@ class StatsResources extends Action // Reset documents for each job $this->documents = []; + $startTime = microtime(true); $this->countForProject($dbForPlatform, $getLogsDB, $getProjectDB, $project); + $endTime = microtime(true); + $executionTime = $endTime - $startTime; + Console::info('Project: ' . $project->getId() . '(' . $project->getInternalId() . ') aggregated in ' . $this->formatTime($executionTime) .''); + } + + public function formatTime($microseconds) + { + $seconds = $microseconds / 1000000; // Convert microseconds to seconds + $hours = floor($seconds / 3600); + $minutes = floor(($seconds % 3600) / 60); + $remainingSeconds = $seconds % 60; + + return sprintf('%02d:%02d:%06.3f', $hours, $minutes, $remainingSeconds); } From 5c25b583519b868ac994f2866dfff9a885a3113a Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 12 Mar 2025 10:19:55 +0000 Subject: [PATCH 2/3] Fix date format --- src/Appwrite/Platform/Workers/StatsResources.php | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/Appwrite/Platform/Workers/StatsResources.php b/src/Appwrite/Platform/Workers/StatsResources.php index 420aeb5f77..ecfe80bf2d 100644 --- a/src/Appwrite/Platform/Workers/StatsResources.php +++ b/src/Appwrite/Platform/Workers/StatsResources.php @@ -81,20 +81,9 @@ class StatsResources extends Action $this->countForProject($dbForPlatform, $getLogsDB, $getProjectDB, $project); $endTime = microtime(true); $executionTime = $endTime - $startTime; - Console::info('Project: ' . $project->getId() . '(' . $project->getInternalId() . ') aggregated in ' . $this->formatTime($executionTime) .''); + Console::info('Project: ' . $project->getId() . '(' . $project->getInternalId() . ') aggregated in ' . date('H:i:s.u', intval($executionTime)) .''); } - public function formatTime($microseconds) - { - $seconds = $microseconds / 1000000; // Convert microseconds to seconds - $hours = floor($seconds / 3600); - $minutes = floor(($seconds % 3600) / 60); - $remainingSeconds = $seconds % 60; - - return sprintf('%02d:%02d:%06.3f', $hours, $minutes, $remainingSeconds); - } - - protected function countForProject(Database $dbForPlatform, callable $getLogsDB, callable $getProjectDB, Document $project): void { Console::info('Begining count for: ' . $project->getId()); From 81159e82d588a93c4b26827636a7c7c7eac40399 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 12 Mar 2025 10:29:07 +0000 Subject: [PATCH 3/3] show time in seconds --- src/Appwrite/Platform/Workers/StatsResources.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Workers/StatsResources.php b/src/Appwrite/Platform/Workers/StatsResources.php index ecfe80bf2d..1140698342 100644 --- a/src/Appwrite/Platform/Workers/StatsResources.php +++ b/src/Appwrite/Platform/Workers/StatsResources.php @@ -81,7 +81,7 @@ class StatsResources extends Action $this->countForProject($dbForPlatform, $getLogsDB, $getProjectDB, $project); $endTime = microtime(true); $executionTime = $endTime - $startTime; - Console::info('Project: ' . $project->getId() . '(' . $project->getInternalId() . ') aggregated in ' . date('H:i:s.u', intval($executionTime)) .''); + Console::info('Project: ' . $project->getId() . '(' . $project->getInternalId() . ') aggregated in ' . $executionTime .' seconds'); } protected function countForProject(Database $dbForPlatform, callable $getLogsDB, callable $getProjectDB, Document $project): void