[PATCH] Convert to using on-the-fly RB trees, no post-traversal.
[blktrace.git] / btt / bt_timeline.c
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 <stdio.h>
22 #include <string.h>
23 #include <unistd.h>
24 #include "globals.h"
25
26 char bt_timeline_version[] = "0.99";
27
28 char *devices, *exes, *input_name, *output_name, *seek_name;
29 char *d2c_name, *q2c_name;
30 double range_delta = 0.1;
31 FILE *ranges_ofp, *avgs_ofp;
32 int ifd, verbose = 0;
33 unsigned long n_traces;
34 struct avgs_info all_avgs;
35 __u64 last_q = (__u64)-1;
36 unsigned int n_devs;
37 time_t genesis, last_vtrace;
38 LIST_HEAD(all_devs);
39 LIST_HEAD(all_procs);
40 LIST_HEAD(free_ios);
41
42 struct region_info all_regions = {
43         .qranges = LIST_HEAD_INIT(all_regions.qranges),
44         .cranges = LIST_HEAD_INIT(all_regions.cranges),
45         .qr_cur = NULL,
46         .cr_cur = NULL
47 };
48
49 int process(void);
50
51 int main(int argc, char *argv[])
52 {
53         handle_args(argc, argv);
54
55         init_dev_heads();
56         iostat_init();
57         if (process() || output_avgs(avgs_ofp) || output_ranges(ranges_ofp))
58                 return 1;
59
60         return 0;
61 }
62
63 int process(void)
64 {
65         int ret = 0;
66         struct blk_io_trace *t;
67         struct io *iop = io_alloc();
68
69         genesis = last_vtrace = time(NULL);
70         while (!do_read(ifd, &iop->t, sizeof(struct blk_io_trace))) {
71                 t = convert_to_cpu(&iop->t);
72                 if (t->pdu_len > 0) {
73                         iop->pdu = malloc(t->pdu_len);
74                         if (do_read(ifd, iop->pdu, t->pdu_len)) {
75                                 ret = 1;
76                                 break;
77                         }
78                 }
79                 add_trace(iop);
80                 iop = io_alloc();
81         }
82         io_release(iop);
83
84         if (iostat_ofp) {
85                 fprintf(iostat_ofp, "\n");
86                 iostat_dump_stats(iostat_last_stamp, 1);
87         }
88
89         seek_clean();
90         latency_clean();
91
92         if (verbose) {
93                 double tps = (double)n_traces / (double)(time(NULL) - genesis);
94                 printf("%10lu traces @ %.1lf Ktps\n", n_traces, tps/1000.0);
95         }
96
97         return ret;
98 }