Skip to content

Commit

Permalink
feat: Easier entry point using bench commands
Browse files Browse the repository at this point in the history
Use `bench --site sitename run-microbenchmarks` to run all benchmarks.

Use `--filter=substring` to filter benchmarks. There are no other custom
flags, rest are inherited from `pyperf`.

Use `bench --site sitename run-microbenchmarks --help` or refer to https://pyperf.readthedocs.io/
  • Loading branch information
ankush committed Dec 19, 2024
1 parent afafa44 commit 5e151ee
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ jobs:
working-directory: /home/runner/frappe-bench/sites
run: |
bench --site test_site set-config allow_tests true
source ../env/bin/activate
../apps/caffeine/caffeine/microbenchmarks/run_benchmarks.py --site test_site -l2 -p2 -w0 --quiet
bench --site test_site run-microbenchmarks -l2 -p2 -w0 --quiet
env:
TYPE: server
32 changes: 32 additions & 0 deletions caffeine/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import subprocess

import click
from frappe.commands import pass_context
from frappe.exceptions import SiteNotSpecifiedError


@click.command(
"run-microbenchmarks",
context_settings=dict(
ignore_unknown_options=True,
),
add_help_option=False,
)
@click.argument("benchargs", nargs=-1, type=click.UNPROCESSED)
@pass_context
def run_benchmarks(ctx, benchargs):
if not ctx.sites:
raise SiteNotSpecifiedError
site = ctx.sites[0]
benchargs = ("--site", site) + benchargs

from caffeine.microbenchmarks import run_benchmarks

# XXX: We can't invoke it directly pyperf wants to be the entry point
# Anyway, this shouldn't be a problem. It's no different than shell invoking it.
subprocess.check_call(["../env/bin/python3", run_benchmarks.__file__, *benchargs])


commands = [
run_benchmarks,
]

0 comments on commit 5e151ee

Please sign in to comment.