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 void usage(char *prog)
233 fprintf(stderr, "Usage: %s %s %s", prog, bt_timeline_version,
237 static FILE *setup_ofile(char *fname)
241 FILE *ofp = my_fopen(fname, "w");
248 buf = malloc(SETBUFFER_SIZE);
249 setbuffer(ofp, buf, SETBUFFER_SIZE);
251 add_file(ofp, fname);
260 static FILE *std_open(char *output_name, char *sfx, char *msg)
263 char fname[strlen(output_name) + 32];
265 sprintf(fname, "%s.%s", output_name, sfx);
266 fp = my_fopen(fname, "w");
272 printf("Sending %s to %s\n", msg, fname);
277 void handle_args(int argc, char *argv[])
281 while ((c = getopt_long(argc, argv, S_OPTS, l_opts, NULL)) != -1) {
290 bno_dump_name = optarg;
293 sscanf(optarg, "%lf", &range_delta);
311 plat_freq = atof(optarg);
314 iostat_name = strdup(optarg);
320 if (dev_map_read(optarg))
324 output_name = optarg;
327 per_io_name = strdup(optarg);
330 per_io_trees = optarg;
342 unsigned int interval;
344 sscanf(optarg, "%u", &interval);
345 iostat_interval = (__u64)interval * 1000000000LL;
349 sscanf(optarg, "%lf", &t_astart);
353 sscanf(optarg, "%lf", &t_aend);
357 unplug_hist_name = optarg;
363 printf("%s version %s\n", argv[0], bt_timeline_version);
377 if (input_name == NULL) {
382 if (sps_name && !seek_name) {
383 fprintf(stderr, "FATAL: -m option requires -s options\n");
387 setup_ifile(input_name);
389 if (output_name == NULL) {
390 rngs_ofp = avgs_ofp = msgs_ofp = stdout;
393 rngs_ofp = std_open(output_name, ".dat", "range data");
394 avgs_ofp = std_open(output_name, ".avg", "stats data");
395 msgs_ofp = std_open(output_name, ".msg", "K messages");
396 if (easy_parse_avgs) {
397 xavgs_ofp = std_open(output_name, ".xvg",
402 iostat_ofp = setup_ofile(iostat_name);
403 per_io_ofp = setup_ofile(per_io_name);