The runner is the actual thing that measures the difference between time moments.
It can create performance timers that are just proxies that execute measurement methods of the runner they created.
The main responsibility of timers is to store the whole namespace of current metrics to make them easy to use.
// Only metrics which namespace starts with 'network' will be printed in the console construnner = newPerfTimersRunner(engines.console, {filter:filterPredicate});
A performance timer is used to make time measurements.
After its creation, the timer has only a group name. The timer stores the whole namespace inside.
When new metrics are created, the timer's namespace prepends to metrics name, forming the full name of the metrics.
Two methods start and finish are designed for local measurements.
Method start marks the beginning of measurement and returns a timer identifier to finish the measurement.
The advantage of this approach is that there could be a number of concurrent measurements with the same name,
and none of them will affect each other since every timer identifier is unique.
The finish method also acquires some additional information for the metrics as a second parameter.
This kind of measurement is not affected by the runner's time origin because it measures the time difference between two moments.
This method measures time from the runner's time origin to the moment the method was called.
It is possible to pass additional data as the second argument to the method.
core/perf/timer/impl
This module contains a runner implementation for performance timers.
Overview
The runner is the actual thing that measures the difference between time moments. It can create performance timers that are just proxies that execute measurement methods of the runner they created. The main responsibility of timers is to store the whole namespace of current metrics to make them easy to use.
Runner
Constructor
The
PerfTimersRunner
class has several parameters in its constructor:engine
- the most important argument isPerfTimerEngine
instance. It is required.filter
- predicate to filter metrics. If it returnsfalse
, the metrics won't be sent anywhere.keepTImeOffset
- the runner becomes a scoped one. All new timestamps measure from the moment the runner was created.A simple runner:
A scoped runner:
A runner with filtering:
Methods
The class has only one public method
createTimer
that returns an instance of performance timer.Some protected methods are used by performance timer instances.
Timer
A performance timer is used to make time measurements.
After its creation, the timer has only a group name. The timer stores the whole namespace inside. When new metrics are created, the timer's namespace prepends to metrics name, forming the full name of the metrics.
Methods
The performance timer has several methods to measure and one method to define a namespace.
Namespace
Returns a new performance timer instance with the updated namespace.
Local measurement
Two methods
start
andfinish
are designed for local measurements. Methodstart
marks the beginning of measurement and returns a timer identifier to finish the measurement.The advantage of this approach is that there could be a number of concurrent measurements with the same name, and none of them will affect each other since every timer identifier is unique.
The
finish
method also acquires some additional information for the metrics as a second parameter. This kind of measurement is not affected by the runner's time origin because it measures the time difference between two moments.Time marks
Also, there is a possibility to measure time from the runner's time origin with
markTimestamp
method.This method measures time from the runner's time origin to the moment the method was called. It is possible to pass additional data as the second argument to the method.