The timers' factory is created using getTimerFactory function. The function acquires timers' config as the first
argument. It means that there could be several timers' factories with different configurations simultaneously.
Each factory has the following methods: getTimer, getScopedTimer. These methods are entry points to work with timers.
Each of them uses runners inside to create a timer and return it. Also, the methods create a runner for passed arguments
only once and then use the same runner for the next call with the same arguments.
These methods are called from the main perf object, so there is no need to create the timers' factory directly.
The following examples imply that a factory has already created and use it only for educational purpose.
// A page was created scopedTimer.markTimestamp('created');
// A page was mounted // It's possible to send additional data with timestamp scopedTimer.markTimestamp('mounted', {id:data.id});
Using the same factory in different files and calling getTimer method with the same arguments guarantees that inside
it will be used the same instance of the timers' runner. But the method returns different instances of the performance
timer itself.
file1.ts
consttimer = factory.getTimer('components');
file2.ts
// A different timer from the same runner consttimer = factory.getTimer('components');
This method returns a scoped timer that starts time measurement from the moment its runner was created.
Timers from getTimer and getScopedTimer have the same interfaces.
Since the next call of the method with the same arguments uses the already created runner, then the time origin
for the new timer will be the same as for the previously created one.
file1.ts
// A time origin for the internal runner is exact this moment — m0 consttimer = factory.getScopedTimer('tools', 'page-helpers');
file2.ts
// A different timer but its time origin is m0 as well consttimer = factory.getScopedTimer('tools', 'page-helpers');
core/perf/timer
This module provides an implementation of the performance timer API. It allows calculating and sending time metrics.
Overview
The module consists of several abstractions:
Factory
The timers' factory is created using
getTimerFactory
function. The function acquires timers' config as the first argument. It means that there could be several timers' factories with different configurations simultaneously.Methods
Each factory has the following methods:
getTimer
,getScopedTimer
. These methods are entry points to work with timers. Each of them uses runners inside to create a timer and return it. Also, the methods create a runner for passed arguments only once and then use the same runner for the next call with the same arguments.These methods are called from the main
perf
object, so there is no need to create the timers' factory directly. The following examples imply that a factory has already created and use it only for educational purpose.Regular timer
This method returns a regular timer that starts time measurement from the time origin.
Duration measurement
Time marks from the time origin
Using the same factory in different files and calling
getTimer
method with the same arguments guarantees that inside it will be used the same instance of the timers' runner. But the method returns different instances of the performance timer itself.file1.ts
file2.ts
Scoped timer
This method returns a scoped timer that starts time measurement from the moment its runner was created. Timers from
getTimer
andgetScopedTimer
have the same interfaces.Since the next call of the method with the same arguments uses the already created runner, then the time origin for the new timer will be the same as for the previously created one.
file1.ts
file2.ts