From 3b6d8a3185fc9291c348f2472f56d99dfd91edc5 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Thu, 18 May 2017 12:04:38 +0200 Subject: [PATCH] move startup profiler into perf.contrib --- src/vs/workbench/electron-browser/shell.ts | 34 -------- .../performance.contribution.ts | 81 ++++++++++++++++--- 2 files changed, 70 insertions(+), 45 deletions(-) diff --git a/src/vs/workbench/electron-browser/shell.ts b/src/vs/workbench/electron-browser/shell.ts index ef12343f326..59955d70049 100644 --- a/src/vs/workbench/electron-browser/shell.ts +++ b/src/vs/workbench/electron-browser/shell.ts @@ -16,7 +16,6 @@ import aria = require('vs/base/browser/ui/aria/aria'); import { dispose, IDisposable, Disposables } from 'vs/base/common/lifecycle'; import errors = require('vs/base/common/errors'); import { toErrorMessage } from 'vs/base/common/errorMessage'; -import { stopProfiling } from 'vs/base/node/profiler'; import product from 'vs/platform/node/product'; import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'; import pkg from 'vs/platform/node/package'; @@ -97,8 +96,6 @@ import { MainProcessTextMateSyntax } from 'vs/editor/electron-browser/textMate/T import { BareFontInfo } from 'vs/editor/common/config/fontInfo'; import { restoreFontInfo, readFontInfo, saveFontInfo } from 'vs/editor/browser/config/configuration'; import * as browser from 'vs/base/browser/browser'; -import { readdir } from 'vs/base/node/pfs'; -import { join } from 'path'; import 'vs/platform/opener/browser/opener.contribution'; import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService'; import { WorkbenchThemeService } from 'vs/workbench/services/themes/electron-browser/workbenchThemeService'; @@ -263,37 +260,6 @@ export class WorkbenchShell { if ((platform.isLinux || platform.isMacintosh) && process.getuid() === 0) { this.messageService.show(Severity.Warning, nls.localize('runningAsRoot', "It is recommended not to run Code as 'root'.")); } - - // Profiler: startup cpu profile - const { profileStartup } = this.environmentService; - if (profileStartup) { - this.extensionService.onReady().then(() => stopProfiling(profileStartup.dir, profileStartup.prefix)).then(() => { - readdir(profileStartup.dir).then(files => { - return files.filter(value => value.indexOf(profileStartup.prefix) === 0); - }).then(files => { - const profileFiles = files.reduce((prev, cur) => `${prev}${join(profileStartup.dir, cur)}\n`, '\n'); - - const primaryButton = this.messageService.confirm({ - type: 'info', - message: nls.localize('prof.message', "Successfully created profiles."), - detail: nls.localize('prof.detail', "Please create an issue and manually attach the following files:\n{0}", profileFiles), - primaryButton: nls.localize('prof.restartAndFileIssue', "Create Issue and Restart"), - secondaryButton: nls.localize('prof.restart', "Restart") - }); - - let createIssue = TPromise.as(void 0); - if (primaryButton) { - const action = this.workbench.getInstantiationService().createInstance(ReportPerformanceIssueAction, ReportPerformanceIssueAction.ID, ReportPerformanceIssueAction.LABEL); - - createIssue = action.run(`:warning: Make sure to **attach** these files: :warning:\n${files.map(file => `-\`${join(profileStartup.dir, file)}\``).join('\n')}`).then(() => { - return this.windowsService.showItemInFolder(join(profileStartup.dir, files[0])); - }); - } - createIssue.then(() => this.windowsService.relaunch({ removeArgs: ['--prof-startup'] })); - }); - - }, err => console.error(err)); - } } private handleNegativePerformanceNumbers(i: IInstantiationService, time: number): void { 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 f7b481f4c50..393dc2a5dc9 100644 --- a/src/vs/workbench/parts/performance/electron-browser/performance.contribution.ts +++ b/src/vs/workbench/parts/performance/electron-browser/performance.contribution.ts @@ -5,19 +5,25 @@ 'use strict'; -import { localize } from 'vs/nls'; -import { virtualMachineHint } from 'vs/base/node/id'; -import { Registry } from 'vs/platform/platform'; -import { IWindowsService } from 'vs/platform/windows/common/windows'; -import { IEnvironmentService } from 'vs/platform/environment/common/environment'; -import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage'; -import { IMessageService } from 'vs/platform/message/common/message'; -import { ITimerService } from 'vs/workbench/services/timer/common/timerService'; -import { IWorkbenchContributionsRegistry, IWorkbenchContribution, Extensions } from 'vs/workbench/common/contributions'; import product from 'vs/platform/node/product'; +import { IEnvironmentService } from 'vs/platform/environment/common/environment'; +import { IExtensionService } from 'vs/platform/extensions/common/extensions'; +import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; +import { IMessageService } from 'vs/platform/message/common/message'; +import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage'; +import { ITimerService } from 'vs/workbench/services/timer/common/timerService'; +import { IWindowsService } from 'vs/platform/windows/common/windows'; +import { IWorkbenchContributionsRegistry, IWorkbenchContribution, Extensions } from 'vs/workbench/common/contributions'; +import { Registry } from 'vs/platform/platform'; +import { ReportPerformanceIssueAction } from 'vs/workbench/electron-browser/actions'; +import { TPromise } from 'vs/base/common/winjs.base'; +import { join } from 'path'; +import { localize } from 'vs/nls'; import { platform, Platform } from 'vs/base/common/platform'; +import { readdir } from 'vs/base/node/pfs'; import { release } from 'os'; - +import { stopProfiling } from 'vs/base/node/profiler'; +import { virtualMachineHint } from 'vs/base/node/id'; class ProfilingHint implements IWorkbenchContribution { @@ -73,7 +79,7 @@ class ProfilingHint implements IWorkbenchContribution { } getId(): string { - return 'performance'; + return 'performance.ProfilingHint'; } private _checkTimersAndSuggestToProfile() { @@ -131,5 +137,58 @@ class ProfilingHint implements IWorkbenchContribution { } } +class StartupProfiler implements IWorkbenchContribution { + + constructor( + @IWindowsService private readonly _windowsService: IWindowsService, + @IMessageService private readonly _messageService: IMessageService, + @IEnvironmentService private readonly _environmentService: IEnvironmentService, + @IInstantiationService private readonly _instantiationService: IInstantiationService, + @IExtensionService extensionService: IExtensionService, + ) { + + extensionService.onReady().then(() => this._stopProfiling()); + } + + getId(): string { + return 'performance.StartupProfiler'; + } + + private _stopProfiling(): void { + + const { profileStartup } = this._environmentService; + if (!profileStartup) { + return; + } + + stopProfiling(profileStartup.dir, profileStartup.prefix).then(() => { + readdir(profileStartup.dir).then(files => { + return files.filter(value => value.indexOf(profileStartup.prefix) === 0); + }).then(files => { + const profileFiles = files.reduce((prev, cur) => `${prev}${join(profileStartup.dir, cur)}\n`, '\n'); + + const primaryButton = this._messageService.confirm({ + type: 'info', + message: localize('prof.message', "Successfully created profiles."), + detail: localize('prof.detail', "Please create an issue and manually attach the following files:\n{0}", profileFiles), + primaryButton: localize('prof.restartAndFileIssue', "Create Issue and Restart"), + secondaryButton: localize('prof.restart', "Restart") + }); + + let createIssue = TPromise.as(void 0); + if (primaryButton) { + const action = this._instantiationService.createInstance(ReportPerformanceIssueAction, ReportPerformanceIssueAction.ID, ReportPerformanceIssueAction.LABEL); + + createIssue = action.run(`:warning: Make sure to **attach** these files: :warning:\n${files.map(file => `-\`${join(profileStartup.dir, file)}\``).join('\n')}`).then(() => { + return this._windowsService.showItemInFolder(join(profileStartup.dir, files[0])); + }); + } + createIssue.then(() => this._windowsService.relaunch({ removeArgs: ['--prof-startup'] })); + }); + }); + } +} + const registry = Registry.as(Extensions.Workbench); registry.registerWorkbenchContribution(ProfilingHint); +registry.registerWorkbenchContribution(StartupProfiler);