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.

1 > /*--------------------------------------------------------------------------------------------- performance.ts ×6
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import type { INodeProcess } from './platform.js';
7 >
8 > function _definePolyfillMarks(timeOrigin?: number) {
9 > const _data: [string?, number?] = [];
10 > if (typeof timeOrigin === 'number') {
11 > _data.push('code/timeOrigin', timeOrigin);
12 > }
13 >
14 > function mark(name: string, markOptions?: { startTime?: number }) {
15 > _data.push(name, markOptions?.startTime ?? Date.now()); performance.ts ×1
16 > }
17 > function getMarks() { performance.ts ×6
18 > const result = []; performance.ts ×1
19 > for (let i = 0; i < _data.length; i += 2) {
20 > result.push({
21 > name: _data[i],
22 > startTime: _data[i + 1],
23 > });
24 > }
25 > return result;
26 > }
27 > function clearMarks(name?: string) { performance.ts ×6
28 > if (typeof name === 'undefined') { performance.ts ×2
29 > const hasTimeOrigin = _data.length >= 2 && _data[0] === 'code/timeOrigin'; performance.ts ×1
30 > const timeOriginValue = hasTimeOrigin ? _data[1] : undefined;
31 > _data.length = 0;
32 > if (hasTimeOrigin) {
33 > _data.push('code/timeOrigin', timeOriginValue);
34 > }
35 > } else { performance.ts ×2
36 > for (let i = _data.length - 2; i >= 0; i -= 2) {
37 > if (_data[i] === name) {
38 > _data.splice(i, 2);
39 > }
40 > }
41 > }
42 > }
43 > return { mark, getMarks, clearMarks }; performance.ts ×6
44 > }
45 >
46 > declare const process: INodeProcess;
47 >
48 > interface IPerformanceEntry {
49 > readonly name: string;
50 > readonly startTime: number;
51 > }
52 >
53 > interface IPerformanceTiming {
54 > readonly navigationStart?: number;
55 > readonly redirectStart?: number;
56 > readonly fetchStart?: number;
57 > }
58 >
59 > interface IPerformance {
60 > mark(name: string, markOptions?: { startTime?: number }): void;
61 > clearMarks(name?: string): void;
62 > getEntriesByType(type: string): IPerformanceEntry[];
63 > readonly timeOrigin: number;
64 > readonly timing: IPerformanceTiming;
65 > readonly nodeTiming?: any;
66 > }
67 >
68 > declare const performance: IPerformance;
69 >
70 > function _define() {
71 >
72 > // Identify browser environment when following property is not present
73 > // https://nodejs.org/dist/latest-v16.x/docs/api/perf_hooks.html#performancenodetiming
74 > // @ts-ignore
75 > if (typeof performance === 'object' && typeof performance.mark === 'function' && !performance.nodeTiming) {
76 // in a browser context, reuse performance-util
77
78 if (typeof performance.timeOrigin !== 'number' && !performance.timing) {
79 // safari & webworker: because there is no timeOrigin and no workaround
80 // we use the `Date.now`-based polyfill.
81 return _definePolyfillMarks();
82
83 } else {
84 // use "native" performance for mark and getMarks
85 return {
86 mark(name: string, markOptions?: { startTime?: number }) {
87 performance.mark(name, markOptions);
88 },
89 clearMarks(name?: string) {
90 performance.clearMarks(name);
91 },
92 getMarks() {
93 let timeOrigin = performance.timeOrigin;
94 if (typeof timeOrigin !== 'number') {
95 // safari: there is no timerOrigin but in renderers there is the timing-property
96 // see https://bugs.webkit.org/show_bug.cgi?id=174862
97 timeOrigin = (performance.timing.navigationStart || performance.timing.redirectStart || performance.timing.fetchStart) ?? 0;
98 }
99 const result = [{ name: 'code/timeOrigin', startTime: Math.round(timeOrigin) }];
100 for (const entry of performance.getEntriesByType('mark')) {
101 result.push({
102 name: entry.name,
103 startTime: Math.round(timeOrigin + entry.startTime)
104 });
105 }
106 return result;
107 }
108 };
109 }
110
111 > } else if (typeof process === 'object') { performance.ts ×6
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;