diff --git a/src/sentry/runner/__init__.py b/src/sentry/runner/__init__.py index 4f83697400fbcb..68f55c74a218e1 100644 --- a/src/sentry/runner/__init__.py +++ b/src/sentry/runner/__init__.py @@ -71,7 +71,6 @@ def cli(ctx, config): "sentry.runner.commands.permissions.permissions", "sentry.runner.commands.devservices.devservices", "sentry.runner.commands.performance.performance", - "sentry.runner.commands.performance.detect", "sentry.runner.commands.spans.spans", "sentry.runner.commands.spans.write_hashes", ), diff --git a/src/sentry/runner/commands/performance.py b/src/sentry/runner/commands/performance.py index de40f6849005f5..6ec4ab058ca831 100644 --- a/src/sentry/runner/commands/performance.py +++ b/src/sentry/runner/commands/performance.py @@ -71,3 +71,36 @@ def detect(filename, detector_class, verbose): click.echo(problem) click.echo("\n") + + +@performance.command() +@click.argument("filename", type=click.Path(exists=True)) +@click.option("-d", "--detector", "detector_class", help="Detector class", required=True) +@click.option( + "-n", required=False, type=int, default=1000, help="Number of times to run detection." +) +@configuration +def timeit(filename, detector_class, n): + """ + Runs timing on performance problem detection on event data in the supplied + filename and report results. + """ + + click.echo(f"Running timeit {n} times on {detector_class}") + + import timeit + + from sentry.utils.performance_issues import performance_detection + + settings = performance_detection.get_detection_settings() + + with open(filename) as file: + data = json.loads(file.read()) + + detector = performance_detection.__dict__[detector_class](settings, data) + + def detect(): + performance_detection.run_detector_on_data(detector, data) + + result = timeit.timeit(stmt=detect, number=n) + click.echo(f"Average runtime: {result * 1000 / n} ms")