-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: store more benchmark metadata in results
Use json reprensation as benchmark identifier in valgrind instrumentation
- Loading branch information
1 parent
41cdf39
commit fbae262
Showing
12 changed files
with
317 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from __future__ import annotations | ||
|
||
import json | ||
from dataclasses import dataclass | ||
|
||
import pytest | ||
|
||
from pytest_codspeed.utils import get_git_relative_path | ||
|
||
|
||
def has_args(item: pytest.Item) -> bool: | ||
return isinstance(item, pytest.Function) and "callspec" in item.__dict__ | ||
|
||
|
||
@dataclass | ||
class Benchmark: | ||
file: str | ||
module: str | ||
groups: list[str] | ||
name: str | ||
args: list | ||
args_names: list[str] | ||
|
||
@classmethod | ||
def from_item(cls, item: pytest.Item) -> Benchmark: | ||
file = str(get_git_relative_path(item.path)) | ||
module = "::".join( | ||
[node.name for node in item.listchain() if isinstance(node, pytest.Class)] | ||
) | ||
name = item.originalname if isinstance(item, pytest.Function) else item.name | ||
args = list(item.callspec.params.values()) if has_args(item) else [] | ||
args_names = list(item.callspec.params.keys()) if has_args(item) else [] | ||
groups = [] | ||
benchmark_marker = item.get_closest_marker("benchmark") | ||
if benchmark_marker is not None: | ||
benchmark_marker_kwargs = benchmark_marker.kwargs.get("group") | ||
if benchmark_marker_kwargs is not None: | ||
groups.append(benchmark_marker_kwargs) | ||
|
||
return cls( | ||
file=file, | ||
module=module, | ||
groups=groups, | ||
name=name, | ||
args=args, | ||
args_names=args_names, | ||
) | ||
|
||
@property | ||
def display_name(self) -> str: | ||
args_str = f"[{'-'.join(map(str, self.args))}]" if len(self.args) > 0 else "" | ||
return f"{self.name}{args_str}" | ||
|
||
def to_json_string(self) -> str: | ||
return json.dumps(self.__dict__, separators=(",", ":"), sort_keys=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.