Skip to content

Commit

Permalink
Merge pull request iovisor#2263 from joelagnel/fix-filetop
Browse files Browse the repository at this point in the history
filetop: Avoid missing important entries
  • Loading branch information
brendangregg authored Mar 8, 2019
2 parents 873e939 + c2b371d commit f515901
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions tools/filetop.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
help="don't clear the screen")
parser.add_argument("-r", "--maxrows", default=20,
help="maximum rows to print, default 20")
parser.add_argument("-s", "--sort", default="rbytes",
choices=["reads", "writes", "rbytes", "wbytes"],
parser.add_argument("-s", "--sort", default="all",
choices=["all", "reads", "writes", "rbytes", "wbytes"],
help="sort column, default rbytes")
parser.add_argument("-p", "--pid", type=int, metavar="PID", dest="tgid",
help="trace this PID only")
Expand Down Expand Up @@ -166,6 +166,12 @@ def signal_ignore(signal_value, frame):

print('Tracing... Output every %d secs. Hit Ctrl-C to end' % interval)

def sort_fn(counts):
if args.sort == "all":
return (counts[1].rbytes + counts[1].wbytes + counts[1].reads + counts[1].writes)
else:
return getattr(counts[1], args.sort)

# output
exiting = 0
while 1:
Expand All @@ -188,8 +194,7 @@ def signal_ignore(signal_value, frame):
counts = b.get_table("counts")
line = 0
for k, v in reversed(sorted(counts.items(),
key=lambda counts:
getattr(counts[1], args.sort))):
key=sort_fn)):
name = k.name.decode('utf-8', 'replace')
if k.name_len > DNAME_INLINE_LEN:
name = name[:-3] + "..."
Expand Down

0 comments on commit f515901

Please sign in to comment.