Skip to content

Commit

Permalink
Do not instantiate useless TracerData class (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementWalter authored Dec 30, 2024
1 parent 7fa1396 commit c2feefc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
5 changes: 1 addition & 4 deletions cairo/tests/fixtures/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from starkware.cairo.lang.builtins.all_builtins import ALL_BUILTINS
from starkware.cairo.lang.compiler.ast.cairo_types import CairoType, TypeStruct
from starkware.cairo.lang.compiler.scoped_name import ScopedName
from starkware.cairo.lang.tracer.tracer_data import TracerData
from starkware.cairo.lang.vm.cairo_run import (
write_air_public_input,
write_binary_memory,
Expand Down Expand Up @@ -283,14 +282,12 @@ def _factory(entrypoint, *args, **kwargs):
f"{output_stem[:160]}_{int(time_ns())}_{md5(output_stem.encode()).digest().hex()[:8]}"
)
if request.config.getoption("profile_cairo"):
tracer_data = TracerData(
stats, prof_dict = profile_from_tracer_data(
program=cairo_program,
memory=runner.relocated_memory,
trace=runner.relocated_trace,
debug_info=runner.get_relocated_debug_info(),
program_base=PROGRAM_BASE,
)
stats, prof_dict = profile_from_tracer_data(tracer_data)
stats = stats[
"scope",
"primitive_call",
Expand Down
12 changes: 4 additions & 8 deletions cairo/tests/utils/reporting.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import json
import logging
from dataclasses import asdict
from pathlib import Path
from time import perf_counter
from typing import Any, Callable, List, TypeVar, Union
from typing import List, Union

import polars as pl

Expand All @@ -12,8 +11,6 @@
logging.basicConfig(format="%(levelname)-8s %(message)s")
logger = logging.getLogger("timer")

T = TypeVar("T", bound=Callable[..., Any])


def dump_coverage(path: Union[str, Path], files: List[CoverageFile]):
p = Path(path)
Expand All @@ -33,15 +30,14 @@ def dump_coverage(path: Union[str, Path], files: List[CoverageFile]):
)


def profile_from_tracer_data(tracer_data):
def profile_from_tracer_data(program, trace, debug_info, program_base):
logger.info("Begin profiling")
start = perf_counter()
program = tracer_data.program
trace = pl.DataFrame([asdict(x) for x in tracer_data.trace])
trace = pl.DataFrame([{"pc": x.pc, "ap": x.ap, "fp": x.fp} for x in trace])
debug_info = (
pl.DataFrame(
{
"pc": key + tracer_data.program_base,
"pc": key + program_base,
"scope": str(instruction_location.accessible_scopes[-1]),
"instruction": str(instruction_location.inst),
}
Expand Down

0 comments on commit c2feefc

Please sign in to comment.