Skip to content

Commit 2a18cf5

Browse files
committed
perf: add -F +symline support
1 parent 9da69db commit 2a18cf5

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

gprofiler/utils/perf.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
r"(?:(?P<freq>\d+)\s+)?(?P<event_family>[\w\-_/]+):(?:(?P<event>[\w-]+):)?(?P<suffix>[^\n]*)(?:\n(?P<stack>.*))?",
4848
re.MULTILINE | re.DOTALL,
4949
)
50+
SYMLINE_REGEX = re.compile(r"(?:\+([^+]+):(\d+)){2}$")
5051

5152

5253
class SupportedPerfEvent(Enum):
@@ -160,7 +161,8 @@ def collapse_stack(comm: str, stack: str, insert_dso_name: bool = False) -> str:
160161
m = FRAME_REGEX.match(line)
161162
assert m is not None, f"bad line: {line}"
162163
sym, dso = m.group("symbol"), m.group("dso_brackets") or m.group("dso_plain")
163-
sym = sym.split("+")[0] # strip the offset part.
164+
if not SYMLINE_REGEX.search(sym):
165+
sym = sym.split("+")[0] # strip the offset part.
164166
if sym == "[unknown]" and dso != "unknown":
165167
sym = f"({dso})"
166168
# append kernel annotation

gprofiler/utils/perf_process.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def wait_and_script(self) -> str:
190190
perf_data = inject_data
191191

192192
perf_script_proc = run_process(
193-
[perf_path(), "script", "-F", "+pid", "-i", str(perf_data)],
193+
[perf_path(), "script", "-F", "+pid,+symline", "-i", str(perf_data)],
194194
suppress_log=True,
195195
)
196196
return perf_script_proc.stdout.decode("utf8")

scripts/perf_build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
set -euo pipefail
1818

1919
# downloading the zip because the git is very large (this is also very large, but still smaller)
20-
curl -SL https://codeload.github.com/Granulate/linux/zip/5c103bf97fb268e4ea157f5e1c2a5bd6ad8c40dc -o linux.zip
20+
curl -SL https://codeload.github.com/Granulate/linux/zip/9909d736d8b8927d79003dfa9732050a08c11221 -o linux.zip
2121
unzip -qq linux.zip
2222
rm linux.zip
2323
cd linux-*/

tests/test_perf.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,14 @@ def test_get_average_frame_count(samples: str, count: float) -> None:
397397
),
398398
id="frame_with_space_parenthesis",
399399
),
400+
pytest.param(
401+
" 4af76b main.cpuIntensiveWork+bar.go:21+bar.go:14 (/tmp/perf/my_go_app)",
402+
dict(
403+
dso_true="main.cpuIntensiveWork+bar.go:21+bar.go:14 (/tmp/perf/my_go_app)",
404+
dso_false="main.cpuIntensiveWork+bar.go:21+bar.go:14",
405+
),
406+
id="frame_with_symline",
407+
),
400408
],
401409
)
402410
def test_collapse_stack_consider_dso(stack: str, insert_dso_name: bool, outcome_dict: Dict[str, str]) -> None:

0 commit comments

Comments
 (0)