Blame SOURCES/Bytes-string-encoding-2004.patch

33c334
From b96ebcd2f328cd694101d657341faeb5869556a9 Mon Sep 17 00:00:00 2001
33c334
From: jeromemarchand <38073585+jeromemarchand@users.noreply.github.com>
33c334
Date: Wed, 10 Oct 2018 01:58:15 +0200
33c334
Subject: [PATCH] Bytes/string encoding (#2004)
33c334
33c334
* tools: uses 'replace' error handler by default in decode()
33c334
33c334
Tools might encouter characters from non utf-8 charset (e.g. a file
33c334
name). When this happen, it's better to replace the unexpected
33c334
character by a question mark than crash the tool when all we do is
33c334
to print the string.
33c334
33c334
* tools: fix a bytes/string issue in attach_perf_event()
33c334
---
33c334
 tools/bashreadline.py   |  2 +-
33c334
 tools/biosnoop.py       |  4 ++--
33c334
 tools/biotop.py         |  4 ++--
33c334
 tools/btrfsslower.py    | 10 ++++++----
33c334
 tools/cachetop.py       |  2 +-
33c334
 tools/capable.py        |  4 ++--
33c334
 tools/dcsnoop.py        |  5 +++--
33c334
 tools/ext4slower.py     | 10 ++++++----
33c334
 tools/filelife.py       |  3 ++-
33c334
 tools/fileslower.py     |  6 +++---
33c334
 tools/filetop.py        |  7 ++++---
33c334
 tools/funcslower.py     |  4 ++--
33c334
 tools/gethostlatency.py |  4 ++--
33c334
 tools/hardirqs.py       |  2 +-
33c334
 tools/llcstat.py        |  2 +-
33c334
 tools/mdflush.py        |  3 ++-
33c334
 tools/mountsnoop.py     |  4 ++--
33c334
 tools/nfsslower.py      |  4 ++--
33c334
 tools/offcputime.py     |  4 ++--
33c334
 tools/offwaketime.py    |  8 ++++----
33c334
 tools/old/offcputime.py |  2 +-
33c334
 tools/old/oomkill.py    |  4 ++--
33c334
 tools/old/profile.py    |  2 +-
33c334
 tools/old/wakeuptime.py |  8 ++++----
33c334
 tools/oomkill.py        |  4 ++--
33c334
 tools/opensnoop.py      |  3 ++-
33c334
 tools/profile.py        |  8 ++++----
33c334
 tools/sslsniff.py       |  5 +++--
33c334
 tools/stackcount.py     |  2 +-
33c334
 tools/statsnoop.py      |  5 +++--
33c334
 tools/tcpaccept.py      |  7 ++++---
33c334
 tools/tcpconnect.py     |  7 ++++---
33c334
 tools/tcpconnlat.py     |  8 ++++----
33c334
 tools/tcplife.py        |  4 ++--
33c334
 tools/tcpstates.py      |  4 ++--
33c334
 tools/tcptracer.py      |  4 ++--
33c334
 tools/trace.py          |  3 ++-
33c334
 tools/ttysnoop.py       |  2 +-
33c334
 tools/zfsslower.py      | 10 ++++++----
33c334
 39 files changed, 100 insertions(+), 84 deletions(-)
33c334
33c334
diff --git a/tools/bashreadline.py b/tools/bashreadline.py
33c334
index aaf6fc7..89c37c3 100755
33c334
--- a/tools/bashreadline.py
33c334
+++ b/tools/bashreadline.py
33c334
@@ -57,7 +57,7 @@ print("%-9s %-6s %s" % ("TIME", "PID", "COMMAND"))
33c334
 def print_event(cpu, data, size):
33c334
     event = ct.cast(data, ct.POINTER(Data)).contents
33c334
     print("%-9s %-6d %s" % (strftime("%H:%M:%S"), event.pid,
33c334
-                            event.str.decode()))
33c334
+                            event.str.decode('utf-8', 'replace')))
33c334
 
33c334
 b["events"].open_perf_buffer(print_event)
33c334
 while 1:
33c334
diff --git a/tools/biosnoop.py b/tools/biosnoop.py
33c334
index 7f61180..2b1e77d 100755
33c334
--- a/tools/biosnoop.py
33c334
+++ b/tools/biosnoop.py
33c334
@@ -176,8 +176,8 @@ delta = 0
33c334
         delta = float(delta) + (event.ts - prev_ts)
33c334
 
33c334
     print("%-14.9f %-14.14s %-6s %-7s %-2s %-9s %-7s %7.2f" % (
33c334
-        delta / 1000000, event.name.decode(), event.pid,
33c334
-        event.disk_name.decode(), rwflg, val,
33c334
+        delta / 1000000, event.name.decode('utf-8', 'replace'), event.pid,
33c334
+        event.disk_name.decode('utf-8', 'replace'), rwflg, val,
33c334
         event.len, float(event.delta) / 1000000))
33c334
 
33c334
     prev_ts = event.ts
33c334
diff --git a/tools/biotop.py b/tools/biotop.py
33c334
index 63d6642..c6e1ca2 100755
33c334
--- a/tools/biotop.py
33c334
+++ b/tools/biotop.py
33c334
@@ -221,8 +221,8 @@ exiting = 0
33c334
         # print line
33c334
         avg_ms = (float(v.us) / 1000) / v.io
33c334
         print("%-6d %-16s %1s %-3d %-3d %-8s %5s %7s %6.2f" % (k.pid,
33c334
-            k.name.decode(), "W" if k.rwflag else "R", k.major, k.minor,
33c334
-            diskname, v.io, v.bytes / 1024, avg_ms))
33c334
+            k.name.decode('utf-8', 'replace'), "W" if k.rwflag else "R",
33c334
+            k.major, k.minor, diskname, v.io, v.bytes / 1024, avg_ms))
33c334
 
33c334
         line += 1
33c334
         if line >= maxrows:
33c334
diff --git a/tools/btrfsslower.py b/tools/btrfsslower.py
33c334
index 644cb22..d48e04c 100755
33c334
--- a/tools/btrfsslower.py
33c334
+++ b/tools/btrfsslower.py
33c334
@@ -316,12 +316,14 @@ TASK_COMM_LEN = 16      # linux/sched.h
33c334
 
