MediaWiki  master
ProfilerXhprof Class Reference

Profiler wrapper for XHProf extension. More...

Inheritance diagram for ProfilerXhprof:
Collaboration diagram for ProfilerXhprof:

Public Member Functions

 __construct (array $params=[])
 
 close ()
 No-op for xhprof profiling. More...
 
 getFunctionStats ()
 Get the aggregated inclusive profiling data for each method. More...
 
 getOutput ()
 Returns a profiling output to be stored in debug file. More...
 
 getRawData ()
 Retrieve raw data from xhprof. More...
 
 getXhprofData ()
 
 scopedProfileIn ( $section)
 Mark the start of a custom profiling frame (e.g. More...
 
- Public Member Functions inherited from Profiler
 getAllowOutput ()
 Whether appending profiles is allowed. More...
 
 getContentType ()
 Get the Content-Type for deciding how to format appended profile output. More...
 
 getContext ()
 Gets the context for this Profiler. More...
 
 getProfileID ()
 
 getTemplated ()
 Was this call as templated or not. More...
 
 getTransactionProfiler ()
 
 logData ()
 Log the data to the backing store for all ProfilerOutput instances that have one. More...
 
 logDataPageOutputOnly ()
 Log the data to the script/request output for all ProfilerOutput instances that do so. More...
 
 profileIn ( $functionname)
 
 profileOut ( $functionname)
 
 scopedProfileOut (SectionProfileCallback &$section=null)
 
 setAllowOutput ()
 Enable appending profiles to standard output. More...
 
 setContext ( $context)
 Sets the context for this Profiler. More...
 
 setProfileID ( $id)
 
 setTemplated ( $t)
 Mark this call as templated or not. More...
 

Protected Member Functions

 getFunctionReport ()
 Get a report of profiled functions sorted by inclusive wall clock time in descending order. More...
 

Protected Attributes

SectionProfiler $sprofiler
 Profiler for explicit, arbitrary, frame labels. More...
 
XhprofData null $xhprofData
 
- Protected Attributes inherited from Profiler
IContextSource $context = null
 Current request context. More...
 
array $params = []
 All of the params passed from $wgProfiler. More...
 
string bool $profileID = false
 Profiler ID for bucketing data. More...
 
TransactionProfiler $trxProfiler
 

Private Member Functions

 shouldExclude ( $name)
 Check if a function or section should be excluded from the output. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from Profiler
static instance ()
 Singleton. More...
 
static replaceStubInstance (Profiler $profiler)
 Replace the current profiler with $profiler if no non-stub profiler is set. More...
 

Detailed Description

Profiler wrapper for XHProf extension.

$wgProfiler['class'] = ProfilerXhprof::class;
$wgProfiler['flags'] = XHPROF_FLAGS_NO_BUILTINS;
$wgProfiler['output'] = 'text';
$wgProfiler['visible'] = true;
$wgProfiler['class'] = ProfilerXhprof::class;
$wgProfiler['flags'] = XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY | XHPROF_FLAGS_NO_BUILTINS;
$wgProfiler['output'] = 'udp';

ProfilerXhprof profiles all functions using the XHProf PHP extenstion. This extension can be installed via PECL or your operating system's package manager.

To restrict the functions for which profiling data is collected, you can use either a whitelist ($wgProfiler['include']) or a blacklist ($wgProfiler['exclude']) containing an array of function names. Shell-style patterns are also accepted.

This also supports Tideways-XHProf PHP extension, which is mostly a drop-in replacement for Xhprof (replace XHPROF_FLAGS_* with TIDEWAYS_XHPROF_FLAGS_*), as well as the older (discontinued) Tideways extension (TIDEWAYS_FLAGS_*).

Note
© 2014 Wikimedia Foundation and contributors
See also
Xhprof
https://php.net/xhprof
https://github.com/tideways/php-xhprof-extension

Definition at line 55 of file ProfilerXhprof.php.

Constructor & Destructor Documentation

◆ __construct()

ProfilerXhprof::__construct ( array  $params = [])
Parameters
array$params
See also
Xhprof::__construct()

Reimplemented from Profiler.

Definition at line 71 of file ProfilerXhprof.php.

References Profiler\$params, and Xhprof\enable().

Member Function Documentation

◆ close()

ProfilerXhprof::close ( )

No-op for xhprof profiling.

Reimplemented from Profiler.

Definition at line 99 of file ProfilerXhprof.php.

◆ getFunctionReport()

ProfilerXhprof::getFunctionReport ( )
protected

Get a report of profiled functions sorted by inclusive wall clock time in descending order.

Each line of the report includes this data:

  • Function name
  • Number of times function was called
  • Total wall clock time spent in function in microseconds
  • Minimum wall clock time spent in function in microseconds
  • Average wall clock time spent in function in microseconds
  • Maximum wall clock time spent in function in microseconds
  • Percentage of total wall clock time spent in function
  • Total delta of memory usage from start to end of function in bytes
Returns
string

Definition at line 199 of file ProfilerXhprof.php.

References getFunctionStats().

Referenced by getOutput().

◆ getFunctionStats()

ProfilerXhprof::getFunctionStats ( )

Get the aggregated inclusive profiling data for each method.

The percent time for each time is based on the current "total" time used is based on all methods so far. This method can therefore be called several times in between several profiling calls without the delays in usage of the profiler skewing the results. A "-total" entry is always included in the results.

When a call chain involves a method invoked within itself, any entries for the cyclic invocation should be be demarked with "@". This makes filtering them out easier and follows the xhprof style.

Returns
array[] List of method entries arrays, each having:
  • name : method name
  • calls : the number of invoking calls
  • real : real time elapsed (ms)
  • real : percent real time
  • cpu : CPU time elapsed (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

Reimplemented from Profiler.

Definition at line 130 of file ProfilerXhprof.php.

References getXhprofData(), and shouldExclude().

Referenced by getFunctionReport().

◆ getOutput()

ProfilerXhprof::getOutput ( )

Returns a profiling output to be stored in debug file.

Returns
string

Reimplemented from Profiler.

Definition at line 179 of file ProfilerXhprof.php.

References getFunctionReport().

◆ getRawData()

ProfilerXhprof::getRawData ( )

Retrieve raw data from xhprof.

Returns
array

Definition at line 231 of file ProfilerXhprof.php.

References getXhprofData().

◆ getXhprofData()

ProfilerXhprof::getXhprofData ( )
Returns
XhprofData

Definition at line 84 of file ProfilerXhprof.php.

References $xhprofData, and Xhprof\disable().

Referenced by getFunctionStats(), and getRawData().

◆ scopedProfileIn()

ProfilerXhprof::scopedProfileIn (   $section)

Mark the start of a custom profiling frame (e.g.

DB queries). The frame ends when the result of this method falls out of scope.

Parameters
string$section
Returns
ScopedCallback|null
Since
1.25

Reimplemented from Profiler.

Definition at line 91 of file ProfilerXhprof.php.

◆ shouldExclude()

ProfilerXhprof::shouldExclude (   $name)
private

Check if a function or section should be excluded from the output.

Parameters
string$nameFunction or section name.
Returns
bool

Definition at line 108 of file ProfilerXhprof.php.

Referenced by getFunctionStats().

Member Data Documentation

◆ $sprofiler

SectionProfiler ProfilerXhprof::$sprofiler
protected

Profiler for explicit, arbitrary, frame labels.

Definition at line 65 of file ProfilerXhprof.php.

◆ $xhprofData

XhprofData null ProfilerXhprof::$xhprofData
protected

Definition at line 59 of file ProfilerXhprof.php.

Referenced by getXhprofData().


The documentation for this class was generated from the following file:
$wgProfiler
$wgProfiler
Profiler configuration.
Definition: DefaultSettings.php:6843