From b778e7f53862ced7d70af70ee0d34fe5bf441966 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Tue, 3 Jul 2018 15:18:06 +0200 Subject: [PATCH] debt - add switch to append the ellased-time to a file and then shutdown --- .../environment/common/environment.ts | 1 + .../performance.contribution.ts | 1 + .../startupTimingsAppender.ts | 49 +++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 src/vs/workbench/parts/performance/electron-browser/startupTimingsAppender.ts diff --git a/src/vs/platform/environment/common/environment.ts b/src/vs/platform/environment/common/environment.ts index 06f80764726..99792a19f00 100644 --- a/src/vs/platform/environment/common/environment.ts +++ b/src/vs/platform/environment/common/environment.ts @@ -25,6 +25,7 @@ export interface ParsedArgs { performance?: boolean; 'prof-startup'?: string; 'prof-startup-prefix'?: string; + 'prof-append-timers'?: string; verbose?: boolean; log?: string; logExtensionHostCommunication?: boolean; diff --git a/src/vs/workbench/parts/performance/electron-browser/performance.contribution.ts b/src/vs/workbench/parts/performance/electron-browser/performance.contribution.ts index 771485b80f1..8c55379ff49 100644 --- a/src/vs/workbench/parts/performance/electron-browser/performance.contribution.ts +++ b/src/vs/workbench/parts/performance/electron-browser/performance.contribution.ts @@ -7,4 +7,5 @@ import './startupProfiler'; import './startupTimings'; +import './startupTimingsAppender'; import './stats'; diff --git a/src/vs/workbench/parts/performance/electron-browser/startupTimingsAppender.ts b/src/vs/workbench/parts/performance/electron-browser/startupTimingsAppender.ts new file mode 100644 index 00000000000..04ed3bb7d25 --- /dev/null +++ b/src/vs/workbench/parts/performance/electron-browser/startupTimingsAppender.ts @@ -0,0 +1,49 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions'; +import { ILifecycleService, LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle'; +import { IWindowsService } from 'vs/platform/windows/common/windows'; +import { IWorkbenchContributionsRegistry, IWorkbenchContribution, Extensions } from 'vs/workbench/common/contributions'; +import { Registry } from 'vs/platform/registry/common/platform'; +import { ITimerService } from 'vs/workbench/services/timer/common/timerService'; +import { IEnvironmentService } from 'vs/platform/environment/common/environment'; +import { nfcall } from 'vs/base/common/async'; +import { appendFile } from 'fs'; + +class StartupTimingsAppender implements IWorkbenchContribution { + + constructor( + @ITimerService timerService: ITimerService, + @IWindowsService windowsService: IWindowsService, + @ILifecycleService lifecycleService: ILifecycleService, + @IExtensionService extensionService: IExtensionService, + @IEnvironmentService environmentService: IEnvironmentService, + ) { + + let appendTo = environmentService.args['prof-append-timers']; + if (!appendTo) { + return; + } + + Promise.all([ + lifecycleService.when(LifecyclePhase.Eventually), + extensionService.whenInstalledExtensionsRegistered() + ]).then(() => { + const { startupMetrics } = timerService; + return nfcall(appendFile, appendTo, `${Date.now()}\t${startupMetrics.ellapsed}\n`); + }).then(() => { + windowsService.quit(); + }).catch(err => { + console.error(err); + windowsService.quit(); + }); + } +} + +const registry = Registry.as(Extensions.Workbench); +registry.registerWorkbenchContribution(StartupTimingsAppender, LifecyclePhase.Running);