Skip to content

Commit b55a31a

Browse files
authored
Add torch.profiler submodule telemetry (microsoft#15830)
1 parent 126d096 commit b55a31a

5 files changed

Lines changed: 14 additions & 1 deletion

File tree

news/3 Code Health/15825.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add telemetry for identifying torch.profiler users.

src/client/telemetry/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export enum EventName {
135135
TENSORBOARD_INSTALL_PROMPT_SELECTION = 'TENSORBOARD.INSTALL_PROMPT_SELECTION',
136136
TENSORBOARD_DETECTED_IN_INTEGRATED_TERMINAL = 'TENSORBOARD_DETECTED_IN_INTEGRATED_TERMINAL',
137137
TENSORBOARD_PACKAGE_INSTALL_RESULT = 'TENSORBOARD.PACKAGE_INSTALL_RESULT',
138+
TENSORBOARD_TORCH_PROFILER_IMPORT = 'TENSORBOARD.TORCH_PROFILER_IMPORT',
138139
}
139140

140141
export enum PlatformErrors {

src/client/telemetry/importTracker.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { isTestExecution } from '../common/constants';
1414
import '../common/extensions';
1515
import { IDisposableRegistry } from '../common/types';
1616
import { noop } from '../common/utils/misc';
17+
import { TorchProfilerImportRegEx } from '../tensorBoard/helpers';
1718
import { EventName } from './constants';
1819

1920
/*
@@ -139,6 +140,9 @@ export class ImportTracker implements IExtensionSingleActivationService {
139140
packageNames.forEach((p) => this.sendTelemetry(p));
140141
}
141142
}
143+
if (s && TorchProfilerImportRegEx.test(s)) {
144+
sendTelemetryEvent(EventName.TENSORBOARD_TORCH_PROFILER_IMPORT);
145+
}
142146
}
143147
} catch {
144148
// Don't care about failures since this is just telemetry.

src/client/telemetry/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,4 +1816,11 @@ export interface IEventNamePropertyMapping {
18161816
wasProfilerPluginInstalled: boolean;
18171817
wasTensorBoardInstalled: boolean;
18181818
};
1819+
/**
1820+
* Telemetry event sent when the user's files contain a PyTorch profiler module
1821+
* import. Files are checked for matching imports when they are opened or saved.
1822+
* Matches cover import statements of the form `import torch.profiler` and
1823+
* `from torch import profiler`.
1824+
*/
1825+
[EventName.TENSORBOARD_TORCH_PROFILER_IMPORT]: never | undefined;
18191826
}

src/client/tensorBoard/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { noop } from '../common/utils/misc';
1010
// matches the 'main' module.
1111

1212
// RegEx to match `import torch.profiler` or `from torch import profiler`
13-
const TorchProfilerImportRegEx = /^\s*(?:import (?:(\w+, )*torch\.profiler(, \w+)*))|(?:from torch import (?:(\w+, )*profiler(, \w+)*))/;
13+
export const TorchProfilerImportRegEx = /^\s*(?:import (?:(\w+, )*torch\.profiler(, \w+)*))|(?:from torch import (?:(\w+, )*profiler(, \w+)*))/;
1414
// RegEx to match `from torch.utils import tensorboard`, `import torch.utils.tensorboard`, `import tensorboardX`, `import tensorboard`
1515
const TensorBoardImportRegEx = /^\s*(?:from torch\.utils\.tensorboard import \w+)|(?:from torch\.utils import (?:(\w+, )*tensorboard(, \w+)*))|(?:from tensorboardX import \w+)|(?:import (\w+, )*((torch\.utils\.tensorboard)|(tensorboardX)|(tensorboard))(, \w+)*)/;
1616

0 commit comments

Comments
 (0)