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
38 #define N_HIST_BKTS 1025
40 #define BIT_TIME(t) ((double)SECONDS(t) + ((double)NANO_SECONDS(t) / 1.0e9))
42 #define BIT_START(iop) ((iop)->t.sector)
43 #define BIT_END(iop) ((iop)->t.sector + ((iop)->t.bytes >> 9))
44 #define IOP_READ(iop) ((iop)->t.action & BLK_TC_ACT(BLK_TC_READ))
45 #define IOP_RW(iop) (IOP_READ(iop) ? 1 : 0)
47 #define TO_SEC(nanosec) ((double)(nanosec) / 1.0e9)
48 #define TO_MSEC(nanosec) (1000.0 * TO_SEC(nanosec))
51 #define DBG_PING() dbg_ping()
52 #define ASSERT(truth) do { \
60 #define LIST_DEL(hp) list_del(hp)
64 #define LIST_DEL(hp) do { \
65 ASSERT((hp)->next != NULL); \
66 ASSERT(!list_empty(hp)); \
82 #define N_IOP_TYPES (IOP_I + 1)
85 struct file_info *next;
97 struct list_head head;
103 __u64 min, max, total;
109 struct avg_info q2q_dm;
110 struct avg_info q2a_dm;
111 struct avg_info q2c_dm;
123 struct avg_info blks; /* Blocks transferred */
127 struct list_head head; /* on: qranges OR cranges */
132 struct list_head qranges;
133 struct list_head cranges;
137 struct region_info regions;
138 struct avgs_info avgs;
146 unsigned int host, bus, target, lun, irq, cpu;
148 char device[32], node[32], pci[32], devno[32];
152 __u64 rqm[2], ios[2], sec[2], wait, svctm;
153 double last_qu_change, last_dev_change, tot_qusz, idle_time;
154 int cur_qusz, cur_dev;
159 double rqm_s[2], ios_s[2], sec_s[2];
160 double avgrq_sz, avgqu_sz, await, svctm, p_util;
164 struct list_head all_head, hash_head;
166 struct region_info regions;
168 void *q2q_handle, *seek_handle, *bno_dump_handle, *unplug_hist_handle;
170 FILE *d2c_ofp, *q2c_ofp;
171 struct avgs_info avgs;
172 struct stats stats, all_stats;
173 __u64 last_q, n_qs, n_ds;
174 __u64 n_act_q, t_act_q; /* # currently active when Q comes in */
178 int is_plugged, nplugs, n_timer_unplugs;
179 double start_time, last_plug, plugged_time, end_time;
183 struct rb_node rb_node;
184 struct list_head f_head;
188 __u64 bytes_left, g_time, i_time, m_time, d_time, c_time, d_sec, c_sec;
189 __u32 d_nsec, c_nsec;
191 struct blk_io_trace t;
196 #if defined(COUNT_IOS)
197 struct list_head cio_head;
203 extern char bt_timeline_version[], *devices, *exes, *input_name, *output_name;
204 extern char *seek_name, *iostat_name, *d2c_name, *q2c_name, *per_io_name;
205 extern char *bno_dump_name, *unplug_hist_name;
206 extern double range_delta;
207 extern FILE *ranges_ofp, *avgs_ofp, *iostat_ofp, *per_io_ofp;
208 extern int verbose, done, time_bounded, output_all_data, seek_absolute;
209 extern unsigned int n_devs;
210 extern unsigned long n_traces;
211 extern struct list_head all_devs, all_procs;
212 extern struct avgs_info all_avgs;
214 extern struct region_info all_regions;
215 extern struct list_head free_ios;
216 extern __u64 iostat_interval, iostat_last_stamp;
217 extern time_t genesis, last_vtrace;
218 extern double t_astart, t_aend;
219 extern __u64 q_histo[N_HIST_BKTS], d_histo[N_HIST_BKTS];
221 extern int rb_tree_size;
223 #if defined(COUNT_IOS)
224 extern unsigned long nios_reused, nios_alloced, nios_freed;
225 extern struct list_head cios;
229 void handle_args(int argc, char *argv[]);
232 int dev_map_read(char *fname);
233 struct devmap *dev_map_find(__u32 device);
234 void dev_map_exit(void);
238 void dump_rb_trees(void);
240 void init_dev_heads(void);
241 struct d_info *dip_add(__u32 device, struct io *iop);
242 void dip_rem(struct io *iop);
243 struct d_info *__dip_find(__u32 device);
244 void dip_foreach_list(struct io *iop, enum iop_type type, struct list_head *hd);
245 void dip_foreach(struct io *iop, enum iop_type type,
246 void (*fnc)(struct io *iop, struct io *this), int rm_after);
247 struct io *dip_find_sec(struct d_info *dip, enum iop_type type, __u64 sec);
248 void dip_foreach_out(void (*func)(struct d_info *, void *), void *arg);
249 void dip_plug(__u32 dev, double cur_time);
250 void dip_unplug(__u32 dev, double cur_time, int is_timer);
254 int rb_insert(struct rb_root *root, struct io *iop);
255 struct io *rb_find_sec(struct rb_root *root, __u64 sec);
256 void rb_foreach(struct rb_node *n, struct io *iop,
257 void (*fnc)(struct io *iop, struct io *this),
258 struct list_head *head);
261 void iostat_init(void);
262 void iostat_getrq(struct io *iop);
263 void iostat_merge(struct io *iop);
264 void iostat_issue(struct io *iop);
265 void iostat_unissue(struct io *iop);
266 void iostat_complete(struct io *d_iop, struct io *c_iop);
267 void iostat_check_time(__u64 stamp);
268 void iostat_dump_stats(__u64 stamp, int all);
271 void latency_init(struct d_info *dip);
272 void latency_clean(void);
273 void latency_d2c(struct d_info *dip, __u64 tstamp, __u64 latency);
274 void latency_q2c(struct d_info *dip, __u64 tstamp, __u64 latency);
277 int in_devices(struct blk_io_trace *t);
278 void add_file(struct file_info **fipp, FILE *fp, char *oname);
279 void clean_files(struct file_info **fipp);
280 void add_buf(void *buf);
281 void clean_bufs(void);
285 void setup_ifile(char *fname);
286 void cleanup_ifile(void);
287 int next_trace(struct blk_io_trace *t, void **pdu);
290 int output_avgs(FILE *ofp);
291 int output_ranges(FILE *ofp);
292 char *make_dev_hdr(char *pad, size_t len, struct d_info *dip);
295 void add_process(__u32 pid, char *name);
296 struct p_info *find_process(__u32 pid, char *name);
297 void pip_update_q(struct io *iop);
298 void pip_foreach_out(void (*f)(struct p_info *, void *), void *arg);
302 void *bno_dump_init(__u32 device);
303 void bno_dump_exit(void *param);
304 void bno_dump_add(void *handle, struct io *iop);
305 void bno_dump_clean(void);
308 void q2d_histo_add(void *priv, __u64 q2d);
309 void *q2d_init(void);
310 void q2d_release(void *priv);
311 void q2d_display_header(FILE *fp);
312 void q2d_display_dashes(FILE *fp);
313 void q2d_display(FILE *fp, void *priv);
314 int q2d_ok(void *priv);
315 void q2d_acc(void *a1, void *a2);
318 void *seeki_init(char *str);
319 void seeki_exit(void *param);
320 void seek_clean(void);
321 void seeki_add(void *handle, struct io *iop);
322 double seeki_mean(void *handle);
323 long long seeki_nseeks(void *handle);
324 long long seeki_median(void *handle);
325 int seeki_mode(void *handle, struct mode *mp);
328 void add_trace(struct io *iop);
330 /* trace_complete.c */
331 void trace_complete(struct io *c_iop);
334 void run_im(struct io *im_iop, struct io *d_iop, struct io *c_iop);
335 void run_unim(struct io *im_iop, struct io *d_iop, struct io *c_iop);
336 int ready_im(struct io *im_iop, struct io *c_iop);
337 void trace_insert(struct io *i_iop);
338 void trace_merge(struct io *m_iop);
339 void trace_getrq(struct io *g_iop);
342 void run_issue(struct io *d_iop, struct io *u_iop, struct io *c_iop);
343 void run_unissue(struct io *d_iop, struct io *u_iop, struct io *c_iop);
344 int ready_issue(struct io *d_iop, struct io *c_iop);
345 void trace_issue(struct io *d_iop);
348 void trace_plug(struct io *p_iop);
349 void trace_unplug_io(struct io *u_iop);
350 void trace_unplug_timer(struct io *u_iop);
353 void run_queue(struct io *q_iop, struct io *u_iop, struct io *c_iop);
354 int ready_queue(struct io *q_iop, struct io *c_iop);
355 void trace_queue(struct io *q_iop);
358 void run_remap(struct io *a_iop, struct io *u_iop, struct io *c_iop);
359 int ready_remap(struct io *a_iop, struct io *c_iop);
360 void trace_remap(struct io *a_iop);
362 /* trace_requeue.c */
363 void trace_requeue(struct io *r_iop);
366 void *unplug_hist_init(__u32 device);
367 void unplug_hist_exit(void *arg);
368 void unplug_hist_add(struct io *u_iop);