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