33c334
     if (csv):
33c334
         print("%d,%s,%d,%s,%d,%d,%d,%s" % (
33c334
-            event.ts_us, event.task.decode(), event.pid, type, event.size,
33c334
-            event.offset, event.delta_us, event.file.decode()))
33c334
+            event.ts_us, event.task.decode('utf-8', 'replace'), event.pid,
33c334
+            type, event.size, event.offset, event.delta_us,
33c334
+            event.file.decode('utf-8', 'replace')))
33c334
         return
33c334
     print("%-8s %-14.14s %-6s %1s %-7s %-8d %7.2f %s" % (strftime("%H:%M:%S"),
33c334
-        event.task.decode(), event.pid, type, event.size, event.offset / 1024,
33c334
-        float(event.delta_us) / 1000, event.file.decode()))
33c334
+        event.task.decode('utf-8', 'replace'), event.pid, type, event.size,
33c334
+        event.offset / 1024, float(event.delta_us) / 1000,
33c334
+        event.file.decode('utf-8', 'replace')))
33c334
 
33c334
 # initialize BPF
33c334
 b = BPF(text=bpf_text)
33c334
diff --git a/tools/cachetop.py b/tools/cachetop.py
33c334
index 0e08af9..1013675 100755
33c334
--- a/tools/cachetop.py
33c334
+++ b/tools/cachetop.py
33c334
@@ -72,7 +72,7 @@ def get_processes_stats(
33c334
     counts = bpf.get_table("counts")
33c334
     stats = defaultdict(lambda: defaultdict(int))
33c334
     for k, v in counts.items():
33c334
-        stats["%d-%d-%s" % (k.pid, k.uid, k.comm.decode())][k.ip] = v.value
33c334
+        stats["%d-%d-%s" % (k.pid, k.uid, k.comm.decode('utf-8', 'replace'))][k.ip] = v.value
33c334
     stats_list = []
33c334
 
33c334
     for pid, count in sorted(stats.items(), key=lambda stat: stat[0]):
33c334
diff --git a/tools/capable.py b/tools/capable.py
33c334
index 3e032e9..efcff4d 100755
33c334
--- a/tools/capable.py
33c334
+++ b/tools/capable.py
33c334
@@ -148,8 +148,8 @@ print("%-9s %-6s %-6s %-16s %-4s %-20s %s" % (
33c334
     else:
33c334
         name = "?"
33c334
     print("%-9s %-6d %-6d %-16s %-4d %-20s %d" % (strftime("%H:%M:%S"),
33c334
-        event.uid, event.pid, event.comm.decode(), event.cap, name,
33c334
-        event.audit))
33c334
+        event.uid, event.pid, event.comm.decode('utf-8', 'replace'),
33c334
+        event.cap, name, event.audit))
33c334
 
33c334
 # loop with callback to print_event
33c334
 b["events"].open_perf_buffer(print_event)
33c334
diff --git a/tools/dcsnoop.py b/tools/dcsnoop.py
33c334
index 070c87a..13152c2 100755
33c334
--- a/tools/dcsnoop.py
33c334
+++ b/tools/dcsnoop.py
33c334
@@ -153,8 +153,9 @@ start_ts = time.time()
33c334
 def print_event(cpu, data, size):
33c334
     event = ct.cast(data, ct.POINTER(Data)).contents
33c334
     print("%-11.6f %-6d %-16s %1s %s" % (
33c334
-            time.time() - start_ts, event.pid, event.comm.decode(),
33c334
-            mode_s[event.type], event.filename.decode()))
33c334
+            time.time() - start_ts, event.pid,
33c334
+            event.comm.decode('utf-8', 'replace'), mode_s[event.type],
33c334
+            event.filename.decode('utf-8', 'replace')))
33c334
 
33c334
 # header
33c334
 print("%-11s %-6s %-16s %1s %s" % ("TIME(s)", "PID", "COMM", "T", "FILE"))
33c334
diff --git a/tools/ext4slower.py b/tools/ext4slower.py
33c334
index eb6430e..88db831 100755
33c334
--- a/tools/ext4slower.py
33c334
+++ b/tools/ext4slower.py
33c334
@@ -314,12 +314,14 @@ TASK_COMM_LEN = 16      # linux/sched.h
33c334
 
33c334
     if (csv):
33c334
         print("%d,%s,%d,%s,%d,%d,%d,%s" % (
33c334
-            event.ts_us, event.task.decode(), event.pid, type, event.size,
33c334
-            event.offset, event.delta_us, event.file.decode()))
33c334
+            event.ts_us, event.task.decode('utf-8', 'replace'), event.pid,
33c334
+            type, event.size, event.offset, event.delta_us,
33c334
+            event.file.decode('utf-8', 'replace')))
33c334
         return
33c334
     print("%-8s %-14.14s %-6s %1s %-7s %-8d %7.2f %s" % (strftime("%H:%M:%S"),
33c334
-        event.task.decode(), event.pid, type, event.size, event.offset / 1024,
33c334
-        float(event.delta_us) / 1000, event.file.decode()))
33c334
+        event.task.decode('utf-8', 'replace'), event.pid, type, event.size,
33c334
+        event.offset / 1024, float(event.delta_us) / 1000,
33c334
+        event.file.decode('utf-8', 'replace')))
33c334
 
33c334
 # initialize BPF
33c334
 b = BPF(text=bpf_text)
33c334
diff --git a/tools/filelife.py b/tools/filelife.py
33c334
index 0f4e269..410659d 100755
33c334
--- a/tools/filelife.py
33c334
+++ b/tools/filelife.py
33c334
@@ -136,7 +136,8 @@ print("%-8s %-6s %-16s %-7s %s" % ("TIME", "PID", "COMM", "AGE(s)", "FILE"))
33c334
 def print_event(cpu, data, size):
33c334
     event = ct.cast(data, ct.POINTER(Data)).contents
33c334
     print("%-8s %-6d %-16s %-7.2f %s" % (strftime("%H:%M:%S"), event.pid,
33c334
-        event.comm.decode(), float(event.delta) / 1000, event.fname.decode()))
33c334
+        event.comm.decode('utf-8', 'replace'), float(event.delta) / 1000,
33c334
+        event.fname.decode('utf-8', 'replace')))
33c334
 
