Skip to content

Commit

Permalink
biotop.py: fix compiler error on newer kernels
Browse files Browse the repository at this point in the history
  • Loading branch information
brendangregg committed Nov 29, 2016
1 parent ae6d979 commit 51add78
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion man/man8/biotop.8
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Cached process name, if present. This usually (but isn't guaranteed) to identify
the responsible process for the I/O.
.TP
D
Direction: R == read, W == write.
Direction: R == read, W == write. This is a simplification.
.TP
MAJ
Major device number.
Expand Down
18 changes: 15 additions & 3 deletions tools/biotop.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def signal_ignore(signal, frame):
// the key for the output summary
struct info_t {
u32 pid;
int type;
int rwflag;
int major;
int minor;
char name[TASK_COMM_LEN];
Expand Down Expand Up @@ -128,7 +128,19 @@ def signal_ignore(signal, frame):
struct info_t info = {};
info.major = req->rq_disk->major;
info.minor = req->rq_disk->first_minor;
info.type = req->cmd_flags & REQ_WRITE;
/*
* The following deals with a kernel version change (in mainline 4.7, although
* it may be backported to earlier kernels) with how block request write flags
* are tested. We handle both pre- and post-change versions here. Please avoid
* kernel version tests like this as much as possible: they inflate the code,
* test, and maintenance burden.
*/
#ifdef REQ_WRITE
info.rwflag = !!(req->cmd_flags & REQ_WRITE);
#else
info.rwflag = !!((req->cmd_flags >> REQ_OP_SHIFT) == REQ_OP_WRITE);
#endif
whop = whobyreq.lookup(&req);
if (whop == 0) {
// missed pid who, save stats as pid 0
Expand Down Expand Up @@ -199,7 +211,7 @@ def signal_ignore(signal, frame):
# print line
avg_ms = (float(v.us) / 1000) / v.io
print("%-6d %-16s %1s %-3d %-3d %-8s %5s %7s %6.2f" % (k.pid, k.name,
"W" if k.type else "R", k.major, k.minor, diskname, v.io,
"W" if k.rwflag else "R", k.major, k.minor, diskname, v.io,
v.bytes / 1024, avg_ms))

line += 1
Expand Down

0 comments on commit 51add78

Please sign in to comment.