2 * blktrace output analysis: generate a timeline & gather statistics
4 * Copyright (C) 2006 Alan D. Brunelle <Alan.Brunelle@hp.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 static inline void dump_dev(FILE *ofp, __u32 dev)
28 fprintf(ofp, "%3d,%-3d ", MAJOR(dev), MINOR(dev));
31 static inline void dump_desc(FILE *ofp, struct io *iop)
33 fprintf(ofp, "%10llu+%-4u ", (unsigned long long)iop->t.sector,
37 void dump_iop(FILE *ofp, struct io *to_iop, struct io *from_iop, int indent)
42 if (to_iop->displayed) return;
44 fprintf(ofp, "%5d.%09lu ", (int)SECONDS(to_iop->t.time),
45 (unsigned long)NANO_SECONDS(to_iop->t.time));
47 for (i = 0; i < ((dump_level * 4) + indent); i++)
50 dump_dev(ofp, to_iop->t.device);
52 switch (to_iop->type) {
53 case IOP_Q: c = 'Q'; break;
54 case IOP_L: c = 'L'; break;
55 case IOP_A: c = 'A'; break;
56 case IOP_I: c = 'I'; break;
57 case IOP_M: c = 'M'; break;
58 case IOP_D: c = 'D'; break;
59 case IOP_C: c = 'C'; break;
60 default : c = '?'; break;
63 fprintf(ofp, "%c ", c);
64 dump_desc(ofp, to_iop);
67 dump_dev(ofp, from_iop->t.device);
68 dump_desc(ofp, from_iop);
73 to_iop->displayed = 1;
76 void release_iops(struct list_head *del_head)
79 struct list_head *p, *q;
81 list_for_each_safe(p, q, del_head) {
82 x_iop = list_entry(p, struct io, f_head);
83 LIST_DEL(&x_iop->f_head);
88 static void do_retries(void)
91 struct list_head *p, *q;
93 list_for_each_safe(p, q, &retries) {
94 iop = list_entry(p, struct io, retry);
95 // iop could be gone after call...
96 if (iop->type == IOP_C)
103 static void __add_trace(struct io *iop)
105 time_t now = time(NULL);
108 iostat_check_time(iop->t.time);
110 if (verbose && ((now - last_vtrace) > 0)) {
111 printf("%10lu t\r", n_traces);
112 if ((n_traces % 1000000) == 0) printf("\n");
117 switch (iop->t.action & 0xffff) {
118 case __BLK_TA_QUEUE: trace_queue(iop); break;
119 case __BLK_TA_REMAP: trace_remap(iop); break;
120 case __BLK_TA_INSERT: trace_insert(iop); break;
121 case __BLK_TA_BACKMERGE: trace_merge(iop); break;
122 case __BLK_TA_FRONTMERGE: trace_merge(iop); break;
123 case __BLK_TA_REQUEUE: trace_requeue(iop); break;
124 case __BLK_TA_ISSUE: trace_issue(iop); break;
125 case __BLK_TA_COMPLETE: trace_complete(iop); break;
131 if (((iop->t.action & 0xffff) != __BLK_TA_REQUEUE) &&
132 !list_empty(&retries))
136 void add_trace(struct io *iop)
138 if (iop->t.time == 15717167961) dbg_ping();
139 if (iop->t.action & BLK_TC_ACT(BLK_TC_NOTIFY)) {
140 char *slash = strchr(iop->pdu, '/');
145 add_process(iop->t.pid, iop->pdu);
148 else if (iop->t.action & BLK_TC_ACT(BLK_TC_PC))