Skip to content

Commit

Permalink
log some localStorage perf counters (for #18439)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Jan 18, 2018
1 parent a010ff7 commit 67051d0
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/vs/platform/storage/common/storageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import types = require('vs/base/common/types');
import errors = require('vs/base/common/errors');
import strings = require('vs/base/common/strings');
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import * as perf from 'vs/base/common/performance';

// Browser localStorage interface
export interface IStorage {
Expand Down Expand Up @@ -89,7 +90,9 @@ export class StorageService implements IStorageService {
private cleanupWorkspaceScope(workspaceUid: number): void {

// Get stored identifier from storage
perf.mark('willReadWorkspaceIdentifier');
const id = this.getInteger(StorageService.WORKSPACE_IDENTIFIER, StorageScope.WORKSPACE);
perf.mark('didReadWorkspaceIdentifier');

// If identifier differs, assume the workspace got recreated and thus clean all storage for this workspace
if (types.isNumber(id) && workspaceUid !== id) {
Expand Down
14 changes: 11 additions & 3 deletions src/vs/workbench/electron-browser/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { IWindowConfiguration, IWindowsService } from 'vs/platform/windows/commo
import { WindowsChannelClient } from 'vs/platform/windows/common/windowsIpc';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { StorageService, inMemoryLocalStorageInstance } from 'vs/platform/storage/common/storageService';
import { StorageService, inMemoryLocalStorageInstance, IStorage } from 'vs/platform/storage/common/storageService';
import { Client as ElectronIPCClient } from 'vs/base/parts/ipc/electron-browser/ipc.electron-browser';
import { webFrame } from 'electron';
import { UpdateChannelClient } from 'vs/platform/update/common/updateIpc';
Expand Down Expand Up @@ -82,7 +82,6 @@ function openWorkbench(configuration: IWindowConfiguration): TPromise<void> {
// Since the configuration service is one of the core services that is used in so many places, we initialize it
// right before startup of the workbench shell to have its data ready for consumers
return createAndInitializeWorkspaceService(configuration, environmentService).then(workspaceService => {

const timerService = new TimerService((<any>window).MonacoEnvironment.timers as IInitData, workspaceService.getWorkbenchState() === WorkbenchState.EMPTY);
const storageService = createStorageService(workspaceService, environmentService);

Expand Down Expand Up @@ -185,7 +184,16 @@ function createStorageService(workspaceService: IWorkspaceContextService, enviro
}

const disableStorage = !!environmentService.extensionTestsPath; // never keep any state when running extension tests!
const storage = disableStorage ? inMemoryLocalStorageInstance : window.localStorage;

let storage: IStorage;
if (disableStorage) {
storage = inMemoryLocalStorageInstance;
} else {
// TODO@Ben remove me after a while
perf.mark('willAccessLocalStorage');
storage = window.localStorage;
perf.mark('didAccessLocalStorage');
}

return new StorageService(storage, storage, workspaceId, secondaryWorkspaceId);
}
Expand Down
38 changes: 38 additions & 0 deletions src/vs/workbench/electron-browser/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ import { IBroadcastService, BroadcastService } from 'vs/platform/broadcast/elect
import { HashService } from 'vs/workbench/services/hash/node/hashService';
import { IHashService } from 'vs/workbench/services/hash/common/hashService';
import { ILogService } from 'vs/platform/log/common/log';
import { stat } from 'fs';
import { join } from 'path';

/**
* Services that we require for the Shell
Expand Down Expand Up @@ -206,6 +208,11 @@ export class WorkbenchShell {
}
}
});

// localStorage metrics (TODO@Ben remove me later)
if (!this.environmentService.extensionTestsPath && this.contextService.getWorkbenchState() === WorkbenchState.FOLDER) {
this.logLocalStorageMetrics();
}
});

return workbench;
Expand Down Expand Up @@ -274,6 +281,37 @@ export class WorkbenchShell {
});
}

private logLocalStorageMetrics(): void {
perf.mark('willReadLocalStorage');
if (!this.storageService.getBoolean('localStorageMetricsSent')) {
perf.mark('didReadLocalStorage');

perf.mark('willWriteLocalStorage');
this.storageService.store('localStorageMetricsSent', true);

stat(join(this.environmentService.userDataPath, 'Local Storage', 'file__0.localstorage'), (error, stat) => {
/* __GDPR__
"localStorageMetrics" : {
"accessTime" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
"firstReadTime" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
"subsequentReadTime" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
"writeTime" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
"keys" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
"size": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
}
*/
this.telemetryService.publicLog('localStorageMetrics', {
'accessTime': perf.getDuration('willAccessLocalStorage', 'didAccessLocalStorage'),
'firstReadTime': perf.getDuration('willReadWorkspaceIdentifier', 'didReadWorkspaceIdentifier'),
'subsequentReadTime': perf.getDuration('willReadLocalStorage', 'didReadLocalStorage'),
'writeTime': perf.getDuration('willWriteLocalStorage', 'willComputeLocalStorageSize'),
'keys': window.localStorage.length,
'size': stat ? stat.size : -1
});
});
}
}

private initServiceCollection(container: HTMLElement): [IInstantiationService, ServiceCollection] {
const serviceCollection = new ServiceCollection();
serviceCollection.set(IWorkspaceContextService, this.contextService);
Expand Down

0 comments on commit 67051d0

Please sign in to comment.