Feature request: magic command to use viztracer from within jupyter notebook
See original GitHub issueNote sure what would be the best way to implement this, but the usability of viztracer could be greatly improved for datascientists and other Python users who work in interactive envrionments based on Jupyter such as Jupyter Lab and VS Code notebooks.
The setup use case would work as follow in jupyter notebook with the following cells:
# Notebook cell to enable the viztracer <=> jupyter extension
%load_ext viztracer
# Here is a notebook
biggish_data = prepare_big_datastructure_or_load_from_disk()
# Here is a notebook cell with some code to interactively
# define some complex data processing function.
def some_function(some_data, some_param=0.):
# do complicated stuff
...
# Here is a cell that profiles on
%%viztracer
some_function(biggish_data, some_param=42)
The last cell would execute some_function(biggish_data, some_param=42)
while recording the profiling events to a temp file on the disk and then automatically display an iframe with the perfetto viewer of the recorded events right below the code cell with the %%viztracer
statement.
If instead one uses %%viztracer --new-tab
would open a new browser tab to the viewer instead of using an iframe.
Finally %%viztracer --static-html
would embed the legacy static HTML viewer in the output of the cell of the notebok document to make it easier to publish and share the notebook (e.g. on https://nbviewer.jupyter.org) so that other can browse the profiling output without having to run a (local or remote) server (for jupyter and vizviewer).
It would also be possible to pass any viztracer commandline options to the magic command itself, for instance %%viztracer --log_gc --log_subprocess
.
This setup is really nice, because prepare_big_datastructure_or_load_from_disk
can be very slow and the user might want to iterate quickly by editing the code of some_function
in the previous cell based on the result of the previous profiling output without calling prepare_big_datastructure_or_load_from_disk()
again each time.
The last 2 cells could be even be collapsed into one for even faster coding iterations:
# Here is a notebook cell with some code to interactively
# define some complex data processing function and profile
# it on the fly:
def some_function(some_data, some_param=0.):
# do complicated stuff
...
%viztracer some_function(biggish_data, some_param=42)
Related jupyter extensions for profilers that can be used for inspiration:
- jupyter supports the
%%prun
profiler magic based oncProfile
from the standard library by default. - line_profiler can register the
%%lprun
magic command. - snakeviz can register the
%%snakeviz
magic command. It has the--new-tab
option I mentioned before.
Issue Analytics
- State:
- Created 2 years ago
- Comments:23 (21 by maintainers)
Hmm, how large are we talking about? It’s possible that Firefox has a different resource limit than Chrome which lead to this issue. If that’s the case, then there’s probably nothing I can do. Personally I use Chrome as my default browser and for the default trace entries I have never met a case where it fails to load. I’m sorry that this causes inconvenience for you, but it seems like at this point there’s not much I can do on viztracer side to solve the issue.
I found a workaround, after getting the same RPC framing error:
You can load the json in https://ui.perfetto.dev/ and it works just fine.
So, this does not seem like a issue with Perfetto, rather with a interaction between Perfetto and vizviewer.