Refactored xhprof getFunctionReport() to use getFunctionStats()
authorAaron Schulz <aschulz@wikimedia.org>
Mon, 8 Dec 2014 21:36:19 +0000 (13:36 -0800)
committerBryanDavis <bdavis@wikimedia.org>
Mon, 8 Dec 2014 23:39:18 +0000 (23:39 +0000)
* Also added more doc comments to getFunctionStats()

Change-Id: I3741713d3c80b0bbc622eb17ce4c3a047bf5a06c

includes/profiler/Profiler.php
includes/profiler/ProfilerStandard.php
includes/profiler/ProfilerXhprof.php

index 2be142f..667a9e2 100644 (file)
@@ -241,14 +241,16 @@ abstract class Profiler {
         * This makes filtering them out easier and follows the xhprof style.
         *
         * @return array List of method entries arrays, each having:
-        *   - name    : method name
-        *   - calls   : the number of invoking calls
-        *   - real    : real time ellapsed (ms)
-        *   - %real   : percent real time
-        *   - cpu     : CPU time ellapsed (ms)
-        *   - %cpu    : percent CPU time
-        *   - memory  : memory used (bytes)
-        *   - %memory : percent memory used
+        *   - name     : method name
+        *   - calls    : the number of invoking calls
+        *   - real     : real time ellapsed (ms)
+        *   - %real    : percent real time
+        *   - cpu      : CPU time ellapsed (ms)
+        *   - %cpu     : percent CPU time
+        *   - memory   : memory used (bytes)
+        *   - %memory  : percent memory used
+        *   - min_real : min real time in a call (ms)
+        *   - max_real : max real time in a call (ms)
         * @since 1.25
         */
        abstract public function getFunctionStats();
index ffcd7d9..b40519e 100644 (file)
@@ -485,8 +485,8 @@ class ProfilerStandard extends Profiler {
                                '%cpu' => $totalCpu ? 100 * $data['cpu'] / $totalCpu : 0,
                                'memory' => $data['memory'],
                                '%memory' => $totalMem ? 100 * $data['memory'] / $totalMem : 0,
-                               'min' => $data['min_real'] * 1000,
-                               'max' => $data['max_real'] * 1000
+                               'min_real' => $data['min_real'] * 1000,
+                               'max_real' => $data['max_real'] * 1000
                        );
                }
 
index d3d4cf1..2fef011 100644 (file)
@@ -157,8 +157,8 @@ class ProfilerXhprof extends Profiler {
                                '%cpu' => isset( $stats['cpu'] ) ? $stats['cpu']['percent'] : 0,
                                'memory' => isset( $stats['mu'] ) ? $stats['mu']['total'] : 0,
                                '%memory' => isset( $stats['mu'] ) ? $stats['mu']['percent'] : 0,
-                               'min' => $stats['wt']['min'] / 1000,
-                               'max' => $stats['wt']['max'] / 1000
+                               'min_real' => $stats['wt']['min'] / 1000,
+                               'max_real' => $stats['wt']['max'] / 1000
                        );
                }
 
@@ -191,8 +191,13 @@ class ProfilerXhprof extends Profiler {
         * @return string
         */
        protected function getFunctionReport() {
-               $data = $this->xhprof->getInclusiveMetrics();
-               uasort( $data, Xhprof::makeSortFunction( 'wt', 'total' ) );
+               $data = $this->getFunctionStats();
+               usort( $data, function( $a, $b ) {
+                       if ( $a['real'] === $b['real'] ) {
+                               return 0;
+                       }
+                       return ( $a['real'] > $b['real'] ) ? -1 : 1; // descending
+               } );
 
                $width = 140;
                $nameWidth = $width - 65;
@@ -201,16 +206,16 @@ class ProfilerXhprof extends Profiler {
                $out[] = sprintf( "%-{$nameWidth}s %6s %9s %9s %9s %9s %7s %9s",
                        'Name', 'Calls', 'Total', 'Min', 'Each', 'Max', '%', 'Mem'
                );
-               foreach ( $data as $func => $stats ) {
+               foreach ( $data as $stats ) {
                        $out[] = sprintf( $format,
-                               $func,
-                               $stats['ct'],
-                               $stats['wt']['total'],
-                               $stats['wt']['min'],
-                               $stats['wt']['mean'],
-                               $stats['wt']['max'],
-                               $stats['wt']['percent'],
-                               isset( $stats['mu'] ) ? $stats['mu']['total'] : 0
+                               $stats['name'],
+                               $stats['calls'],
+                               $stats['real'] * 1000,
+                               $stats['min_real'] * 1000,
+                               $stats['real'] / $stats['calls'] * 1000,
+                               $stats['max_real'] * 1000,
+                               $stats['%real'],
+                               $stats['memory']
                        );
                }
                return implode( "\n", $out );