33c334
 b["events"].open_perf_buffer(print_event)
33c334
 while 1:
33c334
diff --git a/tools/fileslower.py b/tools/fileslower.py
33c334
index 5caa4ca..25443a2 100755
33c334
--- a/tools/fileslower.py
33c334
+++ b/tools/fileslower.py
33c334
@@ -240,13 +240,13 @@ start_ts = time.time()
33c334
     event = ct.cast(data, ct.POINTER(Data)).contents
33c334
 
33c334
     ms = float(event.delta_us) / 1000
33c334
-    name = event.name.decode()
33c334
+    name = event.name.decode('utf-8', 'replace')
33c334
     if event.name_len > DNAME_INLINE_LEN:
33c334
         name = name[:-3] + "..."
33c334
 
33c334
     print("%-8.3f %-14.14s %-6s %1s %-7s %7.2f %s" % (
33c334
-        time.time() - start_ts, event.comm.decode(), event.pid,
33c334
-        mode_s[event.mode], event.sz, ms, name))
33c334
+        time.time() - start_ts, event.comm.decode('utf-8', 'replace'),
33c334
+        event.pid, mode_s[event.mode], event.sz, ms, name))
33c334
 
33c334
 b["events"].open_perf_buffer(print_event, page_cnt=64)
33c334
 while 1:
33c334
diff --git a/tools/filetop.py b/tools/filetop.py
33c334
index 454dfd8..4c7a28a 100755
33c334
--- a/tools/filetop.py
33c334
+++ b/tools/filetop.py
33c334
@@ -190,14 +190,15 @@ exiting = 0
33c334
     for k, v in reversed(sorted(counts.items(),
33c334
                                 key=lambda counts:
33c334
                                   getattr(counts[1], args.sort))):
33c334
-        name = k.name.decode()
33c334
+        name = k.name.decode('utf-8', 'replace')
33c334
         if k.name_len > DNAME_INLINE_LEN:
33c334
             name = name[:-3] + "..."
33c334
 
33c334
         # print line
33c334
         print("%-6d %-16s %-6d %-6d %-7d %-7d %1s %s" % (k.pid,
33c334
-            k.comm.decode(), v.reads, v.writes, v.rbytes / 1024,
33c334
-            v.wbytes / 1024, k.type.decode(), name))
33c334
+            k.comm.decode('utf-8', 'replace'), v.reads, v.writes,
33c334
+            v.rbytes / 1024, v.wbytes / 1024,
33c334
+            k.type.decode('utf-8', 'replace'), name))
33c334
 
33c334
         line += 1
33c334
         if line >= maxrows:
33c334
diff --git a/tools/funcslower.py b/tools/funcslower.py
33c334
index 93fb846..261869e 100755
33c334
--- a/tools/funcslower.py
33c334
+++ b/tools/funcslower.py
33c334
@@ -306,7 +306,7 @@ earliest_ts = 0
33c334
         # print folded stack output
33c334
         user_stack = list(user_stack)
33c334
         kernel_stack = list(kernel_stack)
33c334
-        line = [event.comm.decode()] + \
33c334
+        line = [event.comm.decode('utf-8', 'replace')] + \
33c334
             [b.sym(addr, event.tgid_pid) for addr in reversed(user_stack)] + \
33c334
             (do_delimiter and ["-"] or []) + \
33c334
             [b.ksym(addr) for addr in reversed(kernel_stack)]
33c334
@@ -323,7 +323,7 @@ earliest_ts = 0
33c334
     ts = float(event.duration_ns) / time_multiplier
33c334
     if not args.folded:
33c334
         print((time_str(event) + "%-14.14s %-6s %7.2f %16x %s %s") %
33c334
-            (event.comm.decode(), event.tgid_pid >> 32,
33c334
+            (event.comm.decode('utf-8', 'replace'), event.tgid_pid >> 32,
33c334
              ts, event.retval, args.functions[event.id], args_str(event)))
33c334
     if args.user_stack or args.kernel_stack:
33c334
         print_stack(event)
33c334
diff --git a/tools/gethostlatency.py b/tools/gethostlatency.py
33c334
index f1d7dea..3a967ae 100755
33c334
--- a/tools/gethostlatency.py
33c334
+++ b/tools/gethostlatency.py
33c334
@@ -129,8 +129,8 @@ print("%-9s %-6s %-16s %10s %s" % ("TIME", "PID", "COMM", "LATms", "HOST"))
33c334
 def print_event(cpu, data, size):
33c334
     event = ct.cast(data, ct.POINTER(Data)).contents
33c334
     print("%-9s %-6d %-16s %10.2f %s" % (strftime("%H:%M:%S"), event.pid,
33c334
-        event.comm.decode(), (float(event.delta) / 1000000),
33c334
-        event.host.decode()))
33c334
+        event.comm.decode('utf-8', 'replace'), (float(event.delta) / 1000000),
33c334
+        event.host.decode('utf-8', 'replace')))
33c334
 
33c334
 # loop with callback to print_event
33c334
 b["events"].open_perf_buffer(print_event)
33c334
diff --git a/tools/hardirqs.py b/tools/hardirqs.py
33c334
index 3835d63..589a890 100755
33c334
--- a/tools/hardirqs.py
33c334
+++ b/tools/hardirqs.py
33c334
@@ -172,7 +172,7 @@ dist = b.get_table("dist")
33c334
     else:
33c334
         print("%-26s %11s" % ("HARDIRQ", "TOTAL_" + label))
33c334
         for k, v in sorted(dist.items(), key=lambda dist: dist[1].value):
33c334
-            print("%-26s %11d" % (k.name.decode(), v.value / factor))
33c334
+            print("%-26s %11d" % (k.name.decode('utf-8', 'replace'), v.value / factor))
33c334
     dist.clear()
33c334
 
33c334
     countdown -= 1
33c334
diff --git a/tools/llcstat.py b/tools/llcstat.py
33c334
index fe8bdd9..ec2c1f8 100755
33c334
--- a/tools/llcstat.py
33c334
+++ b/tools/llcstat.py
33c334
@@ -113,7 +113,7 @@ tot_miss = 0
33c334
     # This happens on some PIDs due to missed counts caused by sampling
33c334
     hit = (v.value - miss) if (v.value >= miss) else 0
