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 "Ad:D:e:hi:I:l:M:o:p:q:s:S:t:T:Vv"
31 static struct option l_opts[] = {
34 .has_arg = no_argument,
39 .name = "range-delta",
40 .has_arg = required_argument,
46 .has_arg = required_argument,
52 .has_arg = required_argument,
58 .has_arg = no_argument,
64 .has_arg = required_argument,
70 .has_arg = required_argument,
75 .name = "d2c-latencies",
76 .has_arg = required_argument,
82 .has_arg = required_argument,
87 .name = "output-file",
88 .has_arg = required_argument,
93 .name = "per-io-dump",
94 .has_arg = required_argument,
99 .name = "q2c-latencies",
100 .has_arg = required_argument,
106 .has_arg = required_argument,
111 .name = "iostat-interval",
112 .has_arg = required_argument,
117 .name = "time-start",
118 .has_arg = required_argument,
124 .has_arg = required_argument,
130 .has_arg = no_argument,
136 .has_arg = no_argument,
145 static char usage_str[] = \
146 "\n[ -d <seconds> | --range-delta=<seconds> ]\n" \
147 "[ -D <dev;...> | --devices=<dev;...> ]\n" \
148 "[ -e <exe,...> | --exes=<exe,...> ]\n" \
149 "[ -h | --help ]\n" \
150 "[ -i <input name> | --input-file=<input name> ]\n" \
151 "[ -I <output name> | --iostat=<output name> ]\n" \
152 "[ -l <output name> | --d2c-latencies=<output name> ]\n" \
153 "[ -M <dev map> | --dev-maps=<dev map>\n" \
154 "[ -o <output name> | --output-file=<output name> ]\n" \
155 "[ -p <output name> | --per-io-dump=<output name> ]\n" \
156 "[ -q <output name> | --q2c-latencies=<output name> ]\n" \
157 "[ -s <output name> | --seeks=<output name> ]\n" \
158 "[ -S <interval> | --iostat-interval=<interval> ]\n" \
159 "[ -t <sec> | --time-start=<sec> ]\n" \
160 "[ -T <sec> | --time-end=<sec> ]\n" \
161 "[ -V | --version ]\n" \
162 "[ -v | --verbose ]\n\n";
164 static void usage(char *prog)
166 fprintf(stderr, "Usage: %s %s %s", prog, bt_timeline_version,
170 void handle_args(int argc, char *argv[])
174 while ((c = getopt_long(argc, argv, S_OPTS, l_opts, NULL)) != -1) {
180 sscanf(optarg, "%lf", &range_delta);
183 devices = strdup(optarg);
186 exes = strdup(optarg);
192 input_name = strdup(optarg);
195 d2c_name = strdup(optarg);
198 iostat_name = strdup(optarg);
201 if (dev_map_read(optarg))
205 output_name = strdup(optarg);
208 per_io_name = strdup(optarg);
211 q2c_name = strdup(optarg);
214 seek_name = strdup(optarg);
217 unsigned int interval;
218 sscanf(optarg, "%u", &interval);
219 iostat_interval = (__u64)interval * 1000000000LL;
223 sscanf(optarg, "%lf", &t_astart);
227 sscanf(optarg, "%lf", &t_aend);
234 printf("%s version %s\n", argv[0], bt_timeline_version);
242 if (input_name == NULL) {
247 setup_ifile(input_name);
249 if (output_name == NULL)
250 ranges_ofp = avgs_ofp = stdout;
252 char *fname = malloc(strlen(output_name) + 32);
254 sprintf(fname, "%s.dat", output_name);
255 ranges_ofp = fopen(fname, "w");
256 if (ranges_ofp == NULL) {
261 printf("Sending range data to %s.dat\n", output_name);
263 sprintf(fname, "%s.avg", output_name);
264 avgs_ofp = fopen(fname, "w");
265 if (avgs_ofp == NULL) {
270 printf("Sending stats data to %s.avg\n", output_name);
275 if (iostat_name != NULL) {
276 iostat_ofp = fopen(iostat_name, "w");
277 if (iostat_ofp == NULL) {
281 setbuffer(iostat_ofp, malloc(64 * 1024), 64 * 1024);
284 if (per_io_name != NULL) {
285 per_io_ofp = fopen(per_io_name, "w");
286 if (per_io_ofp == NULL) {
290 setbuffer(per_io_ofp, malloc(64 * 1024), 64 * 1024);