From e222ba36285d5162447524291f2acafabfaacfcb Mon Sep 17 00:00:00 2001 From: Bryan Davis Date: Wed, 3 Dec 2014 18:48:44 -0700 Subject: [PATCH] xhprof: Guard against division by 0 when computing percentages Change-Id: Icce3b5be1136c541dc87c44b01a42709f19ca885 --- includes/libs/Xhprof.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/includes/libs/Xhprof.php b/includes/libs/Xhprof.php index 990e2c3053..98ff675c89 100644 --- a/includes/libs/Xhprof.php +++ b/includes/libs/Xhprof.php @@ -267,13 +267,16 @@ class Xhprof { foreach ( $stats as $name => $value ) { if ( $value instanceof RunningStat ) { $total = $value->m1 * $value->n; + $percent = ( isset( $main[$name] ) && $main[$name] ) + ? 100 * $total / $main[$name] + : 0; $this->inclusive[$func][$name] = array( 'total' => $total, 'min' => $value->min, 'mean' => $value->m1, 'max' => $value->max, 'variance' => $value->m2, - 'percent' => 100 * $total / $main[$name], + 'percent' => $percent, ); } } -- 2.20.1