Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use monotonic timer in rex_timer #5773

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions redaxo/src/core/lib/util/timer.php
Expand Up @@ -78,9 +78,9 @@
$duration += $timer->getDelta(self::MILLISEC);

self::$serverTimings[$label]['sum'] = $duration;
self::$serverTimings[$label]['timings'][] = [

Check failure on line 81 in redaxo/src/core/lib/util/timer.php

View workflow job for this annotation

GitHub Actions / psalm static code analysis

MixedPropertyTypeCoercion

redaxo/src/core/lib/util/timer.php:81:9: MixedPropertyTypeCoercion: rex_timer::$serverTimings expects 'array<string, array{sum: mixed, timings: list<array{end: float, start: float}>}>', parent type `non-empty-array<string, array{sum: mixed, timings: list<array{end: float|mixed, start: float}>}>` provided (see https://psalm.dev/196)
'start' => $timer->start,
'end' => microtime(true),
'end' => self::now(),
];
}

Expand All @@ -90,7 +90,7 @@
*/
public function reset()
{
$this->start = microtime(true);
$this->start = self::now();

Check failure on line 93 in redaxo/src/core/lib/util/timer.php

View workflow job for this annotation

GitHub Actions / psalm static code analysis

MixedAssignment

redaxo/src/core/lib/util/timer.php:93:9: MixedAssignment: Unable to determine the type that $this->start is being assigned to (see https://psalm.dev/032)
}

/**
Expand All @@ -99,7 +99,7 @@
*/
public function stop()
{
$this->duration = microtime(true) - $this->start;
$this->duration = self::now() - $this->start;

Check failure on line 102 in redaxo/src/core/lib/util/timer.php

View workflow job for this annotation

GitHub Actions / psalm static code analysis

MixedAssignment

redaxo/src/core/lib/util/timer.php:102:9: MixedAssignment: Unable to determine the type that $this->duration is being assigned to (see https://psalm.dev/032)

Check failure on line 102 in redaxo/src/core/lib/util/timer.php

View workflow job for this annotation

GitHub Actions / psalm static code analysis

MixedOperand

redaxo/src/core/lib/util/timer.php:102:27: MixedOperand: Left operand cannot be mixed (see https://psalm.dev/059)
}

/**
Expand All @@ -107,13 +107,13 @@
*
* @param int $precision Factor which will be multiplied, for convertion into different units (e.g. 1000 for milli,...)
*
* @return float Time difference

Check failure on line 110 in redaxo/src/core/lib/util/timer.php

View workflow job for this annotation

GitHub Actions / psalm static code analysis

MixedInferredReturnType

redaxo/src/core/lib/util/timer.php:110:16: MixedInferredReturnType: Could not verify return type 'float' for rex_timer::getDelta (see https://psalm.dev/047)
*/
public function getDelta($precision = self::MILLISEC)
{
$duration = $this->duration ?? microtime(true) - $this->start;
$duration = $this->duration ?? self::now() - $this->start;

Check failure on line 114 in redaxo/src/core/lib/util/timer.php

View workflow job for this annotation

GitHub Actions / psalm static code analysis

MixedAssignment

redaxo/src/core/lib/util/timer.php:114:9: MixedAssignment: Unable to determine the type that $duration is being assigned to (see https://psalm.dev/032)

Check failure on line 114 in redaxo/src/core/lib/util/timer.php

View workflow job for this annotation

GitHub Actions / psalm static code analysis

MixedOperand

redaxo/src/core/lib/util/timer.php:114:40: MixedOperand: Left operand cannot be mixed (see https://psalm.dev/059)

return $duration * $precision;

Check failure on line 116 in redaxo/src/core/lib/util/timer.php

View workflow job for this annotation

GitHub Actions / psalm static code analysis

MixedOperand

redaxo/src/core/lib/util/timer.php:116:16: MixedOperand: Left operand cannot be mixed (see https://psalm.dev/059)

Check failure on line 116 in redaxo/src/core/lib/util/timer.php

View workflow job for this annotation

GitHub Actions / psalm static code analysis

MixedReturnStatement

redaxo/src/core/lib/util/timer.php:116:16: MixedReturnStatement: Could not infer a return type (see https://psalm.dev/138)
}

/**
Expand All @@ -129,4 +129,8 @@
$time = $this->getDelta($precision);
return rex_formatter::number($time, [$decimals]);
}

static private function now() {

Check failure on line 133 in redaxo/src/core/lib/util/timer.php

View workflow job for this annotation

GitHub Actions / phpstan static code analysis

Method rex_timer::now() has no return type specified.

Check failure on line 133 in redaxo/src/core/lib/util/timer.php

View workflow job for this annotation

GitHub Actions / psalm static code analysis

MissingReturnType

redaxo/src/core/lib/util/timer.php:133:29: MissingReturnType: Method rex_timer::now does not have a return type, expecting float (see https://psalm.dev/050)
return hrtime(true) / 1e9;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inspired by guzzle/guzzle#2242

}
}