Skip to content

Commit 6fe3f71

Browse files
committed
Improve support of metrics
1 parent 3387216 commit 6fe3f71

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

packages/app/src/sandbox/utils/metrics.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import _debug from '@codesandbox/common/lib/utils/debug';
2+
import { getGlobal } from '@codesandbox/common/lib/utils/global';
23

34
const debug = _debug('cs:compiler:measurements');
45

@@ -7,11 +8,16 @@ type MeasurementKey = string;
78
const runningMeasurements = new Map<string, number>();
89
const measurements: { [measurement: string]: number } = {};
910

10-
export function measure(key: MeasurementKey) {
11-
if (process.env.NODE_ENV !== 'production') {
12-
return;
13-
}
11+
const global = getGlobal();
12+
if (typeof global.performance === 'undefined') {
13+
global.performance = {
14+
mark: () => {},
15+
now: () => Date.now(),
16+
measure: () => {},
17+
};
18+
}
1419

20+
export function measure(key: MeasurementKey) {
1521
try {
1622
performance.mark(`${key}_start`);
1723
runningMeasurements.set(key, performance.now());
@@ -27,10 +33,6 @@ export function endMeasure(
2733
lastTime?: number;
2834
} = {}
2935
) {
30-
if (process.env.NODE_ENV !== 'production') {
31-
return;
32-
}
33-
3436
try {
3537
const { lastTime } = options;
3638
performance.mark(`${key}_end`);

0 commit comments

Comments
 (0)