class RuntimeMeasurement in Purge 8.3
Provides a execution time measurer for invalidation processing.
Hierarchy
- class \Drupal\purge\Counter\Counter implements CounterInterface
- class \Drupal\purge\Plugin\Purge\Purger\RuntimeMeasurement implements RuntimeMeasurementInterface
Expanded class hierarchy of RuntimeMeasurement
File
- src/
Plugin/ Purge/ Purger/ RuntimeMeasurement.php, line 11
Namespace
Drupal\purge\Plugin\Purge\PurgerView source
class RuntimeMeasurement extends Counter implements RuntimeMeasurementInterface {
/**
* The initial time measurement.
*
* @var null|float
*/
protected $start = NULL;
/**
* {@inheritdoc}
*/
public function getSafeTimeHintValue($value) {
if ($value < 0.1) {
return 0.1;
}
elseif ($value > 10.0) {
return 10.0;
}
return $value;
}
/**
* {@inheritdoc}
*/
public function start() {
if (!is_null($this->start)) {
throw new \LogicException("Already started, call ->stop() first!");
}
$this->start = microtime(TRUE);
}
/**
* {@inheritdoc}
*/
public function stop(array $invalidations) {
if (empty($invalidations)) {
throw new \LogicException('The $invalidations parameter is empty.');
}
if (is_null($this->start)) {
throw new \LogicException("Not yet started, call ->start first!");
}
// Check if any of the invalidations failed, if so, stop.
foreach ($invalidations as $invalidation) {
if (!$invalidation instanceof InvalidationInterface) {
throw new \LogicException('One of the $invalidations is not a InvalidationInterface derivative!');
}
if ($invalidation
->getState() !== InvalidationInterface::SUCCEEDED) {
$this->start = NULL;
return;
}
}
// Calculate the spent execution time per invalidation by dividing it
// through the number of invalidations processed. We're also adding 15% of
// time for theoretic overhead and ensure that the final value remains
// within the boundaries of ::getTimeHint().
if (($spent = microtime(TRUE) - $this->start) === 0.0) {
$this->start = NULL;
return;
}
$spent = $this
->getSafeTimeHintValue($spent / count($invalidations) * 1.15);
// Immediately write fresh or slower measurements.
if ($this->value === 0.0 || $spent > $this->value) {
$this
->set($spent);
}
elseif ($spent < $this->value) {
$slow_adjustment = $this
->getSafeTimeHintValue($this->value * 0.9);
if ($slow_adjustment >= $spent) {
$this
->set($slow_adjustment);
}
}
// Reset the start value so that new measurements can happen.
$this->start = NULL;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Counter:: |
protected | property | The callback that is called on writes when not NULL. | |
Counter:: |
protected | property | Whether it is possible to call ::decrement() or not. | |
Counter:: |
protected | property | Whether it is possible to call ::increment() or not. | |
Counter:: |
protected | property | Whether it is possible to call ::set() or not. | |
Counter:: |
protected | property | The value of the counter. | |
Counter:: |
public | function |
Decrease the counter. Overrides CounterInterface:: |
|
Counter:: |
public | function |
Disable the possibility to decrement the counter. Overrides CounterInterface:: |
|
Counter:: |
public | function |
Disable the possibility to increment the counter. Overrides CounterInterface:: |
|
Counter:: |
public | function |
Disable the possibility of setting counter. Overrides CounterInterface:: |
|
Counter:: |
public | function |
Get the current value. Overrides CounterInterface:: |
|
Counter:: |
public | function |
Get the current value as integer. Overrides CounterInterface:: |
|
Counter:: |
public | function |
Increase the counter. Overrides CounterInterface:: |
|
Counter:: |
public | function |
Overwrite the counter value. Overrides CounterInterface:: |
|
Counter:: |
protected | function | Overwrite the counter value (permission bypass). | |
Counter:: |
public | function |
Set the callback that gets called when writes occur. Overrides CounterInterface:: |
|
Counter:: |
public | function |
Construct a counter object. Overrides CounterInterface:: |
3 |
RuntimeMeasurement:: |
protected | property | The initial time measurement. | |
RuntimeMeasurement:: |
public | function |
Return a value safe for time hints, between 0.1 and 10.00. Overrides RuntimeMeasurementInterface:: |
|
RuntimeMeasurement:: |
public | function |
Start measuring execution time. Overrides RuntimeMeasurementInterface:: |
|
RuntimeMeasurement:: |
public | function |
Stop measuring execution time and store if necessary. Overrides RuntimeMeasurementInterface:: |