Skip to content

Commit

Permalink
Use snapshot(save)
Browse files Browse the repository at this point in the history
  • Loading branch information
leowrites committed Sep 23, 2024
1 parent a4e20b5 commit ea956ee
Showing 1 changed file with 9 additions and 28 deletions.
37 changes: 9 additions & 28 deletions python_ta/debug/snapshot_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ def __init__(

def _trace_func(self, frame: types.FrameType, event: str, _arg: Any) -> None:
if event == "line" and frame.f_locals:
# TODO: use snapshot(save=True)
var_data = snapshot(include=self.include)
json_data = snapshot_to_json(var_data)
if json_data:
self._output_snapshot(json_data)
self.snapshot_counts += 1
if self.output_filepath:
self.memory_viz_args.extend(
[
"--output",
os.path.join(self.output_filepath, f"snapshot-{self.snapshot_counts}.svg"),
]
)
snapshot(include=self.include, save=True, memory_viz_args=self.memory_viz_args)
self.snapshot_counts += 1

def get_snapshot_count(self):
return self.snapshot_counts
Expand All @@ -51,25 +54,3 @@ def __enter__(self):

def __exit__(self, exc_type, exc_val, exc_tb) -> None:
sys.settrace(None)

def _output_snapshot(self, data):
command = ["npx", "memory-viz"]
command.extend(self.memory_viz_args)
if self.output_filepath is not None:
command.extend(
[
"--output",
os.path.join(self.output_filepath, f"snapshot-{self.snapshot_counts}.svg"),
]
)
npx_path = shutil.which("npx")
subprocess.run(
command,
input=json.dumps(data),
executable=npx_path,
stdout=sys.stdout,
stderr=sys.stderr,
encoding="utf-8",
text=True,
check=True,
)

0 comments on commit ea956ee

Please sign in to comment.