* 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();
'%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
);
}
'%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
);
}
* @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;
$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 );