Skip to content

Commit

Permalink
Add some telemetry to measure times to loading controllers (#9613)
Browse files Browse the repository at this point in the history
  • Loading branch information
DonJayamanne authored Apr 7, 2022
1 parent 9252659 commit 42e3f38
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
52 changes: 50 additions & 2 deletions src/notebooks/controllers/notebookControllerManager.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ export class NotebookControllerManager implements INotebookControllerManager, IE
private get isLocalLaunch(): boolean {
return isLocalLaunch(this.configuration);
}
private startTimeForFetchingControllers?: StopWatch;
private readonly controllerLoadingTelemetry = {
loadWithoutCacheSent: false,
loadWithCacheSent: false,
loadRemoteSent: false
};
private wasPythonInstalledWhenFetchingControllers?: boolean;
private interactiveNoPythonController?: NoPythonKernelsNotebookController;
private notebookNoPythonController?: NoPythonKernelsNotebookController;
Expand Down Expand Up @@ -204,10 +210,24 @@ export class NotebookControllerManager implements INotebookControllerManager, IE
// Find all the notebook controllers that we have registered
public async loadNotebookControllers(refresh?: boolean): Promise<void> {
if (!this.controllersPromise || refresh) {
this.startTimeForFetchingControllers = this.startTimeForFetchingControllers || new StopWatch();
const stopWatch = new StopWatch();

// Fetch the list of kernels ignoring the cache.
this.loadLocalNotebookControllersImpl('ignoreCache')
.then(() => {
if (!this.controllerLoadingTelemetry.loadWithoutCacheSent && this.startTimeForFetchingControllers) {
this.controllerLoadingTelemetry.loadWithoutCacheSent = true;
sendTelemetryEvent(
Telemetry.FetchControllers,
this.startTimeForFetchingControllers.elapsedTime,
{
firstTime: true,
kind: 'local'
}
);
}
})
.catch((ex) => traceError('Failed to fetch controllers without cache', ex))
.finally(() => {
this._controllersLoaded = true;
Expand Down Expand Up @@ -239,9 +259,37 @@ export class NotebookControllerManager implements INotebookControllerManager, IE
// Fetch kernel the fastest possible way (local kernels from cache but remote fetch latest).
// Fetch the list of kernels from the cache (note: if there's nothing in the case, it will fallback to searching).
// Fetching remote kernels cannot be done from cache.
const promises = [this.loadLocalNotebookControllersImpl('useCache')];
const promises = [
this.loadLocalNotebookControllersImpl('useCache').then(() => {
if (!this.controllerLoadingTelemetry.loadWithCacheSent && this.startTimeForFetchingControllers) {
this.controllerLoadingTelemetry.loadWithCacheSent = true;
sendTelemetryEvent(
Telemetry.FetchControllers,
this.startTimeForFetchingControllers.elapsedTime,
{
firstTime: false,
kind: 'local'
}
);
}
})
];
if (!this.isLocalLaunch) {
promises.push(this.loadRemoteNotebookControllersImpl());
promises.push(
this.loadRemoteNotebookControllersImpl().then(() => {
if (!this.controllerLoadingTelemetry.loadRemoteSent && this.startTimeForFetchingControllers) {
this.controllerLoadingTelemetry.loadRemoteSent = true;
sendTelemetryEvent(
Telemetry.FetchControllers,
this.startTimeForFetchingControllers.elapsedTime,
{
firstTime: true,
kind: 'remote'
}
);
}
})
);
}
this.controllersPromise = Promise.all(promises)
.then(() => noop())
Expand Down
14 changes: 14 additions & 0 deletions src/telemetry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1533,4 +1533,18 @@ export interface IEventNamePropertyMapping {
[Telemetry.KernelCrash]: never | undefined;
[Telemetry.JupyterKernelHiddenViaFilter]: never | undefined;
[Telemetry.JupyterKernelFilterUsed]: never | undefined;
/**
* Telemetry sent when we have loaded some controllers.
*/
[Telemetry.FetchControllers]: {
/**
* Whether this is the first time we're loading this (same as not using caches).
* In the case of remotes, this is always `true` (as we don't cache anything for remote kernels).
*/
firstTime: boolean;
/**
* Whether we've loaded local or remote controllers.
*/
kind: 'local' | 'remote';
};
}
1 change: 1 addition & 0 deletions src/webviews/webview-side/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ export enum Telemetry {
*/
ExportNotebookAsFailed = 'DATASCIENCE.EXPORT_NOTEBOOK_AS_FAILED',
FailedToCreateNotebookController = 'DATASCIENCE.FAILED_TO_CREATE_CONTROLLER',
FetchControllers = 'DATASCIENCE.FETCH_CONTROLLERS',
FailedToFindKernelSpecInterpreterForInteractive = 'DATASCIENCE.FAILED_TO_FIND_INTERPRETER_KERNEL_CONNECTION_FOR_INTERACTIVE',

StartJupyter = 'DS_INTERNAL.JUPYTERSTARTUPCOST',
Expand Down

0 comments on commit 42e3f38

Please sign in to comment.