Skip to content

ftrace: Update ftrace event regex#262

Draft
felix-khlmnn wants to merge 2 commits intoeclipse-tracecompass-incubator:masterfrom
felix-khlmnn:ftrace-regex-update
Draft

ftrace: Update ftrace event regex#262
felix-khlmnn wants to merge 2 commits intoeclipse-tracecompass-incubator:masterfrom
felix-khlmnn:ftrace-regex-update

Conversation

@felix-khlmnn
Copy link
Copy Markdown

@felix-khlmnn felix-khlmnn commented Jan 5, 2026

What it does

Fixes: #239

As described in issue #239, the regex used for parsing ftrace events currently fails to correctly parse text files under specific circumstances. I have found that to be the case with event names that start with opening parentheses. It only occurs when parsing text files, which was necessary in my case.

In my case, the event (udev-worker) caused the parsing of the file to be halted. It only managed to fully parse the file when I changed every occurence of (udev-worker) to udev-worker. This led me to assume that the parentheses mess with the parsing of the data fields.

Using regex101, I have adopted the regex to correctly parse the trace provided in the "How to test" section. No further testing could be done yet as explained in the issue.

How to test

The testing can be done using an example of a trace I have provided here.

  1. Download the ZIP file from the link above.
  2. Transform the binary file "long_program.dat" into a text file with trace-cmd report -i long_program.dat > long_program.txt
  3. Load both the binary (dat) and the ascii (txt) file into Trace Compass
  4. Compare the number of events, if equal, parsing worked correctly.

Follow-ups

If I encounter similar issues I will report them in reference to this topic and update the regex if appropriate.

Review checklist

  • As an author, I have thoroughly tested my changes and carefully followed the instructions in this template
    (To the best of my ability, see linked issue)

Summary by CodeRabbit

  • Bug Fixes

    • FTRACE event parsing now captures the full remainder of each event line, ensuring trailing content (including previously excluded characters) is consistently extracted and displayed in trace views.
  • Tests

    • Added a parsing test covering lines that start with parentheses to validate correct field extraction and guard against regressions in this edge case.

✏️ Tip: You can customize this high-level summary in your review settings.

The regex used for the parsing of ftrace events proved inadequate for
parsing certain events, namely those that started with opening
parentheses, as described in issue eclipse-tracecompass-incubator#239.

The solution is an update to the regex which I have attempted to verify
using regex101 in Java mode.

Fixes: eclipse-tracecompass-incubator#239
Signed-off-by: Felix Kuhlmann <felix-kuhlmann@gmx.de>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 5, 2026

📝 Walkthrough

Walkthrough

The FTRACE_PATTERN regex was changed to capture the entire remainder of the line (including any parentheses) instead of stopping before a closing parenthesis. A unit test was added to validate parsing of event names that begin with "(".

Changes

Cohort / File(s) Summary
Ftrace Event Parser Pattern
tracetypes/org.eclipse.tracecompass.incubator.ftrace.core/src/org/eclipse/tracecompass/incubator/internal/ftrace/core/event/IGenericFtraceConstants.java
Modified FTRACE_PATTERN regex: data group changed from (?<data>[^\\)]*)(\\))? to (?<data>.*)$, removing the exclusion of ) and the optional terminator so the remainder of the line is captured.
Tests (leading '(' name case)
tracetypes/org.eclipse.tracecompass.incubator.ftrace.core.tests/src/org/eclipse/tracecompass/incubator/ftrace/core/tests/event/FtraceFieldTest.java
Added testParseStartsWithParentheses() to verify parsing of a line starting with ( (e.g., (udev-worker)), asserting parsed fields including cpu, pid, name, comm, runtime, and vruntime.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I nudged the pattern, widened the line,
Parentheses linger — parsing's fine.
No slice at the start, no event denied,
Fields hop through clearly, nothing to hide. 🥕

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'ftrace: Update ftrace event regex' clearly and concisely describes the primary change made in the PR, which is updating the regular expression used for parsing ftrace events.
Linked Issues check ✅ Passed The PR successfully addresses the requirements from issue #239 by modifying the ftrace event regex pattern to handle event names starting with parentheses and adding a test case to validate the fix.
Out of Scope Changes check ✅ Passed All changes in the PR are directly related to fixing the ftrace parsing bug: the regex pattern modification in IGenericFtraceConstants.java and the new test case in FtraceFieldTest.java are both in scope.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 514d557 and 4e75b76.

📒 Files selected for processing (1)
  • tracetypes/org.eclipse.tracecompass.incubator.ftrace.core.tests/src/org/eclipse/tracecompass/incubator/ftrace/core/tests/event/FtraceFieldTest.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • tracetypes/org.eclipse.tracecompass.incubator.ftrace.core.tests/src/org/eclipse/tracecompass/incubator/ftrace/core/tests/event/FtraceFieldTest.java

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tracetypes/org.eclipse.tracecompass.incubator.ftrace.core/src/org/eclipse/tracecompass/incubator/internal/ftrace/core/event/IGenericFtraceConstants.java (1)

60-71: The regex change has been applied, but test coverage for the issue is incomplete.

The regex pattern on line 70 has been updated to (?<data>.*)$ (merged in commit ff0676e to fix issue #239). The change correctly makes the data capture group more permissive by capturing everything until end-of-line, which allows handling of events with parentheses.

However, while the test suite includes testSpecialCharsInComm() which covers brackets like runc:[2:INIT] and spaces in comm fields, there is no specific test case for the actual issue being fixed: parentheses in the comm field (e.g., (udev-worker)-PID).

Add a test case to FtraceFieldTest.java that covers the specific scenario described in issue #239:

Suggested test case
new ResultsParse("(udev-worker)-1234  [002] d...   149.136514: sched_process_fork: prev_comm=(udev-worker) prev_pid=1234 child_comm=systemd child_pid=1",
    2, "sched_process_fork", Objects.requireNonNull(Map.of("prev_comm", "(udev-worker)")), 3)

This ensures the regex properly handles comm fields enclosed in parentheses as intended by the fix.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 11f36c0 and ff0676e.

📒 Files selected for processing (1)
  • tracetypes/org.eclipse.tracecompass.incubator.ftrace.core/src/org/eclipse/tracecompass/incubator/internal/ftrace/core/event/IGenericFtraceConstants.java

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
tracetypes/org.eclipse.tracecompass.incubator.ftrace.core.tests/src/org/eclipse/tracecompass/incubator/ftrace/core/tests/event/FtraceFieldTest.java (1)

194-212: Consider validating all content fields and TID for test completeness.

The test correctly validates the parentheses parsing fix. However, for consistency with other tests in this class:

  1. Line 204 asserts 4 content fields exist, but only 3 are validated (comm, runtime, vruntime). The pid field from the event content is not checked.
  2. Similar tests (e.g., lines 49-50 in testParseSchedWakeupLine) also assert the TID value.
🔎 Suggested additions for completeness
     assertNotNull(field);
     assertEquals(4, field.getContent().getFields().size());
     assertEquals((Integer) 0, field.getCpu());
     assertEquals((Integer) 299, field.getPid());
+    assertEquals((Integer) 299, field.getTid());
     assertEquals("sched_stat_runtime", field.getName());
     
     assertEquals("systemd-udevd", field.getContent().getFieldValue(String.class, "comm"));
+    assertEquals((Long) 299L, field.getContent().getFieldValue(Long.class, "pid"));
     assertEquals((Long) 65790, field.getContent().getFieldValue(Long.class, "runtime"));
     assertEquals((Long) 6269486605L, field.getContent().getFieldValue(Long.class, "vruntime"));
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ff0676e and 1af2812.

📒 Files selected for processing (1)
  • tracetypes/org.eclipse.tracecompass.incubator.ftrace.core.tests/src/org/eclipse/tracecompass/incubator/ftrace/core/tests/event/FtraceFieldTest.java

@felix-khlmnn
Copy link
Copy Markdown
Author

I have added a unit test as per CodeRabbits recommendation that tests the specific use case that doesn't with status quo.

If the test should instead be moved to the special chars test case, I'll adapt the test.

MatthewKhouzam
MatthewKhouzam previously approved these changes Jan 5, 2026
Copy link
Copy Markdown
Contributor

@MatthewKhouzam MatthewKhouzam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a no-brainer, thanks for finding and fixing the bug!

@MatthewKhouzam
Copy link
Copy Markdown
Contributor

Let's wait for CI thought.

@felix-khlmnn
Copy link
Copy Markdown
Author

Let's wait for CI thought.

Had a minor mistake in the test implementation, the test itself should be correctly implemented now.

@MatthewKhouzam
Copy link
Copy Markdown
Contributor

Could you please squash the last two commits? I approve them! ;)

Implements a test case for the parentheses error described in eclipse-tracecompass-incubator#239.

Signed-off-by: Felix Kuhlmann <felix-kuhlmann@gmx.de>
@felix-khlmnn
Copy link
Copy Markdown
Author

That's not good, the CI fails at another test which means I need to rework the string.

I'll still squash the commits and fix the regex afterwards.

@MatthewKhouzam
Copy link
Copy Markdown
Contributor

FtraceFieldTest.testParseSysCallEnterFTrace:108 expected:<0> but was:

@MatthewKhouzam
Copy link
Copy Markdown
Contributor

Perfect, again, thanks!

@felix-khlmnn
Copy link
Copy Markdown
Author

Alright, the original regex works as intended with the (udev-line), but at the same time I have verified that TC still has the parsing error. I'll have to look into it a bit deeper, thus I'll mark this PR as a draft in the meantime.

Thanks @MatthewKhouzam for the support :)

@felix-khlmnn felix-khlmnn marked this pull request as draft January 5, 2026 20:26
@MatthewKhouzam
Copy link
Copy Markdown
Contributor

I checked the code...
String line = "test/1-1316 [005] ....... 713.920983: sys_recvmsg(fd: 3, msg: 7ffe3bd38070, flags: 0)";
Parses flags as the string '0)' keeping the closing bracket.

This is because of the greedy .*. I am tempted to implement a basic bracket parser. i.e. a +1 on ( and -1 on ) to reliably fix it. But it may be overkill.

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.

ftrace: Suspected parser errors cause majority of events after a certain point to not be listed

2 participants