send telemetry about git-exec duration (#162731)

* send telemetry about git-exec duration

* measure spawn and exec
This commit is contained in:
Johannes Rieken
2022-10-06 13:04:35 +02:00
committed by GitHub
parent 8245b4770a
commit b2b7e0be6e
2 changed files with 21 additions and 4 deletions

View File

@@ -18,6 +18,7 @@ import { detectEncoding } from './encoding';
import { Ref, RefType, Branch, Remote, ForcePushMode, GitErrorCodes, LogOptions, Change, Status, CommitOptions, BranchQuery } from './api/git';
import * as byline from 'byline';
import { StringDecoder } from 'string_decoder';
import TelemetryReporter from '@vscode/extension-telemetry';
// https://github.com/microsoft/vscode/issues/65693
const MAX_CLI_LENGTH = 30000;
@@ -373,11 +374,14 @@ export class Git {
private _onOutput = new EventEmitter();
get onOutput(): EventEmitter { return this._onOutput; }
constructor(options: IGitOptions) {
private readonly telemetryReporter: TelemetryReporter;
constructor(options: IGitOptions, telemetryReporter: TelemetryReporter) {
this.path = options.gitPath;
this.version = options.version;
this.userAgent = options.userAgent;
this.env = options.env || {};
this.telemetryReporter = telemetryReporter;
const onConfigurationChanged = (e?: ConfigurationChangeEvent) => {
if (e !== undefined && !e.affectsConfiguration('git.commandsToLog')) {
@@ -555,7 +559,9 @@ export class Git {
}
private async _exec(args: string[], options: SpawnOptions = {}): Promise<IExecutionResult<string>> {
const startSpawn = Date.now();
const child = this.spawn(args, options);
const durSpawn = Date.now() - startSpawn;
options.onSpawn?.(child);
@@ -563,12 +569,13 @@ export class Git {
child.stdin!.end(options.input, 'utf8');
}
const startTime = Date.now();
const startExec = Date.now();
const bufferResult = await exec(child, options.cancellationToken);
const durExec = Date.now() - startExec;
if (options.log !== false) {
// command
this.log(`> git ${args.join(' ')} [${Date.now() - startTime}ms]\n`);
this.log(`> git ${args.join(' ')} [${durExec}ms]\n`);
// stdout
if (bufferResult.stdout.length > 0 && args.find(a => this.commandsToLog.includes(a))) {
@@ -581,6 +588,16 @@ export class Git {
}
}
/* __GDPR__
"git.execDuration" : {
"owner": "lszomoru",
"comment": "Time it takes to spawn and execute a git command",
"durSpawn": { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth","isMeasurement": true, "comment": "Time it took to run spawn git" },
"durExec": { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth","isMeasurement": true, "comment": "Time git took" },
}
*/
this.telemetryReporter.sendTelemetryEvent('git.execDuration', undefined, { durSpawn, durExec });
let encoding = options.encoding || 'utf8';
encoding = iconv.encodingExists(encoding) ? encoding : 'utf8';

View File

@@ -89,7 +89,7 @@ async function createModel(context: ExtensionContext, outputChannelLogger: Outpu
userAgent: `git/${info.version} (${(os as any).version?.() ?? os.type()} ${os.release()}; ${os.platform()} ${os.arch()}) vscode/${vscodeVersion} (${env.appName})`,
version: info.version,
env: environment,
});
}, telemetryReporter);
const model = new Model(git, askpass, context.globalState, outputChannelLogger, telemetryReporter);
disposables.push(model);