From 998f817c3ec863d6592287493e69899693ac0225 Mon Sep 17 00:00:00 2001 From: Jan Nedbal Date: Thu, 11 Jul 2024 15:18:43 +0200 Subject: [PATCH] ResultCacheManager: output restore time in debug mode --- src/Analyser/ResultCache/ResultCacheManager.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Analyser/ResultCache/ResultCacheManager.php b/src/Analyser/ResultCache/ResultCacheManager.php index e0517d7058..416ce41108 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,14 @@ public function restore(array $allAnalysedFiles, bool $debug, bool $onlyFiles, ? $filesToAnalyseCount = count($filesToAnalyse); if ($output->isDebug()) { + $elapsed = microtime(true) - $startTime; + $elapsedString = $elapsed > 5 + ? sprintf(' in %f seconds', round($elapsed, 1)) + : ''; + $output->writeLineFormatted(sprintf( - 'Result cache restored. %d %s will be reanalysed.', + 'Result cache restored%s. %d %s will be reanalysed.', + $elapsedString, $filesToAnalyseCount, $filesToAnalyseCount === 1 ? 'file' : 'files', ));