Commit 29392650 authored by Rafael Fonseca's avatar Rafael Fonseca

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 <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.
parent 9da5a972
...@@ -185,14 +185,14 @@ while 1: ...@@ -185,14 +185,14 @@ while 1:
line = 0 line = 0
for k, v in reversed(sorted(counts.items(), for k, v in reversed(sorted(counts.items(),
key=lambda counts: counts[1].rbytes)): key=lambda counts: counts[1].rbytes)):
name = k.name name = k.name.decode()
if k.name_len > DNAME_INLINE_LEN: if k.name_len > DNAME_INLINE_LEN:
name = name[:-3] + "..." name = name[:-3] + "..."
# print line # print line
print("%-6d %-16s %-6d %-6d %-7d %-7d %1s %s" % (k.pid, k.comm, print("%-6d %-16s %-6d %-6d %-7d %-7d %1s %s" % (k.pid,
v.reads, v.writes, v.rbytes / 1024, v.wbytes / 1024, k.type, k.comm.decode(), v.reads, v.writes, v.rbytes / 1024,
name)) v.wbytes / 1024, k.type.decode(), name))
line += 1 line += 1
if line >= maxrows: if line >= maxrows:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment