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: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 = "per-io-trees",
126 .has_arg = required_argument,
131 .name = "q2c-latencies",
132 .has_arg = required_argument,
137 .name = "active-queue-depth",
138 .has_arg = required_argument,
144 .has_arg = required_argument,
149 .name = "iostat-interval",
150 .has_arg = required_argument,
155 .name = "time-start",
156 .has_arg = required_argument,
162 .has_arg = required_argument,
167 .name = "unplug-hist",
168 .has_arg = required_argument,
174 .has_arg = no_argument,
180 .has_arg = no_argument,
185 .name = "easy-parse-avgs",
186 .has_arg = no_argument,
191 .name = "q2d-latencies",
192 .has_arg = required_argument,
201 static char usage_str[] = \
202 "\n[ -a | --seek-absolute ]\n" \
203 "[ -A | --all-data ]\n" \
204 "[ -B <output name> | --dump-blocknos=<output name> ]\n" \
205 "[ -d <seconds> | --range-delta=<seconds> ]\n" \
206 "[ -D <dev;...> | --devices=<dev;...> ]\n" \
207 "[ -e <exe,...> | --exes=<exe,...> ]\n" \
208 "[ -h | --help ]\n" \
209 "[ -i <input name> | --input-file=<input name> ]\n" \
210 "[ -I <output name> | --iostat=<output name> ]\n" \
211 "[ -l <output name> | --d2c-latencies=<output name> ]\n" \
212 "[ -L <freq> | --periodic-latencies=<freq> ]\n" \
213 "[ -m <output name> | --seeks-per-second=<output name> ]\n" \
214 "[ -M <dev map> | --dev-maps=<dev map>\n" \
215 "[ -o <output name> | --output-file=<output name> ]\n" \
216 "[ -p <output name> | --per-io-dump=<output name> ]\n" \
217 "[ -P <output name> | --per-io-trees=<output name> ]\n" \
218 "[ -q <output name> | --q2c-latencies=<output name> ]\n" \
219 "[ -Q <output name> | --active-queue-depth=<output name> ]\n" \
220 "[ -s <output name> | --seeks=<output name> ]\n" \
221 "[ -S <interval> | --iostat-interval=<interval> ]\n" \
222 "[ -t <sec> | --time-start=<sec> ]\n" \
223 "[ -T <sec> | --time-end=<sec> ]\n" \
224 "[ -u <output name> | --unplug-hist=<output name> ]\n" \
225 "[ -V | --version ]\n" \
226 "[ -v | --verbose ]\n" \
227 "[ -X | --easy-parse-avgs ]\n" \
228 "[ -z <output name> | --q2d-latencies=<output name> ]\n" \
231 static struct file_info *arg_files = NULL;
233 static void usage(char *prog)
235 fprintf(stderr, "Usage: %s %s %s", prog, bt_timeline_version,
239 static FILE *setup_ofile(char *fname)
243 FILE *ofp = fopen(fname, "w");
250 buf = malloc(SETBUFFER_SIZE);
252 setbuffer(ofp, buf, SETBUFFER_SIZE);
253 add_file(&arg_files, ofp, fname);
261 void clean_args(void)
263 clean_files(&arg_files);
266 void handle_args(int argc, char *argv[])
270 while ((c = getopt_long(argc, argv, S_OPTS, l_opts, NULL)) != -1) {
279 bno_dump_name = strdup(optarg);
282 sscanf(optarg, "%lf", &range_delta);
285 devices = strdup(optarg);
288 exes = strdup(optarg);
294 input_name = strdup(optarg);
297 d2c_name = strdup(optarg);
300 plat_freq = atof(optarg);
303 iostat_name = strdup(optarg);
306 sps_name = strdup(optarg);
309 if (dev_map_read(optarg))
313 output_name = strdup(optarg);
316 per_io_name = strdup(optarg);
319 per_io_trees = strdup(optarg);
322 q2c_name = strdup(optarg);
325 aqd_name = strdup(optarg);
328 seek_name = strdup(optarg);
331 unsigned int interval;
332 sscanf(optarg, "%u", &interval);
333 iostat_interval = (__u64)interval * 1000000000LL;
337 sscanf(optarg, "%lf", &t_astart);
341 sscanf(optarg, "%lf", &t_aend);
345 unplug_hist_name = strdup(optarg);
351 printf("%s version %s\n", argv[0], bt_timeline_version);
357 q2d_name = strdup(optarg);
365 if (input_name == NULL) {
370 if (sps_name && !seek_name) {
371 fprintf(stderr, "FATAL: -m option requires -s options\n");
375 setup_ifile(input_name);
377 if (output_name == NULL) {
378 ranges_ofp = avgs_ofp = msgs_ofp = stdout;
382 char *fname = malloc(strlen(output_name) + 32);
384 sprintf(fname, "%s.dat", output_name);
385 ranges_ofp = fopen(fname, "w");
386 if (ranges_ofp == NULL) {
391 printf("Sending range data to %s\n", fname);
393 sprintf(fname, "%s.avg", output_name);
394 avgs_ofp = fopen(fname, "w");
395 if (avgs_ofp == NULL) {
400 printf("Sending stats data to %s\n", fname);
402 sprintf(fname, "%s.msg", output_name);
403 msgs_ofp = fopen(fname, "w");
404 if (msgs_ofp == NULL) {
409 printf("Sending K messages to %s\n", fname);
411 if (easy_parse_avgs) {
412 sprintf(fname, "%s.xvg", output_name);
413 xavgs_ofp = fopen(fname, "w");
414 if (avgs_ofp == NULL) {
419 printf("Sending X stats data to %s\n", fname);
425 iostat_ofp = setup_ofile(iostat_name);
426 per_io_ofp = setup_ofile(per_io_name);