Skip to content

Commit bb596c6

Browse files
authored
Track TensorBoard usage in integrated terminals (#15125)
1 parent 4c0c642 commit bb596c6

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

src/client/telemetry/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ export enum EventName {
130130
TENSORBOARD_INSTALL_PROMPT_SELECTION = 'TENSORBOARD.INSTALL_PROMPT_SELECTION',
131131
TENSORBOARD_IMPORT_CODEACTION_CLICKED = 'TENSORBOARD_IMPORT_CODEACTION_SHOWN',
132132
TENSORBOARD_IMPORT_CODELENS_CLICKED = 'TENSORBOARD_IMPORT_CODELENS_SHOWN',
133+
TENSORBOARD_DETECTED_IN_INTEGRATED_TERMINAL = 'TENSORBOARD_DETECTED_IN_INTEGRATED_TERMINAL',
133134
}
134135

135136
export enum PlatformErrors {

src/client/telemetry/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,4 +1813,8 @@ export interface IEventNamePropertyMapping {
18131813
* Used for A/B testing codeaction vs codelens.
18141814
*/
18151815
[EventName.TENSORBOARD_IMPORT_CODELENS_CLICKED]: never | undefined;
1816+
/**
1817+
* Telemetry event sent when we find an active integrated terminal running tensorboard.
1818+
*/
1819+
[EventName.TENSORBOARD_DETECTED_IN_INTEGRATED_TERMINAL]: never | undefined;
18161820
}

src/client/tensorBoard/serviceRegistry.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { TensorBoardUsageTracker } from './tensorBoardUsageTracker';
1010
import { TensorBoardPrompt } from './tensorBoardPrompt';
1111
import { TensorBoardSessionProvider } from './tensorBoardSessionProvider';
1212
import { TensorBoardNbextensionCodeLensProvider } from './nbextensionCodeLensProvider';
13+
import { TerminalWatcher } from './terminalWatcher';
1314

1415
export function registerTypes(serviceManager: IServiceManager): void {
1516
serviceManager.addSingleton<TensorBoardSessionProvider>(TensorBoardSessionProvider, TensorBoardSessionProvider);
@@ -35,4 +36,5 @@ export function registerTypes(serviceManager: IServiceManager): void {
3536
IExtensionSingleActivationService,
3637
TensorBoardCodeActionProvider,
3738
);
39+
serviceManager.addSingleton(IExtensionSingleActivationService, TerminalWatcher);
3840
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { inject, injectable } from 'inversify';
2+
import { window } from 'vscode';
3+
import { IExtensionSingleActivationService } from '../activation/types';
4+
import { IDisposable, IDisposableRegistry } from '../common/types';
5+
import { sendTelemetryEvent } from '../telemetry';
6+
import { EventName } from '../telemetry/constants';
7+
8+
// Every 5 min look, through active terminals to see if any are running `tensorboard`
9+
@injectable()
10+
export class TerminalWatcher implements IExtensionSingleActivationService, IDisposable {
11+
private handle: NodeJS.Timeout | undefined;
12+
13+
constructor(@inject(IDisposableRegistry) private disposables: IDisposableRegistry) {}
14+
15+
public async activate(): Promise<void> {
16+
const handle = setInterval(() => {
17+
// When user runs a command in VSCode terminal, the terminal's name
18+
// becomes the program that is currently running. Since tensorboard
19+
// stays running in the terminal while the webapp is running and
20+
// until the user kills it, the terminal with the updated name should
21+
// stick around for long enough that we only need to run this check
22+
// every 5 min or so
23+
const matches = window.terminals.filter((terminal) => terminal.name === 'tensorboard');
24+
if (matches.length > 0) {
25+
sendTelemetryEvent(EventName.TENSORBOARD_DETECTED_IN_INTEGRATED_TERMINAL);
26+
clearInterval(handle); // Only need telemetry sent once per VS Code session
27+
}
28+
}, 300_000);
29+
this.handle = handle;
30+
this.disposables.push(this);
31+
}
32+
33+
public dispose(): void {
34+
if (this.handle) {
35+
clearInterval(this.handle);
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)