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
23 void im2d_func(struct io *d_iop, struct io *im_iop)
25 update_i2d(im_iop, d_iop->t.time - im_iop->t.time);
28 void q2c_func(struct io *c_iop, struct io *q_iop)
30 __u64 q2c = c_iop->t.time - q_iop->t.time;
32 update_q2c(q_iop, q2c);
33 latency_q2c(q_iop->dip, q_iop->t.time, q2c);
36 static inline void handle_im(struct io *im_iop)
40 q_iop = dip_find_sec(im_iop->dip, IOP_Q, BIT_START(im_iop));
42 update_q2i(q_iop, im_iop->t.time - q_iop->t.time);
45 void handle_queue(struct io *q_iop)
47 io_setup(q_iop, IOP_Q, 1);
48 update_lq(&last_q, &all_avgs.q2q, q_iop->t.time);
49 update_qregion(&all_regions, q_iop->t.time);
50 dip_update_q(q_iop->dip, q_iop);
54 void handle_remap(struct io *a_iop)
57 struct blk_io_trace_remap *rp = a_iop->pdu;
58 struct d_info *dip = __dip_find(be32_to_cpu(rp->device));
60 io_setup(a_iop, IOP_A, 0);
61 q_iop = dip_find_sec(dip, IOP_Q, be64_to_cpu(rp->sector));
63 update_q2a(q_iop, a_iop->t.time - q_iop->t.time);
67 void handle_insert(struct io *i_iop)
69 io_setup(i_iop, IOP_I, 1);
74 void handle_merge(struct io *m_iop)
76 io_setup(m_iop, IOP_M, 1);
81 void handle_issue(struct io *d_iop)
83 io_setup(d_iop, IOP_D, 1);
86 dip_foreach(d_iop, IOP_I, im2d_func, 0);
87 dip_foreach(d_iop, IOP_M, im2d_func, 0);
90 seeki_add(d_iop->dip->seek_handle, d_iop);
94 void handle_complete(struct io *c_iop)
98 io_setup(c_iop, IOP_C, 0);
100 update_cregion(&all_regions, c_iop->t.time);
101 update_cregion(&c_iop->dip->regions, c_iop->t.time);
103 update_cregion(&c_iop->pip->regions, c_iop->t.time);
105 d_iop = dip_find_sec(c_iop->dip, IOP_D, BIT_START(c_iop));
107 __u64 d2c = c_iop->t.time - d_iop->t.time;
108 update_d2c(d_iop, d2c);
109 latency_d2c(d_iop->dip, c_iop->t.time, d2c);
110 iostat_complete(d_iop, c_iop);
111 dip_foreach(d_iop, IOP_I, NULL, 1);
112 dip_foreach(d_iop, IOP_M, NULL, 1);
116 dip_foreach(c_iop, IOP_Q, q2c_func, 1);
120 void rq_im2d_func(struct io *d_iop, struct io *im_iop)
122 unupdate_i2d(im_iop, d_iop->t.time - im_iop->t.time);
127 * (1) Need to remove D & its I & M's
128 * (2) Need to leave I's Q and M's Q's
129 * (3) XXX: Need to downward adjust stats, but we don't carry PREVIOUS
130 * XXX: min/maxes?! We'll just adjust what we can, and hope that
131 * XXX: the min/maxes are "pretty close". (REQUEUEs are rare, right?)
133 void handle_requeue(struct io *r_iop)
137 io_setup(r_iop, IOP_R, 0);
138 d_iop = dip_find_sec(r_iop->dip, IOP_D, BIT_START(r_iop));
140 dip_foreach(d_iop, IOP_I, rq_im2d_func, 1);
141 dip_foreach(d_iop, IOP_M, rq_im2d_func, 1);
142 iostat_unissue(d_iop);
148 void __add_trace(struct io *iop)
150 time_t now = time(NULL);
153 iostat_check_time(iop->t.time);
155 if (verbose && ((now - last_vtrace) > 0)) {
156 printf("%10lu t\r", n_traces);
157 if ((n_traces % 1000000) == 0) printf("\n");
162 switch (iop->t.action & 0xffff) {
163 case __BLK_TA_QUEUE: handle_queue(iop); break;
164 case __BLK_TA_BACKMERGE: handle_merge(iop); break;
165 case __BLK_TA_FRONTMERGE: handle_merge(iop); break;
166 case __BLK_TA_ISSUE: handle_issue(iop); break;
167 case __BLK_TA_COMPLETE: handle_complete(iop); break;
168 case __BLK_TA_INSERT: handle_insert(iop); break;
169 case __BLK_TA_REMAP: handle_remap(iop); break;
170 case __BLK_TA_REQUEUE: handle_requeue(iop); break;
171 default: io_release(iop); break;
175 void add_trace(struct io *iop)
177 if (iop->t.action & BLK_TC_ACT(BLK_TC_NOTIFY)) {
178 char *slash = strchr(iop->pdu, '/');
183 add_process(iop->t.pid, iop->pdu);
186 else if (iop->t.action & BLK_TC_ACT(BLK_TC_PC))