MediaWiki  1.27.1
SectionProfiler Class Reference

Custom PHP profiler for parser/DB type section names that xhprof/xdebug can't handle. More...

Public Member Functions

 __construct (array $params=[])
 
 getCallTreeReport ()
 Returns a tree of function calls with their real times. More...
 
 getFunctionStats ()
 Get the aggregated inclusive profiling data for each method. More...
 
 profileInInternal ($functionname)
 This method should not be called outside SectionProfiler. More...
 
 profileOutInternal ($functionname)
 This method should not be called outside SectionProfiler. More...
 
 reset ()
 Clear all of the profiling data for another run. More...
 
 scopedProfileIn ($section)
 
 scopedProfileOut (ScopedCallback &$section)
 

Protected Member Functions

 calculateOverhead ($profileCount)
 Dummy calls to calculate profiling overhead. More...
 
 calltreeCount ($stack, $start)
 Counts the number of profiled function calls sitting under the given point in the call graph. More...
 
 collateData ()
 Populate collated data. More...
 
 debug ($s)
 Add an entry in the debug log file. More...
 
 debugGroup ($group, $s)
 Add an entry in the debug log group. More...
 
 getCallTreeLine ($entry)
 Callback to get a formatted line for the call tree. More...
 
 getErrorEntry ()
 
 getTime ($metric= 'wall')
 Get the initial time of the request, based on getrusage() More...
 
 getZeroEntry ()
 
 remapCallTree (array $stack)
 Recursive function the format the current profiling array into a tree. More...
 
 updateEntry ($name, $elapsedCpu, $elapsedReal, $memChange)
 Update the collation entry for a given method name. More...
 

Protected Attributes

array $collated = []
 Map of (function name => aggregate data array) More...
 
bool $collateDone = false
 
bool $collateOnly = true
 Whether to collect the full stack trace or just aggregates. More...
 
array $end
 Map of (mem,real,cpu) More...
 
array $errorEntry
 Cache of a standard broken collation entry. More...
 
callable $profileOutCallback
 Cache of a profile out callback. More...
 
array $stack = []
 List of resolved profile calls with start/end data. More...
 
array $start
 Map of (mem,real,cpu) More...
 
array $workStack = []
 Queue of open profile calls with start data. More...
 

Detailed Description

Custom PHP profiler for parser/DB type section names that xhprof/xdebug can't handle.

Since
1.25

Definition at line 30 of file SectionProfiler.php.

Constructor & Destructor Documentation

SectionProfiler::__construct ( array  $params = [])
Parameters
array$params

Definition at line 55 of file SectionProfiler.php.

References $params, $section, and getErrorEntry().

Member Function Documentation

SectionProfiler::calculateOverhead (   $profileCount)
protected

Dummy calls to calculate profiling overhead.

Parameters
int$profileCount

Definition at line 427 of file SectionProfiler.php.

References profileInInternal(), and profileOutInternal().

Referenced by collateData().

SectionProfiler::calltreeCount (   $stack,
  $start 
)
protected

Counts the number of profiled function calls sitting under the given point in the call graph.

Not the most efficient algo.

Parameters
array$stack
int$start
Returns
int

Definition at line 444 of file SectionProfiler.php.

References $count, and $start.

Referenced by collateData().

SectionProfiler::collateData ( )
protected

Populate collated data.

Definition at line 351 of file SectionProfiler.php.

References $end, $fname, as, calculateOverhead(), calltreeCount(), profileOutInternal(), and updateEntry().

Referenced by getFunctionStats().

SectionProfiler::debug (   $s)
protected

Add an entry in the debug log file.

Parameters
string$sString to output

Definition at line 486 of file SectionProfiler.php.

References $s, and wfDebug().

SectionProfiler::debugGroup (   $group,
  $s 
)
protected

Add an entry in the debug log group.

Parameters
string$groupGroup to send the message to
string$sString to output

Definition at line 498 of file SectionProfiler.php.

References $s, and wfDebugLog().

Referenced by profileOutInternal().

SectionProfiler::getCallTreeLine (   $entry)
protected

Callback to get a formatted line for the call tree.

Parameters
array$entry
Returns
string

Definition at line 337 of file SectionProfiler.php.

References $fname, and list.

SectionProfiler::getCallTreeReport ( )

Returns a tree of function calls with their real times.

