From 29392650a9b038b7c739166a06da7b3db6f9e547 Mon Sep 17 00:00:00 2001 From: Rafael Fonseca Date: Mon, 6 Feb 2017 17:07:28 +0100 Subject: [PATCH] filetop: Fix TypeError by not mixing bytes and str. When executing the filetop command tool, the following message was generated: Traceback (most recent call last): File "/usr/share/bcc/tools/filetop", line 190, in name = name[:-3] + "..." TypeError: can't concat bytes to str Also, by decoding the bytes we print the strings without a leading "b'" making the output more readable. --- tools/filetop.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/filetop.py b/tools/filetop.py index 9f7c58df19e0..ed7e716cc795 100755 --- a/tools/filetop.py +++ b/tools/filetop.py @@ -185,14 +185,14 @@ def signal_ignore(signal, frame): line = 0 for k, v in reversed(sorted(counts.items(), key=lambda counts: counts[1].rbytes)): - name = k.name + name = k.name.decode() if k.name_len > DNAME_INLINE_LEN: name = name[:-3] + "..." # print line - print("%-6d %-16s %-6d %-6d %-7d %-7d %1s %s" % (k.pid, k.comm, - v.reads, v.writes, v.rbytes / 1024, v.wbytes / 1024, k.type, - name)) + print("%-6d %-16s %-6d %-6d %-7d %-7d %1s %s" % (k.pid, + k.comm.decode(), v.reads, v.writes, v.rbytes / 1024, + v.wbytes / 1024, k.type.decode(), name)) line += 1 if line >= maxrows: