Skip to content

Commit 7fe102e

Browse files
authored
feat(perf-issues): Add performance issue detection timing runner command (#44912)
Pretty handy, and I think it'll be useful in the future. Good for verifying time complexity
1 parent fb648cc commit 7fe102e

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/sentry/runner/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ def cli(ctx, config):
7171
"sentry.runner.commands.permissions.permissions",
7272
"sentry.runner.commands.devservices.devservices",
7373
"sentry.runner.commands.performance.performance",
74-
"sentry.runner.commands.performance.detect",
7574
"sentry.runner.commands.spans.spans",
7675
"sentry.runner.commands.spans.write_hashes",
7776
),

src/sentry/runner/commands/performance.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,36 @@ def detect(filename, detector_class, verbose):
7171
click.echo(problem)
7272

7373
click.echo("\n")
74+
75+
76+
@performance.command()
77+
@click.argument("filename", type=click.Path(exists=True))
78+
@click.option("-d", "--detector", "detector_class", help="Detector class", required=True)
79+
@click.option(
80+
"-n", required=False, type=int, default=1000, help="Number of times to run detection."
81+
)
82+
@configuration
83+
def timeit(filename, detector_class, n):
84+
"""
85+
Runs timing on performance problem detection on event data in the supplied
86+
filename and report results.
87+
"""
88+
89+
click.echo(f"Running timeit {n} times on {detector_class}")
90+
91+
import timeit
92+
93+
from sentry.utils.performance_issues import performance_detection
94+
95+
settings = performance_detection.get_detection_settings()
96+
97+
with open(filename) as file:
98+
data = json.loads(file.read())
99+
100+
detector = performance_detection.__dict__[detector_class](settings, data)
101+
102+
def detect():
103+
performance_detection.run_detector_on_data(detector, data)
104+
105+
result = timeit.timeit(stmt=detect, number=n)
106+
click.echo(f"Average runtime: {result * 1000 / n} ms")

0 commit comments

Comments
 (0)