Add the %i format specifier which prints the I/O priority of an event as "class,hint,level", in the same format as the kernel's block tracepoints, or "-" if the event does not carry an I/O priority. Events with an I/O priority also show it after the RWBS field in the default output, so the default output of traces without I/O priorities does not change. Signed-off-by: Johannes Thumshirn --- blkparse_fmt.c | 33 +++++++++++++++++++++++++++++++++ doc/blkparse.1 | 7 +++++++ 2 files changed, 40 insertions(+) diff --git a/blkparse_fmt.c b/blkparse_fmt.c index ef9f745..67345b1 100644 --- a/blkparse_fmt.c +++ b/blkparse_fmt.c @@ -16,6 +16,10 @@ #define HEADER "%D %2c %8s %5T.%9t %5p %2a %3d " +#define IOPRIO_CLASS(ioprio) (((ioprio) >> 13) & 0x7) +#define IOPRIO_HINT(ioprio) (((ioprio) >> 3) & 0x3ff) +#define IOPRIO_LEVEL(ioprio) ((ioprio) & 0x7) + static char *override_format[256]; static inline int valid_spec(int spec) @@ -116,6 +120,29 @@ static inline void fill_rwbs(char *rwbs, struct blk_io_trace2 *t) rwbs[i] = '\0'; } +static const char *ioprio_class_str(unsigned int class) +{ + static const char * const names[] = { "none", "rt", "be", "idle" }; + + if (class < sizeof(names) / sizeof(names[0])) + return names[class]; + return "invalid"; +} + +static const char *ioprio_str(struct blk_io_trace2 *t) +{ + static char iopbuff[128]; + + if (!(t->action & __BLK_TA_IOPRIO)) + return "-"; + + snprintf(iopbuff, sizeof(iopbuff), "%s,%u,%u", + ioprio_class_str(IOPRIO_CLASS(t->ioprio)), + IOPRIO_HINT(t->ioprio), IOPRIO_LEVEL(t->ioprio)); + + return iopbuff; +} + static const char * print_time(unsigned long long timestamp) { @@ -298,6 +325,9 @@ static void print_field(char *act, struct per_cpu_info *pci, case 'z': fprintf(ofp, strcat(format, "s"), print_time(t->time)); break; + case 'i': + fprintf(ofp, strcat(format, "s"), ioprio_str(t)); + break; default: fprintf(ofp,strcat(format, "c"), field); break; @@ -373,6 +403,9 @@ static void process_default(char *act, struct per_cpu_info *pci, (int) SECONDS(t->time), (unsigned long) NANO_SECONDS(t->time), t->pid, act, rwbs); + if (t->action & __BLK_TA_IOPRIO) + fprintf(ofp, "%s ", ioprio_str(t)); + name = find_process_name(t->pid); switch (act[0]) { diff --git a/doc/blkparse.1 b/doc/blkparse.1 index 80e7019..b17035f 100644 --- a/doc/blkparse.1 +++ b/doc/blkparse.1 @@ -343,6 +343,13 @@ Error value Cgroup identifier of the cgroup that generated the IO. Note that this requires appropriate kernel support (kernel version at least 4.14). +.IP \fBi\fR 4 +I/O priority as \fIclass,hint,level\fR (for example \fIbe,3,4\fR), or +\fI-\fR if the event carries no I/O priority. The hint is the SCSI/ATA +command duration limit (CDL) descriptor index for hints 1 to 7. This +requires a trace recorded with \fBblktrace \-\-ioprio\fR. Such events +also show the I/O priority after the RWBS field in the default output. + .IP \fBm\fR 4 Minor number of event's device. -- 2.56.1