Skip to content

tools/trace: fix -M/--max-events exceeding the specified limit#5536

Open
Gbell26 wants to merge 1 commit into
iovisor:masterfrom
Gbell26:fix_trace
Open

tools/trace: fix -M/--max-events exceeding the specified limit#5536
Gbell26 wants to merge 1 commit into
iovisor:masterfrom
Gbell26:fix_trace

Conversation

@Gbell26

@Gbell26 Gbell26 commented Jul 16, 2026

Copy link
Copy Markdown

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 491
Add 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

  • [ x] Commit prefix matches changed area (e.g., tools/toolname:, libbpf-tools/toolname:, src/cc:, docs:, build:, tests/python:)
  • [x ] Commit body explains why this change is needed

For new tools only

  • Explains why this tool is needed and what existing tools cannot cover this use case
  • Includes at least one real production use case
  • Man page (man/man8/) with an OVERHEAD section
  • Example output file (*_example.txt)
  • README.md entry added
  • Smoke test added to tests/python/test_tools_smoke.py

About AI Code Review: This project uses GitHub Copilot to assist with code review.
If a Copilot review is added, treat its feedback as you would any reviewer comment — you can
agree, disagree (with explanation), or ask questions. The maintainer makes all final decisions.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant