public inbox for linux-rt-users@vger.kernel.org
 help / color / mirror / Atom feed
From: John Kacur <jkacur@redhat.com>
To: linux-rt-users <linux-rt-users@vger.kernel.org>
Cc: Clark Williams <williams@redhat.com>,
	John Kacur <jkacur@redhat.com>,
	"Claude Sonnet 4.5" <noreply@anthropic.com>
Subject: [PATCH 1/5] hwlatdetect: Make count field backward compatible
Date: Thu, 19 Feb 2026 16:21:19 -0500	[thread overview]
Message-ID: <20260219212120.227106-2-jkacur@redhat.com> (raw)
In-Reply-To: <20260219212120.227106-1-jkacur@redhat.com>

The count field was added to hwlat trace output in kernel v5.10
(commit b396bfdebffc). Make this field optional to maintain backward
compatibility with older kernels:

- Set count to None when the field is not present in trace output
- Only include count in __str__ output when it exists
- Fall back to len(samples) in get("count") for older kernels

This allows hwlatdetect to work correctly on both kernels with and
without the count field.

Assisted-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Signed-off-by: John Kacur <jkacur@redhat.com>
---
 src/hwlatdetect/hwlatdetect.py | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/hwlatdetect/hwlatdetect.py b/src/hwlatdetect/hwlatdetect.py
index af9852cc95e8..c128f60bc8db 100755
--- a/src/hwlatdetect/hwlatdetect.py
+++ b/src/hwlatdetect/hwlatdetect.py
@@ -264,10 +264,12 @@ class Tracer(Detector):
             self.timestamp = str(ts)
             self.inner = int(i)
             self.outer = int(o)
-            self.count = int(kv["count"])
+            self.count = int(kv["count"]) if "count" in kv else None
 
         def __str__(self):
-            return f"ts: {self.timestamp}, inner:{self.inner}, outer:{self.outer}, cpu:{self.cpu}, count:{self.count}"
+            if self.count is not None:
+                return f"ts: {self.timestamp}, inner:{self.inner}, outer:{self.outer}, cpu:{self.cpu}, count:{self.count}"
+            return f"ts: {self.timestamp}, inner:{self.inner}, outer:{self.outer}, cpu:{self.cpu}"
 
         def display(self):
             """ convert object to string and print """
@@ -299,7 +301,10 @@ class Tracer(Detector):
 
     def get(self, field):
         if field == "count":
-            return sum(s.count for s in self.samples)
+            # Use new count field if available, otherwise fall back to sample count
+            if self.samples and self.samples[0].count is not None:
+                return sum(s.count for s in self.samples)
+            return len(self.samples)
         if field == "max":
             max = 0
             for values in self.samples:
-- 
2.53.0


  reply	other threads:[~2026-02-19 21:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-19 21:21 [PATCH 4/5] hwlatdetect: Add bounds checking and improve code readability John Kacur
2026-02-19 21:21 ` John Kacur [this message]
2026-02-19 21:21 ` [PATCH 5/5] rt-tests: cyclictest: Remove duplicate option in getopt string John Kacur

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260219212120.227106-2-jkacur@redhat.com \
    --to=jkacur@redhat.com \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=noreply@anthropic.com \
    --cc=williams@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox