MediaWiki REL1_35
XhprofData Class Reference

Convenience class for working with XHProf profiling data https://github.com/phacility/xhprof. More...

Public Member Functions

 __construct (array $data, array $config=[])
 Configuration data can contain:
 
 getCallees ( $function)
 Get a list of all callees from a given function.
 
 getCallers ( $function)
 Get a list of all callers of a given function.
 
 getCompleteMetrics ()
 Get the inclusive and exclusive metrics for each function call.
 
 getCriticalPath ( $metric='wt')
 Find the critical path for the given metric.
 
 getInclusiveMetrics ()
 Get the inclusive metrics for each function call.
 
 getRawData ()
 Get raw data collected by xhprof.
 

Static Public Member Functions

static makeSortFunction ( $key, $sub)
 Make a closure to use as a sort function.
 
static splitKey ( $key)
 Convert an xhprof data key into an array of ['parent', 'child'] function names.
 

Protected Member Functions

 pruneData ( $data)
 Remove data for functions that are not included in the 'include' configuration array.
 

Protected Attributes

array[] $complete
 Per-function inclusive and exclusive data.
 
array $config
 
array[] $hieraData
 Hierarchical profiling data returned by xhprof.
 
array[][] $inclusive
 Per-function inclusive data.
 

Detailed Description

Convenience class for working with XHProf profiling data https://github.com/phacility/xhprof.

XHProf can be installed via PECL.

Note
© 2014 Wikimedia Foundation and contributors
Since
1.28

Definition at line 30 of file XhprofData.php.

Constructor & Destructor Documentation

◆ __construct()

XhprofData::__construct ( array  $data,
array  $config = [] 
)

Configuration data can contain:

  • include: Array of function names to include in profiling.
  • sort: Key to sort per-function reports on.
Parameters
array$dataXhprof profiling data, as returned by xhprof_disable()
array$config

Definition at line 63 of file XhprofData.php.

References $config, and pruneData().

Member Function Documentation

◆ getCallees()

XhprofData::getCallees (   $function)

Get a list of all callees from a given function.

Parameters
string$functionFunction name
Returns
array
See also
getEdges()

Definition at line 319 of file XhprofData.php.

References getCompleteMetrics().

Referenced by getCriticalPath().

◆ getCallers()

XhprofData::getCallers (   $function)

Get a list of all callers of a given function.

Parameters
string$functionFunction name
Returns
array
See also
getEdges()

Definition at line 303 of file XhprofData.php.

References getCompleteMetrics().

◆ getCompleteMetrics()

XhprofData::getCompleteMetrics ( )

Get the inclusive and exclusive metrics for each function call.

In addition to the normal data contained in the inclusive metrics, the metrics have an additional 'exclusive' measurement which is the total minus the totals of all child function calls.

Returns
array[]
See also
getRawData()
getInclusiveMetrics()

Definition at line 246 of file XhprofData.php.

References $complete, getInclusiveMetrics(), and splitKey().

Referenced by getCallees(), and getCallers().

◆ getCriticalPath()

XhprofData::getCriticalPath (   $metric = 'wt')

Find the critical path for the given metric.

Parameters
string$metricMetric to find critical path for
Returns
array

Definition at line 334 of file XhprofData.php.

References $path, and getCallees().

◆ getInclusiveMetrics()

XhprofData::getInclusiveMetrics ( )

Get the inclusive metrics for each function call.

Inclusive metrics for given function include the metrics for all functions that were called from that function during the measurement period.

See getRawData() for a description of the metric that are returned for each funcition call. The values for the wt, cpu, mu and pmu metrics are arrays with these values:

  • total: Cumulative value
  • min: Minimum value
  • mean: Mean (average) value
  • max: Maximum value
  • variance: Variance (spread) of the values
Returns
array[][]
See also
getRawData()
getCompleteMetrics()

Definition at line 159 of file XhprofData.php.

References $inclusive, and splitKey().

Referenced by getCompleteMetrics().

◆ getRawData()

XhprofData::getRawData ( )

Get raw data collected by xhprof.

Each key in the returned array is an edge label for the call graph in the form "caller==>callee". There is once special case edge labled simply "main()" which represents the global scope entry point of the application.

XHProf will collect different data depending on the flags that are used:

  • ct: Number of matching events seen.
  • wt: Inclusive elapsed wall time for this event in microseconds.
  • cpu: Inclusive elapsed cpu time for this event in microseconds. (XHPROF_FLAGS_CPU)
  • mu: Delta of memory usage from start to end of callee in bytes. (XHPROF_FLAGS_MEMORY)
  • pmu: Delta of peak memory usage from start to end of callee in bytes. (XHPROF_FLAGS_MEMORY)
  • alloc: Delta of amount memory requested from malloc() by the callee, in bytes. (XHPROF_FLAGS_MALLOC)
  • free: Delta of amount of memory passed to free() by the callee, in bytes. (XHPROF_FLAGS_MALLOC)
Returns
array
See also
getInclusiveMetrics()
getCompleteMetrics()

Definition at line 98 of file XhprofData.php.

References $hieraData.

◆ makeSortFunction()

static XhprofData::makeSortFunction (   $key,
  $sub 
)
static

Make a closure to use as a sort function.

The resulting function will sort by descending numeric values (largest value first).

Parameters
string$keyData key to sort on
string$subSub key to sort array values on
Returns
Closure

Definition at line 369 of file XhprofData.php.

◆ pruneData()

XhprofData::pruneData (   $data)
protected

Remove data for functions that are not included in the 'include' configuration array.

Parameters
array[]$dataRaw xhprof data
Returns
array[]

Definition at line 123 of file XhprofData.php.

References splitKey().

Referenced by __construct().

◆ splitKey()

static XhprofData::splitKey (   $key)
static

Convert an xhprof data key into an array of ['parent', 'child'] function names.

The resulting array is left padded with nulls, so a key with no parent (eg 'main()') will return [null, 'function'].

Parameters
string$key
Returns
array

Definition at line 112 of file XhprofData.php.

Referenced by getCompleteMetrics(), getInclusiveMetrics(), and pruneData().

Member Data Documentation

◆ $complete

array [] XhprofData::$complete
protected

Per-function inclusive and exclusive data.

Definition at line 53 of file XhprofData.php.

Referenced by getCompleteMetrics().

◆ $config

array XhprofData::$config
protected

Definition at line 35 of file XhprofData.php.

Referenced by __construct().

◆ $hieraData

array [] XhprofData::$hieraData
protected

Hierarchical profiling data returned by xhprof.

Definition at line 41 of file XhprofData.php.

Referenced by getRawData().

◆ $inclusive

array [][] XhprofData::$inclusive
protected

Per-function inclusive data.

Definition at line 47 of file XhprofData.php.

Referenced by getInclusiveMetrics().


The documentation for this class was generated from the following file: