diff --git a/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts b/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts index b4802da503f52..7e094d01c99a0 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts @@ -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'; @@ -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'; @@ -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); @@ -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 = { @@ -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 = { @@ -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']; @@ -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('notebook/editorOpenPerf', { scheme: input.resource.scheme, ext: extname(input.resource), @@ -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 }); }