33c334
     print('{:<8d} {:<16s} {:<4d} {:>12d} {:>12d} {:>6.2f}%'.format(
33c334
-        k.pid, k.name.decode(), k.cpu, v.value, miss,
33c334
+        k.pid, k.name.decode('utf-8', 'replace'), k.cpu, v.value, miss,
33c334
         (float(hit) / float(v.value)) * 100.0))
33c334
 print('Total References: {} Total Misses: {} Hit Rate: {:.2f}%'.format(
33c334
     tot_ref, tot_miss, (float(tot_ref - tot_miss) / float(tot_ref)) * 100.0))
33c334
diff --git a/tools/mdflush.py b/tools/mdflush.py
33c334
index 1d29bf1..70afc4d 100755
33c334
--- a/tools/mdflush.py
33c334
+++ b/tools/mdflush.py
33c334
@@ -72,7 +72,8 @@ print("%-8s %-6s %-16s %s" % ("TIME", "PID", "COMM", "DEVICE"))
33c334
 def print_event(cpu, data, size):
33c334
     event = ct.cast(data, ct.POINTER(Data)).contents
33c334
     print("%-8s %-6d %-16s %s" % (strftime("%H:%M:%S"), event.pid,
33c334
-        event.comm.decode(), event.disk.decode()))
33c334
+        event.comm.decode('utf-8', 'replace'),
33c334
+        event.disk.decode('utf-8', 'replace')))
33c334
 
33c334
 # read events
33c334
 b["events"].open_perf_buffer(print_event)
33c334
diff --git a/tools/mountsnoop.py b/tools/mountsnoop.py
33c334
index 2d0fa1a..e9b5865 100755
33c334
--- a/tools/mountsnoop.py
33c334
+++ b/tools/mountsnoop.py
33c334
@@ -382,8 +382,8 @@ _escape_chars = {
33c334
                     flags=decode_umount_flags(syscall['flags']),
33c334
                     retval=decode_errno(event.union.retval))
33c334
             print('{:16} {:<7} {:<7} {:<11} {}'.format(
33c334
-                syscall['comm'].decode(), syscall['tgid'], syscall['pid'],
33c334
-                syscall['mnt_ns'], call))
33c334
+                syscall['comm'].decode('utf-8', 'replace'), syscall['tgid'],
33c334
+                syscall['pid'], syscall['mnt_ns'], call))
33c334
     except KeyError:
33c334
         # This might happen if we lost an event.
33c334
         pass
33c334
diff --git a/tools/nfsslower.py b/tools/nfsslower.py
33c334
index 0f836af..2f92c90 100755
33c334
--- a/tools/nfsslower.py
33c334
+++ b/tools/nfsslower.py
33c334
@@ -280,13 +280,13 @@ TASK_COMM_LEN = 16      # linux/sched.h
33c334
         return
33c334
     print("%-8s %-14.14s %-6s %1s %-7s %-8d %7.2f %s" %
33c334
           (strftime("%H:%M:%S"),
33c334
-           event.task.decode(),
33c334
+           event.task.decode('utf-8', 'replace'),
33c334
            event.pid,
33c334
            type,
33c334
            event.size,
33c334
            event.offset / 1024,
33c334
            float(event.delta_us) / 1000,
33c334
-           event.file.decode()))
33c334
+           event.file.decode('utf-8', 'replace')))
33c334
 
33c334
 
33c334
 # Currently specifically works for NFSv4, the other kprobes are generic
33c334
diff --git a/tools/offcputime.py b/tools/offcputime.py
33c334
index de77fb4..d84ae52 100755
33c334
--- a/tools/offcputime.py
33c334
+++ b/tools/offcputime.py
33c334
@@ -281,7 +281,7 @@ stack_traces = b.get_table("stack_traces")
33c334
         # print folded stack output
33c334
         user_stack = list(user_stack)
33c334
         kernel_stack = list(kernel_stack)
33c334
-        line = [k.name.decode()]
33c334
+        line = [k.name.decode('utf-8', 'replace')]
33c334
         # if we failed to get the stack is, such as due to no space (-ENOMEM) or
33c334
         # hash collision (-EEXIST), we still print a placeholder for consistency
33c334
         if not args.kernel_stacks_only:
33c334
@@ -312,7 +312,7 @@ stack_traces = b.get_table("stack_traces")
33c334
             else:
33c334
                 for addr in user_stack:
33c334
                     print("    %s" % b.sym(addr, k.tgid))
33c334
-        print("    %-16s %s (%d)" % ("-", k.name.decode(), k.pid))
33c334
+        print("    %-16s %s (%d)" % ("-", k.name.decode('utf-8', 'replace'), k.pid))
33c334
         print("        %d\n" % v.value)
33c334
 
33c334
 if missing_stacks > 0:
