109
}
110
112
>
// node.js: use the normal polyfill but add the timeOrigin
113
>
// from the node perf_hooks API as very first mark
114
>
const timeOrigin = performance?.timeOrigin;
115
>
return _definePolyfillMarks(timeOrigin);
116
>
117
>
} else {
118
// unknown environment
119
console.trace('perf-util loaded in UNKNOWN environment');
120
return _definePolyfillMarks();
121
}
123
>
124
>
function _factory(sharedObj: any) {
125
>
if (!sharedObj.MonacoPerformanceMarks) {
126
>
sharedObj.MonacoPerformanceMarks = _define();
127
>
}
128
>
return sharedObj.MonacoPerformanceMarks;
129
>
}
130
>
131
>
const perf = _factory(globalThis);
132
>
133
>
export const mark: (name: string, markOptions?: { startTime?: number }) => void = perf.mark;
134
>
135
>
/**
136
>
* Clears performance marks. If a name is given, only marks with that exact
137
>
* name are removed. If no name is given, all marks are removed.
138
>
*/
139
>
export const clearMarks: (name?: string) => void = perf.clearMarks;
140
>
141
>
export interface PerformanceMark {
142
>
readonly name: string;
143
>
readonly startTime: number;
144
>
}
145
>
146
>
/**
147
>
* Returns all marks, sorted by `startTime`.
148
>
*/
149
>
export const getMarks: () => PerformanceMark[] = perf.getMarks;