Commit | Line | Data |
---|---|---|
63eba147 JA |
1 | /* |
2 | * blktrace output analysis: generate a timeline & gather statistics | |
3 | * | |
4 | * Copyright (C) 2006 Alan D. Brunelle <Alan.Brunelle@hp.com> | |
5 | * | |
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. | |
10 | * | |
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. | |
15 | * | |
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 | |
19 | * | |
20 | */ | |
21 | #include "globals.h" | |
22 | ||
095181f2 | 23 | int dump_level; |
63eba147 | 24 | |
d76c5b81 | 25 | void __dump_iop(FILE *ofp, struct io *iop, int extra_nl) |
63eba147 | 26 | { |
d76c5b81 AB |
27 | fprintf(ofp, "%5d.%09lu %3d,%-3d %c %10llu+%-4u\n", |
28 | (int)SECONDS(iop->t.time), | |
29 | (unsigned long)NANO_SECONDS(iop->t.time), | |
30 | MAJOR(iop->t.device), MINOR(iop->t.device), type2c(iop->type), | |
31 | (unsigned long long)iop->t.sector, t_sec(&iop->t)); | |
32 | if (extra_nl) fprintf(ofp, "\n"); | |
63eba147 JA |
33 | } |
34 | ||
d76c5b81 | 35 | void __dump_iop2(FILE *ofp, struct io *a_iop, struct io *l_iop) |
63eba147 | 36 | { |
d76c5b81 AB |
37 | fprintf(ofp, "%5d.%09lu %3d,%-3d %c %10llu+%-4u <- (%3d,%-3d) %10llu\n", |
38 | (int)SECONDS(a_iop->t.time), | |
39 | (unsigned long)NANO_SECONDS(a_iop->t.time), | |
40 | MAJOR(a_iop->t.device), MINOR(a_iop->t.device), | |
41 | type2c(a_iop->type), (unsigned long long)a_iop->t.sector, | |
42 | t_sec(&a_iop->t), MAJOR(l_iop->t.device), | |
43 | MINOR(l_iop->t.device), (unsigned long long)l_iop->t.sector); | |
63eba147 JA |
44 | } |
45 | ||
c8b0b334 | 46 | void release_iops(void) |
63eba147 | 47 | { |
095181f2 JA |
48 | struct io *x_iop; |
49 | struct list_head *p, *q; | |
50 | ||
c8b0b334 AB |
51 | list_for_each_safe(p, q, &rmhd) { |
52 | x_iop = list_entry(p, struct io, rm_head); | |
53 | LIST_DEL(&x_iop->rm_head); | |
095181f2 JA |
54 | io_release(x_iop); |
55 | } | |
63eba147 JA |
56 | } |
57 | ||
d76c5b81 | 58 | void do_retries(__u64 now) |
63eba147 | 59 | { |
095181f2 JA |
60 | struct io *iop; |
61 | struct list_head *p, *q; | |
62 | ||
63 | list_for_each_safe(p, q, &retries) { | |
64 | iop = list_entry(p, struct io, retry); | |
d76c5b81 AB |
65 | ASSERT(iop->type == IOP_C); |
66 | ||
095181f2 | 67 | // iop could be gone after call... |
d76c5b81 | 68 | retry_complete(iop, now); |
63eba147 | 69 | } |
63eba147 JA |
70 | } |
71 | ||
d76c5b81 AB |
72 | static inline int retry_check_time(__u64 t) |
73 | { | |
74 | return next_retry_check && (t > next_retry_check); | |
75 | } | |
76 | ||
095181f2 | 77 | static void __add_trace(struct io *iop) |
63eba147 | 78 | { |
6eb42155 | 79 | time_t now = time(NULL); |
d76c5b81 AB |
80 | __u64 tstamp = iop->t.time; |
81 | int run_retry = retry_check_time(iop->t.time); | |
63eba147 | 82 | |
6eb42155 | 83 | n_traces++; |
21e47d90 | 84 | iostat_check_time(iop->t.time); |
6eb42155 ADB |
85 | |
86 | if (verbose && ((now - last_vtrace) > 0)) { | |
c8b0b334 AB |
87 | |
88 | # if defined(DEBUG) | |
d76c5b81 AB |
89 | printf("%10lu t\tretries=|%10d|\ttree size=|%10d|\r", |
90 | n_traces, list_len(&retries), rb_tree_size); | |
c8b0b334 | 91 | # else |
6eb42155 | 92 | printf("%10lu t\r", n_traces); |
c8b0b334 AB |
93 | # endif |
94 | ||
63eba147 | 95 | if ((n_traces % 1000000) == 0) printf("\n"); |
6eb42155 ADB |
96 | fflush(stdout); |
97 | last_vtrace = now; | |
63eba147 JA |
98 | } |
99 | ||
100 | switch (iop->t.action & 0xffff) { | |
095181f2 JA |
101 | case __BLK_TA_QUEUE: trace_queue(iop); break; |
102 | case __BLK_TA_REMAP: trace_remap(iop); break; | |
6dee1e20 | 103 | case __BLK_TA_GETRQ: trace_insert(iop); break; |
095181f2 JA |
104 | case __BLK_TA_BACKMERGE: trace_merge(iop); break; |
105 | case __BLK_TA_FRONTMERGE: trace_merge(iop); break; | |
106 | case __BLK_TA_REQUEUE: trace_requeue(iop); break; | |
107 | case __BLK_TA_ISSUE: trace_issue(iop); break; | |
108 | case __BLK_TA_COMPLETE: trace_complete(iop); break; | |
b2822cea AB |
109 | case __BLK_TA_PLUG: trace_plug(iop); break; |
110 | case __BLK_TA_UNPLUG_IO: trace_unplug_io(iop); break; | |
111 | case __BLK_TA_UNPLUG_TIMER: trace_unplug_timer(iop); break; | |
095181f2 JA |
112 | default: |
113 | io_release(iop); | |
114 | return; | |
63eba147 | 115 | } |
095181f2 | 116 | |
d76c5b81 AB |
117 | if (run_retry && !list_empty(&retries)) { |
118 | do_retries(tstamp); | |
119 | bump_retry(tstamp); | |
120 | } | |
63eba147 JA |
121 | } |
122 | ||
123 | void add_trace(struct io *iop) | |
124 | { | |
125 | if (iop->t.action & BLK_TC_ACT(BLK_TC_NOTIFY)) { | |
d76c5b81 AB |
126 | if (iop->t.pid == 0) |
127 | add_process(0, "kernel"); | |
128 | else { | |
129 | char *slash = strchr(iop->pdu, '/'); | |
130 | if (slash) | |
131 | *slash = '\0'; | |
132 | ||
133 | add_process(iop->t.pid, iop->pdu); | |
134 | } | |
6eb42155 | 135 | io_release(iop); |
63eba147 | 136 | } |
f8d501e1 | 137 | else if (iop->t.action & BLK_TC_ACT(BLK_TC_PC)) |
6eb42155 | 138 | io_release(iop); |
001b2633 JA |
139 | else { |
140 | if (time_bounded) { | |
141 | if (BIT_TIME(iop->t.time) < t_astart) { | |
142 | io_release(iop); | |
143 | return; | |
144 | } | |
145 | else if (BIT_TIME(iop->t.time) > t_aend) { | |
146 | io_release(iop); | |
147 | done = 1; | |
148 | return; | |
149 | } | |
150 | } | |
63eba147 | 151 | __add_trace(iop); |
001b2633 | 152 | } |
63eba147 | 153 | } |