Skip to content

Commit

Permalink
Merge pull request #41 from Kanti/feature/configure-number-description
Browse files Browse the repository at this point in the history
  • Loading branch information
Kanti authored Feb 9, 2024
2 parents ccbe1d0 + eb61d15 commit 8b8d5a2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
20 changes: 20 additions & 0 deletions Classes/Service/ConfigService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Check warning on line 43 in Classes/Service/ConfigService.php

View workflow job for this annotation

GitHub Actions / php: 8.2 TYPO3: 11 sentry/sdk: true

Escaped Mutant for Mutator "CastInt": --- Original +++ New @@ @@ } public function getDescriptionLength() : int { - return (int) ($this->getConfig('length_of_description') ?: self::DEFAULT_DESCRIPTION_LENGTH); + return $this->getConfig('length_of_description') ?: self::DEFAULT_DESCRIPTION_LENGTH; } public function getMaxNumberOfTimings() : int {

Check warning on line 43 in Classes/Service/ConfigService.php

View workflow job for this annotation

GitHub Actions / php: 8.1 TYPO3: 11 sentry/sdk: false

Escaped Mutant for Mutator "CastInt": --- Original +++ New @@ @@ } public function getDescriptionLength() : int { - return (int) ($this->getConfig('length_of_description') ?: self::DEFAULT_DESCRIPTION_LENGTH); + return $this->getConfig('length_of_description') ?: self::DEFAULT_DESCRIPTION_LENGTH; } public function getMaxNumberOfTimings() : int {

Check warning on line 43 in Classes/Service/ConfigService.php

View workflow job for this annotation

GitHub Actions / php: 8.2 TYPO3: 12 sentry/sdk: true

Escaped Mutant for Mutator "CastInt": --- Original +++ New @@ @@ } public function getDescriptionLength() : int { - return (int) ($this->getConfig('length_of_description') ?: self::DEFAULT_DESCRIPTION_LENGTH); + return $this->getConfig('length_of_description') ?: self::DEFAULT_DESCRIPTION_LENGTH; } public function getMaxNumberOfTimings() : int {

Check warning on line 43 in Classes/Service/ConfigService.php

View workflow job for this annotation

GitHub Actions / php: 8.1 TYPO3: 12 sentry/sdk: false

Escaped Mutant for Mutator "CastInt": --- Original +++ New @@ @@ } public function getDescriptionLength() : int { - return (int) ($this->getConfig('length_of_description') ?: self::DEFAULT_DESCRIPTION_LENGTH); + return $this->getConfig('length_of_description') ?: self::DEFAULT_DESCRIPTION_LENGTH; } public function getMaxNumberOfTimings() : int {

Check warning on line 43 in Classes/Service/ConfigService.php

View workflow job for this annotation

GitHub Actions / php: 8.2 TYPO3: 11 sentry/sdk: true

Escaped Mutant for Mutator "CastInt": --- Original +++ New @@ @@ } public function getDescriptionLength() : int { - return (int) ($this->getConfig('length_of_description') ?: self::DEFAULT_DESCRIPTION_LENGTH); + return $this->getConfig('length_of_description') ?: self::DEFAULT_DESCRIPTION_LENGTH; } public function getMaxNumberOfTimings() : int {

Check warning on line 43 in Classes/Service/ConfigService.php

View workflow job for this annotation

GitHub Actions / php: 8.2 TYPO3: 12 sentry/sdk: true

Escaped Mutant for Mutator "CastInt": --- Original +++ New @@ @@ } public function getDescriptionLength() : int { - return (int) ($this->getConfig('length_of_description') ?: self::DEFAULT_DESCRIPTION_LENGTH); + return $this->getConfig('length_of_description') ?: self::DEFAULT_DESCRIPTION_LENGTH; } public function getMaxNumberOfTimings() : int {

Check warning on line 43 in Classes/Service/ConfigService.php

View workflow job for this annotation

GitHub Actions / php: 8.1 TYPO3: 12 sentry/sdk: false

Escaped Mutant for Mutator "CastInt": --- Original +++ New @@ @@ } public function getDescriptionLength() : int { - return (int) ($this->getConfig('length_of_description') ?: self::DEFAULT_DESCRIPTION_LENGTH); + return $this->getConfig('length_of_description') ?: self::DEFAULT_DESCRIPTION_LENGTH; } public function getMaxNumberOfTimings() : int {

Check warning on line 43 in Classes/Service/ConfigService.php

View workflow job for this annotation

GitHub Actions / php: 8.1 TYPO3: 12 sentry/sdk: true

Escaped Mutant for Mutator "CastInt": --- Original +++ New @@ @@ } public function getDescriptionLength() : int { - return (int) ($this->getConfig('length_of_description') ?: self::DEFAULT_DESCRIPTION_LENGTH); + return $this->getConfig('length_of_description') ?: self::DEFAULT_DESCRIPTION_LENGTH; } public function getMaxNumberOfTimings() : int {

Check warning on line 43 in Classes/Service/ConfigService.php

View workflow job for this annotation

GitHub Actions / php: 8.2 TYPO3: 12 sentry/sdk: false

Escaped Mutant for Mutator "CastInt": --- Original +++ New @@ @@ } public function getDescriptionLength() : int { - return (int) ($this->getConfig('length_of_description') ?: self::DEFAULT_DESCRIPTION_LENGTH); + return $this->getConfig('length_of_description') ?: self::DEFAULT_DESCRIPTION_LENGTH; } public function getMaxNumberOfTimings() : int {

Check warning on line 43 in Classes/Service/ConfigService.php

View workflow job for this annotation

GitHub Actions / php: 8.2 TYPO3: 11 sentry/sdk: false

Escaped Mutant for Mutator "CastInt": --- Original +++ New @@ @@ } public function getDescriptionLength() : int { - return (int) ($this->getConfig('length_of_description') ?: self::DEFAULT_DESCRIPTION_LENGTH); + return $this->getConfig('length_of_description') ?: self::DEFAULT_DESCRIPTION_LENGTH; } public function getMaxNumberOfTimings() : int {

Check warning on line 43 in Classes/Service/ConfigService.php

View workflow job for this annotation

GitHub Actions / php: 8.1 TYPO3: 11 sentry/sdk: false

Escaped Mutant for Mutator "CastInt": --- Original +++ New @@ @@ } public function getDescriptionLength() : int { - return (int) ($this->getConfig('length_of_description') ?: self::DEFAULT_DESCRIPTION_LENGTH); + return $this->getConfig('length_of_description') ?: self::DEFAULT_DESCRIPTION_LENGTH; } public function getMaxNumberOfTimings() : int {

Check warning on line 43 in Classes/Service/ConfigService.php

View workflow job for this annotation

GitHub Actions / php: 8.1 TYPO3: 12 sentry/sdk: true

Escaped Mutant for Mutator "CastInt": --- Original +++ New @@ @@ } public function getDescriptionLength() : int { - return (int) ($this->getConfig('length_of_description') ?: self::DEFAULT_DESCRIPTION_LENGTH); + return $this->getConfig('length_of_description') ?: self::DEFAULT_DESCRIPTION_LENGTH; } public function getMaxNumberOfTimings() : int {

Check warning on line 43 in Classes/Service/ConfigService.php

View workflow job for this annotation

GitHub Actions / php: 8.1 TYPO3: 11 sentry/sdk: true

Escaped Mutant for Mutator "CastInt": --- Original +++ New @@ @@ } public function getDescriptionLength() : int { - return (int) ($this->getConfig('length_of_description') ?: self::DEFAULT_DESCRIPTION_LENGTH); + return $this->getConfig('length_of_description') ?: self::DEFAULT_DESCRIPTION_LENGTH; } public function getMaxNumberOfTimings() : int {

Check warning on line 43 in Classes/Service/ConfigService.php

View workflow job for this annotation

GitHub Actions / php: 8.1 TYPO3: 11 sentry/sdk: true

Escaped Mutant for Mutator "CastInt": --- Original +++ New @@ @@ } public function getDescriptionLength() : int { - return (int) ($this->getConfig('length_of_description') ?: self::DEFAULT_DESCRIPTION_LENGTH); + return $this->getConfig('length_of_description') ?: self::DEFAULT_DESCRIPTION_LENGTH; } public function getMaxNumberOfTimings() : int {

Check warning on line 43 in Classes/Service/ConfigService.php

View workflow job for this annotation

GitHub Actions / php: 8.2 TYPO3: 12 sentry/sdk: false

Escaped Mutant for Mutator "CastInt": --- Original +++ New @@ @@ } public function getDescriptionLength() : int { - return (int) ($this->getConfig('length_of_description') ?: self::DEFAULT_DESCRIPTION_LENGTH); + return $this->getConfig('length_of_description') ?: self::DEFAULT_DESCRIPTION_LENGTH; } public function getMaxNumberOfTimings() : int {

Check warning on line 43 in Classes/Service/ConfigService.php

View workflow job for this annotation

GitHub Actions / php: 8.2 TYPO3: 11 sentry/sdk: false

Escaped Mutant for Mutator "CastInt": --- Original +++ New @@ @@ } public function getDescriptionLength() : int { - return (int) ($this->getConfig('length_of_description') ?: self::DEFAULT_DESCRIPTION_LENGTH); + return $this->getConfig('length_of_description') ?: self::DEFAULT_DESCRIPTION_LENGTH; } public function getMaxNumberOfTimings() : int {
}

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] ?? '');
Expand Down
19 changes: 14 additions & 5 deletions Classes/Utility/TimingUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}


Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 6 additions & 0 deletions ext_conf_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion infection.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8b8d5a2

Please sign in to comment.