33c334
diff --git a/tools/offwaketime.py b/tools/offwaketime.py
33c334
index 01961ee..674be22 100755
33c334
--- a/tools/offwaketime.py
33c334
+++ b/tools/offwaketime.py
33c334
@@ -316,7 +316,7 @@ need_delimiter = args.delimited and not (args.kernel_stacks_only or
33c334
 
33c334
     if folded:
33c334
         # print folded stack output
33c334
-        line = [k.target.decode()]
33c334
+        line = [k.target.decode('utf-8', 'replace')]
33c334
         if not args.kernel_stacks_only:
33c334
             if stack_id_err(k.t_u_stack_id):
33c334
                 line.append("[Missed User Stack]")
33c334
@@ -344,11 +344,11 @@ need_delimiter = args.delimited and not (args.kernel_stacks_only or
33c334
             else:
33c334
                 line.extend([b.sym(addr, k.w_tgid)
33c334
                     for addr in reversed(list(waker_user_stack))])
33c334
-        line.append(k.waker.decode())
33c334
+        line.append(k.waker.decode('utf-8', 'replace'))
33c334
         print("%s %d" % (";".join(line), v.value))
33c334
     else:
33c334
         # print wakeup name then stack in reverse order
33c334
-        print("    %-16s %s %s" % ("waker:", k.waker.decode(), k.t_pid))
33c334
+        print("    %-16s %s %s" % ("waker:", k.waker.decode('utf-8', 'replace'), k.t_pid))
33c334
         if not args.kernel_stacks_only:
33c334
             if stack_id_err(k.w_u_stack_id):
33c334
                 print("    [Missed User Stack]")
33c334
@@ -381,7 +381,7 @@ need_delimiter = args.delimited and not (args.kernel_stacks_only or
33c334
             else:
33c334
                 for addr in target_user_stack:
33c334
                     print("    %s" % b.sym(addr, k.t_tgid))
33c334
-        print("    %-16s %s %s" % ("target:", k.target.decode(), k.w_pid))
33c334
+        print("    %-16s %s %s" % ("target:", k.target.decode('utf-8', 'replace'), k.w_pid))
33c334
         print("        %d\n" % v.value)
33c334
 
33c334
 if missing_stacks > 0:
33c334
diff --git a/tools/old/offcputime.py b/tools/old/offcputime.py
33c334
index 680d924..38d12a2 100755
33c334
--- a/tools/old/offcputime.py
33c334
+++ b/tools/old/offcputime.py
33c334
@@ -185,7 +185,7 @@ matched = b.num_open_kprobes()
33c334
     for k, v in sorted(counts.items(), key=lambda counts: counts[1].value):
33c334
         if folded:
33c334
             # print folded stack output
33c334
-            line = k.name.decode() + ";"
33c334
+            line = k.name.decode('utf-8', 'replace') + ";"
33c334
             for i in reversed(range(0, maxdepth)):
33c334
                 if k.ret[i] == 0:
33c334
                     continue
33c334
diff --git a/tools/old/oomkill.py b/tools/old/oomkill.py
33c334
index e8e0321..b99f852 100755
33c334
--- a/tools/old/oomkill.py
33c334
+++ b/tools/old/oomkill.py
33c334
@@ -68,8 +68,8 @@ TASK_COMM_LEN = 16  # linux/sched.h
33c334
         avgline = stats.read().rstrip()
33c334
     print(("%s Triggered by PID %d (\"%s\"), OOM kill of PID %d (\"%s\")"
33c334
         ", %d pages, loadavg: %s") % (strftime("%H:%M:%S"), event.fpid,
33c334
-        event.fcomm.decode(), event.tpid, event.tcomm.decode(), event.pages,
33c334
-        avgline))
33c334
+        event.fcomm.decode('utf-8', 'replace'), event.tpid,
33c334
+        event.tcomm.decode('utf-8', 'replace'), event.pages, avgline))
33c334
 
33c334
 # initialize BPF
33c334
 b = BPF(text=bpf_text)
33c334
diff --git a/tools/old/profile.py b/tools/old/profile.py
33c334
index 04ca13a..e308208 100755
33c334
--- a/tools/old/profile.py
33c334
+++ b/tools/old/profile.py
33c334
@@ -339,7 +339,7 @@ stack_traces = b.get_table("stack_traces")
33c334
         # print folded stack output
33c334
         user_stack = list(user_stack)
33c334
         kernel_stack = list(kernel_stack)
33c334
-        line = [k.name.decode()] + \
33c334
+        line = [k.name.decode('utf-8', 'replace')] + \
33c334
             [b.sym(addr, k.pid) for addr in reversed(user_stack)] + \
33c334
             (do_delimiter and ["-"] or []) + \
33c334
             [aksym(addr) for addr in reversed(kernel_stack)]
33c334
diff --git a/tools/old/wakeuptime.py b/tools/old/wakeuptime.py
33c334
index e09840a..783c7ff 100644
33c334
--- a/tools/old/wakeuptime.py
33c334
+++ b/tools/old/wakeuptime.py
33c334
@@ -199,23 +199,23 @@ matched = b.num_open_kprobes()
33c334
     for k, v in sorted(counts.items(), key=lambda counts: counts[1].value):
33c334
         if folded:
33c334
             # print folded stack output
33c334
-            line = k.waker.decode() + ";"
33c334
+            line = k.waker.decode('utf-8', 'replace') + ";"
33c334
             for i in reversed(range(0, maxdepth)):
33c334
                 if k.ret[i] == 0:
33c334
                     continue
33c334
                 line = line + b.ksym(k.ret[i])
33c334
                 if i != 0:
33c334
                     line = line + ";"
33c334
-            print("%s;%s %d" % (line, k.target.decode(), v.value))
33c334
+            print("%s;%s %d" % (line, k.target.decode('utf-8', 'replace'), v.value))
33c334
         else:
33c334
             # print default multi-line stack output
33c334
-            print("    %-16s %s" % ("target:", k.target.decode()))
33c334
+            print("    %-16s %s" % ("target:", k.target.decode('utf-8', 'replace')))
33c334
             for i in range(0, maxdepth):
33c334
                 if k.ret[i] == 0:
33c334
                     break
33c334
                 print("    %-16x %s" % (k.ret[i],
33c334
                     b.ksym(k.ret[i])))
33c334
-            print("    %-16s %s" % ("waker:", k.waker.decode()))
33c334
+            print("    %-16s %s" % ("waker:", k.waker.decode('utf-8', 'replace')))
33c334
             print("        %d\n" % v.value)
33c334
     counts.clear()
33c334
 
33c334
diff --git a/tools/oomkill.py b/tools/oomkill.py
33c334
index e831d44..0677e49 100755
33c334
--- a/tools/oomkill.py
33c334
+++ b/tools/oomkill.py
33c334
@@ -69,8 +69,8 @@ TASK_COMM_LEN = 16  # linux/sched.h
33c334
         avgline = stats.read().rstrip()
33c334
     print(("%s Triggered by PID %d (\"%s\"), OOM kill of PID %d (\"%s\")"
33c334
         ", %d pages, loadavg: %s") % (strftime("%H:%M:%S"), event.fpid,
33c334
-        event.fcomm.decode(), event.tpid, event.tcomm.decode(), event.pages,
33c334
-        avgline))
33c334
+        event.fcomm.decode('utf-8', 'replace'), event.tpid,
33c334
+        event.tcomm.decode('utf-8', 'replace'), event.pages, avgline))
33c334
 
33c334
 # initialize BPF
33c334
 b = BPF(text=bpf_text)