Returns
string
Exceptions
Exception

Definition at line 282 of file SectionProfiler.php.

References remapCallTree().

SectionProfiler::getErrorEntry ( )
protected
Returns
array Initial collation entry for errors

Definition at line 169 of file SectionProfiler.php.

References getZeroEntry().

Referenced by __construct().

SectionProfiler::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.

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 : real time elapsed (ms)
  • cpu : percent real 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)

Definition at line 101 of file SectionProfiler.php.

References $fname, as, and collateData().

SectionProfiler::getTime (   $metric = 'wall')
protected

Get the initial time of the request, based on getrusage()

Parameters
string | bool$metricMetric to use, with the following possibilities:
  • user: User CPU time (without system calls)
  • cpu: Total CPU time (user and system calls)
  • wall (or any other string): elapsed time
  • false (default): will fall back to default metric
Returns
float

Definition at line 463 of file SectionProfiler.php.

References $time, and wfGetRusage().

Referenced by profileInInternal(), and profileOutInternal().

SectionProfiler::getZeroEntry ( )
protected
Returns
array Initial collation entry

Definition at line 155 of file SectionProfiler.php.

Referenced by getErrorEntry(), and updateEntry().

SectionProfiler::profileInInternal (   $functionname)

This method should not be called outside SectionProfiler.

Parameters
string$functionname

Definition at line 202 of file SectionProfiler.php.

References getTime().

Referenced by calculateOverhead(), and scopedProfileIn().

SectionProfiler::profileOutInternal (   $functionname)

This method should not be called outside SectionProfiler.

Parameters
string$functionname

Definition at line 230 of file SectionProfiler.php.

References $errorEntry, debugGroup(), getTime(), list, and updateEntry().

Referenced by calculateOverhead(), and collateData().

SectionProfiler::remapCallTree ( array  $stack)
protected

Recursive function the format the current profiling array into a tree.

Parameters
array$stackProfiling array
Returns
array

Definition at line 297 of file SectionProfiler.php.

References $output, $stack, and as.

Referenced by getCallTreeReport().

SectionProfiler::reset ( )

Clear all of the profiling data for another run.

Definition at line 143 of file SectionProfiler.php.

SectionProfiler::scopedProfileIn (   $section)
Parameters
string$section
Returns
ScopedCallback

Definition at line 67 of file SectionProfiler.php.

References $section, and profileInInternal().

SectionProfiler::scopedProfileOut ( ScopedCallback $section)
Parameters
ScopedCallback$section

Definition at line 76 of file SectionProfiler.php.

SectionProfiler::updateEntry (   $name,
  $elapsedCpu,
  $elapsedReal,
  $memChange 
)
protected

Update the collation entry for a given method name.

Parameters
string$name
float$elapsedCpu
float$elapsedReal
int$memChange

Definition at line 183 of file SectionProfiler.php.

References $name, and getZeroEntry().

Referenced by collateData(), and profileOutInternal().

Member Data Documentation

array SectionProfiler::$collated = []
protected

Map of (function name => aggregate data array)

Definition at line 41 of file SectionProfiler.php.

bool SectionProfiler::$collateDone = false
protected

Definition at line 43 of file SectionProfiler.php.

bool SectionProfiler::$collateOnly = true
protected

Whether to collect the full stack trace or just aggregates.

Definition at line 46 of file SectionProfiler.php.

array SectionProfiler::$end
protected

Map of (mem,real,cpu)

Definition at line 34 of file SectionProfiler.php.

Referenced by collateData().

array SectionProfiler::$errorEntry
protected

Cache of a standard broken collation entry.

Definition at line 48 of file SectionProfiler.php.

Referenced by profileOutInternal().

callable SectionProfiler::$profileOutCallback
protected

Cache of a profile out callback.

Definition at line 50 of file SectionProfiler.php.

array SectionProfiler::$stack = []
protected

List of resolved profile calls with start/end data.

Definition at line 36 of file SectionProfiler.php.

Referenced by remapCallTree().

array SectionProfiler::$start
protected

Map of (mem,real,cpu)

Definition at line 32 of file SectionProfiler.php.

Referenced by calltreeCount().

array SectionProfiler::$workStack = []
protected

Queue of open profile calls with start data.

Definition at line 38 of file SectionProfiler.php.


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