MediaWiki REL1_37
SectionProfiler Class Reference

Arbitrary section name based PHP profiling. More...

Collaboration diagram for SectionProfiler:

Public Member Functions

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

Protected Member Functions

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

Protected Attributes

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

Detailed Description

Arbitrary section name based PHP profiling.

This custom profiler can track code execution that doesn't cleanly map to a function call and thus can't be handled by ProfilerXhprof or ProfilerExcimer. For example, parser invocations or DB queries.

Since
1.25

Definition at line 35 of file SectionProfiler.php.

Constructor & Destructor Documentation

◆ __construct()

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

Definition at line 60 of file SectionProfiler.php.

References getErrorEntry().

Member Function Documentation

◆ calculateOverhead()

SectionProfiler::calculateOverhead (   $profileCount)
protected

Dummy calls to calculate profiling overhead.

Parameters
int$profileCount

Definition at line 436 of file SectionProfiler.php.

References profileInInternal(), and profileOutInternal().

Referenced by collateData().

◆ calltreeCount()

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 453 of file SectionProfiler.php.

References $stack, and $start.

Referenced by collateData().

◆ collateData()

SectionProfiler::collateData ( )
protected

Populate collated data.

Definition at line 360 of file SectionProfiler.php.

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

Referenced by getFunctionStats().

◆ getCallTreeLine()

SectionProfiler::getCallTreeLine (   $entry)
protected

Callback to get a formatted line for the call tree.

Parameters
array$entry
Returns
string

Definition at line 346 of file SectionProfiler.php.

◆ getCallTreeReport()

SectionProfiler::getCallTreeReport ( )

Returns a tree of function calls with their real times.

Returns
string
Exceptions
Exception

Definition at line 291 of file SectionProfiler.php.

References remapCallTree().

◆ getErrorEntry()

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

Definition at line 178 of file SectionProfiler.php.

References getZeroEntry().

Referenced by __construct().

◆ getFunctionStats()

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 104 of file SectionProfiler.php.

References collateData().

◆ getTime()

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 472 of file SectionProfiler.php.

Referenced by profileInInternal(), and profileOutInternal().

◆ getZeroEntry()

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

Definition at line 164 of file SectionProfiler.php.

Referenced by getErrorEntry(), and updateEntry().

◆ profileInInternal()

SectionProfiler::profileInInternal (   $functionname)

This method should not be called outside SectionProfiler.

Parameters
string$functionname

Definition at line 211 of file SectionProfiler.php.

References getTime().

Referenced by calculateOverhead(), and scopedProfileIn().

◆ profileOutInternal()

SectionProfiler::profileOutInternal (   $functionname)

This method should not be called outside SectionProfiler.

Parameters
string$functionname

Definition at line 239 of file SectionProfiler.php.

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

Referenced by calculateOverhead(), and collateData().

◆ remapCallTree()

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 306 of file SectionProfiler.php.

References $stack, and remapCallTree().

Referenced by getCallTreeReport(), and remapCallTree().

◆ reset()

SectionProfiler::reset ( )

Clear all of the profiling data for another run.

Definition at line 152 of file SectionProfiler.php.

◆ scopedProfileIn()

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

Definition at line 70 of file SectionProfiler.php.

References profileInInternal().

◆ scopedProfileOut()

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

Definition at line 79 of file SectionProfiler.php.

◆ updateEntry()

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 192 of file SectionProfiler.php.

References getZeroEntry().

Referenced by collateData(), and profileOutInternal().

Member Data Documentation

◆ $collated

array [] SectionProfiler::$collated = []
protected

Map of (function name => aggregate data array)

Definition at line 46 of file SectionProfiler.php.

◆ $collateDone

bool SectionProfiler::$collateDone = false
protected

Definition at line 48 of file SectionProfiler.php.

◆ $collateOnly

bool SectionProfiler::$collateOnly = true
protected

Whether to collect the full stack trace or just aggregates.

Definition at line 51 of file SectionProfiler.php.

◆ $end

array null SectionProfiler::$end
protected

Map of (mem,real,cpu)

Definition at line 39 of file SectionProfiler.php.

Referenced by collateData().

◆ $errorEntry

array SectionProfiler::$errorEntry
protected

Cache of a standard broken collation entry.

Definition at line 53 of file SectionProfiler.php.

Referenced by profileOutInternal().

◆ $logger

LoggerInterface SectionProfiler::$logger
protected

Definition at line 55 of file SectionProfiler.php.

◆ $stack

array [] SectionProfiler::$stack = []
protected

List of resolved profile calls with start/end data.

Definition at line 41 of file SectionProfiler.php.

Referenced by calltreeCount(), and remapCallTree().

◆ $start

array null SectionProfiler::$start
protected

Map of (mem,real,cpu)

Definition at line 37 of file SectionProfiler.php.

Referenced by calltreeCount().

◆ $workStack

array SectionProfiler::$workStack = []
protected

Queue of open profile calls with start data.

Definition at line 43 of file SectionProfiler.php.


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