33c334
diff --git a/tools/opensnoop.py b/tools/opensnoop.py
33c334
index a0657d4..418d47b 100755
33c334
--- a/tools/opensnoop.py
33c334
+++ b/tools/opensnoop.py
33c334
@@ -184,7 +184,8 @@ print("%-6s %-16s %4s %3s %s" %
33c334
 
33c334
     print("%-6d %-16s %4d %3d %s" %
33c334
           (event.id & 0xffffffff if args.tid else event.id >> 32,
33c334
-           event.comm.decode(), fd_s, err, event.fname.decode()))
33c334
+           event.comm.decode('utf-8', 'replace'), fd_s, err,
33c334
+           event.fname.decode('utf-8', 'replace')))
33c334
 
33c334
 # loop with callback to print_event
33c334
 b["events"].open_perf_buffer(print_event, page_cnt=64)
33c334
diff --git a/tools/profile.py b/tools/profile.py
33c334
index 1530b98..d1d3d26 100755
33c334
--- a/tools/profile.py
33c334
+++ b/tools/profile.py
33c334
@@ -268,7 +268,7 @@ b.attach_perf_event(ev_type=PerfType.SOFTWARE,
33c334
 
33c334
 def aksym(addr):
33c334
     if args.annotations:
33c334
-        return b.ksym(addr) + "_[k]"
33c334
+        return b.ksym(addr) + "_[k]".encode()
33c334
     else:
33c334
         return b.ksym(addr)
33c334
 
33c334
@@ -320,7 +320,7 @@ need_delimiter = args.delimited and not (args.kernel_stacks_only or
33c334
                 line.append("[Missed Kernel Stack]")
33c334
             else:
33c334
                 line.extend([b.ksym(addr) for addr in reversed(kernel_stack)])
33c334
-        print("%s %d" % (b";".join(line).decode(), v.value))
33c334
+        print("%s %d" % (b";".join(line).decode('utf-8', 'replace'), v.value))
33c334
     else:
33c334
         # print default multi-line stack output
33c334
         if not args.user_stacks_only:
33c334
@@ -336,8 +336,8 @@ need_delimiter = args.delimited and not (args.kernel_stacks_only or
33c334
                 print("    [Missed User Stack]")
33c334
             else:
33c334
                 for addr in user_stack:
33c334
-                    print("    %s" % b.sym(addr, k.pid).decode())
33c334
-        print("    %-16s %s (%d)" % ("-", k.name.decode(), k.pid))
33c334
+                    print("    %s" % b.sym(addr, k.pid).decode('utf-8', 'replace'))
33c334
+        print("    %-16s %s (%d)" % ("-", k.name.decode('utf-8', 'replace'), k.pid))
33c334
         print("        %d\n" % v.value)
33c334
 
33c334
 # check missing
33c334
diff --git a/tools/sslsniff.py b/tools/sslsniff.py
33c334
index 2e74fba..0c9f976 100755
33c334
--- a/tools/sslsniff.py
33c334
+++ b/tools/sslsniff.py
33c334
@@ -221,8 +221,9 @@ start = 0
33c334
                 " bytes lost) " + "-" * 5
33c334
 
33c334
     fmt = "%-12s %-18.9f %-16s %-6d %-6d\n%s\n%s\n%s\n\n"
33c334
-    print(fmt % (rw, time_s, event.comm.decode(), event.pid, event.len, s_mark,
33c334
-                 event.v0.decode(), e_mark))
33c334
+    print(fmt % (rw, time_s, event.comm.decode('utf-8', 'replace'),
33c334
+                 event.pid, event.len, s_mark,
33c334
+                 event.v0.decode('utf-8', 'replace'), e_mark))
33c334
 
33c334
 b["perf_SSL_write"].open_perf_buffer(print_event_write)
33c334
 b["perf_SSL_read"].open_perf_buffer(print_event_read)
33c334
diff --git a/tools/stackcount.py b/tools/stackcount.py
33c334
index 8781879..5554014 100755
33c334
--- a/tools/stackcount.py
33c334
+++ b/tools/stackcount.py
33c334
@@ -339,7 +339,7 @@ BPF_STACK_TRACE(stack_traces, 1024);
33c334
                     # print folded stack output
33c334
                     user_stack = list(user_stack)
33c334
                     kernel_stack = list(kernel_stack)
33c334
-                    line = [k.name.decode()] + \
33c334
+                    line = [k.name.decode('utf-8', 'replace')] + \
33c334
                         [b.sym(addr, k.tgid) for addr in
33c334
                         reversed(user_stack)] + \
33c334
                         (self.need_delimiter and ["-"] or []) + \
33c334
diff --git a/tools/statsnoop.py b/tools/statsnoop.py
33c334
index 6fd8049..4e62ebd 100755
33c334
--- a/tools/statsnoop.py
33c334
+++ b/tools/statsnoop.py
33c334
@@ -172,8 +172,9 @@ print("%-6s %-16s %4s %3s %s" % ("PID", "COMM", "FD", "ERR", "PATH"))
33c334
     if args.timestamp:
33c334
         print("%-14.9f" % (float(event.ts_ns - start_ts) / 1000000000), end="")
33c334
 
33c334
-    print("%-6d %-16s %4d %3d %s" % (event.pid, event.comm.decode(),
33c334
-        fd_s, err, event.fname.decode()))
33c334
+    print("%-6d %-16s %4d %3d %s" % (event.pid,
33c334
+        event.comm.decode('utf-8', 'replace'), fd_s, err,
33c334
+        event.fname.decode('utf-8', 'replace')))
33c334
 
33c334
 # loop with callback to print_event
33c334
 b["events"].open_perf_buffer(print_event, page_cnt=64)
33c334
diff --git a/tools/tcpaccept.py b/tools/tcpaccept.py
33c334
index 044f15c..884b0c5 100755
33c334
--- a/tools/tcpaccept.py
33c334
+++ b/tools/tcpaccept.py
33c334
@@ -239,7 +239,7 @@ TASK_COMM_LEN = 16      # linux/sched.h
33c334
             start_ts = event.ts_us
33c334
         print("%-9.3f" % ((float(event.ts_us) - start_ts) / 1000000), end="")
33c334
     print("%-6d %-12.12s %-2d %-16s %-16s %-4d" % (event.pid,
33c334
-        event.task.decode(), event.ip,
33c334
+        event.task.decode('utf-8', 'replace'), event.ip,
33c334
         inet_ntop(AF_INET, pack("I", event.daddr)),
33c334
         inet_ntop(AF_INET, pack("I", event.saddr)), event.lport))
33c334
 
33c334
@@ -251,8 +251,9 @@ TASK_COMM_LEN = 16      # linux/sched.h
33c334
             start_ts = event.ts_us
33c334
         print("%-9.3f" % ((float(event.ts_us) - start_ts) / 1000000), end="")
33c334
     print("%-6d %-12.12s %-2d %-16s %-16s %-4d" % (event.pid,
33c334
-        event.task.decode(), event.ip, inet_ntop(AF_INET6, event.daddr),
33c334
-        inet_ntop(AF_INET6, event.saddr), event.lport))
33c334
+        event.task.decode('utf-8', 'replace'), event.ip,
33c334
+        inet_ntop(AF_INET6, event.daddr),inet_ntop(AF_INET6, event.saddr),
33c334
+        event.lport))
33c334
 
33c334
 # initialize BPF
33c334
 b = BPF(text=bpf_text)
33c334
diff --git a/tools/tcpconnect.py b/tools/tcpconnect.py
33c334
index f0b23b0..ac84326 100755
33c334
--- a/tools/tcpconnect.py
33c334
+++ b/tools/tcpconnect.py
33c334
@@ -202,7 +202,7 @@ TASK_COMM_LEN = 16      # linux/sched.h
33c334
             start_ts = event.ts_us
33c334
         print("%-9.3f" % ((float(event.ts_us) - start_ts) / 1000000), end="")
33c334
     print("%-6d %-12.12s %-2d %-16s %-16s %-4d" % (event.pid,
33c334
-        event.task.decode(), event.ip,
33c334
+        event.task.decode('utf-8', 'replace'), event.ip,
33c334
         inet_ntop(AF_INET, pack("I", event.saddr)),
33c334
         inet_ntop(AF_INET, pack("I", event.daddr)), event.dport))
33c334
 
33c334
@@ -214,8 +214,9 @@ TASK_COMM_LEN = 16      # linux/sched.h
33c334
             start_ts = event.ts_us
33c334
         print("%-9.3f" % ((float(event.ts_us) - start_ts) / 1000000), end="")
33c334
     print("%-6d %-12.12s %-2d %-16s %-16s %-4d" % (event.pid,
33c334
-        event.task.decode(), event.ip, inet_ntop(AF_INET6, event.saddr),
33c334
-        inet_ntop(AF_INET6, event.daddr), event.dport))
33c334
+        event.task.decode('utf-8', 'replace'), event.ip,
33c334
+        inet_ntop(AF_INET6, event.saddr), inet_ntop(AF_INET6, event.daddr),
33c334
+        event.dport))
33c334
 
