From e145b81e5d7669e1c646e002b6c031ed405a8486 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Mon, 8 Dec 2014 13:36:19 -0800 Subject: [PATCH] Refactored xhprof getFunctionReport() to use getFunctionStats() * Also added more doc comments to getFunctionStats() Change-Id: I3741713d3c80b0bbc622eb17ce4c3a047bf5a06c --- includes/profiler/Profiler.php | 18 ++++++++------- includes/profiler/ProfilerStandard.php | 4 ++-- includes/profiler/ProfilerXhprof.php | 31 +++++++++++++++----------- 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/includes/profiler/Profiler.php b/includes/profiler/Profiler.php index 2be142fc6c..667a9e2206 100644 --- a/includes/profiler/Profiler.php +++ b/includes/profiler/Profiler.php @@ -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(); diff --git a/includes/profiler/ProfilerStandard.php b/includes/profiler/ProfilerStandard.php index ffcd7d91a9..b40519e089 100644 --- a/includes/profiler/ProfilerStandard.php +++ b/includes/profiler/ProfilerStandard.php @@ -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 ); } diff --git a/includes/profiler/ProfilerXhprof.php b/includes/profiler/ProfilerXhprof.php index d3d4cf1398..2fef011133 100644 --- a/includes/profiler/ProfilerXhprof.php +++ b/includes/profiler/ProfilerXhprof.php @@ -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 ); -- 2.20.1