diff --git a/src/vs/base/common/performance.js b/src/vs/base/common/performance.js index 46c834352b9..5a03e119067 100644 --- a/src/vs/base/common/performance.js +++ b/src/vs/base/common/performance.js @@ -9,31 +9,50 @@ function _factory(sharedObj) { - sharedObj.MonacoPerformanceMarks = sharedObj.MonacoPerformanceMarks || []; - - const _dataLen = 2; - const _nativeMark = typeof performance === 'object' && typeof performance.mark === 'function' ? performance.mark.bind(performance) : () => { }; - - function getMarks() { - const result = []; - const entries = sharedObj.MonacoPerformanceMarks; - for (let i = 0; i < entries.length; i += _dataLen) { - result.push({ - name: entries[i], - startTime: entries[i + 1], + if (typeof performance === 'object' && typeof performance.mark === 'function') { + // in a browser context, reuse performance-util + function mark(name) { + performance.mark(name); + } + function getMarks() { + let timeOrigin = performance.timeOrigin; + if (!timeOrigin) { + // polyfill for Safari + const entry = performance.timing; + timeOrigin = entry.navigationStart || entry.redirectStart || entry.fetchStart; + } + return performance.getEntriesByType('mark').map(entry => { + return { + name: entry.name, + startTime: Math.round(timeOrigin + entry.startTime) + }; }); } - return result; + + return { mark, getMarks }; + + } else { + // node.js context, use mock and a shared obj that's share between module systems + sharedObj.MonacoPerformanceMarks = sharedObj.MonacoPerformanceMarks || []; + + function mark(name) { + sharedObj.MonacoPerformanceMarks.push(name, Date.now()); + } + + function getMarks() { + const result = []; + const entries = sharedObj.MonacoPerformanceMarks; + for (let i = 0; i < entries.length; i += 2) { + result.push({ + name: entries[i], + startTime: entries[i + 1], + }); + } + return result; + } + + return { mark, getMarks }; } - - function mark(name) { - sharedObj.MonacoPerformanceMarks.push(name, Date.now()); - _nativeMark(name); - } - - const exports = { mark, getMarks }; - - return exports; } // This module can be loaded in an amd and commonjs-context. diff --git a/src/vs/workbench/services/timer/browser/timerService.ts b/src/vs/workbench/services/timer/browser/timerService.ts index 31dd63a4d6d..93d042637f1 100644 --- a/src/vs/workbench/services/timer/browser/timerService.ts +++ b/src/vs/workbench/services/timer/browser/timerService.ts @@ -399,13 +399,8 @@ export abstract class AbstractTimerService implements ITimerService { _lifecycleService.when(LifecyclePhase.Restored) ]).then(() => { - // 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()); + // set perf mark from renderer + this.setPerformanceMarks('renderer', perf.getMarks()); return this._computeStartupMetrics(); }).then(metrics => { @@ -414,22 +409,6 @@ 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: Math.round(timeOrigin + entry.startTime) - }; - }); - this.setPerformanceMarks('renderer', marks); - } - setPerformanceMarks(source: string, marks: perf.PerformanceMark[]): void { this._marks.setMarks(source, marks); }