33c334
 # initialize BPF
33c334
 b = BPF(text=bpf_text)
33c334
diff --git a/tools/tcpconnlat.py b/tools/tcpconnlat.py
33c334
index 233612b..0d21b83 100755
33c334
--- a/tools/tcpconnlat.py
33c334
+++ b/tools/tcpconnlat.py
33c334
@@ -237,7 +237,7 @@ start_ts = 0
33c334
             start_ts = event.ts_us
33c334
         print("%-9.3f" % ((float(event.ts_us) - start_ts) / 1000000), end="")
33c334
     print("%-6d %-12.12s %-2d %-16s %-16s %-5d %.2f" % (event.pid,
33c334
-        event.task.decode(), event.ip,
33c334
+        event.task.decode('utf-8', 'replace'), event.ip,
33c334
         inet_ntop(AF_INET, pack("I", event.saddr)),
33c334
         inet_ntop(AF_INET, pack("I", event.daddr)), event.dport,
33c334
         float(event.delta_us) / 1000))
33c334
@@ -250,9 +250,9 @@ start_ts = 0
33c334
             start_ts = event.ts_us
33c334
         print("%-9.3f" % ((float(event.ts_us) - start_ts) / 1000000), end="")
33c334
     print("%-6d %-12.12s %-2d %-16s %-16s %-5d %.2f" % (event.pid,
33c334
-        event.task.decode(), event.ip, inet_ntop(AF_INET6, event.saddr),
33c334
-        inet_ntop(AF_INET6, event.daddr), event.dport,
33c334
-        float(event.delta_us) / 1000))
33c334
+        event.task.decode('utf-8', 'replace'), event.ip,
33c334
+        inet_ntop(AF_INET6, event.saddr), inet_ntop(AF_INET6, event.daddr),
33c334
+        event.dport, float(event.delta_us) / 1000))
33c334
 
33c334
 # header
33c334
 if args.timestamp:
33c334
diff --git a/tools/tcplife.py b/tools/tcplife.py
33c334
index f8bab43..51ed7ae 100755
33c334
--- a/tools/tcplife.py
33c334
+++ b/tools/tcplife.py
33c334
@@ -454,7 +454,7 @@ format_string = "%-5d %-10.10s %s%-15s %-5d %-15s %-5d %5d %5d %.2f"
33c334
             print("%.6f," % delta_s, end="")
33c334
         else:
33c334
             print("%-9.6f " % delta_s, end="")
