Skip to content

Commit

Permalink
filetop: Fix TypeError by not mixing bytes and str.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
r4f4 committed Feb 14, 2017
1 parent 9da5a97 commit 2939265
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions tools/filetop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 2939265

Please sign in to comment.