Skip to content

Commit

Permalink
perf: add -F +symline support
Browse files Browse the repository at this point in the history
  • Loading branch information
slicklash committed Oct 24, 2024
1 parent 9da69db commit 2a18cf5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion gprofiler/utils/perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
r"(?:(?P<freq>\d+)\s+)?(?P<event_family>[\w\-_/]+):(?:(?P<event>[\w-]+):)?(?P<suffix>[^\n]*)(?:\n(?P<stack>.*))?",
re.MULTILINE | re.DOTALL,
)
SYMLINE_REGEX = re.compile(r"(?:\+([^+]+):(\d+)){2}$")


class SupportedPerfEvent(Enum):
Expand Down Expand Up @@ -160,7 +161,8 @@ def collapse_stack(comm: str, stack: str, insert_dso_name: bool = False) -> str:
m = FRAME_REGEX.match(line)
assert m is not None, f"bad line: {line}"
sym, dso = m.group("symbol"), m.group("dso_brackets") or m.group("dso_plain")
sym = sym.split("+")[0] # strip the offset part.
if not SYMLINE_REGEX.search(sym):
sym = sym.split("+")[0] # strip the offset part.
if sym == "[unknown]" and dso != "unknown":
sym = f"({dso})"
# append kernel annotation
Expand Down
2 changes: 1 addition & 1 deletion gprofiler/utils/perf_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def wait_and_script(self) -> str:
perf_data = inject_data

perf_script_proc = run_process(
[perf_path(), "script", "-F", "+pid", "-i", str(perf_data)],
[perf_path(), "script", "-F", "+pid,+symline", "-i", str(perf_data)],
suppress_log=True,
)
return perf_script_proc.stdout.decode("utf8")
Expand Down
2 changes: 1 addition & 1 deletion scripts/perf_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
set -euo pipefail

# downloading the zip because the git is very large (this is also very large, but still smaller)
curl -SL https://codeload.github.com/Granulate/linux/zip/5c103bf97fb268e4ea157f5e1c2a5bd6ad8c40dc -o linux.zip
curl -SL https://codeload.github.com/Granulate/linux/zip/9909d736d8b8927d79003dfa9732050a08c11221 -o linux.zip
unzip -qq linux.zip
rm linux.zip
cd linux-*/
Expand Down
8 changes: 8 additions & 0 deletions tests/test_perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,14 @@ def test_get_average_frame_count(samples: str, count: float) -> None:
),
id="frame_with_space_parenthesis",
),
pytest.param(
" 4af76b main.cpuIntensiveWork+bar.go:21+bar.go:14 (/tmp/perf/my_go_app)",
dict(
dso_true="main.cpuIntensiveWork+bar.go:21+bar.go:14 (/tmp/perf/my_go_app)",
dso_false="main.cpuIntensiveWork+bar.go:21+bar.go:14",
),
id="frame_with_symline",
),
],
)
def test_collapse_stack_consider_dso(stack: str, insert_dso_name: bool, outcome_dict: Dict[str, str]) -> None:
Expand Down

0 comments on commit 2a18cf5

Please sign in to comment.