Skip to content

Commit 19a0196

Browse files
committed
tiny improvement to the cprofile wrapper
ghstack-source-id: fd2d5c4 Pull Request resolved: #120100
1 parent 8a3c241 commit 19a0196

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

torch/_dynamo/utils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,17 @@ def cprofile_wrapper(func):
130130
@wraps(func)
131131
def profile_wrapper(*args, **kwargs):
132132
global timer_counter
133-
profile_path = Path(func.__name__ + f"{next(timer_counter)}.profile")
133+
profile_cnt = next(timer_counter)
134+
profile_path = Path(func.__name__ + f"{profile_cnt}.profile")
134135
prof = cProfile.Profile()
135136
prof.enable()
137+
start_ts = time.time()
136138
retval = prof.runcall(func, *args, **kwargs)
139+
profile_latency = time.time() - start_ts
137140
prof.disable()
138-
print(f"### Cprofile for {func.__name__} iter {next(timer_counter)} ###")
141+
print(
142+
f"### Cprofile for {func.__name__} iter {profile_cnt} took {profile_latency:.3f} seconds ###"
143+
)
139144
ps = pstats.Stats(prof)
140145
prof.dump_stats(profile_path)
141146
svg_path = profile_path.with_suffix(".svg")

0 commit comments

Comments
 (0)