[PATCH 1/5] hwlatdetect: Make count field backward compatible
John Kacur <[email protected]>
| Newsgroups | org.kernel.vger.linux-rt-users |
|---|---|
| Message-ID | <[email protected]> |
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 <[email protected]>
Signed-off-by: John Kacur <[email protected]>
---
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