-
-
Notifications
You must be signed in to change notification settings - Fork 447
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
Fix a possible division by zero #634
Conversation
When you go to Symfony profiler -> Query Metrics and when Query time = 0ms there is an exception: "An exception has been thrown during the rendering of a template ("Warning: Division by zero")." [1/2] ContextErrorException: Warning: Division by zero in vendor\doctrine\doctrine-bundle\DataCollector\DoctrineDataCollector.php at line 232 [2/2] Twig_Error_Runtime: An exception has been thrown during the rendering of a template ("Warning: Division by zero") in vendor\doctrine\doctrine-bundle\Resources\views\Collector\db.html.twig at line 157
foreach ($groupedQueries as $connection => $queries) { | ||
foreach ($queries as $i => $query) { | ||
$groupedQueries[$connection][$i]['executionPercent'] = $query['executionMS'] / $totalExecutionMS * 100; | ||
$groupedQueries[$connection][$i]['executionPercent'] = | ||
$this->executionTimePercentage($query['executionMS'], $totalExecutionMS ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not wrap the line here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stof the first parens is after 120 chars, so I think this was the right choice. @mikeSimonson you should remove the space after $totalExecutionMS
.
} | ||
} | ||
|
||
return $groupedQueries; | ||
} | ||
|
||
private function executionTimePercentage($executionTimeMS, $totalExecutionTimeMS) | ||
{ | ||
if ($totalExecutionTimeMS === 0.0 || $totalExecutionTimeMS === 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it safe to compare float values like this? Maybe we can use very small epsilon value e.g. if ($totalExecutionTimeMS < $eps) where $eps = 1e-5 or something like this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this comparison looks dangerous.
private function executionTimePercentage($executionTimeMS, $totalExecutionTimeMS) | ||
{ | ||
if ($totalExecutionTimeMS === 0.0 || $totalExecutionTimeMS === 0) { | ||
return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning 100 would make more sense IMO
Is there any remaining issues which is blocking a merge? |
* Fixed Division by zero when total execution time is 0ms When you go to Symfony profiler -> Query Metrics and when Query time = 0ms there is an exception: "An exception has been thrown during the rendering of a template ("Warning: Division by zero")." [1/2] ContextErrorException: Warning: Division by zero in vendor\doctrine\doctrine-bundle\DataCollector\DoctrineDataCollector.php at line 232 [2/2] Twig_Error_Runtime: An exception has been thrown during the rendering of a template ("Warning: Division by zero") in vendor\doctrine\doctrine-bundle\Resources\views\Collector\db.html.twig at line 157 * Fix division by zero in the data collector
* 1.6.x: Fix deprecation with Symfony 3.4 fixed tests fixed compat with PHP 5.5 removed unused use statement changed services to be public for compat with Symfony 4 Fix check for DoctrineType::reset() existence Fixed for SF > 3.0 on shutdown container create and close connections Add "kernel.reset" tag to "form.type.entity" Bugfixes to CreateDatabaseCommand and its tests, fixes #686 fixes doctrine/orm#6689 Removing extra space Fix a possible division by zero (#634) Add autowiring for Doctrine\DBAL\Connection (#685) Use ChildDefinition class when available
No description provided.