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 SETBUFFER_SIZE (64 * 1024)
32 #define S_OPTS "aAB:d:D:e:hi:I:l:m:M:o:p:q:s:S:t:T:u:VvX"
33 static struct option l_opts[] = {
35 .name = "seek-absolute",
36 .has_arg = no_argument,
42 .has_arg = no_argument,
47 .name = "dump-blocknos",
48 .has_arg = required_argument,
53 .name = "range-delta",
54 .has_arg = required_argument,
60 .has_arg = required_argument,
66 .has_arg = required_argument,
72 .has_arg = no_argument,
78 .has_arg = required_argument,
84 .has_arg = required_argument,
89 .name = "d2c-latencies",
90 .has_arg = required_argument,
95 .name = "seeks-per-second",
96 .has_arg = required_argument,
102 .has_arg = required_argument,
107 .name = "output-file",
108 .has_arg = required_argument,
113 .name = "per-io-dump",
114 .has_arg = required_argument,
119 .name = "q2c-latencies",
120 .has_arg = required_argument,
126 .has_arg = required_argument,
131 .name = "iostat-interval",
132 .has_arg = required_argument,
137 .name = "time-start",
138 .has_arg = required_argument,
144 .has_arg = required_argument,
149 .name = "unplug-hist",
150 .has_arg = required_argument,
156 .has_arg = no_argument,
162 .has_arg = no_argument,
167 .name = "easy-parse-avgs",
168 .has_arg = no_argument,
177 static char usage_str[] = \
178 "\n[ -a | --seek-absolute ]\n" \
179 "[ -A | --all-data ]\n" \
180 "[ -B <output name> | --dump-blocknos=<output name> ]\n" \
181 "[ -d <seconds> | --range-delta=<seconds> ]\n" \
182 "[ -D <dev;...> | --devices=<dev;...> ]\n" \
183 "[ -e <exe,...> | --exes=<exe,...> ]\n" \
184 "[ -h | --help ]\n" \
185 "[ -i <input name> | --input-file=<input name> ]\n" \
186 "[ -I <output name> | --iostat=<output name> ]\n" \
187 "[ -l <output name> | --d2c-latencies=<output name> ]\n" \
188 "[ -m <output name> | --seeks-per-second=<output name> ]\n" \
189 "[ -M <dev map> | --dev-maps=<dev map>\n" \
190 "[ -o <output name> | --output-file=<output name> ]\n" \
191 "[ -p <output name> | --per-io-dump=<output name> ]\n" \
192 "[ -q <output name> | --q2c-latencies=<output name> ]\n" \
193 "[ -s <output name> | --seeks=<output name> ]\n" \
194 "[ -S <interval> | --iostat-interval=<interval> ]\n" \
195 "[ -t <sec> | --time-start=<sec> ]\n" \
196 "[ -T <sec> | --time-end=<sec> ]\n" \
197 "[ -u <output name> | --unplug-hist=<output name> ]\n" \
198 "[ -V | --version ]\n" \
199 "[ -v | --verbose ]\n" \
200 "[ -X | --easy-parse-avgs ]\n" \
203 static struct file_info *arg_files = NULL;
205 static void usage(char *prog)
207 fprintf(stderr, "Usage: %s %s %s", prog, bt_timeline_version,
211 static FILE *setup_ofile(char *fname)
215 FILE *ofp = fopen(fname, "w");
222 buf = malloc(SETBUFFER_SIZE);
224 setbuffer(ofp, buf, SETBUFFER_SIZE);
225 add_file(&arg_files, ofp, fname);
233 void clean_args(void)
235 clean_files(&arg_files);
238 void handle_args(int argc, char *argv[])
242 while ((c = getopt_long(argc, argv, S_OPTS, l_opts, NULL)) != -1) {
251 bno_dump_name = strdup(optarg);
254 sscanf(optarg, "%lf", &range_delta);
257 devices = strdup(optarg);
260 exes = strdup(optarg);
266 input_name = strdup(optarg);
269 d2c_name = strdup(optarg);
272 iostat_name = strdup(optarg);
275 sps_name = strdup(optarg);
278 if (dev_map_read(optarg))
282 output_name = strdup(optarg);
285 per_io_name = strdup(optarg);
288 q2c_name = strdup(optarg);
291 seek_name = strdup(optarg);
294 unsigned int interval;
295 sscanf(optarg, "%u", &interval);
296 iostat_interval = (__u64)interval * 1000000000LL;
300 sscanf(optarg, "%lf", &t_astart);
304 sscanf(optarg, "%lf", &t_aend);
308 unplug_hist_name = strdup(optarg);
314 printf("%s version %s\n", argv[0], bt_timeline_version);
325 if (input_name == NULL) {
330 if (sps_name && !seek_name) {
331 fprintf(stderr, "FATAL: -m option requires -s options\n");
335 setup_ifile(input_name);
337 if (output_name == NULL) {
338 ranges_ofp = avgs_ofp = stdout;
342 char *fname = malloc(strlen(output_name) + 32);
344 sprintf(fname, "%s.dat", output_name);
345 ranges_ofp = fopen(fname, "w");
346 if (ranges_ofp == NULL) {
351 printf("Sending range data to %s\n", fname);
353 sprintf(fname, "%s.avg", output_name);
354 avgs_ofp = fopen(fname, "w");
355 if (avgs_ofp == NULL) {
360 printf("Sending stats data to %s\n", fname);
362 if (easy_parse_avgs) {
363 sprintf(fname, "%s.xvg", output_name);
364 xavgs_ofp = fopen(fname, "w");
365 if (avgs_ofp == NULL) {
370 printf("Sending X stats data to %s\n", fname);
376 iostat_ofp = setup_ofile(iostat_name);
377 per_io_ofp = setup_ofile(per_io_name);