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: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 = "q2c-latencies",
88 .has_arg = required_argument,
94 .has_arg = required_argument,
99 .name = "iostat-interval",
100 .has_arg = required_argument,
106 .has_arg = no_argument,
112 .has_arg = no_argument,
121 static char usage_str[] = \
122 "\n[ -d <seconds> | --range-delta=<seconds> ]\n" \
123 "[ -D <dev;...> | --devices=<dev;...> ]\n" \
124 "[ -e <exe,...> | --exes=<exe,...> ]\n" \
125 "[ -h | --help ]\n" \
126 "[ -i <input name> | --input-file=<input name> ]\n" \
127 "[ -I <output name> | --iostat=<output name> ]\n" \
128 "[ -l <output name> | --d2c-latencies=<output name> ]\n" \
129 "[ -M <dev map> | --dev-maps=<dev map>\n" \
130 "[ -o <output name> | --output-file=<output name> ]\n" \
131 "[ -q <output name> | --q2c-latencies=<output name> ]\n" \
132 "[ -s <output name> | --seeks=<output name> ]\n" \
133 "[ -S <interval> | --iostat-interval=<interval> ]\n" \
134 "[ -V | --version ]\n" \
135 "[ -v | --verbose ]\n\n";
137 static void usage(char *prog)
139 fprintf(stderr, "Usage: %s %s %s", prog, bt_timeline_version,
143 void handle_args(int argc, char *argv[])
147 while ((c = getopt_long(argc, argv, S_OPTS, l_opts, NULL)) != -1) {
150 sscanf(optarg, "%lf", &range_delta);
153 devices = strdup(optarg);
156 exes = strdup(optarg);
162 input_name = strdup(optarg);
165 d2c_name = strdup(optarg);
168 iostat_name = strdup(optarg);
171 if (dev_map_read(optarg))
175 output_name = strdup(optarg);
178 q2c_name = strdup(optarg);
181 seek_name = strdup(optarg);
184 unsigned int interval;
185 sscanf(optarg, "%u", &interval);
186 iostat_interval = (__u64)interval * 1000000000LL;
193 printf("%s version %s\n", argv[0], bt_timeline_version);
201 if (input_name == NULL) {
206 ifd = open(input_name, O_RDONLY);
212 if (output_name == NULL)
213 ranges_ofp = avgs_ofp = stdout;
215 char *fname = malloc(strlen(output_name) + 32);
217 sprintf(fname, "%s.dat", output_name);
218 ranges_ofp = fopen(fname, "w");
219 if (ranges_ofp == NULL) {
224 printf("Sending range data to %s.dat\n", output_name);
226 sprintf(fname, "%s.avg", output_name);
227 avgs_ofp = fopen(fname, "w");
228 if (avgs_ofp == NULL) {
233 printf("Sending stats data to %s.avg\n", output_name);
238 if (iostat_name != NULL) {
239 iostat_ofp = fopen(iostat_name, "w");
240 if (iostat_ofp == NULL) {