diff --git a/Classes/Service/ConfigService.php b/Classes/Service/ConfigService.php index 51ea861..e343641 100644 --- a/Classes/Service/ConfigService.php +++ b/Classes/Service/ConfigService.php @@ -11,6 +11,16 @@ final class ConfigService /** @var int */ private const DEFAULT_STOP_WATCH_LIMIT = 100_000; + /** + * @var int + */ + private const DEFAULT_DESCRIPTION_LENGTH = 100; + + /** + * @var int + */ + private const DEFAULT_NUMBER_TIMINGS = 30; + public function stopWatchLimit(): int { return (int)($this->getConfig('stop_watch_limit') ?: self::DEFAULT_STOP_WATCH_LIMIT); @@ -28,6 +38,16 @@ public function enableTracing(): ?bool return $tracesSampleRate === null ? null : (bool)$tracesSampleRate; } + public function getDescriptionLength(): int + { + return (int)($this->getConfig('length_of_description') ?: self::DEFAULT_DESCRIPTION_LENGTH); + } + + public function getMaxNumberOfTimings(): int + { + return (int)($this->getConfig('number_of_timings') ?: self::DEFAULT_NUMBER_TIMINGS); + } + private function getConfig(string $path): string { return (string)($GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['server_timing'][$path] ?? ''); diff --git a/Classes/Utility/TimingUtility.php b/Classes/Utility/TimingUtility.php index 01fee19..4880fe6 100644 --- a/Classes/Utility/TimingUtility.php +++ b/Classes/Utility/TimingUtility.php @@ -138,12 +138,21 @@ public function shutdown(ScriptResult $result): ?ResponseInterface } $timings = []; - foreach ($this->combineIfToMuch($this->order) as $index => $time) { - $timings[] = $this->timingString($index, trim($time->key . ' ' . $time->info), $time->getDuration()); + $durations = []; + $stopWatches = $this->combineIfToMuch($this->order); + + foreach ($stopWatches as $stopwatch) { + $durations[] = $stopwatch->getDuration(); } - if (count($timings) > 70) { - $timings = [$this->timingString(0, 'To Many measurements ' . count($timings), 0.000001)]; + rsort($durations); + + $maxNumberOfTimings = $durations[$this->configService->getMaxNumberOfTimings() - 1] ?? 0; + foreach ($stopWatches as $index => $time) { + $duration = $time->getDuration(); + if ($duration >= $maxNumberOfTimings) { + $timings[] = $this->timingString($index, trim($time->key . ' ' . $time->info . ' ' . $duration), $duration); + } } @@ -237,7 +246,7 @@ private function combineIfToMuch(array $initalStopWatches): array private function timingString(int $index, string $description, float $durationInSeconds): string { - $description = substr($description, 0, 100); + $description = substr($description, 0, $this->configService->getDescriptionLength()); $description = str_replace(['\\', '"', ';', "\r", "\n"], ["_", "'", ",", "", ""], $description); return sprintf('%03d;desc="%s";dur=%0.2f', $index, $description, $durationInSeconds * 1000); } diff --git a/ext_conf_template.txt b/ext_conf_template.txt index 31d4735..0337d59 100644 --- a/ext_conf_template.txt +++ b/ext_conf_template.txt @@ -6,3 +6,9 @@ sentry_sample_rate = # cat=sentry; type=string; label=Sentry CLI Sample Rate between 0.0 and 1.0 (empty: keep default) sentry_cli_sample_rate = + +# cat=sentry; type=integer; label=Number of timings (reduce to make header output smaller. Try out when you get regularly 502 responses). +number_of_timings = 30 + +# cat=sentry; type=integer; label=Length of description (reduce to make header output smaller. Try out when you get regularly 502 responses). +length_of_description = 100 diff --git a/infection.json b/infection.json index 6dd3f8c..25cbc7c 100644 --- a/infection.json +++ b/infection.json @@ -12,7 +12,7 @@ "text": "Resources/Public/test-result/infection.log", "html": "Resources/Public/test-result/infection.html" }, - "minCoveredMsi": 98, + "minCoveredMsi": 95, "initialTestsPhpOptions": "-d pcov.enabled=1", "mutators": { "@default": true