diff --git a/src/vs/base/common/performance.d.ts b/src/vs/base/common/performance.d.ts index 4258c8d76af44280aebde092bacb421d24ef3c4b..e8fdbf4ef12ced694f1e884ef8c51fddfed83c63 100644 --- a/src/vs/base/common/performance.d.ts +++ b/src/vs/base/common/performance.d.ts @@ -26,6 +26,8 @@ export function getEntries(type: 'mark' | 'measure'): PerformanceEntry[]; export function getEntry(type: 'mark' | 'measure', name: string): PerformanceEntry; +export function getDuration(from: string, to: string): number; + type ExportData = any[]; export function importEntries(data: ExportData): void; export function exportEntries(): ExportData; diff --git a/src/vs/base/common/performance.js b/src/vs/base/common/performance.js index 8cfcb4794bd9b0655e6fd7d478b57ec779f78601..2bea079a8e25253e5de9c6329e88bf584115e116 100644 --- a/src/vs/base/common/performance.js +++ b/src/vs/base/common/performance.js @@ -67,6 +67,25 @@ define([], function () { } } + function getDuration(from, to) { + const entries = global._performanceEntries; + let name = from; + let startTime = 0; + for (let i = 0; i < entries.length; i += 4) { + if (entries[i + 1] === name) { + if (name === from) { + // found `from` (start of interval) + name = to; + startTime = entries[i + 2]; + } else { + // from `to` (end of interval) + return entries[i + 2] - startTime; + } + } + } + return 0; + } + function mark(name) { global._performanceEntries.push('mark', name, _now(), 0); if (typeof console.timeStamp === 'function') { @@ -118,6 +137,7 @@ define([], function () { time: time, getEntries: getEntries, getEntry: getEntry, + getDuration: getDuration, importEntries: importEntries, exportEntries: exportEntries }; diff --git a/src/vs/workbench/electron-browser/bootstrap/index.js b/src/vs/workbench/electron-browser/bootstrap/index.js index 4ba96f7418faaaeef358d7c4ee2a2a657d8b077b..9357afcaeab9bd53b30e9b2bd245ed260baf8dd5 100644 --- a/src/vs/workbench/electron-browser/bootstrap/index.js +++ b/src/vs/workbench/electron-browser/bootstrap/index.js @@ -179,13 +179,13 @@ function main() { windowLoad: configuration.perfWindowLoadTime }; - const workbenchMainClock = perf.time('loadWorkbenchMain'); + perf.mark('willLoadWorkbenchMain'); require([ 'vs/workbench/workbench.main', 'vs/nls!vs/workbench/workbench.main', 'vs/css!vs/workbench/workbench.main' ], function () { - workbenchMainClock.stop(); + perf.mark('didLoadWorkbenchMain'); process.lazyEnv.then(function () { perf.mark('main/startup'); diff --git a/src/vs/workbench/electron-browser/shell.ts b/src/vs/workbench/electron-browser/shell.ts index ef000919213d6f5c199b6a9d4d97ca70b7ae7136..27e140a724590ee85502392b1ed1a71333c54e9a 100644 --- a/src/vs/workbench/electron-browser/shell.ts +++ b/src/vs/workbench/electron-browser/shell.ts @@ -252,8 +252,6 @@ export class WorkbenchShell { // Telemetry: startup metrics this.timerService.workbenchStarted = Date.now(); - this.timerService.restoreEditorsDuration = info.restoreEditorsDuration; - this.timerService.restoreViewletDuration = info.restoreViewletDuration; this.extensionService.whenInstalledExtensionsRegistered().done(() => { /* __GDPR__ "startupTime" : { diff --git a/src/vs/workbench/electron-browser/workbench.ts b/src/vs/workbench/electron-browser/workbench.ts index be4fdf873847da1b2a33b5df24c78c3d50117416..b621527249309f7340939c12e374c501eb5ee7c2 100644 --- a/src/vs/workbench/electron-browser/workbench.ts +++ b/src/vs/workbench/electron-browser/workbench.ts @@ -15,8 +15,7 @@ import DOM = require('vs/base/browser/dom'); import { Builder, $ } from 'vs/base/browser/builder'; import { Delayer, RunOnceScheduler } from 'vs/base/common/async'; import * as browser from 'vs/base/browser/browser'; -import { StopWatch } from 'vs/base/common/stopwatch'; -import { time } from 'vs/base/common/performance'; +import * as perf from 'vs/base/common/performance'; import errors = require('vs/base/common/errors'); import { BackupFileService } from 'vs/workbench/services/backup/node/backupFileService'; import { IBackupFileService } from 'vs/workbench/services/backup/common/backup'; @@ -120,8 +119,6 @@ interface IZenModeSettings { export interface IWorkbenchStartedInfo { customKeybindingsCount: number; - restoreViewletDuration: number; - restoreEditorsDuration: number; pinnedViewlets: string[]; restoredViewlet: string; restoredEditors: string[]; @@ -319,8 +316,7 @@ export class Workbench implements IPartService { const restorePromises: TPromise[] = []; // Restore Editors - const editorRestoreStopWatch = StopWatch.create(); - const editorRestoreClock = time('restore:editors'); + perf.mark('willRestoreEditors'); const restoredEditors: string[] = []; restorePromises.push(this.resolveEditorsToOpen().then(inputs => { @@ -337,8 +333,7 @@ export class Workbench implements IPartService { return editorOpenPromise.then(editors => { this.handleEditorBackground(); // make sure we show the proper background in the editor area - editorRestoreClock.stop(); - editorRestoreStopWatch.stop(); + perf.mark('didRestoreEditors'); for (const editor of editors) { if (editor) { @@ -353,7 +348,6 @@ export class Workbench implements IPartService { })); // Restore Sidebar - let viewletRestoreStopWatch: StopWatch; let viewletIdToRestore: string; if (!this.sideBarHidden) { this.sideBarVisibleContext.set(true); @@ -366,11 +360,9 @@ export class Workbench implements IPartService { viewletIdToRestore = this.viewletService.getDefaultViewletId(); } - viewletRestoreStopWatch = StopWatch.create(); - const viewletRestoreClock = time('restore:viewlet'); + perf.mark('willRestoreViewlet'); restorePromises.push(this.viewletService.openViewlet(viewletIdToRestore).then(() => { - viewletRestoreStopWatch.stop(); - viewletRestoreClock.stop(); + perf.mark('didRestoreViewlet'); })); } @@ -395,8 +387,6 @@ export class Workbench implements IPartService { return { customKeybindingsCount: this.keybindingService.customKeybindingsCount(), - restoreViewletDuration: viewletRestoreStopWatch ? Math.round(viewletRestoreStopWatch.elapsed()) : 0, - restoreEditorsDuration: Math.round(editorRestoreStopWatch.elapsed()), pinnedViewlets: this.activitybarPart.getPinned(), restoredViewlet: viewletIdToRestore, restoredEditors diff --git a/src/vs/workbench/services/timer/common/timerService.ts b/src/vs/workbench/services/timer/common/timerService.ts index e3d4887ddbd9d1b7b099c46c7ad406840ed41d24..e4dfd46bbd94205b39861f820b79775b7ba1e5cb 100644 --- a/src/vs/workbench/services/timer/common/timerService.ts +++ b/src/vs/workbench/services/timer/common/timerService.ts @@ -104,8 +104,5 @@ export interface ITimerService extends IInitData { beforeExtensionLoad: number; afterExtensionLoad: number; - restoreViewletDuration: number; - restoreEditorsDuration: number; - readonly startupMetrics: IStartupMetrics; } diff --git a/src/vs/workbench/services/timer/node/timerService.ts b/src/vs/workbench/services/timer/node/timerService.ts index 4e3817cd0b60e0a04cb9a8f110af4e06da129075..9f30c82928bd859d2c188045c559819881c166a6 100644 --- a/src/vs/workbench/services/timer/node/timerService.ts +++ b/src/vs/workbench/services/timer/node/timerService.ts @@ -29,10 +29,6 @@ export class TimerService implements ITimerService { public beforeExtensionLoad: number; public afterExtensionLoad: number; - public restoreViewletDuration: number; - public restoreEditorsDuration: number; - - private _startupMetrics: IStartupMetrics; constructor(initData: IInitData, private isEmptyWorkbench: boolean) { @@ -91,11 +87,11 @@ export class TimerService implements ITimerService { timers: { ellapsedExtensions: this.afterExtensionLoad - this.beforeExtensionLoad, ellapsedExtensionsReady: this.afterExtensionLoad - start, - ellapsedRequire: perf.getEntry('measure', 'loadWorkbenchMain').duration, - ellapsedViewletRestore: this.restoreViewletDuration, - ellapsedEditorRestore: this.restoreEditorsDuration, + ellapsedRequire: perf.getDuration('willLoadWorkbenchMain', 'didLoadWorkbenchMain'), + ellapsedEditorRestore: perf.getDuration('willRestoreEditors', 'didRestoreEditors'), + ellapsedViewletRestore: perf.getDuration('willRestoreViewlet', 'didRestoreViewlet'), ellapsedWorkbench: this.workbenchStarted - this.beforeWorkbenchOpen, - ellapsedWindowLoadToRequire: perf.getEntry('mark', 'loadWorkbenchMain/start').startTime - this.windowLoad, + ellapsedWindowLoadToRequire: perf.getEntry('mark', 'willLoadWorkbenchMain').startTime - this.windowLoad, ellapsedTimersToTimersComputed: Date.now() - now }, platform,