Skip to content

Commit

Permalink
bench: add --benchmark-cprofile-dump
Browse files Browse the repository at this point in the history
  • Loading branch information
skshetry committed Aug 22, 2024
1 parent 705b7bb commit 3f2584d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
14 changes: 11 additions & 3 deletions dvc/testing/benchmarks/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ def make_dvc_bin(
dvc_bin = bench_config.dvc_bin

def _dvc_bin(*args):
return check_output([dvc_bin, *args], text=True) # noqa: S603
check_call([dvc_bin, *args]) # noqa: S603

_dvc_bin.version = _dvc_bin("--version") # type: ignore[attr-defined]
_dvc_bin.version = check_output([dvc_bin, "--version"], text=True) # type: ignore[attr-defined] # noqa: S603
return _dvc_bin


Expand Down Expand Up @@ -167,11 +167,19 @@ def add_suffix(_name):


@pytest.fixture
def bench_dvc(dvc_bin, make_bench):
def bench_dvc(request, dvc_bin, make_bench):
def _bench_dvc(*args, **kwargs):
name = kwargs.pop("name", None)
name = f"-{name}" if name else ""
bench = make_bench(args[0] + name)
if request.config.getoption("--benchmark-cprofile-dump") or kwargs.pop(
"cprofile", False
):
cprofile_results = request.config.invocation_params.dir / "prof"
cprofile_results.mkdir(exist_ok=True)
stats_file = cprofile_results / f"{bench.name}.prof"
args = (*args, "--cprofile-dump", stats_file)

return bench.pedantic(dvc_bin, args=args, **kwargs)

return _bench_dvc
Expand Down
7 changes: 7 additions & 0 deletions dvc/testing/benchmarks/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ def pytest_addoption(parser):
help="Dataset name to use in tests (e.g. tiny/small/large/mnist/etc)",
)

parser.addoption(
"--benchmark-cprofile-dump",
action="store_true",
default=False,
help="Save cprofile results",
)

parser.addoption(
"--dvc-bin",
type=str,
Expand Down

0 comments on commit 3f2584d

Please sign in to comment.