filetop: Fix TypeError by not mixing bytes and str.
authorRafael Fonseca <rdossant@redhat.com>
Mon, 6 Feb 2017 16:07:28 +0000 (17:07 +0100)
committerRafael Fonseca <rdossant@redhat.com>
Tue, 14 Feb 2017 15:15:53 +0000 (16:15 +0100)
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 <module>
    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

index 9f7c58d..ed7e716 100755 (executable)
@@ -185,14 +185,14 @@ while 1:
     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: