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 | static void __add_trace(struct io *iop) |
63eba147 | 24 | { |
6eb42155 | 25 | time_t now = time(NULL); |
63eba147 | 26 | |
dbb8d92d AB |
27 | last_t_seen = BIT_TIME(iop->t.time); |
28 | ||
6eb42155 | 29 | n_traces++; |
21e47d90 | 30 | iostat_check_time(iop->t.time); |
6eb42155 ADB |
31 | |
32 | if (verbose && ((now - last_vtrace) > 0)) { | |
32ff7e3b | 33 | printf("%10lu t (%6.2lf%%)\r", n_traces, pct_done()); |
63eba147 | 34 | if ((n_traces % 1000000) == 0) printf("\n"); |
6eb42155 ADB |
35 | fflush(stdout); |
36 | last_vtrace = now; | |
63eba147 JA |
37 | } |
38 | ||
39 | switch (iop->t.action & 0xffff) { | |
095181f2 JA |
40 | case __BLK_TA_QUEUE: trace_queue(iop); break; |
41 | case __BLK_TA_REMAP: trace_remap(iop); break; | |
4c48f14e AB |
42 | case __BLK_TA_INSERT: trace_insert(iop); break; |
43 | case __BLK_TA_GETRQ: trace_getrq(iop); break; | |
095181f2 JA |
44 | case __BLK_TA_BACKMERGE: trace_merge(iop); break; |
45 | case __BLK_TA_FRONTMERGE: trace_merge(iop); break; | |
46 | case __BLK_TA_REQUEUE: trace_requeue(iop); break; | |
47 | case __BLK_TA_ISSUE: trace_issue(iop); break; | |
48 | case __BLK_TA_COMPLETE: trace_complete(iop); break; | |
b2822cea AB |
49 | case __BLK_TA_PLUG: trace_plug(iop); break; |
50 | case __BLK_TA_UNPLUG_IO: trace_unplug_io(iop); break; | |
51 | case __BLK_TA_UNPLUG_TIMER: trace_unplug_timer(iop); break; | |
354db430 | 52 | case __BLK_TA_SLEEPRQ: trace_sleeprq(iop); break; |
8b10aae0 AB |
53 | default: |
54 | io_release(iop); | |
095181f2 | 55 | return; |
63eba147 JA |
56 | } |
57 | } | |
58 | ||
84a26fcd AB |
59 | static void trace_message(struct io *iop) |
60 | { | |
61 | char scratch[15]; | |
62 | char msg[iop->t.pdu_len + 1]; | |
63 | ||
64 | if (!io_setup(iop, IOP_M)) | |
65 | return; | |
66 | ||
67 | memcpy(msg, iop->pdu, iop->t.pdu_len); | |
68 | msg[iop->t.pdu_len] = '\0'; | |
69 | ||
70 | fprintf(msgs_ofp, "%s %5d.%09lu %s\n", | |
71 | make_dev_hdr(scratch, 15, iop->dip, 1), | |
72 | (int)SECONDS(iop->t.time), | |
73 | (unsigned long)NANO_SECONDS(iop->t.time), msg); | |
74 | } | |
75 | ||
63eba147 JA |
76 | void add_trace(struct io *iop) |
77 | { | |
78 | if (iop->t.action & BLK_TC_ACT(BLK_TC_NOTIFY)) { | |
4c48f14e | 79 | if (iop->t.action == BLK_TN_PROCESS) { |
8b10aae0 | 80 | if (iop->t.pid == 0) |
c053af42 | 81 | process_alloc(0, "kernel"); |
4c48f14e AB |
82 | else { |
83 | char *slash = strchr(iop->pdu, '/'); | |
84 | if (slash) | |
85 | *slash = '\0'; | |
86 | ||
c053af42 | 87 | process_alloc(iop->t.pid, iop->pdu); |
4c48f14e | 88 | } |
c053af42 | 89 | } else if (iop->t.action == BLK_TN_MESSAGE) |
84a26fcd | 90 | trace_message(iop); |
6eb42155 | 91 | io_release(iop); |
c053af42 | 92 | } else if (iop->t.action & BLK_TC_ACT(BLK_TC_PC)) { |
6eb42155 | 93 | io_release(iop); |
c053af42 | 94 | } else { |
001b2633 JA |
95 | if (time_bounded) { |
96 | if (BIT_TIME(iop->t.time) < t_astart) { | |
97 | io_release(iop); | |
98 | return; | |
c053af42 | 99 | } else if (BIT_TIME(iop->t.time) > t_aend) { |
001b2633 JA |
100 | io_release(iop); |
101 | done = 1; | |
102 | return; | |
103 | } | |
104 | } | |
63eba147 | 105 | __add_trace(iop); |
001b2633 | 106 | } |
63eba147 | 107 | } |