73 if ( empty(
$params[
'running'] ) ) {
75 $options = isset(
$params[
'exclude'] )
76 ? [
'ignored_functions' =>
$params[
'exclude'] ]
89 if ( !$this->xhprofData ) {
96 $key =
'section.' . ltrim( $section,
'.' );
97 return $this->sprofiler->scopedProfileIn( $key );
112 private function shouldExclude( $name ) {
113 if ( $name ===
'-total' ) {
116 if ( !empty( $this->params[
'include'] ) ) {
117 foreach ( $this->params[
'include'] as $pattern ) {
118 if ( fnmatch( $pattern, $name, FNM_NOESCAPE ) ) {
124 if ( !empty( $this->params[
'exclude'] ) ) {
125 foreach ( $this->params[
'exclude'] as $pattern ) {
126 if ( fnmatch( $pattern, $name, FNM_NOESCAPE ) ) {
139 foreach ( $metrics as $fname => $stats ) {
140 if ( $this->shouldExclude( $fname ) ) {
146 'calls' => $stats[
'ct'],
147 'real' => $stats[
'wt'][
'total'] / 1000,
148 '%real' => $stats[
'wt'][
'percent'],
149 'cpu' => ( $stats[
'cpu'][
'total'] ?? 0 ) / 1000,
150 '%cpu' => $stats[
'cpu'][
'percent'] ?? 0,
151 'memory' => $stats[
'mu'][
'total'] ?? 0,
152 '%memory' => $stats[
'mu'][
'percent'] ?? 0,
153 'min_real' => $stats[
'wt'][
'min'] / 1000,
154 'max_real' => $stats[
'wt'][
'max'] / 1000
157 if ( $fname ===
'main()' ) {
163 foreach ( $this->sprofiler->getFunctionStats() as $stats ) {
164 if ( $this->shouldExclude( $stats[
'name'] ) ) {
169 $stats[
'%real'] = $main[
'real'] ? $stats[
'real'] / $main[
'real'] * 100 : 0;
170 $stats[
'%cpu'] = $main[
'cpu'] ? $stats[
'cpu'] / $main[
'cpu'] * 100 : 0;
171 $stats[
'%memory'] = $main[
'memory'] ? $stats[
'memory'] / $main[
'memory'] * 100 : 0;
205 usort( $data,
static function ( $a, $b ) {
206 return $b[
'real'] <=> $a[
'real'];
210 $nameWidth = $width - 65;
211 $format =
"%-{$nameWidth}s %6d %9d %9d %9d %9d %7.3f%% %9d";
213 $out[] = sprintf(
"%-{$nameWidth}s %6s %9s %9s %9s %9s %7s %9s",
214 'Name',
'Calls',
'Total',
'Min',
'Each',
'Max',
'%',
'Mem'
216 foreach ( $data as $stats ) {
217 $out[] = sprintf( $format,
220 $stats[
'real'] * 1000,
221 $stats[
'min_real'] * 1000,
222 $stats[
'real'] / $stats[
'calls'] * 1000,
223 $stats[
'max_real'] * 1000,
228 return implode(
"\n", $out );
Profiler that captures all function calls from the XHProf PHP extension.
XhprofData null $xhprofData
getFunctionStats()
Get the aggregated inclusive profiling data for each method.
getRawData()
Retrieve raw data from xhprof.
scopedProfileIn( $section)
Mark the start of a custom profiling frame (e.g.
close()
No-op for xhprof profiling.
__construct(array $params=[])
getFunctionReport()
Get a report of profiled functions sorted by inclusive wall clock time in descending order.
getOutput()
Returns a profiling output to be stored in debug file.
SectionProfiler $sprofiler
Profiler for explicit, arbitrary, frame labels.
Profiler base class that defines the interface and some shared functionality.
array $params
All of the params passed from $wgProfiler.
Arbitrary section name based PHP profiling.
Convenience class for working with XHProf profiling data https://github.com/phacility/xhprof.
static enable( $flags=0, $options=[])
Start profiler.
static disable()
Stop profiler.