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

Fix a possible division by zero #634

Merged
merged 2 commits into from Aug 25, 2017
Merged

Conversation

mikeSimonson
Copy link
Contributor

No description provided.

Andrew and others added 2 commits January 27, 2017 18:53
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
@mikeSimonson mikeSimonson self-assigned this Mar 7, 2017
@mikeSimonson mikeSimonson added this to the 1.7.1 milestone Mar 7, 2017
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 );
Copy link
Member

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

Copy link
Member

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) {
Copy link
Contributor

@e-moe e-moe Mar 27, 2017

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

Copy link
Contributor

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;
Copy link
Member

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

@kimhemsoe
Copy link
Member

Is there any remaining issues which is blocking a merge?

@Ocramius Ocramius modified the milestones: 1.8.0, 1.7.0 Aug 11, 2017
@mikeSimonson mikeSimonson merged commit b3281c1 into doctrine:master Aug 25, 2017
@mikeSimonson mikeSimonson deleted the pr/610 branch August 25, 2017 11:44
@kimhemsoe kimhemsoe modified the milestones: 1.7.1, 1.8.0 Aug 25, 2017
fabpot pushed a commit to fabpot/DoctrineBundle that referenced this pull request Sep 29, 2017
* 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
fabpot added a commit that referenced this pull request Oct 4, 2017
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants