Skip to content

Commit c9f6193

Browse files
dshi7facebook-github-bot
authored andcommitted
cprofile every compile id [x/y] to keep consistent with tlparse (#125659)
Summary: This PR moves cprofile decorator to keep consistent with `torch_inductor_stats` logging and is needed by fbcode diffs of profiling enablement in internal e2e jobs. X-link: pytorch/pytorch#125659 Approved by: https://github.com/ezyang Reviewed By: huydhn Differential Revision: D57036096 Pulled By: dshi7 fbshipit-source-id: 864cb5af139e12cf918b9947f013b4af739a3853
1 parent 869abca commit c9f6193

File tree

1 file changed

+0
-63
lines changed
  • userbenchmark/dynamo/dynamobench/_dynamo

1 file changed

+0
-63
lines changed

userbenchmark/dynamo/dynamobench/_dynamo/utils.py

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import collections
33
import contextlib
44
import copy
5-
import cProfile
65
import dataclasses
76
import datetime
87
import dis
@@ -16,9 +15,7 @@
1615
import math
1716
import operator
1817
import os
19-
import pstats
2018
import re
21-
import subprocess
2219
import sys
2320
import textwrap
2421
import threading
@@ -28,7 +25,6 @@
2825
import weakref
2926
from contextlib import contextmanager
3027
from functools import lru_cache, wraps
31-
from pathlib import Path
3228
from types import MethodWrapperType
3329
from typing import (
3430
Any,
@@ -50,8 +46,6 @@
5046
ValuesView,
5147
)
5248

53-
from torch._utils_internal import maybe_upload_prof_stats_to_manifold
54-
5549
from ..utils.hooks import RemovableHandle
5650

5751
try:
@@ -135,63 +129,6 @@ def tabulate(rows, headers):
135129
)
136130

137131

138-
def maybe_cprofile(func):
139-
if config.cprofile:
140-
return cprofile_wrapper(func)
141-
return func
142-
143-
144-
def cprofile_wrapper(func):
145-
@wraps(func)
146-
def profile_wrapper(*args, **kwargs):
147-
global timer_counter
148-
profile_cnt = next(timer_counter)
149-
profile_path = Path("/tmp/" + func.__name__ + f"{profile_cnt}.profile")
150-
prof = cProfile.Profile()
151-
prof.enable()
152-
start_ts = time.time()
153-
retval = prof.runcall(func, *args, **kwargs)
154-
profile_latency = time.time() - start_ts
155-
prof.disable()
156-
print(
157-
f"### Cprofile for {func.__name__} iter {profile_cnt} took {profile_latency:.3f} seconds ###"
158-
)
159-
ps = pstats.Stats(prof)
160-
prof.dump_stats(profile_path)
161-
svg_path = profile_path.with_suffix(".svg")
162-
try:
163-
gprof2dot_process = subprocess.Popen(
164-
[
165-
"gprof2dot",
166-
"-f",
167-
"pstats",
168-
"--node-label=total-time-percentage",
169-
"--node-label=self-time-percentage",
170-
"--node-label=total-time",
171-
str(profile_path),
172-
],
173-
stdout=subprocess.PIPE,
174-
)
175-
subprocess.check_call(
176-
["dot", "-Tsvg", "-o", str(svg_path)],
177-
stdin=gprof2dot_process.stdout,
178-
)
179-
print(f"Generated SVG from profile at {str(svg_path)}")
180-
except FileNotFoundError:
181-
print(
182-
"Failed to generate SVG from profile -- dumping stats instead."
183-
"Try installing gprof2dot and dot for a better visualization"
184-
)
185-
ps.sort_stats(pstats.SortKey.TIME).print_stats(20)
186-
ps.sort_stats(pstats.SortKey.CUMULATIVE).print_stats(20)
187-
188-
maybe_upload_prof_stats_to_manifold(str(profile_path)) # fb-only
189-
190-
return retval
191-
192-
return profile_wrapper
193-
194-
195132
curr_frame = 0
196133

197134

0 commit comments

Comments
 (0)