Skip to content

Commit 8c5ef74

Browse files
authored
Gather basic notebook info along with perf data (microsoft#210712)
1 parent d94941f commit 8c5ef74

File tree

1 file changed

+50
-4
lines changed

1 file changed

+50
-4
lines changed

src/vs/workbench/contrib/notebook/browser/notebookEditor.ts

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import { IBorrowValue, INotebookEditorService } from 'vs/workbench/contrib/noteb
3232
import { NotebookEditorWidget } from 'vs/workbench/contrib/notebook/browser/notebookEditorWidget';
3333
import { NotebooKernelActionViewItem } from 'vs/workbench/contrib/notebook/browser/viewParts/notebookKernelView';
3434
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
35-
import { NOTEBOOK_EDITOR_ID, NotebookWorkingCopyTypeIdentifier } from 'vs/workbench/contrib/notebook/common/notebookCommon';
35+
import { CellKind, NOTEBOOK_EDITOR_ID, NotebookWorkingCopyTypeIdentifier } from 'vs/workbench/contrib/notebook/common/notebookCommon';
3636
import { NotebookEditorInput } from 'vs/workbench/contrib/notebook/common/notebookEditorInput';
3737
import { NotebookPerfMarks } from 'vs/workbench/contrib/notebook/common/notebookPerformance';
3838
import { GroupsOrder, IEditorGroup, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
@@ -48,6 +48,7 @@ import { ILogService } from 'vs/platform/log/common/log';
4848
import { INotebookEditorWorkerService } from 'vs/workbench/contrib/notebook/common/services/notebookWorkerService';
4949
import { IPreferencesService } from 'vs/workbench/services/preferences/common/preferences';
5050
import { IActionViewItemOptions } from 'vs/base/browser/ui/actionbar/actionViewItems';
51+
import { StopWatch } from 'vs/base/common/stopwatch';
5152

5253
const NOTEBOOK_EDITOR_VIEW_STATE_PREFERENCE_KEY = 'NotebookEditorViewState';
5354

@@ -332,7 +333,7 @@ export class NotebookEditor extends EditorPane implements INotebookEditorPane, I
332333
return;
333334
}
334335

335-
this._handlePerfMark(perf, input);
336+
this._handlePerfMark(perf, input, model.notebook);
336337
this._handlePromptRecommendations(model.notebook);
337338
} catch (e) {
338339
this.logService.warn('NotebookEditorWidget#setInput failed', e);
@@ -385,7 +386,7 @@ export class NotebookEditor extends EditorPane implements INotebookEditorPane, I
385386
}
386387
}
387388

388-
private _handlePerfMark(perf: NotebookPerfMarks, input: NotebookEditorInput) {
389+
private _handlePerfMark(perf: NotebookPerfMarks, input: NotebookEditorInput, notebook?: NotebookTextModel) {
389390
const perfMarks = perf.value;
390391

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

404412
type WorkbenchNotebookOpenEvent = {
@@ -410,6 +418,13 @@ export class NotebookEditor extends EditorPane implements INotebookEditorPane, I
410418
webviewCommLoaded: number;
411419
customMarkdownLoaded: number | undefined;
412420
editorLoaded: number;
421+
codeCellCount: number | undefined;
422+
mdCellCount: number | undefined;
423+
outputCount: number | undefined;
424+
outputBytes: number | undefined;
425+
codeLength: number | undefined;
426+
markdownLength: number | undefined;
427+
notebookStatsLoaded: number | undefined;
413428
};
414429

415430
const startTime = perfMarks['startTime'];
@@ -441,6 +456,30 @@ export class NotebookEditor extends EditorPane implements INotebookEditorPane, I
441456
}
442457
}
443458

459+
// Notebook information
460+
let codeCellCount: number | undefined = undefined;
461+
let mdCellCount: number | undefined = undefined;
462+
let outputCount: number | undefined = undefined;
463+
let outputBytes: number | undefined = undefined;
464+
let codeLength: number | undefined = undefined;
465+
let markdownLength: number | undefined = undefined;
466+
let notebookStatsLoaded: number | undefined = undefined;
467+
if (notebook) {
468+
const stopWatch = new StopWatch();
469+
for (const cell of notebook.cells) {
470+
if (cell.cellKind === CellKind.Code) {
471+
codeCellCount = (codeCellCount || 0) + 1;
472+
codeLength = (codeLength || 0) + cell.getTextLength();
473+
outputCount = (outputCount || 0) + cell.outputs.length;
474+
outputBytes = (outputBytes || 0) + cell.outputs.reduce((prev, cur) => prev + cur.outputs.reduce((size, item) => size + item.data.byteLength, 0), 0);
475+
} else {
476+
mdCellCount = (mdCellCount || 0) + 1;
477+
markdownLength = (codeLength || 0) + cell.getTextLength();
478+
}
479+
}
480+
notebookStatsLoaded = stopWatch.elapsed();
481+
}
482+
444483
this.telemetryService.publicLog2<WorkbenchNotebookOpenEvent, WorkbenchNotebookOpenClassification>('notebook/editorOpenPerf', {
445484
scheme: input.resource.scheme,
446485
ext: extname(input.resource),
@@ -449,7 +488,14 @@ export class NotebookEditor extends EditorPane implements INotebookEditorPane, I
449488
inputLoaded: inputLoadingTimespan,
450489
webviewCommLoaded: webviewCommLoadingTimespan,
451490
customMarkdownLoaded: customMarkdownLoadingTimespan,
452-
editorLoaded: editorLoadingTimespan
491+
editorLoaded: editorLoadingTimespan,
492+
codeCellCount,
493+
mdCellCount,
494+
outputCount,
495+
outputBytes,
496+
codeLength,
497+
markdownLength,
498+
notebookStatsLoaded
453499
});
454500
}
455501

0 commit comments

Comments
 (0)