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>
31 #define S_OPTS "d:D:e:hi:I:lmM:o:s:S:Vv"
32 static struct option l_opts[] = {
34 .name = "range-delta",
35 .has_arg = required_argument,
41 .has_arg = required_argument,
47 .has_arg = required_argument,
53 .has_arg = no_argument,
59 .has_arg = required_argument,
65 .has_arg = required_argument,
71 .has_arg = no_argument,
77 .has_arg = no_argument,
83 .has_arg = required_argument,
88 .name = "output-file",
89 .has_arg = required_argument,
95 .has_arg = required_argument,
100 .name = "iostat-interval",
101 .has_arg = required_argument,
107 .has_arg = no_argument,
113 .has_arg = no_argument,
122 static char usage_str[] = \
123 "\n[ -d <seconds> | --range-delta=<seconds> ]\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 | -m) | (--lvm | -md)\n" \
129 "[ -M <dev map> | --dev-maps=<dev map>\n" \
130 "[ -o <output name> | --output-file=<output name> ]\n" \
131 "[ -s <output name> | --seeks=<output name> ]\n" \
132 "[ -S <interval> | --iostat-interval=<interval> ]\n" \
133 "[ -V | --version ]\n" \
134 "[ -v | --verbose ]\n\n";
136 static void usage(char *prog)
138 fprintf(stderr, "Usage: %s %s %s", prog, bt_timeline_version,
142 void handle_args(int argc, char *argv[])
145 char *dev_map_fname = NULL;
147 while ((c = getopt_long(argc, argv, S_OPTS, l_opts, NULL)) != -1) {
150 sscanf(optarg, "%lf", &range_delta);
165 iostat_name = optarg;
174 dev_map_fname = optarg;
177 output_name = optarg;
183 unsigned int interval;
184 sscanf(optarg, "%u", &interval);
185 iostat_interval = (__u64)interval * (1000 * 1000 * 1000);
192 printf("%s version %s\n", argv[0], bt_timeline_version);
200 if (input_name == NULL || is_lvm < 0) {
205 ifd = open(input_name, O_RDONLY);
211 if (dev_map_fname && dev_map_read(dev_map_fname))
214 if (output_name == NULL)
215 ranges_ofp = avgs_ofp = stdout;
217 char *fname = malloc(sizeof(output_name) + 20);
219 sprintf(fname, "%s.dat", output_name);
220 ranges_ofp = fopen(fname, "w");
221 if (ranges_ofp == NULL) {
226 printf("Sending range data to %s\n", output_name);
228 sprintf(fname, "%s.avg", output_name);
229 avgs_ofp = fopen(fname, "w");
230 if (avgs_ofp == NULL) {
235 printf("Sending stats data to %s\n", output_name);
240 if (iostat_name != NULL) {
241 iostat_ofp = fopen(iostat_name, "w");
242 if (iostat_ofp == NULL) {