|
|
379855 |
From f03beca4d6e6bc3fa7089416d752387bd26904dc Mon Sep 17 00:00:00 2001
|
|
|
379855 |
From: Jerome Marchand <jmarchan@redhat.com>
|
|
|
379855 |
Date: Fri, 15 Feb 2019 17:35:37 +0100
|
|
|
379855 |
Subject: [PATCH] tools: fix some python3 bytes vs strings issues (#2205)
|
|
|
379855 |
|
|
|
379855 |
It fixes the following errors:
|
|
|
379855 |
|
|
|
379855 |
$ execsnoop.py -q
|
|
|
379855 |
PCOMM PID PPID RET ARGS
|
|
|
379855 |
Traceback (most recent call last):
|
|
|
379855 |
File "_ctypes/callbacks.c", line 234, in 'calling callback function'
|
|
|
379855 |
File "/usr/lib/python3.6/site-packages/bcc/table.py", line 572, in raw_cb_
|
|
|
379855 |
callback(cpu, data, size)
|
|
|
379855 |
File "tools/execsnoop.py", line 229, in print_event
|
|
|
379855 |
for arg in argv[event.pid]
|
|
|
379855 |
File "tools/execsnoop.py", line 229, in <listcomp>
|
|
|
379855 |
for arg in argv[event.pid]
|
|
|
379855 |
TypeError: a bytes-like object is required, not 'str'
|
|
|
379855 |
|
|
|
379855 |
$ offcputime.py -K -f 5
|
|
|
379855 |
Traceback (most recent call last):
|
|
|
379855 |
File "./tools/offcputime.py", line 298, in <module>
|
|
|
379855 |
print("%s %d" % (";".join(line), v.value))
|
|
|
379855 |
TypeError: sequence item 1: expected str instance, bytes found
|
|
|
379855 |
|
|
|
379855 |
$ offwaketime.py -f 5
|
|
|
379855 |
Traceback (most recent call last):
|
|
|
379855 |
File "./tools/offwaketime.py", line 350, in <module>
|
|
|
379855 |
print("%s %d" % (";".join(line), v.value))
|
|
|
379855 |
TypeError: sequence item 1: expected str instance, bytes found
|
|
|
379855 |
---
|
|
|
379855 |
tools/execsnoop.py | 2 +-
|
|
|
379855 |
tools/offcputime.py | 6 ++++--
|
|
|
379855 |
tools/offwaketime.py | 8 ++++----
|
|
|
379855 |
3 files changed, 9 insertions(+), 7 deletions(-)
|
|
|
379855 |
|
|
|
379855 |
diff --git a/tools/execsnoop.py b/tools/execsnoop.py
|
|
|
379855 |
index c4021165..1ce83e07 100755
|
|
|
379855 |
--- a/tools/execsnoop.py
|
|
|
379855 |
+++ b/tools/execsnoop.py
|
|
|
379855 |
@@ -210,7 +210,7 @@ argv = defaultdict(list)
|
|
|
379855 |
skip = True
|
|
|
379855 |
if args.quote:
|
|
|
379855 |
argv[event.pid] = [
|
|
|
379855 |
- "\"" + arg.replace("\"", "\\\"") + "\""
|
|
|
379855 |
+ b"\"" + arg.replace(b"\"", b"\\\"") + b"\""
|
|
|
379855 |
for arg in argv[event.pid]
|
|
|
379855 |
]
|
|
|
379855 |
|
|
|
379855 |
diff --git a/tools/offcputime.py b/tools/offcputime.py
|
|
|
379855 |
index d84ae529..ac3b7281 100755
|
|
|
379855 |
--- a/tools/offcputime.py
|
|
|
379855 |
+++ b/tools/offcputime.py
|
|
|
379855 |
@@ -288,13 +288,15 @@ stack_traces = b.get_table("stack_traces")
|
|
|
379855 |
if stack_id_err(k.user_stack_id):
|
|
|
379855 |
line.append("[Missed User Stack]")
|
|
|
379855 |
else:
|
|
|
379855 |
- line.extend([b.sym(addr, k.tgid) for addr in reversed(user_stack)])
|
|
|
379855 |
+ line.extend([b.sym(addr, k.tgid).decode('utf-8', 'replace')
|
|
|
379855 |
+ for addr in reversed(user_stack)])
|
|
|
379855 |
if not args.user_stacks_only:
|
|
|
379855 |
line.extend(["-"] if (need_delimiter and k.kernel_stack_id >= 0 and k.user_stack_id >= 0) else [])
|
|
|
379855 |
if stack_id_err(k.kernel_stack_id):
|
|
|
379855 |
line.append("[Missed Kernel Stack]")
|
|
|
379855 |
else:
|
|
|
379855 |
- line.extend([b.ksym(addr) for addr in reversed(kernel_stack)])
|
|
|
379855 |
+ line.extend([b.ksym(addr).decode('utf-8', 'replace')
|
|
|
379855 |
+ for addr in reversed(kernel_stack)])
|
|
|
379855 |
print("%s %d" % (";".join(line), v.value))
|
|
|
379855 |
else:
|
|
|
379855 |
# print default multi-line stack output
|
|
|
379855 |
diff --git a/tools/offwaketime.py b/tools/offwaketime.py
|
|
|
379855 |
index 38a9ff25..4a1cebab 100755
|
|
|
379855 |
--- a/tools/offwaketime.py
|
|
|
379855 |
+++ b/tools/offwaketime.py
|
|
|
379855 |
@@ -323,28 +323,28 @@ need_delimiter = args.delimited and not (args.kernel_stacks_only or
|
|
|
379855 |
if stack_id_err(k.t_u_stack_id):
|
|
|
379855 |
line.append("[Missed User Stack]")
|
|
|
379855 |
else:
|
|
|
379855 |
- line.extend([b.sym(addr, k.t_tgid)
|
|
|
379855 |
+ line.extend([b.sym(addr, k.t_tgid).decode('utf-8', 'replace')
|
|
|
379855 |
for addr in reversed(list(target_user_stack)[1:])])
|
|
|
379855 |
if not args.user_stacks_only:
|
|
|
379855 |
line.extend(["-"] if (need_delimiter and k.t_k_stack_id > 0 and k.t_u_stack_id > 0) else [])
|
|
|
379855 |
if stack_id_err(k.t_k_stack_id):
|
|
|
379855 |
line.append("[Missed Kernel Stack]")
|
|
|
379855 |
else:
|
|
|
379855 |
- line.extend([b.ksym(addr)
|
|
|
379855 |
+ line.extend([b.ksym(addr).decode('utf-8', 'replace')
|
|
|
379855 |
for addr in reversed(list(target_kernel_stack)[1:])])
|
|
|
379855 |
line.append("--")
|
|
|
379855 |
if not args.user_stacks_only:
|
|
|
379855 |
if stack_id_err(k.w_k_stack_id):
|
|
|
379855 |
line.append("[Missed Kernel Stack]")
|
|
|
379855 |
else:
|
|
|
379855 |
- line.extend([b.ksym(addr)
|
|
|
379855 |
+ line.extend([b.ksym(addr).decode('utf-8', 'replace')
|
|
|
379855 |
for addr in reversed(list(waker_kernel_stack))])
|
|
|
379855 |
if not args.kernel_stacks_only:
|
|
|
379855 |
line.extend(["-"] if (need_delimiter and k.w_u_stack_id > 0 and k.w_k_stack_id > 0) else [])
|
|
|
379855 |
if stack_id_err(k.w_u_stack_id):
|
|
|
379855 |
line.append("[Missed User Stack]")
|
|
|
379855 |
else:
|
|
|
379855 |
- line.extend([b.sym(addr, k.w_tgid)
|
|
|
379855 |
+ line.extend([b.sym(addr, k.w_tgid).decode('utf-8', 'replace')
|
|
|
379855 |
for addr in reversed(list(waker_user_stack))])
|
|
|
379855 |
line.append(k.waker.decode('utf-8', 'replace'))
|
|
|
379855 |
print("%s %d" % (";".join(line), v.value))
|
|
|
379855 |
--
|
|
|
379855 |
2.20.1
|
|
|
379855 |
|