-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
Timing.js
52 lines (44 loc) · 1.29 KB
/
Timing.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import getPlatform from '../getPlatform';
import {Graphite_Timer} from '../API';
let timestampData = {};
/**
* Start a performance timing measurement
*
* @param {String} eventName
*/
function start(eventName) {
timestampData[eventName] = Date.now();
}
/**
* End performance timing. Measure the time between event start/end in milliseconds, and push to Grafana
*
* @param {String} eventName - event name used as timestamp key
* @param {String} [secondaryName] - optional secondary event name, passed to grafana
* @param {Number} [offset] - optional param to offset the time
*/
function end(eventName, secondaryName = '', offset = 0) {
if (eventName in timestampData) {
const eventTime = Date.now() - timestampData[eventName] - offset;
const grafanaEventName = secondaryName
? `expensify.cash.${eventName}.${secondaryName}`
: `expensify.cash.${eventName}`;
console.debug(`Timing:${grafanaEventName}`, eventTime);
Graphite_Timer({
name: grafanaEventName,
value: eventTime,
platform: `${getPlatform()}`,
});
delete timestampData[eventName];
}
}
/**
* Clears all timing data
*/
function clearData() {
timestampData = {};
}
export default {
start,
end,
clearData,
};