-
Notifications
You must be signed in to change notification settings - Fork 19
feat:Implement perf event groups, scaled reads, and group snapshots #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4649696
Add support for perf event group management in BPF
SiyuanSun0736 4becf2e
Implement performance event group management and reading enhancements
SiyuanSun0736 68bfab7
Enhanced the output of cache miss counts and branch miss counts for p…
SiyuanSun0736 d1062ed
feat(perf): unify perf reads into PerfRead snapshots
SiyuanSun0736 5c80c4c
fix perf read selection for grouped non-leader events
SiyuanSun0736 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -14,20 +14,26 @@ fn main() -> i32 { | |
| // pid: 0 = current process, cpu: -1 = any CPU (standard per-process monitoring). | ||
| // page_faults (PERF_COUNT_SW_PAGE_FAULTS) is the most reliable software event: | ||
| // every heap/stack allocation triggers minor page faults, no scheduler dependency. | ||
| var att = attach(prog, perf_options { perf_type: perf_type_software, perf_config: page_faults, pid: 0, cpu: -1, period: 1 }, 0) | ||
| print("Page-fault perf_event demo attached") | ||
| var page = attach(prog, perf_options { perf_type: perf_type_software, perf_config: page_faults, pid: 0, cpu: -1, period: 1 }, 0) | ||
| // branch is a standalone hardware event; page_faults remains a separate software event. | ||
| var branch = attach(prog, perf_options { perf_type: perf_type_hardware, perf_config: branch_misses, period: 10000000, inherit: true}, 0) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. branch has no group? |
||
|
|
||
| print("perf_event demo attached") | ||
|
|
||
| // Repeatedly increment a counter; stack/heap activity will generate page faults. | ||
| var x: i64 = 0 | ||
| for (i in 0..10000000) { | ||
| x = x + 1 | ||
| } | ||
|
|
||
| var count = read(att) | ||
| print("Page-fault count: %lld", count) | ||
| var page_fault_count = read(page).scaled | ||
| print("Page-fault count: %lld", page_fault_count) | ||
| var branch_count = read(branch).scaled | ||
| print("Branch-miss count: %lld", branch_count) | ||
|
|
||
| detach(att) | ||
| print("Page-fault perf_event demo detached") | ||
| detach(page) | ||
| detach(branch) | ||
| print("perf_event demo detached") | ||
| detach(prog) | ||
| return 0 | ||
| } | ||
This file contains hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR sets read_format to include PERF_FORMAT_GROUP on every event, and reads into a group buffer:
result->raw = (int64_t)group.values[0].value; // values[0] == leader
result->scaled = result->values[0];
With PERF_FORMAT_GROUP, a read(2) on any fd in the group is serviced by the kernel via that event's group_leader and returns the entries leader-first. The fd you pass picks which group, not which entry. So
whether you read the cache fd or the branch fd, the buffer comes back as:
nr=2, time_enabled, time_running,
values[0] = { cache_misses_value, cache_id } <- always the leader
values[1] = { branch_misses_value, branch_id }
scaled/raw are hardcoded to values[0], which is the leader. So read(branch).scaled returns the cache-miss count, even though the example labels and uses it as the branch-miss count. The branch value is sitting at values[1], but PerfRead gives you no "which index is me" — so you can't reliably pull it out.
If branch had instead been a standalone event (no group:), read(branch).scaled would be correct — nr=1, values[0] is branch's own. The bug only bites when you read() a non-leader member, which is exactly what the example does.