Skip to content

Commit

Permalink
filetop: support specifying sort column via cmdline argument
Browse files Browse the repository at this point in the history
  • Loading branch information
dneiter committed Mar 2, 2017
1 parent cb06c97 commit caa38c5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
14 changes: 9 additions & 5 deletions man/man8/filetop.8
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
.SH NAME
filetop \- File reads and writes by filename and process. Top for files.
.SH SYNOPSIS
.B filetop [\-h] [\-C] [\-r MAXROWS] [\-p PID] [interval] [count]
.B filetop [\-h] [\-C] [\-r MAXROWS] [\-s {reads,writes,rbytes,wbytes}] [\-p PID] [interval] [count]
.SH DESCRIPTION
This is top for files.

This traces file reads and writes, and prints a per-file summary every
interval (by default, 1 second). The summary is sorted on the highest read
throughput (Kbytes). By default only IO on regular files is shown. The -a
option will list all file types (sokets, FIFOs, etc).
This traces file reads and writes, and prints a per-file summary every interval
(by default, 1 second). By default the summary is sorted on the highest read
throughput (Kbytes). Sorting order can be changed via -s option. By default only
IO on regular files is shown. The -a option will list all file types (sokets,
FIFOs, etc).

This uses in-kernel eBPF maps to store per process summaries for efficiency.

Expand Down Expand Up @@ -39,6 +40,9 @@ Don't clear the screen.
\-r MAXROWS
Maximum number of rows to print. Default is 20.
.TP
\-s {reads,writes,rbytes,wbytes}
Sort column. Default is rbytes (read throughput).
.TP
\-p PID
Trace this PID only.
.TP
Expand Down
6 changes: 5 additions & 1 deletion tools/filetop.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
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"],
help="sort column, default rbytes")
parser.add_argument("-p", "--pid", type=int, metavar="PID", dest="tgid",
help="trace this PID only")
parser.add_argument("interval", nargs="?", default=1,
Expand Down Expand Up @@ -184,7 +187,8 @@ def signal_ignore(signal, frame):
counts = b.get_table("counts")
line = 0
for k, v in reversed(sorted(counts.items(),
key=lambda counts: counts[1].rbytes)):
key=lambda counts:
getattr(counts[1], args.sort))):
name = k.name.decode()
if k.name_len > DNAME_INLINE_LEN:
name = name[:-3] + "..."
Expand Down
11 changes: 7 additions & 4 deletions tools/filetop_example.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ PID COMM READS WRITES R_Kb W_Kb T FILE
26628 ld 12 0 52 0 R swap.o
[...]

This shows various files read and written during a Linux kernel build. The
output is sorted by the total read size in Kbytes (R_Kb). This is instrumenting
at the VFS interface, so this is reads and writes that may return entirely
from the file system cache (page cache).
This shows various files read and written during a Linux kernel build. By
default the output is sorted by the total read size in Kbytes (R_Kb). Sorting
order can be changed via -s option. This is instrumenting at the VFS interface,
so this is reads and writes that may return entirely from the file system cache
(page cache).

While not printed, the average read and write size can be calculated by
dividing R_Kb by READS, and the same for writes.
Expand Down Expand Up @@ -146,6 +147,8 @@ optional arguments:
-C, --noclear don't clear the screen
-r MAXROWS, --maxrows MAXROWS
maximum rows to print, default 20
-s {reads,writes,rbytes,wbytes}, --sort {reads,writes,rbytes,wbytes}
sort column, default rbytes
-p PID, --pid PID trace this PID only

examples:
Expand Down

0 comments on commit caa38c5

Please sign in to comment.