From 47c70d4d3b97e129fbf492cbf1230a241946e2cb Mon Sep 17 00:00:00 2001 From: Marc Udoff Date: Mon, 2 Dec 2019 19:15:28 -0500 Subject: [PATCH 1/2] Allow for a global track timing setting This allows for a global default of whether or not to record timing metadata into the notebook metadata. --- packages/cells/src/widget.ts | 2 ++ packages/notebook-extension/schema/tracker.json | 6 ++++++ packages/notebook-extension/src/index.ts | 5 +++-- packages/notebook/src/actions.tsx | 8 +++++++- packages/notebook/src/widget.ts | 8 +++++++- 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/packages/cells/src/widget.ts b/packages/cells/src/widget.ts index 7556e8c03d4e..1bf1cc34d962 100644 --- a/packages/cells/src/widget.ts +++ b/packages/cells/src/widget.ts @@ -1089,6 +1089,8 @@ export namespace CodeCell { return true; }; cell.outputArea.future.registerMessageHook(recordTimingHook); + } else { + model.metadata.delete('execution'); } // Save this execution's future so we can compare in the catch below. future = cell.outputArea.future; diff --git a/packages/notebook-extension/schema/tracker.json b/packages/notebook-extension/schema/tracker.json index bc75cb91b87b..a52b78848175 100644 --- a/packages/notebook-extension/schema/tracker.json +++ b/packages/notebook-extension/schema/tracker.json @@ -352,6 +352,12 @@ "description": "Whether to be able to scroll so the last cell is at the top of the panel", "type": "boolean", "default": true + }, + "recordTiming": { + "title": "Recording timing", + "description": "Should timing data be recorded in cell metadata", + "type": "boolean", + "default": false } }, "additionalProperties": false, diff --git a/packages/notebook-extension/src/index.ts b/packages/notebook-extension/src/index.ts index 2dc2c0bdeacc..2daea62996db 100644 --- a/packages/notebook-extension/src/index.ts +++ b/packages/notebook-extension/src/index.ts @@ -631,7 +631,8 @@ function activateNotebookHandler( factory.editorConfig = { code, markdown, raw }; factory.notebookConfig = { scrollPastEnd: settings.get('scrollPastEnd').composite as boolean, - defaultCell: settings.get('defaultCell').composite as nbformat.CellType + defaultCell: settings.get('defaultCell').composite as nbformat.CellType, + recordTiming: settings.get('recordTiming').composite as boolean }; factory.shutdownOnClose = settings.get('kernelShutdown') .composite as boolean; @@ -1561,7 +1562,7 @@ function addCommands( isEnabled }); commands.addCommand(CommandIDs.toggleRecordTiming, { - label: 'Toggle Recording Cell Timing', + label: 'Toggle Recording Cell Timing for this Notebook', execute: args => { const current = getCurrent(args); diff --git a/packages/notebook/src/actions.tsx b/packages/notebook/src/actions.tsx index d2a03deab8bf..30852bf31a5d 100644 --- a/packages/notebook/src/actions.tsx +++ b/packages/notebook/src/actions.tsx @@ -1562,9 +1562,15 @@ namespace Private { break; case 'code': if (session) { + let recordTiming = false; + if (notebook.model.metadata.get('record_timing') === true) { + recordTiming = true; + } else if (notebook.model.metadata.get('record_timing') !== false) { + recordTiming = notebook.notebookConfig.recordTiming; + } return CodeCell.execute(cell as CodeCell, session, { deletedCells: notebook.model.deletedCells, - recordTiming: notebook.model.metadata.get('record_timing') || false + recordTiming }) .then(reply => { notebook.model.deletedCells.splice( diff --git a/packages/notebook/src/widget.ts b/packages/notebook/src/widget.ts index d1c3e1edae5a..3c842a71485f 100644 --- a/packages/notebook/src/widget.ts +++ b/packages/notebook/src/widget.ts @@ -759,13 +759,19 @@ export namespace StaticNotebook { * The default type for new notebook cells. */ defaultCell: nbformat.CellType; + + /** + * Should timing be recorded in metadata + */ + recordTiming: boolean; } /** * Default configuration options for notebooks. */ export const defaultNotebookConfig: INotebookConfig = { scrollPastEnd: true, - defaultCell: 'code' + defaultCell: 'code', + recordTiming: false }; /** From 2f2f9c2bcead57d93e71ae646357db7a8557964e Mon Sep 17 00:00:00 2001 From: Saul Shanabrook Date: Wed, 4 Dec 2019 14:21:42 -0600 Subject: [PATCH 2/2] Remove record timing notebook metadata --- packages/notebook-extension/src/index.ts | 14 -------------- packages/notebook/src/actions.tsx | 21 +-------------------- 2 files changed, 1 insertion(+), 34 deletions(-) diff --git a/packages/notebook-extension/src/index.ts b/packages/notebook-extension/src/index.ts index 2daea62996db..1137aa0cbb9f 100644 --- a/packages/notebook-extension/src/index.ts +++ b/packages/notebook-extension/src/index.ts @@ -177,8 +177,6 @@ namespace CommandIDs { export const toggleAllLines = 'notebook:toggle-all-cell-line-numbers'; - export const toggleRecordTiming = 'notebook:toggle-record-timing'; - export const undoCellAction = 'notebook:undo-cell-action'; export const redoCellAction = 'notebook:redo-cell-action'; @@ -1561,17 +1559,6 @@ function addCommands( }, isEnabled }); - commands.addCommand(CommandIDs.toggleRecordTiming, { - label: 'Toggle Recording Cell Timing for this Notebook', - execute: args => { - const current = getCurrent(args); - - if (current) { - return NotebookActions.toggleRecordTiming(current.content); - } - }, - isEnabled - }); commands.addCommand(CommandIDs.commandMode, { label: 'Enter Command Mode', execute: args => { @@ -1923,7 +1910,6 @@ function populatePalette( CommandIDs.deselectAll, CommandIDs.clearAllOutputs, CommandIDs.toggleAllLines, - CommandIDs.toggleRecordTiming, CommandIDs.editMode, CommandIDs.commandMode, CommandIDs.changeKernel, diff --git a/packages/notebook/src/actions.tsx b/packages/notebook/src/actions.tsx index 30852bf31a5d..e17592b738f2 100644 --- a/packages/notebook/src/actions.tsx +++ b/packages/notebook/src/actions.tsx @@ -1021,19 +1021,6 @@ export namespace NotebookActions { Private.handleState(notebook, state); } - /** - * Toggle whether to record cell timing execution. - * - * @param notebook - The target notebook widget. - */ - export function toggleRecordTiming(notebook: Notebook): void { - if (!notebook.model) { - return; - } - const currentValue = notebook.model.metadata.get('record_timing') || false; - notebook.model.metadata.set('record_timing', !currentValue); - } - /** * Clear the code outputs of the selected cells. * @@ -1562,15 +1549,9 @@ namespace Private { break; case 'code': if (session) { - let recordTiming = false; - if (notebook.model.metadata.get('record_timing') === true) { - recordTiming = true; - } else if (notebook.model.metadata.get('record_timing') !== false) { - recordTiming = notebook.notebookConfig.recordTiming; - } return CodeCell.execute(cell as CodeCell, session, { deletedCells: notebook.model.deletedCells, - recordTiming + recordTiming: notebook.notebookConfig.recordTiming }) .then(reply => { notebook.model.deletedCells.splice(