Skip to content

Commit 3f033aa

Browse files
Send telemetry for OmniSharp server requests
1 parent 89377d1 commit 3f033aa

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

src/omnisharpMain.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export function activate(context: vscode.ExtensionContext): any {
8282
// stop server on deactivate
8383
disposables.push(new vscode.Disposable(() => {
8484
advisor.dispose();
85+
server.reportAndClearTelemetry();
8586
server.stop();
8687
}));
8788

src/omnisharpServer.ts

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class Delays {
6666
nonFocusDelays: number = 0; // 1501-3000 milliseconds
6767
bigDelays: number = 0; // 3000+ milliseconds
6868

69-
public reportDelay(elapsedTime: number) {
69+
public report(elapsedTime: number) {
7070
if (elapsedTime <= 25) {
7171
this.immediateDelays += 1;
7272
}
@@ -89,12 +89,23 @@ class Delays {
8989
this.bigDelays += 1;
9090
}
9191
}
92+
93+
public toMeasures(): {[key: string]: number} {
94+
return {
95+
immedateDelays: this.immediateDelays,
96+
nearImmediateDelays: this.nearImmediateDelays,
97+
shortDelays: this.shortDelays,
98+
mediumDelays: this.mediumDelays,
99+
idleDelays: this.idleDelays,
100+
nonFocusDelays: this.nonFocusDelays
101+
};
102+
}
92103
}
93104

94105
export abstract class OmnisharpServer {
95106

96107
private _reporter: TelemetryReporter;
97-
private _requestDelays: { [path: string]: Delays } = {};
108+
private _telemetryDelays: { [path: string]: Delays };
98109

99110
private _eventBus = new EventEmitter();
100111
private _start: Promise<void>;
@@ -129,13 +140,24 @@ export abstract class OmnisharpServer {
129140
}
130141

131142
private _recordDelay(path: string, elapsedTime: number) {
132-
let delays = this._requestDelays[path];
143+
let delays = this._telemetryDelays[path];
133144
if (!delays) {
134145
delays = new Delays();
135-
this._requestDelays[path] = delays;
146+
this._telemetryDelays[path] = delays;
136147
}
137148

138-
delays.reportDelay(elapsedTime);
149+
delays.report(elapsedTime);
150+
}
151+
152+
public reportAndClearTelemetry() {
153+
for (var path in this._telemetryDelays) {
154+
const eventName = 'omnisharp' + path;
155+
const measures = this._telemetryDelays[path].toMeasures();
156+
157+
this._reporter.sendTelemetryEvent(eventName, null, measures);
158+
}
159+
160+
this._telemetryDelays = null;
139161
}
140162

141163
public getSolutionPathOrFolder(): string {
@@ -244,6 +266,7 @@ export abstract class OmnisharpServer {
244266

245267
return omnisharpLauncher(cwd, argv).then(value => {
246268
this._serverProcess = value.process;
269+
this._telemetryDelays = {};
247270
this._fireEvent(Events.StdOut, `[INFO] Started OmniSharp from '${value.command}' with process id ${value.process.pid}...\n`);
248271
this._fireEvent(Events.ServerStart, solutionPath);
249272
this._setState(ServerState.Started);
@@ -291,7 +314,7 @@ export abstract class OmnisharpServer {
291314
this._start = null;
292315
this._serverProcess = null;
293316
this._setState(ServerState.Stopped);
294-
this._fireEvent('ServerStop', this);
317+
this._fireEvent(Events.ServerStop, this);
295318
return;
296319
});
297320
}

0 commit comments

Comments
 (0)