33c334
-    print(format_string % (event.pid, event.task.decode(),
33c334
+    print(format_string % (event.pid, event.task.decode('utf-8', 'replace'),
33c334
         "4" if args.wide or args.csv else "",
33c334
         inet_ntop(AF_INET, pack("I", event.saddr)), event.ports >> 32,
33c334
         inet_ntop(AF_INET, pack("I", event.daddr)), event.ports & 0xffffffff,
33c334
@@ -476,7 +476,7 @@ format_string = "%-5d %-10.10s %s%-15s %-5d %-15s %-5d %5d %5d %.2f"
33c334
             print("%.6f," % delta_s, end="")
33c334
         else:
33c334
             print("%-9.6f " % delta_s, end="")
33c334
-    print(format_string % (event.pid, event.task.decode(),
33c334
+    print(format_string % (event.pid, event.task.decode('utf-8', 'replace'),
33c334
         "6" if args.wide or args.csv else "",
33c334
         inet_ntop(AF_INET6, event.saddr), event.ports >> 32,
33c334
         inet_ntop(AF_INET6, event.daddr), event.ports & 0xffffffff,
33c334
diff --git a/tools/tcpstates.py b/tools/tcpstates.py
33c334
index ec758d2..381a6d5 100755
33c334
--- a/tools/tcpstates.py
33c334
+++ b/tools/tcpstates.py
33c334
@@ -276,7 +276,7 @@ format_string = ("%-16x %-5d %-10.10s %s%-15s %-5d %-15s %-5d %-11s " +
33c334
             print("%.6f," % delta_s, end="")
33c334
         else:
33c334
             print("%-9.6f " % delta_s, end="")
33c334
-    print(format_string % (event.skaddr, event.pid, event.task.decode(),
33c334
+    print(format_string % (event.skaddr, event.pid, event.task.decode('utf-8', 'replace'),
33c334
         "4" if args.wide or args.csv else "",
33c334
         inet_ntop(AF_INET, pack("I", event.saddr)), event.ports >> 32,
33c334
         inet_ntop(AF_INET, pack("I", event.daddr)), event.ports & 0xffffffff,
33c334
@@ -299,7 +299,7 @@ format_string = ("%-16x %-5d %-10.10s %s%-15s %-5d %-15s %-5d %-11s " +
33c334
             print("%.6f," % delta_s, end="")
33c334
         else:
33c334
             print("%-9.6f " % delta_s, end="")
33c334
-    print(format_string % (event.skaddr, event.pid, event.task.decode(),
33c334
+    print(format_string % (event.skaddr, event.pid, event.task.decode('utf-8', 'replace'),
33c334
         "6" if args.wide or args.csv else "",
33c334
         inet_ntop(AF_INET6, event.saddr), event.ports >> 32,
33c334
         inet_ntop(AF_INET6, event.daddr), event.ports & 0xffffffff,
33c334
diff --git a/tools/tcptracer.py b/tools/tcptracer.py
33c334
index 5e97ee6..16bb4b1 100755
33c334
--- a/tools/tcptracer.py
33c334
+++ b/tools/tcptracer.py
33c334
@@ -556,7 +556,7 @@ verbose_types = {"C": "connect", "A": "accept",
33c334
         print("%-2s " % (type_str), end="")
33c334
 
33c334
     print("%-6d %-16s %-2d %-16s %-16s %-6d %-6d" %
33c334
-          (event.pid, event.comm.decode('utf-8'),
33c334
+          (event.pid, event.comm.decode('utf-8', 'replace'),
33c334
            event.ip,
33c334
            inet_ntop(AF_INET, pack("I", event.saddr)),
33c334
            inet_ntop(AF_INET, pack("I", event.daddr)),
33c334
@@ -593,7 +593,7 @@ verbose_types = {"C": "connect", "A": "accept",
33c334
         print("%-2s " % (type_str), end="")
33c334
 
33c334
     print("%-6d %-16s %-2d %-16s %-16s %-6d %-6d" %
33c334
-          (event.pid, event.comm.decode('utf-8'),
33c334
+          (event.pid, event.comm.decode('utf-8', 'replace'),
33c334
            event.ip,
33c334
            "[" + inet_ntop(AF_INET6, event.saddr) + "]",
33c334
            "[" + inet_ntop(AF_INET6, event.daddr) + "]",
33c334
diff --git a/tools/trace.py b/tools/trace.py
33c334
index 16e9b6b..2233305 100755
33c334
--- a/tools/trace.py
33c334
+++ b/tools/trace.py
33c334
@@ -558,7 +558,8 @@ BPF_PERF_OUTPUT(%s);
33c334
                 if Probe.print_cpu:
33c334
                     print("%-3s " % event.cpu, end="")
33c334
                 print("%-7d %-7d %-15s %-16s %s" %
33c334
-                      (event.tgid, event.pid, event.comm.decode(),
33c334
+                      (event.tgid, event.pid,
33c334
+                       event.comm.decode('utf-8', 'replace'),
33c334
                        self._display_function(), msg))
33c334
 
33c334
                 if self.kernel_stack:
33c334
diff --git a/tools/ttysnoop.py b/tools/ttysnoop.py
33c334
index e934486..9780518 100755
33c334
--- a/tools/ttysnoop.py
33c334
+++ b/tools/ttysnoop.py
33c334
@@ -115,7 +115,7 @@ BUFSIZE = 256
33c334
 # process event
33c334
 def print_event(cpu, data, size):
33c334
     event = ct.cast(data, ct.POINTER(Data)).contents
33c334
-    print("%s" % event.buf[0:event.count].decode(), end="")
33c334
+    print("%s" % event.buf[0:event.count].decode('utf-8', 'replace'), end="")
33c334
     sys.stdout.flush()
33c334
 
33c334
 # loop with callback to print_event
33c334
diff --git a/tools/zfsslower.py b/tools/zfsslower.py
33c334
index 6de4606..8ab283a 100755
33c334
--- a/tools/zfsslower.py
33c334
+++ b/tools/zfsslower.py
33c334
@@ -265,12 +265,14 @@ TASK_COMM_LEN = 16      # linux/sched.h
33c334
 
33c334
     if (csv):
33c334
         print("%d,%s,%d,%s,%d,%d,%d,%s" % (
33c334
-            event.ts_us, event.task.decode(), event.pid, type, event.size,
33c334
-            event.offset, event.delta_us, event.file.decode()))
33c334
+            event.ts_us, event.task.decode('utf-8', 'replace'), event.pid,
33c334
+            type, event.size, event.offset, event.delta_us,
33c334
+            event.file.decode('utf-8', 'replace')))
33c334
         return
33c334
     print("%-8s %-14.14s %-6s %1s %-7s %-8d %7.2f %s" % (strftime("%H:%M:%S"),
33c334
-        event.task.decode(), event.pid, type, event.size, event.offset / 1024,
33c334
-        float(event.delta_us) / 1000, event.file.decode()))
33c334
+        event.task.decode('utf-8', 'replace'), event.pid, type, event.size,
33c334
+        event.offset / 1024, float(event.delta_us) / 1000,
33c334
+        event.file.decode('utf-8', 'replace')))
33c334
 
33c334
 # initialize BPF
33c334
 b = BPF(text=bpf_text)
33c334
-- 
33c334
2.17.2
33c334