X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fprofiler%2FProfilerXhprof.php;h=8fc0b778da82b7ba2ed4b281b1bdbf8944ed56e6;hb=e5facc46bc170c302438f60849041b0d6be75e82;hp=5f7fc0028a0bd4e9bb51b87015c9b7b4f073a995;hpb=01d61265c38178be844fffd9ad9e23688e9d35d0;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/profiler/ProfilerXhprof.php b/includes/profiler/ProfilerXhprof.php index 5f7fc0028a..8fc0b778da 100644 --- a/includes/profiler/ProfilerXhprof.php +++ b/includes/profiler/ProfilerXhprof.php @@ -52,9 +52,9 @@ */ class ProfilerXhprof extends Profiler { /** - * @var Xhprof $xhprof + * @var XhprofData|null $xhprofData */ - protected $xhprof; + protected $xhprofData; /** * Profiler for explicit, arbitrary, frame labels @@ -66,12 +66,26 @@ class ProfilerXhprof extends Profiler { * @param array $params * @see Xhprof::__construct() */ - public function __construct( array $params = array() ) { + public function __construct( array $params = [] ) { parent::__construct( $params ); - $this->xhprof = new Xhprof( $params ); + + $flags = isset( $params['flags'] ) ? $params['flags'] : 0; + $options = isset( $params['exclude'] ) + ? [ 'ignored_functions' => $params['exclude'] ] : []; + Xhprof::enable( $flags, $options ); $this->sprofiler = new SectionProfiler(); } + /** + * @return XhprofData + */ + public function getXhprofData() { + if ( !$this->xhprofData ) { + $this->xhprofData = new XhprofData( Xhprof::disable(), $this->params ); + } + return $this->xhprofData; + } + public function scopedProfileIn( $section ) { $key = 'section.' . ltrim( $section, '.' ); return $this->sprofiler->scopedProfileIn( $key ); @@ -112,8 +126,8 @@ class ProfilerXhprof extends Profiler { } public function getFunctionStats() { - $metrics = $this->xhprof->getCompleteMetrics(); - $profile = array(); + $metrics = $this->getXhprofData()->getCompleteMetrics(); + $profile = []; $main = null; // units in ms foreach ( $metrics as $fname => $stats ) { @@ -121,7 +135,7 @@ class ProfilerXhprof extends Profiler { continue; } // Convert elapsed times from μs to ms to match interface - $entry = array( + $entry = [ 'name' => $fname, 'calls' => $stats['ct'], 'real' => $stats['wt']['total'] / 1000, @@ -132,7 +146,7 @@ class ProfilerXhprof extends Profiler { '%memory' => isset( $stats['mu'] ) ? $stats['mu']['percent'] : 0, 'min_real' => $stats['wt']['min'] / 1000, 'max_real' => $stats['wt']['max'] / 1000 - ); + ]; $profile[] = $entry; if ( $fname === 'main()' ) { $main = $entry; @@ -192,7 +206,7 @@ class ProfilerXhprof extends Profiler { $width = 140; $nameWidth = $width - 65; $format = "%-{$nameWidth}s %6d %9d %9d %9d %9d %7.3f%% %9d"; - $out = array(); + $out = []; $out[] = sprintf( "%-{$nameWidth}s %6s %9s %9s %9s %9s %7s %9s", 'Name', 'Calls', 'Total', 'Min', 'Each', 'Max', '%', 'Mem' ); @@ -216,6 +230,6 @@ class ProfilerXhprof extends Profiler { * @return array */ public function getRawData() { - return $this->xhprof->getRawData(); + return $this->getXhprofData()->getRawData(); } }