Skip to content

Commit

Permalink
Gather basic notebook info along with perf data (#210712)
Browse files Browse the repository at this point in the history
  • Loading branch information
DonJayamanne authored Apr 19, 2024
1 parent d94941f commit 8c5ef74
Showing 1 changed file with 50 additions and 4 deletions.
54 changes: 50 additions & 4 deletions src/vs/workbench/contrib/notebook/browser/notebookEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { IBorrowValue, INotebookEditorService } from 'vs/workbench/contrib/noteb
import { NotebookEditorWidget } from 'vs/workbench/contrib/notebook/browser/notebookEditorWidget';
import { NotebooKernelActionViewItem } from 'vs/workbench/contrib/notebook/browser/viewParts/notebookKernelView';
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
import { NOTEBOOK_EDITOR_ID, NotebookWorkingCopyTypeIdentifier } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { CellKind, NOTEBOOK_EDITOR_ID, NotebookWorkingCopyTypeIdentifier } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { NotebookEditorInput } from 'vs/workbench/contrib/notebook/common/notebookEditorInput';
import { NotebookPerfMarks } from 'vs/workbench/contrib/notebook/common/notebookPerformance';
import { GroupsOrder, IEditorGroup, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
Expand All @@ -48,6 +48,7 @@ import { ILogService } from 'vs/platform/log/common/log';
import { INotebookEditorWorkerService } from 'vs/workbench/contrib/notebook/common/services/notebookWorkerService';
import { IPreferencesService } from 'vs/workbench/services/preferences/common/preferences';
import { IActionViewItemOptions } from 'vs/base/browser/ui/actionbar/actionViewItems';
import { StopWatch } from 'vs/base/common/stopwatch';

const NOTEBOOK_EDITOR_VIEW_STATE_PREFERENCE_KEY = 'NotebookEditorViewState';

Expand Down Expand Up @@ -332,7 +333,7 @@ export class NotebookEditor extends EditorPane implements INotebookEditorPane, I
return;
}

this._handlePerfMark(perf, input);
this._handlePerfMark(perf, input, model.notebook);
this._handlePromptRecommendations(model.notebook);
} catch (e) {
this.logService.warn('NotebookEditorWidget#setInput failed', e);
Expand Down Expand Up @@ -385,7 +386,7 @@ export class NotebookEditor extends EditorPane implements INotebookEditorPane, I
}
}

private _handlePerfMark(perf: NotebookPerfMarks, input: NotebookEditorInput) {
private _handlePerfMark(perf: NotebookPerfMarks, input: NotebookEditorInput, notebook?: NotebookTextModel) {
const perfMarks = perf.value;

type WorkbenchNotebookOpenClassification = {
Expand All @@ -399,6 +400,13 @@ export class NotebookEditor extends EditorPane implements INotebookEditorPane, I
webviewCommLoaded: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'Webview initialization time for the resource opening' };
customMarkdownLoaded: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'Custom markdown loading time for the resource opening' };
editorLoaded: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'Overall editor loading time for the resource opening' };
codeCellCount: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'Total number of code cell' };
mdCellCount: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'Total number of markdown cell' };
outputCount: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'Total number of cell outputs' };
outputBytes: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'Total number of bytes for all outputs' };
codeLength: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'Length of text in all code cells' };
markdownLength: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'Length of text in all markdown cells' };
notebookStatsLoaded: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'Time for generating the notebook level information for telemetry' };
};

type WorkbenchNotebookOpenEvent = {
Expand All @@ -410,6 +418,13 @@ export class NotebookEditor extends EditorPane implements INotebookEditorPane, I
webviewCommLoaded: number;
customMarkdownLoaded: number | undefined;
editorLoaded: number;
codeCellCount: number | undefined;
mdCellCount: number | undefined;
outputCount: number | undefined;
outputBytes: number | undefined;
codeLength: number | undefined;
markdownLength: number | undefined;
notebookStatsLoaded: number | undefined;
};

const startTime = perfMarks['startTime'];
Expand Down Expand Up @@ -441,6 +456,30 @@ export class NotebookEditor extends EditorPane implements INotebookEditorPane, I
}
}

// Notebook information
let codeCellCount: number | undefined = undefined;
let mdCellCount: number | undefined = undefined;
let outputCount: number | undefined = undefined;
let outputBytes: number | undefined = undefined;
let codeLength: number | undefined = undefined;
let markdownLength: number | undefined = undefined;
let notebookStatsLoaded: number | undefined = undefined;
if (notebook) {
const stopWatch = new StopWatch();
for (const cell of notebook.cells) {
if (cell.cellKind === CellKind.Code) {
codeCellCount = (codeCellCount || 0) + 1;
codeLength = (codeLength || 0) + cell.getTextLength();
outputCount = (outputCount || 0) + cell.outputs.length;
outputBytes = (outputBytes || 0) + cell.outputs.reduce((prev, cur) => prev + cur.outputs.reduce((size, item) => size + item.data.byteLength, 0), 0);
} else {
mdCellCount = (mdCellCount || 0) + 1;
markdownLength = (codeLength || 0) + cell.getTextLength();
}
}
notebookStatsLoaded = stopWatch.elapsed();
}

this.telemetryService.publicLog2<WorkbenchNotebookOpenEvent, WorkbenchNotebookOpenClassification>('notebook/editorOpenPerf', {
scheme: input.resource.scheme,
ext: extname(input.resource),
Expand All @@ -449,7 +488,14 @@ export class NotebookEditor extends EditorPane implements INotebookEditorPane, I
inputLoaded: inputLoadingTimespan,
webviewCommLoaded: webviewCommLoadingTimespan,
customMarkdownLoaded: customMarkdownLoadingTimespan,
editorLoaded: editorLoadingTimespan
editorLoaded: editorLoadingTimespan,
codeCellCount,
mdCellCount,
outputCount,
outputBytes,
codeLength,
markdownLength,
notebookStatsLoaded
});
}

Expand Down

0 comments on commit 8c5ef74

Please sign in to comment.