From 6abdbe6fbe58b873e327a17f6fa09040df62e178 Mon Sep 17 00:00:00 2001 From: George Gritsouk <989898+gggritso@users.noreply.github.com> Date: Tue, 21 Feb 2023 15:47:48 -0500 Subject: [PATCH 1/2] Remove unneeded command registration This breaks registration if more than one command is attached to that command group. Only the group should be registered, not the subcommands. --- src/sentry/runner/__init__.py | 1 - 1 file changed, 1 deletion(-) 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", ), From 6c333ad5330c3f44a551c015a0cddf51169265d3 Mon Sep 17 00:00:00 2001 From: George Gritsouk <989898+gggritso@users.noreply.github.com> Date: Tue, 21 Feb 2023 16:03:43 -0500 Subject: [PATCH 2/2] Add performance detection timing runner command --- src/sentry/runner/commands/performance.py | 33 +++++++++++++++++++++++ 1 file changed, 33 insertions(+) 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")