add logic to suggest to profile
This commit is contained in:
parent
b76c8bea27
commit
a050410a77
|
@ -5,15 +5,19 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
import { localize } from 'vs/nls';
|
||||||
import { assign } from 'vs/base/common/objects';
|
import { assign } from 'vs/base/common/objects';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { generateUuid } from 'vs/base/common/uuid';
|
import { generateUuid } from 'vs/base/common/uuid';
|
||||||
|
import { virtualMachineHint } from 'vs/base/node/id';
|
||||||
import { TPromise } from 'vs/base/common/winjs.base';
|
import { TPromise } from 'vs/base/common/winjs.base';
|
||||||
import { Registry } from 'vs/platform/platform';
|
import { Registry } from 'vs/platform/platform';
|
||||||
import { writeFile } from 'vs/base/node/pfs';
|
import { writeFile } from 'vs/base/node/pfs';
|
||||||
import { IWindowsService } from 'vs/platform/windows/common/windows';
|
import { IWindowsService } from 'vs/platform/windows/common/windows';
|
||||||
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
|
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||||
|
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
|
||||||
import { IExtensionService } from 'vs/platform/extensions/common/extensions';
|
import { IExtensionService } from 'vs/platform/extensions/common/extensions';
|
||||||
|
import { IMessageService } from 'vs/platform/message/common/message';
|
||||||
import { ITimerService } from 'vs/workbench/services/timer/common/timerService';
|
import { ITimerService } from 'vs/workbench/services/timer/common/timerService';
|
||||||
import { IWorkbenchContributionsRegistry, IWorkbenchContribution, Extensions } from 'vs/workbench/common/contributions';
|
import { IWorkbenchContributionsRegistry, IWorkbenchContribution, Extensions } from 'vs/workbench/common/contributions';
|
||||||
import product from 'vs/platform/node/product';
|
import product from 'vs/platform/node/product';
|
||||||
|
@ -23,17 +27,25 @@ class PerformanceContribution implements IWorkbenchContribution {
|
||||||
constructor(
|
constructor(
|
||||||
@IWindowsService private _windowsService: IWindowsService,
|
@IWindowsService private _windowsService: IWindowsService,
|
||||||
@ITimerService private _timerService: ITimerService,
|
@ITimerService private _timerService: ITimerService,
|
||||||
@IEnvironmentService envService: IEnvironmentService,
|
@IMessageService private _messageService: IMessageService,
|
||||||
@IExtensionService extensionService: IExtensionService
|
@IEnvironmentService private _envService: IEnvironmentService,
|
||||||
|
@IStorageService private _storageService: IStorageService,
|
||||||
|
@IExtensionService extensionService: IExtensionService,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
const dumpFile = envService.args['prof-startup-timers'];
|
const dumpFile = _envService.args['prof-startup-timers'];
|
||||||
if (dumpFile) {
|
if (dumpFile) {
|
||||||
// wait for extensions being loaded
|
// wait for extensions being loaded
|
||||||
extensionService.onReady()
|
extensionService.onReady()
|
||||||
.then(() => TPromise.timeout(15000)) // time service isn't ready yet because it listens on the same event...
|
.then(() => TPromise.timeout(15000)) // time service isn't ready yet because it listens on the same event...
|
||||||
.then(() => this._dumpTimersAndQuit(dumpFile))
|
.then(() => this._dumpTimersAndQuit(dumpFile))
|
||||||
.done(undefined, err => console.error(err));
|
.done(undefined, err => console.error(err));
|
||||||
|
|
||||||
|
} else if (!_envService.args['performance-startup-profile']) {
|
||||||
|
// notify user of slow start
|
||||||
|
setTimeout(() => {
|
||||||
|
this._checkTimersAndSuggestToProfile();
|
||||||
|
}, 5000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,6 +60,38 @@ class PerformanceContribution implements IWorkbenchContribution {
|
||||||
const raw = JSON.stringify(all);
|
const raw = JSON.stringify(all);
|
||||||
return writeFile(join(folder, `timers-${id}.json`), raw).then(() => this._windowsService.quit());
|
return writeFile(join(folder, `timers-${id}.json`), raw).then(() => this._windowsService.quit());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _checkTimersAndSuggestToProfile() {
|
||||||
|
|
||||||
|
//TODO(joh) use better heuristics (70th percentile, not vm, etc)
|
||||||
|
|
||||||
|
const value = this._storageService.get(this.getId(), StorageScope.GLOBAL, undefined);
|
||||||
|
if (value !== undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (virtualMachineHint.value() >= .5) {
|
||||||
|
//
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { ellapsed } = this._timerService.startupMetrics;
|
||||||
|
if (ellapsed > 5000 && Math.ceil(Math.random() * 10) % 3 === 0) {
|
||||||
|
const profile = this._messageService.confirm({
|
||||||
|
type: 'info',
|
||||||
|
message: localize('slow', "Slow startup detected"),
|
||||||
|
detail: localize('slow.detail', "Sorry that you just had a slow startup. Please restart '{0}' with profiling enabled, share the profiles with us, and we will work hard to make startup great again.", this._envService.appNameLong),
|
||||||
|
primaryButton: 'Restart and profile'
|
||||||
|
});
|
||||||
|
|
||||||
|
if (profile) {
|
||||||
|
this._storageService.store(this.getId(), 'didProfile', StorageScope.GLOBAL);
|
||||||
|
this._windowsService.relaunch({ addArgs: ['--performance-startup-profile'] });
|
||||||
|
} else {
|
||||||
|
this._storageService.store(this.getId(), 'didReject', StorageScope.GLOBAL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const registry = Registry.as<IWorkbenchContributionsRegistry>(Extensions.Workbench);
|
const registry = Registry.as<IWorkbenchContributionsRegistry>(Extensions.Workbench);
|
||||||
|
|
Loading…
Reference in a new issue