MediaWiki  1.30.2
Timing Class Reference

An interface to help developers measure the performance of their applications. More...

Inheritance diagram for Timing:
Collaboration diagram for Timing:

Public Member Functions

 __construct (array $params=[])
 
 clearMarks ( $markName=null)
 
 getEntries ()
 
 getEntriesByType ( $entryType)
 
 getEntryByName ( $name)
 
 mark ( $markName)
 Store a timestamp with the associated name (a "mark") More...
 
 measure ( $measureName, $startMark='requestStart', $endMark=null)
 This method stores the duration between two marks along with the associated name (a "measure"). More...
 
 setLogger (LoggerInterface $logger)
 Sets a logger instance on the object. More...
 

Protected Attributes

LoggerInterface $logger
 

Private Member Functions

 sortEntries ()
 Sort entries in chronological order with respect to startTime. More...
 

Private Attributes

array[] $entries = []
 

Detailed Description

An interface to help developers measure the performance of their applications.

This interface closely matches the W3C's User Timing specification. The key differences are:

  • The reference point for all measurements which do not explicitly specify a start time is $_SERVER['REQUEST_TIME_FLOAT'], not navigationStart.
  • Successive calls to mark() and measure() with the same entry name cause the previous entry to be overwritten. This ensures that there is a 1:1 mapping between names and entries.
  • Because there is a 1:1 mapping, instead of getEntriesByName(), we have getEntryByName().

The in-line documentation incorporates content from the User Timing Specification https://www.w3.org/TR/user-timing/ Copyright © 2013 World Wide Web Consortium, (MIT, ERCIM, Keio, Beihang). https://www.w3.org/Consortium/Legal/2015/doc-license

Since
1.27

Definition at line 45 of file Timing.php.

Constructor & Destructor Documentation

◆ __construct()

Timing::__construct ( array  $params = [])

Definition at line 53 of file Timing.php.

References $params, clearMarks(), and setLogger().

Member Function Documentation

◆ clearMarks()

Timing::clearMarks (   $markName = null)
Parameters
string$markNameThe name of the mark that should be cleared. If not specified, all marks will be cleared.

Definition at line 89 of file Timing.php.

Referenced by __construct().

◆ getEntries()

Timing::getEntries ( )
Returns
array[] All entries in chronological order.

Definition at line 167 of file Timing.php.

References $entries, and sortEntries().

◆ getEntriesByType()

Timing::getEntriesByType (   $entryType)
Parameters
string$entryType
Returns
array[] Entries (in chronological order) that have the same value for the entryType attribute as the $entryType parameter.

Definition at line 177 of file Timing.php.

References $entries, as, and sortEntries().

◆ getEntryByName()

Timing::getEntryByName (   $name)
Parameters
string$name
Returns
array|null Entry named $name or null if it does not exist.

Definition at line 192 of file Timing.php.

References $name.

Referenced by measure().

◆ mark()

Timing::mark (   $markName)

Store a timestamp with the associated name (a "mark")

Parameters
string$markNameThe name associated with the timestamp. If there already exists an entry by that name, it is overwritten.
Returns
array The mark that has been created.

Definition at line 75 of file Timing.php.

Referenced by TimingTest\testClearMarks(), TimingTest\testGetEntriesByType(), TimingTest\testMark(), and TimingTest\testMeasure().

◆ measure()

Timing::measure (   $measureName,
  $startMark = 'requestStart',
  $endMark = null 
)

This method stores the duration between two marks along with the associated name (a "measure").

If neither the startMark nor the endMark argument is specified, measure() will store the duration from $_SERVER['REQUEST_TIME_FLOAT'] to the current time. If the startMark argument is specified, but the endMark argument is not specified, measure() will store the duration from the most recent occurrence of the start mark to the current time. If both the startMark and endMark arguments are specified, measure() will store the duration from the most recent occurrence of the start mark to the most recent occurrence of the end mark.

Parameters
string$measureName
string$startMark
string$endMark
Returns
array|bool The measure that has been created, or false if either the start mark or the end mark do not exist.

Definition at line 126 of file Timing.php.

References getEntryByName().

◆ setLogger()

Timing::setLogger ( LoggerInterface  $logger)

Sets a logger instance on the object.

Parameters
LoggerInterface$logger
Returns
null

Definition at line 64 of file Timing.php.

References $logger.

Referenced by __construct().

◆ sortEntries()

Timing::sortEntries ( )
private

Sort entries in chronological order with respect to startTime.

Definition at line 158 of file Timing.php.

Referenced by getEntries(), and getEntriesByType().

Member Data Documentation

◆ $entries

array [] Timing::$entries = []
private

Definition at line 48 of file Timing.php.

Referenced by getEntries(), and getEntriesByType().

◆ $logger

LoggerInterface Timing::$logger
protected

Definition at line 51 of file Timing.php.

Referenced by setLogger().


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