src/vs/base/common/performance.ts
149 LOC · 110 covered · 39 uncovered · 11 ranges · 5428 concepts · 5 introducers · 2907 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
/*---------------------------------------------------------------------------------------------
performance.ts ×6
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import type { INodeProcess } from './platform.js';
function _definePolyfillMarks(timeOrigin?: number) {
const _data: [string?, number?] = [];
if (typeof timeOrigin === 'number') {
_data.push('code/timeOrigin', timeOrigin);
}
function mark(name: string, markOptions?: { startTime?: number }) {
}
for (let i = 0; i < _data.length; i += 2) {
result.push({
name: _data[i],
startTime: _data[i + 1],
});
}
return result;
}
const timeOriginValue = hasTimeOrigin ? _data[1] : undefined;
_data.length = 0;
if (hasTimeOrigin) {
_data.push('code/timeOrigin', timeOriginValue);
}
for (let i = _data.length - 2; i >= 0; i -= 2) {
if (_data[i] === name) {
_data.splice(i, 2);
}
}
}
}
}
declare const process: INodeProcess;
interface IPerformanceEntry {
readonly name: string;
readonly startTime: number;
}
interface IPerformanceTiming {
readonly navigationStart?: number;
readonly redirectStart?: number;
readonly fetchStart?: number;
}
interface IPerformance {
mark(name: string, markOptions?: { startTime?: number }): void;
clearMarks(name?: string): void;
getEntriesByType(type: string): IPerformanceEntry[];
readonly timeOrigin: number;
readonly timing: IPerformanceTiming;
readonly nodeTiming?: any;
}
declare const performance: IPerformance;
function _define() {
// Identify browser environment when following property is not present
// https://nodejs.org/dist/latest-v16.x/docs/api/perf_hooks.html#performancenodetiming
// @ts-ignore
if (typeof performance === 'object' && typeof performance.mark === 'function' && !performance.nodeTiming) {
// in a browser context, reuse performance-util
if (typeof performance.timeOrigin !== 'number' && !performance.timing) {
// safari & webworker: because there is no timeOrigin and no workaround
// we use the `Date.now`-based polyfill.
return _definePolyfillMarks();
} else {
// use "native" performance for mark and getMarks
return {
mark(name: string, markOptions?: { startTime?: number }) {
performance.mark(name, markOptions);
},
clearMarks(name?: string) {
performance.clearMarks(name);
},
getMarks() {
let timeOrigin = performance.timeOrigin;
if (typeof timeOrigin !== 'number') {
// safari: there is no timerOrigin but in renderers there is the timing-property
// see https://bugs.webkit.org/show_bug.cgi?id=174862
timeOrigin = (performance.timing.navigationStart || performance.timing.redirectStart || performance.timing.fetchStart) ?? 0;
}
const result = [{ name: 'code/timeOrigin', startTime: Math.round(timeOrigin) }];
for (const entry of performance.getEntriesByType('mark')) {
result.push({
name: entry.name,
startTime: Math.round(timeOrigin + entry.startTime)
});
}
return result;
}
};
}
// node.js: use the normal polyfill but add the timeOrigin
// from the node perf_hooks API as very first mark
const timeOrigin = performance?.timeOrigin;
return _definePolyfillMarks(timeOrigin);
} else {
// unknown environment
console.trace('perf-util loaded in UNKNOWN environment');
return _definePolyfillMarks();
}
function _factory(sharedObj: any) {
if (!sharedObj.MonacoPerformanceMarks) {
sharedObj.MonacoPerformanceMarks = _define();
}
return sharedObj.MonacoPerformanceMarks;
}
const perf = _factory(globalThis);
export const mark: (name: string, markOptions?: { startTime?: number }) => void = perf.mark;
/**
* Clears performance marks. If a name is given, only marks with that exact
* name are removed. If no name is given, all marks are removed.
*/
export const clearMarks: (name?: string) => void = perf.clearMarks;
export interface PerformanceMark {
readonly name: string;
readonly startTime: number;
}
/**
* Returns all marks, sorted by `startTime`.
*/
export const getMarks: () => PerformanceMark[] = perf.getMarks;