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:L:m:M:o:p:q:Q:s:S:t:T:u:VvXz:"
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 = "periodic-latencies",
96 .has_arg = required_argument,
101 .name = "seeks-per-second",
102 .has_arg = required_argument,
108 .has_arg = required_argument,
113 .name = "output-file",
114 .has_arg = required_argument,
119 .name = "per-io-dump",
120 .has_arg = required_argument,
125 .name = "q2c-latencies",
126 .has_arg = required_argument,
131 .name = "active-queue-depth",
132 .has_arg = required_argument,
138 .has_arg = required_argument,
143 .name = "iostat-interval",
144 .has_arg = required_argument,
149 .name = "time-start",
150 .has_arg = required_argument,
156 .has_arg = required_argument,
161 .name = "unplug-hist",
162 .has_arg = required_argument,
168 .has_arg = no_argument,
174 .has_arg = no_argument,
179 .name = "easy-parse-avgs",
180 .has_arg = no_argument,
185 .name = "q2d-latencies",
186 .has_arg = required_argument,
195 static char usage_str[] = \
196 "\n[ -a | --seek-absolute ]\n" \
197 "[ -A | --all-data ]\n" \
198 "[ -B <output name> | --dump-blocknos=<output name> ]\n" \
199 "[ -d <seconds> | --range-delta=<seconds> ]\n" \
200 "[ -D <dev;...> | --devices=<dev;...> ]\n" \
201 "[ -e <exe,...> | --exes=<exe,...> ]\n" \
202 "[ -h | --help ]\n" \
203 "[ -i <input name> | --input-file=<input name> ]\n" \
204 "[ -I <output name> | --iostat=<output name> ]\n" \
205 "[ -l <output name> | --d2c-latencies=<output name> ]\n" \
206 "[ -L <freq> | --periodic-latencies=<freq> ]\n" \
207 "[ -m <output name> | --seeks-per-second=<output name> ]\n" \
208 "[ -M <dev map> | --dev-maps=<dev map>\n" \
209 "[ -o <output name> | --output-file=<output name> ]\n" \
210 "[ -p <output name> | --per-io-dump=<output name> ]\n" \
211 "[ -q <output name> | --q2c-latencies=<output name> ]\n" \
212 "[ -Q <output name> | --active-queue-depth=<output name> ]\n" \
213 "[ -s <output name> | --seeks=<output name> ]\n" \
214 "[ -S <interval> | --iostat-interval=<interval> ]\n" \
215 "[ -t <sec> | --time-start=<sec> ]\n" \
216 "[ -T <sec> | --time-end=<sec> ]\n" \
217 "[ -u <output name> | --unplug-hist=<output name> ]\n" \
218 "[ -V | --version ]\n" \
219 "[ -v | --verbose ]\n" \
220 "[ -X | --easy-parse-avgs ]\n" \
221 "[ -z <output name> | --q2d-latencies=<output name> ]\n" \
224 static struct file_info *arg_files = NULL;
226 static void usage(char *prog)
228 fprintf(stderr, "Usage: %s %s %s", prog, bt_timeline_version,
232 static FILE *setup_ofile(char *fname)
236 FILE *ofp = fopen(fname, "w");
243 buf = malloc(SETBUFFER_SIZE);
245 setbuffer(ofp, buf, SETBUFFER_SIZE);
246 add_file(&arg_files, ofp, fname);
254 void clean_args(void)
256 clean_files(&arg_files);
259 void handle_args(int argc, char *argv[])
263 while ((c = getopt_long(argc, argv, S_OPTS, l_opts, NULL)) != -1) {
272 bno_dump_name = strdup(optarg);
275 sscanf(optarg, "%lf", &range_delta);
278 devices = strdup(optarg);
281 exes = strdup(optarg);
287 input_name = strdup(optarg);
290 d2c_name = strdup(optarg);
293 plat_freq = atof(optarg);
296 iostat_name = strdup(optarg);
299 sps_name = strdup(optarg);
302 if (dev_map_read(optarg))
306 output_name = strdup(optarg);
309 per_io_name = strdup(optarg);
312 q2c_name = strdup(optarg);
315 aqd_name = strdup(optarg);
318 seek_name = strdup(optarg);
321 unsigned int interval;
322 sscanf(optarg, "%u", &interval);
323 iostat_interval = (__u64)interval * 1000000000LL;
327 sscanf(optarg, "%lf", &t_astart);
331 sscanf(optarg, "%lf", &t_aend);
335 unplug_hist_name = strdup(optarg);
341 printf("%s version %s\n", argv[0], bt_timeline_version);
347 q2d_name = strdup(optarg);
355 if (input_name == NULL) {
360 if (sps_name && !seek_name) {
361 fprintf(stderr, "FATAL: -m option requires -s options\n");
365 setup_ifile(input_name);
367 if (output_name == NULL) {
368 ranges_ofp = avgs_ofp = msgs_ofp = stdout;
372 char *fname = malloc(strlen(output_name) + 32);
374 sprintf(fname, "%s.dat", output_name);
375 ranges_ofp = fopen(fname, "w");
376 if (ranges_ofp == NULL) {
381 printf("Sending range data to %s\n", fname);
383 sprintf(fname, "%s.avg", output_name);
384 avgs_ofp = fopen(fname, "w");
385 if (avgs_ofp == NULL) {
390 printf("Sending stats data to %s\n", fname);
392 sprintf(fname, "%s.msg", output_name);
393 msgs_ofp = fopen(fname, "w");
394 if (msgs_ofp == NULL) {
399 printf("Sending K messages to %s\n", fname);
401 if (easy_parse_avgs) {
402 sprintf(fname, "%s.xvg", output_name);
403 xavgs_ofp = fopen(fname, "w");
404 if (avgs_ofp == NULL) {
409 printf("Sending X stats data to %s\n", fname);
415 iostat_ofp = setup_ofile(iostat_name);
416 per_io_ofp = setup_ofile(per_io_name);