From 0558287446b193c6e7f7f4b7e41f8a6401c9a0f7 Mon Sep 17 00:00:00 2001 From: Tautvydas Misiunas Date: Tue, 21 Aug 2018 17:21:44 +0100 Subject: [PATCH 1/5] Update script with filtering logic Hide short executions, but still render them if they were reenabled via menus. --- .../nbextensions/execute_time/ExecuteTime.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/jupyter_contrib_nbextensions/nbextensions/execute_time/ExecuteTime.js b/src/jupyter_contrib_nbextensions/nbextensions/execute_time/ExecuteTime.js index 5bc0ca4f3..e23d3cb55 100755 --- a/src/jupyter_contrib_nbextensions/nbextensions/execute_time/ExecuteTime.js +++ b/src/jupyter_contrib_nbextensions/nbextensions/execute_time/ExecuteTime.js @@ -269,6 +269,9 @@ define([ var exec_time = -start_time.diff(end_time); msg = msg.replace('${duration}', humanized_duration(exec_time)); } + if (exec_time < options.hide_shorter_than_threshold_in_ms ) { + toggle_timing_display([cell], false); + } timing_area.text(msg); return timing_area; } From 9152c1976f486dd026f3d6af44c3c3c26507d8d7 Mon Sep 17 00:00:00 2001 From: Tautvydas Misiunas Date: Tue, 21 Aug 2018 17:25:09 +0100 Subject: [PATCH 2/5] Update configuration yaml Set min value to 0, without upper bank and default of 0 --- .../nbextensions/execute_time/ExecuteTime.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/jupyter_contrib_nbextensions/nbextensions/execute_time/ExecuteTime.yaml b/src/jupyter_contrib_nbextensions/nbextensions/execute_time/ExecuteTime.yaml index 583a1e478..846400cae 100644 --- a/src/jupyter_contrib_nbextensions/nbextensions/execute_time/ExecuteTime.yaml +++ b/src/jupyter_contrib_nbextensions/nbextensions/execute_time/ExecuteTime.yaml @@ -86,3 +86,12 @@ Parameters: replacement tokens. default: 'execution queued ${start_time}' input_type: text + +- name: ExecuteTime.hide_shorter_than_threshold_in_ms + description: | + Hide execution timings that are shorter than this threshold (in ms). Set to + zero to show all timings. + default: 0 + input_type: number + step: 1 + min: 1 From d6a691b1349804f3816043cb13e99c3925742252 Mon Sep 17 00:00:00 2001 From: Tautvydas Misiunas Date: Tue, 21 Aug 2018 17:27:48 +0100 Subject: [PATCH 3/5] Update readme.md --- .../nbextensions/execute_time/readme.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/jupyter_contrib_nbextensions/nbextensions/execute_time/readme.md b/src/jupyter_contrib_nbextensions/nbextensions/execute_time/readme.md index 1437f0263..a424eaaa0 100644 --- a/src/jupyter_contrib_nbextensions/nbextensions/execute_time/readme.md +++ b/src/jupyter_contrib_nbextensions/nbextensions/execute_time/readme.md @@ -113,6 +113,10 @@ The available options are: cells. The template uses an ES2015-like syntax, but replaces only the exact strings `${start_time}`, plus (if defined) `${end_time}` and `${duration}`. Defaults to `'execution queued ${start_time}'`. + +* `ExecuteTime.hide_shorter_than_threshold_in_ms`: Threshold to hide execution + timings that are short. Set this to zero to show all timings. + Defaults to `0`. From d5fe4cc815f618693ce64985c4bfdd8acd5715ba Mon Sep 17 00:00:00 2001 From: Tautvydas Misiunas Date: Tue, 21 Aug 2018 17:40:48 +0100 Subject: [PATCH 4/5] Add hide_shorter_than_threshold_in_ms to options --- .../nbextensions/execute_time/ExecuteTime.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/jupyter_contrib_nbextensions/nbextensions/execute_time/ExecuteTime.js b/src/jupyter_contrib_nbextensions/nbextensions/execute_time/ExecuteTime.js index e23d3cb55..ac2b83899 100755 --- a/src/jupyter_contrib_nbextensions/nbextensions/execute_time/ExecuteTime.js +++ b/src/jupyter_contrib_nbextensions/nbextensions/execute_time/ExecuteTime.js @@ -49,6 +49,7 @@ define([ executed: 'executed in ${duration}, finished ${end_time}', queued: 'execution queued ${start_time}', }, + hide_shorter_than_threshold_in_ms: 0, }; function patch_CodeCell_get_callbacks () { From 109ff6c591af58c26f325ecf5573eebe3c596b52 Mon Sep 17 00:00:00 2001 From: Tautvydas Misiunas Date: Sun, 2 Jun 2019 23:27:27 +0100 Subject: [PATCH 5/5] Incorporate MR feedback Fix an issue where exec_time variable could be undefined. --- .../nbextensions/execute_time/ExecuteTime.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/jupyter_contrib_nbextensions/nbextensions/execute_time/ExecuteTime.js b/src/jupyter_contrib_nbextensions/nbextensions/execute_time/ExecuteTime.js index ac2b83899..5ee9fae50 100755 --- a/src/jupyter_contrib_nbextensions/nbextensions/execute_time/ExecuteTime.js +++ b/src/jupyter_contrib_nbextensions/nbextensions/execute_time/ExecuteTime.js @@ -264,15 +264,16 @@ define([ end_time = cell.metadata.ExecuteTime.end_time; var msg = options.template[end_time ? 'executed' : 'queued']; msg = msg.replace('${start_time}', format_moment(start_time)); + var show_timing = true; if (end_time) { end_time = moment(end_time); msg = msg.replace('${end_time}', format_moment(end_time)); var exec_time = -start_time.diff(end_time); msg = msg.replace('${duration}', humanized_duration(exec_time)); + show_timing = exec_time >= options.hide_shorter_than_threshold_in_ms; } - if (exec_time < options.hide_shorter_than_threshold_in_ms ) { - toggle_timing_display([cell], false); - } + toggle_timing_display([cell], show_timing); + timing_area.text(msg); return timing_area; }