tools/trace: fix -M/--max-events exceeding the specified limit#5536
Open
Gbell26 wants to merge 1 commit into
Open
tools/trace: fix -M/--max-events exceeding the specified limit#5536Gbell26 wants to merge 1 commit into
Gbell26 wants to merge 1 commit into
Conversation
When the event count reaches the -M limit, Probe.done is set to True, but remaining events in the current poll continue to be processed because the callback never checks the flag at entry. This causes -M to be unpredictable and occasionally print many more events than max_events Add an early return at the top of print_event when Probe.done is already set, so events beyond the limit are not printed. Signed-off-by: Gregory Bell <grbell@redhat.com>
Gbell26
requested review from
brendangregg,
chenhengqi,
ekyooo and
yonghong-song
as code owners
July 16, 2026 18:53
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
When the event count reaches the -M limit, Probe.done is set to True, but remaining events in the current poll continue to be processed because the callback never checks the flag at entry.
This causes -M to be unpredictable and occasionally print many more events than max_events
ex:
# sudo /usr/share/bcc/tools/trace -M 50 'c:malloc "size = %d", arg1' | wc -l 491Add an early return at the top of print_event when Probe.done is already set, so events beyond the limit are not printed.
Why this approach
AFAICT this is the only point to interrupt inbetween individual events and stopping the entirety of the returned events from being printed
Checklist
tools/toolname:,libbpf-tools/toolname:,src/cc:,docs:,build:,tests/python:)For new tools only
man/man8/) with an OVERHEAD section*_example.txt)tests/python/test_tools_smoke.py