75 $options = isset(
$params[
'exclude'] )
76 ? [
'ignored_functions' =>
$params[
'exclude'] ] : [];
85 if ( !$this->xhprofData ) {
92 $key =
'section.' . ltrim( $section,
'.' );
93 return $this->sprofiler->scopedProfileIn( $key );
109 if ( $name ===
'-total' ) {
112 if ( !empty( $this->params[
'include'] ) ) {
113 foreach ( $this->params[
'include'] as $pattern ) {
114 if ( fnmatch( $pattern, $name, FNM_NOESCAPE ) ) {
120 if ( !empty( $this->params[
'exclude'] ) ) {
121 foreach ( $this->params[
'exclude'] as $pattern ) {
122 if ( fnmatch( $pattern, $name, FNM_NOESCAPE ) ) {
135 foreach ( $metrics as $fname => $stats ) {
142 'calls' => $stats[
'ct'],
143 'real' => $stats[
'wt'][
'total'] / 1000,
144 '%real' => $stats[
'wt'][
'percent'],
145 'cpu' => isset( $stats[
'cpu'] ) ? $stats[
'cpu'][
'total'] / 1000 : 0,
146 '%cpu' => isset( $stats[
'cpu'] ) ? $stats[
'cpu'][
'percent'] : 0,
147 'memory' => isset( $stats[
'mu'] ) ? $stats[
'mu'][
'total'] : 0,
148 '%memory' => isset( $stats[
'mu'] ) ? $stats[
'mu'][
'percent'] : 0,
149 'min_real' => $stats[
'wt'][
'min'] / 1000,
150 'max_real' => $stats[
'wt'][
'max'] / 1000
153 if ( $fname ===
'main()' ) {
159 foreach ( $this->sprofiler->getFunctionStats() as $stats ) {
165 $stats[
'%real'] = $main[
'real'] ? $stats[
'real'] / $main[
'real'] * 100 : 0;
166 $stats[
'%cpu'] = $main[
'cpu'] ? $stats[
'cpu'] / $main[
'cpu'] * 100 : 0;
167 $stats[
'%memory'] = $main[
'memory'] ? $stats[
'memory'] / $main[
'memory'] * 100 : 0;
201 usort( $data,
function ( $a, $b ) {
202 return $b[
'real'] <=> $a[
'real'];
206 $nameWidth = $width - 65;
207 $format =
"%-{$nameWidth}s %6d %9d %9d %9d %9d %7.3f%% %9d";
209 $out[] = sprintf(
"%-{$nameWidth}s %6s %9s %9s %9s %9s %7s %9s",
210 'Name',
'Calls',
'Total',
'Min',
'Each',
'Max',
'%',
'Mem'
212 foreach ( $data as $stats ) {
213 $out[] = sprintf( $format,
216 $stats[
'real'] * 1000,
217 $stats[
'min_real'] * 1000,
218 $stats[
'real'] / $stats[
'calls'] * 1000,
219 $stats[
'max_real'] * 1000,
224 return implode(
"\n", $out );
Profiler wrapper for XHProf 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=[])
shouldExclude( $name)
Check if a function or section should be excluded from the output.
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 xhprof profiler.
static disable()
Stop xhprof profiler.