Skip to content

Commit 5da2bd6

Browse files
authored
Telemetry: log command execution time
Monitoring execution time can be useful when investigating performance issues and detecting performance regressions. VS Code already logs the extension activation times (ExtensionActivationTimesClassification). Logging command execution times seems consistent.
1 parent 08baa8a commit 5da2bd6

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/vs/workbench/api/common/extHostCommands.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ export class ExtHostCommands implements ExtHostCommandsShape {
224224
if (!command) {
225225
throw new Error('Unknown command');
226226
}
227-
this._reportTelemetry(command, id);
228227
const { callback, thisArg, description } = command;
229228
if (description) {
230229
for (let i = 0; i < description.args.length; i++) {
@@ -236,9 +235,13 @@ export class ExtHostCommands implements ExtHostCommandsShape {
236235
}
237236
}
238237

238+
const start = Date.now();
239239
try {
240-
return await callback.apply(thisArg, args);
240+
const result = await callback.apply(thisArg, args);
241+
this._reportTelemetry(command, id, Date.now() - start);
242+
return result;
241243
} catch (err) {
244+
this._reportTelemetry(command, id, Date.now() - start);
242245
// The indirection-command from the converter can fail when invoking the actual
243246
// command and in that case it is better to blame the correct command
244247
if (id === this.converter.delegatingCommandId) {
@@ -263,23 +266,26 @@ export class ExtHostCommands implements ExtHostCommandsShape {
263266
}
264267
}
265268

266-
private _reportTelemetry(command: CommandHandler, id: string) {
269+
private _reportTelemetry(command: CommandHandler, id: string, duration: number) {
267270
if (!command.extension || command.extension.isBuiltin) {
268271
return;
269272
}
270273
type ExtensionActionTelemetry = {
271274
extensionId: string;
272275
id: string;
276+
duration: number;
273277
};
274278
type ExtensionActionTelemetryMeta = {
275279
extensionId: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'The id of the extension handling the command, informing which extensions provide most-used functionality.' };
276280
id: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'The id of the command, to understand which specific extension features are most popular.' };
281+
duration: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'The duration of the command execution, to detect performance issues' };
277282
owner: 'digitarald';
278283
comment: 'Used to gain insight on the most popular commands used from extensions';
279284
};
280285
this.#telemetry.$publicLog2<ExtensionActionTelemetry, ExtensionActionTelemetryMeta>('Extension:ActionExecuted', {
281286
extensionId: command.extension.identifier.value,
282287
id: id,
288+
duration: duration,
283289
});
284290
}
285291

0 commit comments

Comments
 (0)