From c63c92b84ec96fefb56fb38cc6db42fecb6bf6fd Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Fri, 19 Jan 2018 10:46:44 +0100 Subject: [PATCH] remove table from print action, only have new command, #41712 --- src/vs/workbench/electron-browser/actions.ts | 116 ------------------ .../performance/electron-browser/stats.ts | 7 ++ 2 files changed, 7 insertions(+), 116 deletions(-) diff --git a/src/vs/workbench/electron-browser/actions.ts b/src/vs/workbench/electron-browser/actions.ts index f0a5ba05fad..c35e4ffc6c2 100644 --- a/src/vs/workbench/electron-browser/actions.ts +++ b/src/vs/workbench/electron-browser/actions.ts @@ -324,14 +324,6 @@ export class ShowStartupPerformance extends Action { (console).table(this.getStartupMetricsTable(nodeModuleLoadTime)); - if (this.environmentService.performance) { - const data = this.analyzeLoaderStats(); - for (let type in data) { - (console).groupCollapsed(`Loader: ${type}`); - (console).table(data[type]); - (console).groupEnd(); - } - } (console).groupEnd(); @@ -422,114 +414,6 @@ export class ShowStartupPerformance extends Action { return { table: result, duration: Math.round(total) }; } - - private analyzeLoaderStats(): { [type: string]: any[] } { - const stats = (require).getStats().slice(0).sort((a: ILoaderEvent, b: ILoaderEvent) => { - if (a.detail < b.detail) { - return -1; - } else if (a.detail > b.detail) { - return 1; - } else if (a.type < b.type) { - return -1; - } else if (a.type > b.type) { - return 1; - } else { - return 0; - } - }); - - class Tick { - - public readonly duration: number; - public readonly detail: string; - - constructor(public readonly start: ILoaderEvent, public readonly end: ILoaderEvent) { - console.assert(start.detail === end.detail); - - this.duration = this.end.timestamp - this.start.timestamp; - this.detail = start.detail; - } - - toTableObject() { - return { - ['Path']: this.start.detail, - ['Took (ms)']: this.duration.toFixed(2), - // ['Start (ms)']: this.start.timestamp, - // ['End (ms)']: this.end.timestamp - }; - } - - static compareUsingStartTimestamp(a: Tick, b: Tick): number { - if (a.start.timestamp < b.start.timestamp) { - return -1; - } else if (a.start.timestamp > b.start.timestamp) { - return 1; - } else { - return 0; - } - } - } - - const ticks: { [type: number]: Tick[] } = { - [LoaderEventType.BeginLoadingScript]: [], - [LoaderEventType.BeginInvokeFactory]: [], - [LoaderEventType.NodeBeginEvaluatingScript]: [], - [LoaderEventType.NodeBeginNativeRequire]: [], - }; - - for (let i = 1; i < stats.length - 1; i++) { - const stat = stats[i]; - const nextStat = stats[i + 1]; - - if (nextStat.type - stat.type > 2) { - //bad?! - break; - } - - i += 1; - ticks[stat.type].push(new Tick(stat, nextStat)); - } - - ticks[LoaderEventType.BeginInvokeFactory].sort(Tick.compareUsingStartTimestamp); - ticks[LoaderEventType.BeginInvokeFactory].sort(Tick.compareUsingStartTimestamp); - ticks[LoaderEventType.NodeBeginEvaluatingScript].sort(Tick.compareUsingStartTimestamp); - ticks[LoaderEventType.NodeBeginNativeRequire].sort(Tick.compareUsingStartTimestamp); - - const ret = { - 'Load Script': ticks[LoaderEventType.BeginLoadingScript].map(t => t.toTableObject()), - '(Node) Load Script': ticks[LoaderEventType.NodeBeginNativeRequire].map(t => t.toTableObject()), - 'Eval Script': ticks[LoaderEventType.BeginInvokeFactory].map(t => t.toTableObject()), - '(Node) Eval Script': ticks[LoaderEventType.NodeBeginEvaluatingScript].map(t => t.toTableObject()), - }; - - function total(ticks: Tick[]): number { - let sum = 0; - for (const tick of ticks) { - sum += tick.duration; - } - return sum; - } - - // totals - ret['Load Script'].push({ - ['Path']: 'TOTAL TIME', - ['Took (ms)']: total(ticks[LoaderEventType.BeginLoadingScript]).toFixed(2) - }); - ret['Eval Script'].push({ - ['Path']: 'TOTAL TIME', - ['Took (ms)']: total(ticks[LoaderEventType.BeginInvokeFactory]).toFixed(2) - }); - ret['(Node) Load Script'].push({ - ['Path']: 'TOTAL TIME', - ['Took (ms)']: total(ticks[LoaderEventType.NodeBeginNativeRequire]).toFixed(2) - }); - ret['(Node) Eval Script'].push({ - ['Path']: 'TOTAL TIME', - ['Took (ms)']: total(ticks[LoaderEventType.NodeBeginEvaluatingScript]).toFixed(2) - }); - - return ret; - } } export class ReloadWindowAction extends Action { diff --git a/src/vs/workbench/parts/performance/electron-browser/stats.ts b/src/vs/workbench/parts/performance/electron-browser/stats.ts index 252eab924dc..397935d4179 100644 --- a/src/vs/workbench/parts/performance/electron-browser/stats.ts +++ b/src/vs/workbench/parts/performance/electron-browser/stats.ts @@ -7,6 +7,7 @@ import { CommandsRegistry } from 'vs/platform/commands/common/commands'; import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService'; +import { IEnvironmentService } from 'vs/platform/environment/common/environment'; interface IRequire { @@ -109,6 +110,12 @@ function getStats(): Map { CommandsRegistry.registerCommand('dev.stats.loader', accessor => { const clipboard = accessor.get(IClipboardService); + const env = accessor.get(IEnvironmentService); + + if (!env.performance) { + console.warn('no loader stats, start with `--performance`'); + return; + } let value = `Name\tDuration\n`; for (let tick of getStats().get(LoaderEventType.BeginInvokeFactory)) {