fix: giltracer in jupyter
This commit is contained in:
parent
67c25d37e5
commit
78ffee2936
|
@ -217,9 +217,9 @@ First, load the magics
|
|||
%load_ext per4m.cellmagic
|
||||
```
|
||||
|
||||
Run a cell with the `%%giltrace` cell magic.
|
||||
Run a cell with the `%%giltracer` cell magic.
|
||||
```
|
||||
%%giltrace
|
||||
%%giltracer
|
||||
import threading
|
||||
import time
|
||||
import time
|
||||
|
@ -254,8 +254,8 @@ Saving report to /home/maartenbreddels/github/maartenbreddels/per4m/result.html
|
|||
Dumping trace data to json, total entries: 167, estimated json file size: 19.6KiB
|
||||
Generating HTML report
|
||||
Report saved.
|
||||
Download result.html
|
||||
Open result.html in new tab (might not work due to security issue)
|
||||
Download viztracer.html
|
||||
Open viztracer.html in new tab (might not work due to security issue)
|
||||
```
|
||||
|
||||
Click the download link to get the results.
|
||||
|
|
|
@ -11,22 +11,23 @@ from IPython.core.magic import (cell_magic,
|
|||
)
|
||||
|
||||
|
||||
from .giltracer import GilTracer
|
||||
from .giltracer import PerfRecordGIL
|
||||
|
||||
@magics_class
|
||||
class GilTraceMagic(Magics):
|
||||
@needs_local_scope
|
||||
@cell_magic
|
||||
def giltrace(self, line, cell, local_ns):
|
||||
def giltracer(self, line, cell, local_ns):
|
||||
temp_dir = tempfile.mkdtemp()
|
||||
perf_path = os.path.join(temp_dir, 'perf.data')
|
||||
viz_path = os.path.join(temp_dir, 'viztracer.json')
|
||||
gil_path = os.path.join(temp_dir, 'giltracer.json')
|
||||
out_path = 'result.html'
|
||||
out_path = 'giltracer.html'
|
||||
code = self.shell.transform_cell(cell)
|
||||
with GilTracer(perf_path, gil_path) as gt:
|
||||
with PerfRecordGIL(perf_path, gil_path) as gt:
|
||||
with viztracer.VizTracer(output_file=viz_path):
|
||||
exec(code, local_ns, local_ns)
|
||||
gt.post_process()
|
||||
builder = ReportBuilder([viz_path, gil_path])
|
||||
builder.save(output_file=out_path)
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ class PerfRecord:
|
|||
|
||||
def __enter__(self):
|
||||
self.start()
|
||||
return self
|
||||
|
||||
def start(self):
|
||||
pid = os.getpid()
|
||||
|
|
Loading…
Reference in New Issue