提交 22e5e9fc 编写于 作者: J Johannes Rieken

add nodeCachedDataManager for telemetry and cleanup

上级 83b929e1
/*---------------------------------------------------------------------------------------------
* 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 { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { onUnexpectedError } from 'vs/base/common/errors';
import { TPromise } from 'vs/base/common/winjs.base';
import { dirname, join } from 'vs/base/common/paths';
import { readdir, rimraf } from 'vs/base/node/pfs';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
export class NodeCachedDataManager {
private _telemetryService: ITelemetryService;
private _environmentService: IEnvironmentService;
private _disposables: IDisposable[] = [];
constructor(
@ITelemetryService telemetryService: ITelemetryService,
@IEnvironmentService environmentService: IEnvironmentService
) {
this._telemetryService = telemetryService;
this._environmentService = environmentService;
this._handleCachedDataErrors();
this._manageCachedDataSoon();
}
dispose(): void {
this._disposables = dispose(this._disposables);
}
private _handleCachedDataErrors(): void {
const onNodeCachedDataError = (err) => {
this._telemetryService.publicLog('nodeCachedData', { errorCode: err.errorCode, path: err.path });
};
// handle future and past errors
(<any>self).require.config({ onNodeCachedDataError }, true);
(<any[]>(<any>window).MonacoEnvironment.nodeCachedDataErrors).forEach(onNodeCachedDataError);
delete (<any>window).MonacoEnvironment.nodeCachedDataErrors;
// stop when being disposed
this._disposables.push({
dispose() {
(<any>self).require.config({ onNodeCachedDataError: undefined }, true);
}
});
}
private _manageCachedDataSoon(): void {
// Cached data is stored as user data in directories like `CachedData/1.8.0`.
// This function makes sure to delete cached data from previous versions,
// like`CachedData/1.7.2`.
const {nodeCachedDataDir} = this._environmentService;
if (!nodeCachedDataDir) {
return;
}
let handle = setTimeout(() => {
handle = undefined;
const nodeCachedDataBase = dirname(nodeCachedDataDir);
readdir(nodeCachedDataBase).then(entries => {
const deletes = entries.map(entry => {
const path = join(nodeCachedDataBase, entry);
if (path !== nodeCachedDataDir) {
return rimraf(path);
}
});
return TPromise.join(deletes);
}).done(undefined, onUnexpectedError);
}, 3 * 1000);
this._disposables.push({
dispose() { clearTimeout(handle); }
});
}
}
......@@ -74,6 +74,7 @@ import { MainThreadModeServiceImpl } from 'vs/editor/common/services/modeService
import { IModeService } from 'vs/editor/common/services/modeService';
import { IUntitledEditorService, UntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
import { CrashReporter } from 'vs/workbench/electron-browser/crashReporter';
import { NodeCachedDataManager } from 'vs/workbench/electron-browser/nodeCachedDataManager';
import { IThemeService } from 'vs/workbench/services/themes/common/themeService';
import { ThemeService } from 'vs/workbench/services/themes/electron-browser/themeService';
import { getDelayedChannel } from 'vs/base/parts/ipc/common/ipc';
......@@ -169,7 +170,12 @@ export class WorkbenchShell {
this.workbench = instantiationService.createInstance(Workbench, parent.getHTMLElement(), workbenchContainer.getHTMLElement(), this.workspace, this.options, serviceCollection);
this.workbench.startup({
onWorkbenchStarted: (customKeybindingsCount, restoreViewletDuration, restoreEditorsDuration) => {
// run workbench started logic
this.onWorkbenchStarted(customKeybindingsCount, restoreViewletDuration, restoreEditorsDuration);
// start cached data manager
instantiationService.createInstance(NodeCachedDataManager);
}
});
......@@ -276,12 +282,6 @@ export class WorkbenchShell {
const workspaceStats: WorkspaceStats = <WorkspaceStats>this.workbench.getInstantiationService().createInstance(WorkspaceStats);
workspaceStats.reportWorkspaceTags(this.options);
// Telemetry: node cached data error
const onNodeCachedDataError = (err) => { this.telemetryService.publicLog('nodeCachedData', { errorCode: err.errorCode, path: err.path }); };
(<any>self).require.config({ onNodeCachedDataError }, true);
(<any[]>(<any>window).MonacoEnvironment.nodeCachedDataErrors).forEach(onNodeCachedDataError);
delete (<any>window).MonacoEnvironment.nodeCachedDataErrors;
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'."));
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册