Created
February 11, 2024 06:38
-
-
Save illustris/46e15f22583e90adbd581852c4f1d1d9 to your computer and use it in GitHub Desktop.
biosnoop with more details
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bpftrace | |
/* | |
* biosnoop.bt Block I/O tracing tool, showing per I/O latency. | |
* For Linux, uses bpftrace, eBPF. | |
* | |
* TODO: switch to block tracepoints. Add offset and size columns. | |
* | |
* This is a bpftrace version of the bcc tool of the same name. | |
* | |
* 15-Nov-2017 Brendan Gregg Created this. | |
*/ | |
#ifndef BPFTRACE_HAVE_BTF | |
#include <linux/blkdev.h> | |
#include <linux/blk-mq.h> | |
#endif | |
BEGIN | |
{ | |
printf("%-12s %-9s %-16s %-12s %7s %8s %12s", "TIME(ms)", "DISK", "COMM", "PID", "LAT(ms)", "size", "offset"); | |
printf(" %3s\n","r/w"); | |
} | |
kprobe:blk_account_io_start, | |
kprobe:__blk_account_io_start | |
{ | |
@start[arg0] = nsecs; | |
@iopid[arg0] = pid; | |
@iocomm[arg0] = comm; | |
@disk[arg0] = ((struct request *)arg0)->q->disk->disk_name; | |
@len[arg0] = ((struct request *)arg0)->__data_len; | |
@offset[arg0] = ((struct request *)arg0)->__sector; | |
@flags[arg0] = ((struct request *)arg0)->bio->bi_opf; | |
} | |
kprobe:blk_account_io_done, | |
kprobe:__blk_account_io_done | |
/@start[arg0] != 0 && @iopid[arg0] != 0 && @iocomm[arg0] != ""/ | |
{ | |
$now = nsecs; | |
printf("%-12u %-9s %-16s %-12d %7d %8d %12llu %3s\n", | |
elapsed / 1000000, @disk[arg0], @iocomm[arg0], @iopid[arg0], | |
($now - @start[arg0]) / 1000000, @len[arg0], @offset[arg0], (@flags[arg0] & 0x01 ? "w" : "r")); | |
delete(@start[arg0]); | |
delete(@iopid[arg0]); | |
delete(@iocomm[arg0]); | |
delete(@disk[arg0]); | |
delete(@len[arg0]); | |
delete(@offset[arg0]); | |
delete(@flags[arg0]); | |
} | |
END | |
{ | |
clear(@start); | |
clear(@iopid); | |
clear(@iocomm); | |
clear(@disk); | |
clear(@len); | |
clear(@offset); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment