Added in running stats for btt
[blktrace.git] / btt / bt_timeline.c
CommitLineData
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 <stdio.h>
22#include <string.h>
23#include <unistd.h>
d76c5b81
AB
24#include <sys/time.h>
25#include <time.h>
63eba147
JA
26#include "globals.h"
27
ee27874b 28char bt_timeline_version[] = "2.08";
63eba147 29
69040794 30char *devices, *exes, *input_name, *output_name, *seek_name, *bno_dump_name;
fc16a815 31char *d2c_name, *q2c_name, *per_io_name, *unplug_hist_name;
a22df989 32char *sps_name, *aqd_name, *q2d_name, *per_io_trees;
c053af42 33FILE *rngs_ofp, *avgs_ofp, *xavgs_ofp, *per_io_ofp, *msgs_ofp;
69040794 34int verbose, done, time_bounded, output_all_data, seek_absolute;
ee27874b 35int easy_parse_avgs, ignore_remaps;
dbb8d92d 36double t_astart, t_aend, last_t_seen;
6eb42155 37unsigned long n_traces;
63eba147 38struct avgs_info all_avgs;
63eba147 39unsigned int n_devs;
6eb42155 40time_t genesis, last_vtrace;
63eba147 41LIST_HEAD(all_devs);
63eba147 42LIST_HEAD(all_procs);
8b10aae0 43LIST_HEAD(all_ios);
6eb42155 44LIST_HEAD(free_ios);
69040794 45LIST_HEAD(free_bilinks);
fa0ab85d 46__u64 q_histo[N_HIST_BKTS], d_histo[N_HIST_BKTS];
63eba147 47
2baef508 48double plat_freq = 0.0;
001b2633
JA
49double range_delta = 0.1;
50__u64 last_q = (__u64)-1;
51
63eba147
JA
52struct region_info all_regions = {
53 .qranges = LIST_HEAD_INIT(all_regions.qranges),
54 .cranges = LIST_HEAD_INIT(all_regions.cranges),
63eba147
JA
55};
56
63eba147
JA
57int process(void);
58
59int main(int argc, char *argv[])
60{
61 handle_args(argc, argv);
62
6eb42155 63 init_dev_heads();
21e47d90 64 iostat_init();
dbb8d92d
AB
65 if (!rstat_init())
66 return 1;
67
c053af42 68 if (process() || output_avgs(avgs_ofp) || output_ranges(rngs_ofp))
63eba147
JA
69 return 1;
70
69040794
AB
71 if (iostat_ofp) {
72 fprintf(iostat_ofp, "\n");
73 iostat_dump_stats(iostat_last_stamp, 1);
74 }
75
84a26fcd
AB
76 if (msgs_ofp != stdout)
77 fclose(msgs_ofp);
c053af42
AB
78 if (rngs_ofp != stdout)
79 fclose(rngs_ofp);
8b10aae0 80 if (avgs_ofp != stdout)
69040794 81 fclose(avgs_ofp);
c053af42
AB
82 if (xavgs_ofp)
83 fclose(xavgs_ofp);
69040794 84
c053af42 85 dip_cleanup();
69040794
AB
86 dev_map_exit();
87 dip_exit();
dbb8d92d 88 rstat_exit();
69040794
AB
89 pip_exit();
90 io_free_all();
69040794 91 region_exit(&all_regions);
c053af42 92 clean_allocs();
69040794 93
63eba147
JA
94 return 0;
95}
96
d76c5b81
AB
97static inline double tv2dbl(struct timeval *tv)
98{
99 return (double)tv->tv_sec + (((double)tv->tv_usec) / (1000.0 * 1000.0));
100}
101
63eba147
JA
102int process(void)
103{
104 int ret = 0;
6eb42155 105 struct io *iop = io_alloc();
69040794 106 struct timeval tvs, tve;
63eba147 107
6eb42155 108 genesis = last_vtrace = time(NULL);
d76c5b81
AB
109 gettimeofday(&tvs, NULL);
110 while (!done && next_trace(&iop->t, &iop->pdu)) {
63eba147 111 add_trace(iop);
6eb42155 112 iop = io_alloc();
63eba147 113 }
001b2633 114
6eb42155 115 io_release(iop);
d76c5b81 116 gettimeofday(&tve, NULL);
b2ecdd0f 117
6eb42155 118 if (verbose) {
69040794 119 double tps, dt_input = tv2dbl(&tve) - tv2dbl(&tvs);
8b10aae0 120
d76c5b81 121 tps = (double)n_traces / dt_input;
69040794
AB
122 printf("\r "
123 " \r");
124 printf("%10lu traces @ %.1lf Ktps in %.6lf seconds\n",
d76c5b81 125 n_traces, tps/1000.0,
69040794 126 dt_input);
6eb42155 127 }
63eba147 128
63eba147
JA
129 return ret;
130}