Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gather basic notebook info along with perf data #210712

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this to see how much of an impact this will have,
If we find out that this is slow, we can always disable this.
Also from my testing in OSS, this takes less than 1ms.

}

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
Loading