[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20191220122957.8091-1-hws@denx.de>
Date: Fri, 20 Dec 2019 13:29:57 +0100
From: Harald Seiler <hws@...x.de>
To: linux-kernel@...r.kernel.org
Cc: Jiri Olsa <jolsa@...hat.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
Ingo Molnar <mingo@...hat.com>,
Peter Zijlstra <peterz@...radead.org>,
Harald Seiler <hws@...x.de>
Subject: [PATCH] perf python: Convert tracepoint example to python 3
Make the tracepoint example compatible with python 3 and fix string
handling of the prev_comm and next_comm fields so they are properly
truncated.
Signed-off-by: Harald Seiler <hws@...x.de>
---
tools/perf/python/tracepoint.py | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/tools/perf/python/tracepoint.py b/tools/perf/python/tracepoint.py
index eb76f6516247..a5420cfb3a31 100755
--- a/tools/perf/python/tracepoint.py
+++ b/tools/perf/python/tracepoint.py
@@ -3,6 +3,8 @@
# -*- python -*-
# -*- coding: utf-8 -*-
+from __future__ import print_function
+
import perf
class tracepoint(perf.evsel):
@@ -34,15 +36,23 @@ def main():
if not isinstance(event, perf.sample_event):
continue
- print "time %u prev_comm=%s prev_pid=%d prev_prio=%d prev_state=0x%x ==> next_comm=%s next_pid=%d next_prio=%d" % (
+ # The prev_comm and next_comm fields are `bytes` objects but they
+ # are not truncated to the first \x00. This is due to the
+ # underlying code treating the strings as just an array of
+ # arbitrary bytes. Convert them to properly truncated python
+ # strings.
+ prev_comm_str = event.prev_comm.split(b'\x00', 1)[0].decode(errors="ignore")
+ next_comm_str = event.next_comm.split(b'\x00', 1)[0].decode(errors="ignore")
+
+ print("time {} prev_comm={} prev_pid={} prev_prio={} prev_state=0x{:x} ==> next_comm={} next_pid={} next_prio={}".format(
event.sample_time,
- event.prev_comm,
+ prev_comm_str,
event.prev_pid,
event.prev_prio,
event.prev_state,
- event.next_comm,
+ next_comm_str,
event.next_pid,
- event.next_prio)
+ event.next_prio))
if __name__ == '__main__':
main()
--
2.20.1
Powered by blists - more mailing lists