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
25 #include <sys/types.h>
30 #define S_OPTS "Ad:D:e:hi:I:l:M:o:p:q:s:S:t:T:Vv"
31 static struct option l_opts[] = {
34 .has_arg = no_argument,
39 .name = "range-delta",
40 .has_arg = required_argument,
46 .has_arg = required_argument,
52 .has_arg = required_argument,
58 .has_arg = no_argument,
64 .has_arg = required_argument,
70 .has_arg = required_argument,
75 .name = "d2c-latencies",
76 .has_arg = required_argument,
82 .has_arg = required_argument,
87 .name = "output-file",
88 .has_arg = required_argument,
93 .name = "per-io-dump",
94 .has_arg = required_argument,
99 .name = "q2c-latencies",
100 .has_arg = required_argument,
106 .has_arg = required_argument,
111 .name = "iostat-interval",
112 .has_arg = required_argument,
117 .name = "time-start",
118 .has_arg = required_argument,
124 .has_arg = required_argument,
130 .has_arg = no_argument,
136 .has_arg = no_argument,
145 static char usage_str[] = \
146 "\n[ -A | --all-data ]\n" \
147 "[ -d <seconds> | --range-delta=<seconds> ]\n" \
148 "[ -D <dev;...> | --devices=<dev;...> ]\n" \
149 "[ -e <exe,...> | --exes=<exe,...> ]\n" \
150 "[ -h | --help ]\n" \
151 "[ -i <input name> | --input-file=<input name> ]\n" \
152 "[ -I <output name> | --iostat=<output name> ]\n" \
153 "[ -l <output name> | --d2c-latencies=<output name> ]\n" \
154 "[ -M <dev map> | --dev-maps=<dev map>\n" \
155 "[ -o <output name> | --output-file=<output name> ]\n" \
156 "[ -p <output name> | --per-io-dump=<output name> ]\n" \
157 "[ -q <output name> | --q2c-latencies=<output name> ]\n" \
158 "[ -s <output name> | --seeks=<output name> ]\n" \
159 "[ -S <interval> | --iostat-interval=<interval> ]\n" \
160 "[ -t <sec> | --time-start=<sec> ]\n" \
161 "[ -T <sec> | --time-end=<sec> ]\n" \
162 "[ -V | --version ]\n" \
163 "[ -v | --verbose ]\n\n";
165 static void usage(char *prog)
167 fprintf(stderr, "Usage: %s %s %s", prog, bt_timeline_version,
171 void handle_args(int argc, char *argv[])
175 while ((c = getopt_long(argc, argv, S_OPTS, l_opts, NULL)) != -1) {
181 sscanf(optarg, "%lf", &range_delta);
184 devices = strdup(optarg);
187 exes = strdup(optarg);
193 input_name = strdup(optarg);
196 d2c_name = strdup(optarg);
199 iostat_name = strdup(optarg);
202 if (dev_map_read(optarg))
206 output_name = strdup(optarg);
209 per_io_name = strdup(optarg);
212 q2c_name = strdup(optarg);
215 seek_name = strdup(optarg);
218 unsigned int interval;
219 sscanf(optarg, "%u", &interval);
220 iostat_interval = (__u64)interval * 1000000000LL;
224 sscanf(optarg, "%lf", &t_astart);
228 sscanf(optarg, "%lf", &t_aend);
235 printf("%s version %s\n", argv[0], bt_timeline_version);
243 if (input_name == NULL) {
248 setup_ifile(input_name);
250 if (output_name == NULL)
251 ranges_ofp = avgs_ofp = stdout;
253 char *fname = malloc(strlen(output_name) + 32);
255 sprintf(fname, "%s.dat", output_name);
256 ranges_ofp = fopen(fname, "w");
257 if (ranges_ofp == NULL) {
262 printf("Sending range data to %s.dat\n", output_name);
264 sprintf(fname, "%s.avg", output_name);
265 avgs_ofp = fopen(fname, "w");
266 if (avgs_ofp == NULL) {
271 printf("Sending stats data to %s.avg\n", output_name);
276 if (iostat_name != NULL) {
277 iostat_ofp = fopen(iostat_name, "w");
278 if (iostat_ofp == NULL) {
282 setbuffer(iostat_ofp, malloc(64 * 1024), 64 * 1024);
285 if (per_io_name != NULL) {
286 per_io_ofp = fopen(per_io_name, "w");
287 if (per_io_ofp == NULL) {
291 setbuffer(per_io_ofp, malloc(64 * 1024), 64 * 1024);