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:rs:S:t:T:u:VvXz:Z"
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 = no_argument,
150 .has_arg = required_argument,
155 .name = "iostat-interval",
156 .has_arg = required_argument,
161 .name = "time-start",
162 .has_arg = required_argument,
168 .has_arg = required_argument,
173 .name = "unplug-hist",
174 .has_arg = required_argument,
180 .has_arg = no_argument,
186 .has_arg = no_argument,
192 .has_arg = no_argument,
197 .name = "easy-parse-avgs",
198 .has_arg = no_argument,
203 .name = "q2d-latencies",
204 .has_arg = required_argument,
213 static char usage_str[] = \
214 "\n[ -a | --seek-absolute ]\n" \
215 "[ -A | --all-data ]\n" \
216 "[ -B <output name> | --dump-blocknos=<output name> ]\n" \
217 "[ -d <seconds> | --range-delta=<seconds> ]\n" \
218 "[ -D <dev;...> | --devices=<dev;...> ]\n" \
219 "[ -e <exe,...> | --exes=<exe,...> ]\n" \
220 "[ -h | --help ]\n" \
221 "[ -i <input name> | --input-file=<input name> ]\n" \
222 "[ -I <output name> | --iostat=<output name> ]\n" \
223 "[ -l <output name> | --d2c-latencies=<output name> ]\n" \
224 "[ -L <freq> | --periodic-latencies=<freq> ]\n" \
225 "[ -m <output name> | --seeks-per-second=<output name> ]\n" \
226 "[ -M <dev map> | --dev-maps=<dev map>\n" \
227 "[ -o <output name> | --output-file=<output name> ]\n" \
228 "[ -p <output name> | --per-io-dump=<output name> ]\n" \
229 "[ -P <output name> | --per-io-trees=<output name> ]\n" \
230 "[ -q <output name> | --q2c-latencies=<output name> ]\n" \
231 "[ -Q <output name> | --active-queue-depth=<output name> ]\n" \
232 "[ -r | --no-remaps ]\n" \
233 "[ -s <output name> | --seeks=<output name> ]\n" \
234 "[ -S <interval> | --iostat-interval=<interval> ]\n" \
235 "[ -t <sec> | --time-start=<sec> ]\n" \
236 "[ -T <sec> | --time-end=<sec> ]\n" \
237 "[ -u <output name> | --unplug-hist=<output name> ]\n" \
238 "[ -V | --version ]\n" \
239 "[ -v | --verbose ]\n" \
240 "[ -X | --easy-parse-avgs ]\n" \
241 "[ -z <output name> | --q2d-latencies=<output name> ]\n" \
242 "[ -Z | --do-active\n" \
245 static void usage(char *prog)
247 fprintf(stderr, "Usage: %s %s", prog, usage_str);
250 static FILE *setup_ofile(char *fname)
254 FILE *ofp = my_fopen(fname, "w");
261 buf = malloc(SETBUFFER_SIZE);
262 setbuffer(ofp, buf, SETBUFFER_SIZE);
264 add_file(ofp, fname);
273 static FILE *std_open(char *output_name, char *sfx, char *msg)
276 char fname[strlen(output_name) + 32];
278 sprintf(fname, "%s.%s", output_name, sfx);
279 fp = my_fopen(fname, "w");
285 printf("Sending %s to %s\n", msg, fname);
290 void handle_args(int argc, char *argv[])
294 while ((c = getopt_long(argc, argv, S_OPTS, l_opts, NULL)) != -1) {
303 bno_dump_name = optarg;
306 sscanf(optarg, "%lf", &range_delta);
324 plat_freq = atof(optarg);
327 iostat_name = strdup(optarg);
333 if (dev_map_read(optarg))
337 output_name = optarg;
340 per_io_name = strdup(optarg);
343 per_io_trees = optarg;
358 unsigned int interval;
360 sscanf(optarg, "%u", &interval);
361 iostat_interval = (__u64)interval * 1000000000LL;
365 sscanf(optarg, "%lf", &t_astart);
369 sscanf(optarg, "%lf", &t_aend);
373 unplug_hist_name = optarg;
379 printf("%s version %s\n", argv[0], bt_timeline_version);
396 if (input_name == NULL) {
401 if (sps_name && !seek_name) {
402 fprintf(stderr, "FATAL: -m option requires -s options\n");
406 setup_ifile(input_name);
408 if (output_name == NULL) {
409 rngs_ofp = avgs_ofp = msgs_ofp = stdout;
412 rngs_ofp = std_open(output_name, "dat", "range data");
413 avgs_ofp = std_open(output_name, "avg", "stats data");
414 msgs_ofp = std_open(output_name, "msg", "K messages");
415 if (easy_parse_avgs) {
416 xavgs_ofp = std_open(output_name, "xvg",
421 iostat_ofp = setup_ofile(iostat_name);
422 per_io_ofp = setup_ofile(per_io_name);