Skip to content

Commit

Permalink
tiny improvement to the cprofile wrapper (#120100)
Browse files Browse the repository at this point in the history
Summary:
1. right now we double increment the profile counter. The PR avoid that so we don't end up with profile_0, profile_2, profile_4 ...
2. log the latency to run the passed in function with profiling on so we can easily skip those _compile call which returns quickly.

X-link: pytorch/pytorch#120100
Approved by: https://github.com/eellison

Reviewed By: huydhn

Differential Revision: D53930648

Pulled By: shunting314

fbshipit-source-id: e7af70f52c655453c5d7b3d7c82aa3e17f69b1df
  • Loading branch information
shunting314 authored and facebook-github-bot committed Feb 20, 2024
1 parent 49c4a5f commit 687fc0f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions userbenchmark/dynamo/dynamobench/_dynamo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,17 @@ def cprofile_wrapper(func):
@wraps(func)
def profile_wrapper(*args, **kwargs):
global timer_counter
profile_path = Path(func.__name__ + f"{next(timer_counter)}.profile")
profile_cnt = next(timer_counter)
profile_path = Path(func.__name__ + f"{profile_cnt}.profile")
prof = cProfile.Profile()
prof.enable()
start_ts = time.time()
retval = prof.runcall(func, *args, **kwargs)
profile_latency = time.time() - start_ts
prof.disable()
print(f"### Cprofile for {func.__name__} iter {next(timer_counter)} ###")
print(
f"### Cprofile for {func.__name__} iter {profile_cnt} took {profile_latency:.3f} seconds ###"
)
ps = pstats.Stats(prof)
prof.dump_stats(profile_path)
svg_path = profile_path.with_suffix(".svg")
Expand Down

0 comments on commit 687fc0f

Please sign in to comment.