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 <assert.h> | |
22 | #include <stdio.h> | |
23 | #include <string.h> | |
24 | ||
25 | #include "blktrace.h" | |
26 | #include "list.h" | |
27 | ||
28 | #define pdu_start(t) (((void *) (t) + sizeof(struct blk_io_trace))) | |
29 | ||
30 | #define BIT_TIME(t) ((double)SECONDS(t) + ((double)NANO_SECONDS(t) / 1.0e9)) | |
31 | ||
32 | #define BIT_START(iop) ((iop)->t.sector) | |
33 | #define BIT_END(iop) ((iop)->t.sector + ((iop)->t.bytes >> 9)) | |
34 | ||
35 | #if defined(DEBUG) | |
36 | #define ASSERT(truth) do { \ | |
37 | if (!(truth)) { \ | |
38 | DBG_PING(); \ | |
39 | assert(truth); \ | |
40 | } \ | |
41 | } while (0) | |
42 | ||
43 | #define DBG_PING() dbg_ping() | |
44 | ||
45 | #define LIST_DEL(hp) list_del(hp) | |
46 | ||
47 | #else | |
48 | #define ASSERT(truth) | |
49 | #define DBG_PING() | |
50 | ||
51 | #define LIST_DEL(hp) do { \ | |
52 | if (((hp)->next != NULL) && \ | |
53 | ((hp)->next != LIST_POISON1)) \ | |
54 | list_del(hp); \ | |
55 | } while (0) | |
56 | #endif | |
57 | ||
58 | #define IO_ZALLOC() my_zmalloc(&free_ios, sizeof(struct io)) | |
59 | #define IO_FREE(iop) my_free(&free_ios, iop) | |
60 | ||
61 | enum iop_type { | |
62 | IOP_Q = 0, | |
63 | IOP_X = 1, | |
64 | IOP_A = 2, | |
65 | IOP_M = 3, | |
66 | IOP_I = 4, | |
67 | IOP_D = 5, | |
68 | IOP_C = 6, | |
69 | IOP_Y = 7, | |
70 | }; | |
71 | #define N_IOP_TYPES (IOP_Y + 1) | |
72 | ||
73 | struct my_mem { | |
74 | struct my_mem *next; | |
75 | }; | |
76 | ||
77 | struct io; | |
78 | struct io_list { | |
79 | struct list_head head; | |
80 | struct io *iop; | |
81 | int cy_users; | |
82 | }; | |
83 | ||
84 | struct avg_info { | |
85 | __u64 min, max, total; | |
86 | double avg; | |
87 | int n; | |
88 | }; | |
89 | ||
90 | struct avgs_info { | |
91 | struct avg_info q2q; | |
92 | struct avg_info q2c; | |
93 | struct avg_info q2a; /* Q to (A or X) */ | |
94 | struct avg_info q2i; /* Q to (I or M) */ | |
95 | struct avg_info i2d; /* (I or M) to D */ | |
96 | struct avg_info d2c; | |
97 | ||
98 | struct avg_info blks; /* Blocks transferred */ | |
99 | }; | |
100 | ||
101 | struct range_info { | |
102 | struct list_head head; /* on: qranges OR cranges */ | |
103 | __u64 start, end; | |
104 | }; | |
105 | ||
106 | struct region_info { | |
107 | struct list_head qranges; | |
108 | struct list_head cranges; | |
109 | struct range_info *qr_cur, *cr_cur; | |
110 | }; | |
111 | ||
112 | struct p_info; | |
113 | struct p_pid { | |
114 | struct list_head head; | |
115 | struct p_info *pip; | |
116 | __u32 pid; | |
117 | }; | |
118 | ||
119 | struct p_info { | |
120 | struct list_head head; | |
121 | struct region_info regions; | |
122 | struct avgs_info avgs; | |
123 | char *name; | |
124 | __u64 last_q; | |
125 | }; | |
126 | ||
127 | struct devmap { | |
128 | struct devmap *next; | |
129 | char device[32]; | |
130 | char model[64]; | |
131 | unsigned int host, bus, target, lun; | |
132 | char node[32], pci[32]; | |
133 | unsigned int irq, cpu; | |
134 | char devno[32]; | |
135 | }; | |
136 | ||
137 | struct d_info { | |
138 | struct list_head head, hash_head; | |
139 | struct list_head iop_heads[N_IOP_TYPES]; | |
140 | struct region_info regions; | |
141 | struct avgs_info avgs; | |
142 | __u64 last_q; | |
143 | __u32 device; | |
144 | __u64 n_ds; | |
145 | struct devmap *map; | |
146 | }; | |
147 | ||
148 | struct io { | |
149 | struct list_head all_head, dev_head; | |
150 | struct d_info *dip; | |
151 | struct p_info *pip; | |
152 | void *pdu; | |
153 | ||
154 | struct blk_io_trace t; | |
155 | ||
156 | int users, traversed; | |
157 | enum iop_type type; | |
158 | ||
159 | union { | |
160 | struct { | |
161 | union { | |
162 | struct io *q_a; | |
163 | struct io *q_x; | |
164 | } qp; | |
165 | enum { | |
166 | Q_NONE = 10, | |
167 | Q_A = 20, | |
168 | Q_X = 30, | |
169 | } qp_type; | |
170 | } q; | |
171 | struct { struct io *x_q; } x; | |
172 | struct { struct io *a_q; } a; | |
173 | struct { struct io *m_q; } m; | |
174 | struct { struct list_head i_qs_head; } i; | |
175 | struct { struct list_head d_im_head; } d; | |
176 | struct { struct io *c_d; } c; | |
177 | struct { struct io *y_c1, *y_c2; } y; | |
178 | } u; | |
179 | }; | |
180 | ||
181 | extern char bt_timeline_version[], *devices, *exes, *input_name, *output_name; | |
182 | extern double range_delta; | |
183 | extern FILE *ranges_ofp, *avgs_ofp; | |
184 | extern int is_lvm, verbose, ifd; | |
185 | extern unsigned int n_devs; | |
186 | extern unsigned long n_traces, n_io_allocs, n_io_frees; | |
187 | extern struct list_head all_devs, all_ios, all_procs; | |
188 | extern struct avgs_info all_avgs; | |
189 | extern __u64 last_q; | |
190 | extern struct region_info all_regions; | |
191 | extern struct my_mem *free_ios, *free_bits; | |
192 | extern char iop_map[]; | |
193 | extern unsigned int pending_xs; | |
194 | ||
195 | void add_trace(struct io *iop); | |
196 | int in_devices(struct blk_io_trace *t); | |
197 | int output_avgs(FILE *ofp); | |
198 | int output_ranges(FILE *ofp); | |
199 | unsigned int do_read(int ifd, void *buf, int len); | |
200 | void add_process(__u32 pid, char *name); | |
201 | struct p_info *find_process(__u32 pid, char *name); | |
202 | void pip_update_q(struct io *iop); | |
203 | void handle_args(int argc, char *argv[]); | |
204 | struct devmap *dev_map_find(__u32 device); | |
205 | int dev_map_read(char *fname); | |
206 | void add_cy(struct io *iop); | |
207 | void rem_c(struct io *iop); | |
208 | void cy_init(void); | |
209 | void cy_shutdown(void); | |
210 | struct d_info *__dip_find(__u32 device); | |
211 | struct d_info *dip_add(__u32 device, struct io *iop); | |
212 | void traverse(struct io *iop); | |
213 | void io_free_resources(struct io *iop); | |
214 | ||
215 | #include "inlines.h" |