From ebd2e2e57d657b66650bda128ac9891efe58cec9 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Wed, 26 Oct 2016 18:10:55 +0200 Subject: [PATCH] log save participant timings, #13492 --- src/vs/workbench/api/node/extHost.protocol.ts | 2 +- .../api/node/mainThreadSaveParticipant.ts | 29 ++++++++++++++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/vs/workbench/api/node/extHost.protocol.ts b/src/vs/workbench/api/node/extHost.protocol.ts index fe0a73be762..1938377959b 100644 --- a/src/vs/workbench/api/node/extHost.protocol.ts +++ b/src/vs/workbench/api/node/extHost.protocol.ts @@ -235,7 +235,7 @@ export abstract class ExtHostDocumentsShape { } export abstract class ExtHostDocumentSaveParticipantShape { - $participateInSave(resource: URI, reason: SaveReason): TPromise { throw ni(); } + $participateInSave(resource: URI, reason: SaveReason): TPromise { throw ni(); } } export interface ITextEditorAddData { diff --git a/src/vs/workbench/api/node/mainThreadSaveParticipant.ts b/src/vs/workbench/api/node/mainThreadSaveParticipant.ts index 997c2da82ee..fcee60aee33 100644 --- a/src/vs/workbench/api/node/mainThreadSaveParticipant.ts +++ b/src/vs/workbench/api/node/mainThreadSaveParticipant.ts @@ -11,6 +11,7 @@ import { ICodeEditorService } from 'vs/editor/common/services/codeEditorService' import { IThreadService } from 'vs/workbench/services/thread/common/threadService'; import { ISaveParticipant, ITextFileEditorModel, SaveReason } from 'vs/workbench/services/textfile/common/textfiles'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; +import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { IPosition, IModel, ICommonCodeEditor, ISingleEditOperation, IIdentifiedSingleEditOperation } from 'vs/editor/common/editorCommon'; import { Range } from 'vs/editor/common/core/range'; import { Selection } from 'vs/editor/common/core/selection'; @@ -97,7 +98,7 @@ class FormatOnSaveParticipant implements ISaveParticipant { const {tabSize, insertSpaces} = model.getOptions(); return new TPromise((resolve, reject) => { - setTimeout(resolve, 750); + setTimeout(reject, 750); getDocumentFormattingEdits(model, { tabSize, insertSpaces }).then(resolve, reject); }).then(edits => { @@ -167,7 +168,13 @@ class ExtHostSaveParticipant implements ISaveParticipant { } participate(editorModel: ITextFileEditorModel, env: { reason: SaveReason }): TPromise { - return this._proxy.$participateInSave(editorModel.getResource(), env.reason); + return this._proxy.$participateInSave(editorModel.getResource(), env.reason).then(values => { + for (const success of values) { + if (!success) { + return TPromise.wrapError('listener failed'); + } + } + }); } } @@ -177,6 +184,7 @@ export class SaveParticipant implements ISaveParticipant { private _saveParticipants: ISaveParticipant[]; constructor( + @ITelemetryService private _telemetryService: ITelemetryService, @IInstantiationService instantiationService: IInstantiationService, @IThreadService threadService: IThreadService ) { @@ -191,11 +199,24 @@ export class SaveParticipant implements ISaveParticipant { TextFileEditorModel.setSaveParticipant(this); } participate(model: ITextFileEditorModel, env: { reason: SaveReason }): TPromise { + + const stats: { [name: string]: number } = Object.create(null); + const promiseFactory = this._saveParticipants.map(p => () => { - return TPromise.as(p.participate(model, env)).then(undefined, err => { + + const {name} = Object.getPrototypeOf(p).constructor; + const t1 = Date.now(); + + return TPromise.as(p.participate(model, env)).then(() => { + stats[`Success-${name}`] = Date.now() - t1; + }, err => { + stats[`Failure-${name}`] = Date.now() - t1; // console.error(err); }); }); - return sequence(promiseFactory); + + return sequence(promiseFactory).then(() => { + this._telemetryService.publicLog('saveParticipantTimes', stats); + }); } } -- GitLab