From 78ffee29366b8ea8227f4844e4058294505636e4 Mon Sep 17 00:00:00 2001 From: "Maarten A. Breddels" Date: Thu, 17 Dec 2020 19:22:01 +0100 Subject: [PATCH] fix: giltracer in jupyter --- README.md | 8 ++++---- per4m/cellmagic.py | 9 +++++---- per4m/record.py | 1 + 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 7e116f2..aab5a25 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/per4m/cellmagic.py b/per4m/cellmagic.py index 22eb045..d04543e 100644 --- a/per4m/cellmagic.py +++ b/per4m/cellmagic.py @@ -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) diff --git a/per4m/record.py b/per4m/record.py index 3c2e252..10b2c39 100644 --- a/per4m/record.py +++ b/per4m/record.py @@ -34,6 +34,7 @@ class PerfRecord: def __enter__(self): self.start() + return self def start(self): pid = os.getpid()