From 024c2a46011a3d5cd39cbc7c46a1368913a3c0d6 Mon Sep 17 00:00:00 2001 From: Jan Nedbal Date: Thu, 11 Jul 2024 12:25:35 +0200 Subject: [PATCH 1/2] ResultCacheManager: output restore time in debug mode --- src/Analyser/ResultCache/ResultCacheManager.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Analyser/ResultCache/ResultCacheManager.php b/src/Analyser/ResultCache/ResultCacheManager.php index e0517d7058..e959ef562f 100644 --- a/src/Analyser/ResultCache/ResultCacheManager.php +++ b/src/Analyser/ResultCache/ResultCacheManager.php @@ -33,6 +33,8 @@ use function is_array; use function is_file; use function ksort; +use function microtime; +use function round; use function sha1_file; use function sort; use function sprintf; @@ -88,6 +90,7 @@ public function __construct( */ public function restore(array $allAnalysedFiles, bool $debug, bool $onlyFiles, ?array $projectConfigArray, Output $output): ResultCache { + $startTime = microtime(true); if ($debug) { if ($output->isDebug()) { $output->writeLineFormatted('Result cache not used because of debug mode.'); @@ -285,8 +288,10 @@ public function restore(array $allAnalysedFiles, bool $debug, bool $onlyFiles, ? $filesToAnalyseCount = count($filesToAnalyse); if ($output->isDebug()) { + $elapsed = microtime(true) - $startTime; $output->writeLineFormatted(sprintf( - 'Result cache restored. %d %s will be reanalysed.', + 'Result cache restored in %f seconds. %d %s will be reanalysed.', + round($elapsed, 1), $filesToAnalyseCount, $filesToAnalyseCount === 1 ? 'file' : 'files', )); From 2d25905190cdcd35b055988f38b7f7d17c573572 Mon Sep 17 00:00:00 2001 From: Jan Nedbal Date: Thu, 11 Jul 2024 14:04:42 +0200 Subject: [PATCH 2/2] Only for 5+ secs --- src/Analyser/ResultCache/ResultCacheManager.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Analyser/ResultCache/ResultCacheManager.php b/src/Analyser/ResultCache/ResultCacheManager.php index e959ef562f..416ce41108 100644 --- a/src/Analyser/ResultCache/ResultCacheManager.php +++ b/src/Analyser/ResultCache/ResultCacheManager.php @@ -289,9 +289,13 @@ public function restore(array $allAnalysedFiles, bool $debug, bool $onlyFiles, ? if ($output->isDebug()) { $elapsed = microtime(true) - $startTime; + $elapsedString = $elapsed > 5 + ? sprintf(' in %f seconds', round($elapsed, 1)) + : ''; + $output->writeLineFormatted(sprintf( - 'Result cache restored in %f seconds. %d %s will be reanalysed.', - round($elapsed, 1), + 'Result cache restored%s. %d %s will be reanalysed.', + $elapsedString, $filesToAnalyseCount, $filesToAnalyseCount === 1 ? 'file' : 'files', ));