Skip to content

Commit 27bd751

Browse files
committed
[ExecuteTime] optionally clear timing data on clearing cell outputs
1 parent 473d1e8 commit 27bd751

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

src/jupyter_contrib_nbextensions/nbextensions/execute_time/ExecuteTime.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ define([
3333

3434
// defaults, overridden by server's config
3535
var options = {
36+
clear_timings_on_clear_output: false,
3637
clear_timings_on_kernel_restart: false,
3738
default_kernel_to_utc: true,
3839
display_absolute_format: 'HH:mm:ss YYYY-MM-DD',
@@ -80,6 +81,16 @@ define([
8081
};
8182
}
8283

84+
function patch_CodeCell_clear_output () {
85+
console.log(log_prefix, 'Patching CodeCell.prototype.clear_output to clear timings also.');
86+
var orig_clear_output = CodeCell.prototype.clear_output;
87+
CodeCell.prototype.clear_output = function () {
88+
var ret = orig_clear_output.apply(this, arguments);
89+
clear_timing_data([this]);
90+
return ret;
91+
};
92+
}
93+
8394
function toggle_timing_display (cells, vis) {
8495
for (var i = 0; i < cells.length; i++) {
8596
var cell = cells[i];
@@ -315,6 +326,9 @@ define([
315326
}
316327

317328
// setup optional clear-data calls
329+
if (options.clear_timings_on_clear_output) {
330+
patch_CodeCell_clear_output();
331+
}
318332
if (options.clear_timings_on_kernel_restart) {
319333
console.log(log_prefix, 'Binding kernel_restarting.Kernel event to clear timings.');
320334
events.on('kernel_restarting.Kernel', clear_timing_data_all);

src/jupyter_contrib_nbextensions/nbextensions/execute_time/ExecuteTime.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ Main: ExecuteTime.js
77
Compatibility: 4.x, 5.x
88
Parameters:
99

10+
- name: ExecuteTime.clear_timings_on_clear_output
11+
description: |
12+
When cells' outputs are cleared, also clear their timing data, e.g. when
13+
using the "Kernel > Restart & Clear Output" menu item
14+
input_type: checkbox
15+
default: false
16+
1017
- name: ExecuteTime.clear_timings_on_kernel_restart
1118
description: |
1219
Clear all cells' execution timing data on any kernel restart event

src/jupyter_contrib_nbextensions/nbextensions/execute_time/readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ ConfigManager().update('notebook', {'ExecuteTime': {
6060

6161
The available options are:
6262

63+
* `ExecuteTime.clear_timings_on_clear_output`: When cells' outputs are cleared,
64+
also clear their timing data, e.g. when using the
65+
`Kernel > Restart & Clear Output` menu item
66+
6367
* `ExecuteTime.clear_timings_on_kernel_restart`: Clear all cells' execution
6468
timing data on any kernel restart event
6569

0 commit comments

Comments
 (0)