Page MenuHomeWickedGov Phorge

RunningTimer.php
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

RunningTimer.php

<?php
/**
* @license GPL-2.0-or-later
* @file
*/
namespace Wikimedia\Stats\Metrics;
use Wikimedia\Timestamp\ConvertibleTimestamp;
/**
* RunningTimer Implementation
*
* A class to help TimingMetrics handle instances of recursion.
*
* @author Cole White
* @since 1.45
*/
class RunningTimer {
/** @var TimingMetric|NullMetric */
private $metric;
private ?float $startTime;
public function __construct( float $startTime, TimingMetric $metric ) {
$this->startTime = $startTime;
$this->metric = $metric;
}
/**
* Handle for MetricInterface::setLabel
*
* @see MetricInterface::setLabel
* @return self
*/
public function setLabel( string $key, string $value ) {
$this->metric = $this->metric->setLabel( $key, $value );
return $this;
}
/**
* Handle for MetricInterface::setLabels
*
* @see MetricInterface::setLabels
* @return self
*/
public function setLabels( array $labels ) {
$this->metric = $this->metric->setLabels( $labels );
return $this;
}
/**
* Stop the running timer.
*/
public function stop() {
if ( $this->startTime === null ) {
trigger_error(
"Stats: ({$this->metric->getName()}) cannot call stop() more than once on a RunningTimer.",
E_USER_WARNING
);
return;
}
$this->metric->observeNanoseconds( ConvertibleTimestamp::hrtime() - $this->startTime );
$this->startTime = null;
}
}

File Metadata

Mime Type
text/x-php
Expires
Sat, Oct 3, 23:16 (2 w, 24 m ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
ef/d3/996615d52473acd86047de218c51
Default Alt Text
RunningTimer.php (1 KB)

Event Timeline