diff --git a/src/bootstrap-window.js b/src/bootstrap-window.js index fe6059c56de..03491d0fb22 100644 --- a/src/bootstrap-window.js +++ b/src/bootstrap-window.js @@ -145,10 +145,9 @@ try { // Wait for process environment being fully resolved - const perf = perfLib(); - perf.mark('willWaitForShellEnv'); + performance.mark('willWaitForShellEnv'); await whenEnvResolved; - perf.mark('didWaitForShellEnv'); + performance.mark('didWaitForShellEnv'); // Callback only after process environment is resolved const callbackResult = resultCallback(result, configuration); @@ -267,26 +266,8 @@ return window.vscode; } - /** - * @return {{ mark: (name: string) => void }} - */ - function perfLib() { - globalThis.MonacoPerformanceMarks = globalThis.MonacoPerformanceMarks || []; - - return { - /** - * @param {string} name - */ - mark(name) { - globalThis.MonacoPerformanceMarks.push(name, Date.now()); - performance.mark(name); - } - }; - } - return { load, - globals, - perfLib + globals }; })); diff --git a/src/vs/code/browser/workbench/workbench-dev.html b/src/vs/code/browser/workbench/workbench-dev.html index 8b1869294e6..20dbd370976 100644 --- a/src/vs/code/browser/workbench/workbench-dev.html +++ b/src/vs/code/browser/workbench/workbench-dev.html @@ -3,8 +3,7 @@
@@ -56,7 +55,7 @@ @@ -55,7 +54,7 @@ diff --git a/src/vs/code/electron-browser/workbench/workbench.js b/src/vs/code/electron-browser/workbench/workbench.js index 761ce9c812a..e53c44eb702 100644 --- a/src/vs/code/electron-browser/workbench/workbench.js +++ b/src/vs/code/electron-browser/workbench/workbench.js @@ -12,8 +12,7 @@ const bootstrapWindow = bootstrapWindowLib(); // Add a perf entry right from the top - const perf = bootstrapWindow.perfLib(); - perf.mark('renderer/started'); + performance.mark('renderer/started'); // Load workbench main JS, CSS and NLS all in parallel. This is an // optimization to prevent a waterfall of loading to happen, because @@ -27,7 +26,7 @@ async function (workbench, configuration) { // Mark start of workbench - perf.mark('didLoadWorkbenchMain'); + performance.mark('didLoadWorkbenchMain'); // @ts-ignore return require('vs/workbench/electron-browser/desktop.main').main(configuration); @@ -41,7 +40,7 @@ loaderConfig.recordStats = true; }, beforeRequire: function () { - perf.mark('willLoadWorkbenchMain'); + performance.mark('willLoadWorkbenchMain'); } } ); @@ -52,8 +51,7 @@ /** * @returns {{ * load: (modules: string[], resultCallback: (result, configuration: import('../../../platform/windows/common/windows').INativeWindowConfiguration) => any, options: object) => unknown, - * globals: () => typeof import('../../../base/parts/sandbox/electron-sandbox/globals'), - * perfLib: () => { mark: (name: string) => void } + * globals: () => typeof import('../../../base/parts/sandbox/electron-sandbox/globals') * }} */ function bootstrapWindowLib() { @@ -72,7 +70,7 @@ * }} configuration */ function showPartsSplash(configuration) { - perf.mark('willShowPartsSplash'); + performance.mark('willShowPartsSplash'); let data; if (typeof configuration.partsSplashPath === 'string') { @@ -162,7 +160,7 @@ document.body.appendChild(splash); } - perf.mark('didShowPartsSplash'); + performance.mark('didShowPartsSplash'); } //#endregion diff --git a/src/vs/code/electron-sandbox/workbench/workbench.js b/src/vs/code/electron-sandbox/workbench/workbench.js index 6a46ef2b080..e90d470d057 100644 --- a/src/vs/code/electron-sandbox/workbench/workbench.js +++ b/src/vs/code/electron-sandbox/workbench/workbench.js @@ -12,8 +12,7 @@ const bootstrapWindow = bootstrapWindowLib(); // Add a perf entry right from the top - const perf = bootstrapWindow.perfLib(); - perf.mark('renderer/started'); + performance.mark('renderer/started'); // Load workbench main JS, CSS and NLS all in parallel. This is an // optimization to prevent a waterfall of loading to happen, because @@ -27,7 +26,7 @@ async function (workbench, configuration) { // Mark start of workbench - perf.mark('didLoadWorkbenchMain'); + performance.mark('didLoadWorkbenchMain'); // @ts-ignore return require('vs/workbench/electron-sandbox/desktop.main').main(configuration); @@ -41,7 +40,7 @@ loaderConfig.recordStats = true; }, beforeRequire: function () { - perf.mark('willLoadWorkbenchMain'); + performance.mark('willLoadWorkbenchMain'); } } ); @@ -53,7 +52,6 @@ * @returns {{ * load: (modules: string[], resultCallback: (result, configuration: object) => any, options: object) => unknown, * globals: () => typeof import('../../../base/parts/sandbox/electron-sandbox/globals'), - * perfLib: () => { mark: (name: string) => void } * }} */ function bootstrapWindowLib() { diff --git a/src/vs/workbench/services/timer/browser/timerService.ts b/src/vs/workbench/services/timer/browser/timerService.ts index 874fca2c1aa..a3988e8c8e7 100644 --- a/src/vs/workbench/services/timer/browser/timerService.ts +++ b/src/vs/workbench/services/timer/browser/timerService.ts @@ -356,7 +356,7 @@ class PerfMarks { if (!toEntry) { return 0; } - return toEntry.startTime - fromEntry.startTime; + return Math.round(toEntry.startTime - fromEntry.startTime); } @@ -396,7 +396,15 @@ export abstract class AbstractTimerService implements ITimerService { this._extensionService.whenInstalledExtensionsRegistered(), _lifecycleService.when(LifecyclePhase.Restored) ]).then(() => { - this.submitPerformanceMarks(perf.getMarks()); + + // import native-browser marks + this._submitNativeMarks(); + + // because "our" perf.mark-util also adds native performance marks + // no extra import of "our" marks is needed, they are already imported + // by importing native perf marks (see above) + // this.submitPerformanceMarks(perf.getMarks()); + return this._computeStartupMetrics(); }).then(metrics => { this._reportStartupTimes(metrics); @@ -404,6 +412,24 @@ export abstract class AbstractTimerService implements ITimerService { }); } + private _submitNativeMarks(): void { + + let timeOrigin = performance.timeOrigin; + if (!timeOrigin) { + // polyfill for Safari + const entry = performance.timing; + timeOrigin = entry.navigationStart || entry.redirectStart || entry.fetchStart; + } + + const marks: perf.PerformanceMark[] = performance.getEntriesByType('mark').map(entry => { + return { + name: entry.name, + startTime: timeOrigin + entry.startTime + }; + }); + this.submitPerformanceMarks(marks); + } + submitPerformanceMarks(marks: perf.PerformanceMark[]): void { this._marks.submitMarks(marks); }