MediaWiki master
Wikimedia\Stats\Metrics\TimingMetric Class Reference

Timing Metric Implementation. More...

Inherits Wikimedia\Stats\Metrics\MetricInterface.

Collaboration diagram for Wikimedia\Stats\Metrics\TimingMetric:

Public Member Functions

 getTypeIndicator ()
 
Returns
string

 
 observe (float $milliseconds)
 Record a previously calculated observation in milliseconds.
 
 observeNanoseconds (float $nanoseconds)
 Record a previously calculated observation in nanoseconds.
 
 observeSeconds (float $seconds)
 Record a previously calculated observation in seconds.
 
 start ()
 Start the timer.
 
 stop ()
 Stop the running timer.
 
- Public Member Functions inherited from Wikimedia\Stats\Metrics\MetricInterface
 __construct (BaseMetricInterface $baseMetric, LoggerInterface $logger)
 
 copyToStatsdAt ( $statsdNamespaces)
 Copies metric operation to StatsD at provided namespace.
 
 fresh ()
 Returns metric with cleared labels.
 
 getComponent ()
 
 getLabelKeys ()
 Returns the list of defined label keys.
 
 getName ()
 
 getSampleCount ()
 Returns a count of samples recorded by the metric.
 
 getSampleRate ()
 
 getSamples ()
 Returns subset of samples corresponding to sample rate setting.
 
 isHistogram ()
 Indicates the metric instance is used in a Histogram.
 
 setLabel (string $key, string $value)
 Adds a label $key with $value.
 
 setLabels (array $labels)
 Convenience function to set a number of labels at once.
 
 setSampleRate (float $sampleRate)
 Sets sample rate on a new metric instance.
 

Detailed Description

Timing Metric Implementation.

Timing metrics track duration data which can be broken into histograms. They are identified by type "ms".

Author
Cole White
Since
1.38

Definition at line 36 of file TimingMetric.php.

Member Function Documentation

◆ getTypeIndicator()

Wikimedia\Stats\Metrics\TimingMetric::getTypeIndicator ( )

Returns
string

Implements Wikimedia\Stats\Metrics\MetricInterface.

Definition at line 155 of file TimingMetric.php.

◆ observe()

Wikimedia\Stats\Metrics\TimingMetric::observe ( float $milliseconds)

Record a previously calculated observation in milliseconds.

NOTE: You MUST pass values converted to milliseconds.

This method is discouraged in new code, because PHP does not measure time in milliseconds. It will be less error-prone if you use start() and stop(), or pass values from hrtime() directly to observeNanoseconds() without manual multiplication to another unit.

Parameters
float$milliseconds
Returns
void

Definition at line 137 of file TimingMetric.php.

◆ observeNanoseconds()

Wikimedia\Stats\Metrics\TimingMetric::observeNanoseconds ( float $nanoseconds)

Record a previously calculated observation in nanoseconds.

Example:

$startTime = hrtime( true )
# work to be measured...
$metric->observeNanoseconds( hrtime( true ) - $startTime )
Parameters
float$nanoseconds
Returns
void
Since
1.43

Definition at line 95 of file TimingMetric.php.

◆ observeSeconds()

Wikimedia\Stats\Metrics\TimingMetric::observeSeconds ( float $seconds)

Record a previously calculated observation in seconds.

This method is provided for tracking externally-generated values, timestamp deltas, and situations where the expected input value is the expected Prometheus graphed value.

Performance measurements in process should be done with hrtime() and observeNanoseconds() to ensure monotonic time is used and not wall-clock time.

Example:

$startTime = microtime( true )
# work to be measured...
$metric->observeSeconds( microtime( true ) - $startTime )
Parameters
float$seconds
Returns
void
Since
1.43

Definition at line 120 of file TimingMetric.php.

◆ start()

Wikimedia\Stats\Metrics\TimingMetric::start ( )

Start the timer.

Example:

$timer = StatsFactory->getTiming( 'example_seconds' )
->setLabel( 'foo', 'bar' )
->start();
# work to be measured...
$timer->stop();
This is the primary interface for validating metrics definitions, caching defined metrics,...
getTiming(string $name)
Makes a new TimingMetric or fetches one from cache.
Returns
$this

Definition at line 63 of file TimingMetric.php.

◆ stop()

Wikimedia\Stats\Metrics\TimingMetric::stop ( )

Stop the running timer.

Definition at line 71 of file TimingMetric.php.


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