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 S_OPTS "d:D:e:hi:I:l:M:o:p:q:s:S:Vv"
31 static struct option l_opts[] = {
33 .name = "range-delta",
34 .has_arg = required_argument,
40 .has_arg = required_argument,
46 .has_arg = required_argument,
52 .has_arg = no_argument,
58 .has_arg = required_argument,
64 .has_arg = required_argument,
69 .name = "d2c-latencies",
70 .has_arg = required_argument,
76 .has_arg = required_argument,
81 .name = "output-file",
82 .has_arg = required_argument,
87 .name = "per-io-dump",
88 .has_arg = required_argument,
93 .name = "q2c-latencies",
94 .has_arg = required_argument,
100 .has_arg = required_argument,
105 .name = "iostat-interval",
106 .has_arg = required_argument,
112 .has_arg = no_argument,
118 .has_arg = no_argument,
127 static char usage_str[] = \
128 "\n[ -d <seconds> | --range-delta=<seconds> ]\n" \
129 "[ -D <dev;...> | --devices=<dev;...> ]\n" \
130 "[ -e <exe,...> | --exes=<exe,...> ]\n" \
131 "[ -h | --help ]\n" \
132 "[ -i <input name> | --input-file=<input name> ]\n" \
133 "[ -I <output name> | --iostat=<output name> ]\n" \
134 "[ -l <output name> | --d2c-latencies=<output name> ]\n" \
135 "[ -M <dev map> | --dev-maps=<dev map>\n" \
136 "[ -o <output name> | --output-file=<output name> ]\n" \
137 "[ -p <output name> | --per-io-dump=<output name> ]\n" \
138 "[ -q <output name> | --q2c-latencies=<output name> ]\n" \
139 "[ -s <output name> | --seeks=<output name> ]\n" \
140 "[ -S <interval> | --iostat-interval=<interval> ]\n" \
141 "[ -V | --version ]\n" \
142 "[ -v | --verbose ]\n\n";
144 static void usage(char *prog)
146 fprintf(stderr, "Usage: %s %s %s", prog, bt_timeline_version,
150 void handle_args(int argc, char *argv[])
154 while ((c = getopt_long(argc, argv, S_OPTS, l_opts, NULL)) != -1) {
157 sscanf(optarg, "%lf", &range_delta);
160 devices = strdup(optarg);
163 exes = strdup(optarg);
169 input_name = strdup(optarg);
172 d2c_name = strdup(optarg);
175 iostat_name = strdup(optarg);
178 if (dev_map_read(optarg))
182 output_name = strdup(optarg);
185 per_io_name = strdup(optarg);
188 q2c_name = strdup(optarg);
191 seek_name = strdup(optarg);
194 unsigned int interval;
195 sscanf(optarg, "%u", &interval);
196 iostat_interval = (__u64)interval * 1000000000LL;
203 printf("%s version %s\n", argv[0], bt_timeline_version);
211 if (input_name == NULL) {
216 ifd = open(input_name, O_RDONLY);
222 if (output_name == NULL)
223 ranges_ofp = avgs_ofp = stdout;
225 char *fname = malloc(strlen(output_name) + 32);
227 sprintf(fname, "%s.dat", output_name);
228 ranges_ofp = fopen(fname, "w");
229 if (ranges_ofp == NULL) {
234 printf("Sending range data to %s.dat\n", output_name);
236 sprintf(fname, "%s.avg", output_name);
237 avgs_ofp = fopen(fname, "w");
238 if (avgs_ofp == NULL) {
243 printf("Sending stats data to %s.avg\n", output_name);
248 if (iostat_name != NULL) {
249 iostat_ofp = fopen(iostat_name, "w");
250 if (iostat_ofp == NULL) {
256 if (per_io_name != NULL) {
257 per_io_ofp = fopen(per_io_name, "w");
258 if (per_io_ofp == NULL) {