Skip to content

Commit

Permalink
Merge pull request #48654 from margelo/chore/fix-timing-measurement
Browse files Browse the repository at this point in the history
[NoQA] fix: timing measurements are inaccurate
  • Loading branch information
marcaaron authored Sep 6, 2024
2 parents 34ae114 + 340ce91 commit 4bbe332
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/libs/actions/Timing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ let timestampData: Record<string, TimestampData> = {};
* @param shouldUseFirebase - adds an additional trace in Firebase
*/
function start(eventName: string, shouldUseFirebase = true) {
timestampData[eventName] = {startTime: Date.now(), shouldUseFirebase};

if (!shouldUseFirebase) {
return;
if (shouldUseFirebase) {
Firebase.startTrace(eventName);
}

Firebase.startTrace(eventName);
timestampData[eventName] = {startTime: performance.now(), shouldUseFirebase};
}

/**
Expand All @@ -42,13 +40,14 @@ function end(eventName: string, secondaryName = '', maxExecutionTime = 0) {
}

const {startTime, shouldUseFirebase} = timestampData[eventName];
Environment.getEnvironment().then((envName) => {
const eventTime = Date.now() - startTime;

if (shouldUseFirebase) {
Firebase.stopTrace(eventName);
}
const eventTime = performance.now() - startTime;

if (shouldUseFirebase) {
Firebase.stopTrace(eventName);
}

Environment.getEnvironment().then((envName) => {
const baseEventName = `${envName}.new.expensify.${eventName}`;
const grafanaEventName = secondaryName ? `${baseEventName}.${secondaryName}` : baseEventName;

Expand Down

0 comments on commit 4bbe332

Please sign in to comment.