Merge "[search] Fix method call on null value"
[lhc/web/wiklou.git] / includes / libs / Xhprof.php
index 1ad01cc..d2cd0e4 100644 (file)
@@ -1,6 +1,5 @@
 <?php
 /**
- * @section LICENSE
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
@@ -19,6 +18,8 @@
  * @file
  */
 
+use RunningStat\RunningStat;
+
 /**
  * Convenience class for working with XHProf
  * <https://github.com/phacility/xhprof>. XHProf can be installed as a PECL
@@ -255,7 +256,7 @@ class Xhprof {
                                        }
 
                                        for ( $i = 0; $i < $stats['ct']; $i++ ) {
-                                               $this->inclusive[$child][$stat]->push(
+                                               $this->inclusive[$child][$stat]->addObservation(
                                                        $value / $stats['ct']
                                                );
                                        }
@@ -268,13 +269,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,
                                                );
                                        }
                                }
@@ -319,7 +323,7 @@ class Xhprof {
                                $this->complete[$func]['subcalls'] = array();
                        }
 
-                       foreach( $this->hieraData as $key => $stats ) {
+                       foreach ( $this->hieraData as $key => $stats ) {
                                list( $parent, $child ) = self::splitKey( $key );
                                if ( $parent !== null ) {
                                        // Track call tree information