Added in -L option - output periodic latency information
[blktrace.git] / btt / args.c
CommitLineData
63eba147
JA
1/*
2 * blktrace output analysis: generate a timeline & gather statistics
3 *
4 * Copyright (C) 2006 Alan D. Brunelle <Alan.Brunelle@hp.com>
5 *
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.
10 *
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.
15 *
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
19 *
20 */
21
22#include <stdio.h>
23#include <stdlib.h>
24#include <getopt.h>
25#include <sys/types.h>
26#include <sys/stat.h>
27#include <fcntl.h>
63eba147
JA
28#include "globals.h"
29
69040794
AB
30#define SETBUFFER_SIZE (64 * 1024)
31
2baef508 32#define S_OPTS "aAB:d:D:e:hi:I:l:L:m:M:o:p:q:Q:s:S:t:T:u:VvX"
63eba147 33static struct option l_opts[] = {
69040794
AB
34 {
35 .name = "seek-absolute",
36 .has_arg = no_argument,
37 .flag = NULL,
38 .val = 'a'
39 },
74dc9101
AB
40 {
41 .name = "all-data",
42 .has_arg = no_argument,
43 .flag = NULL,
44 .val = 'A'
45 },
69040794
AB
46 {
47 .name = "dump-blocknos",
48 .has_arg = required_argument,
49 .flag = NULL,
50 .val = 'B'
51 },
63eba147
JA
52 {
53 .name = "range-delta",
54 .has_arg = required_argument,
55 .flag = NULL,
56 .val = 'd'
57 },
58 {
59 .name = "devices",
60 .has_arg = required_argument,
61 .flag = NULL,
62 .val = 'D'
63 },
64 {
65 .name = "exes",
66 .has_arg = required_argument,
67 .flag = NULL,
68 .val = 'e'
69 },
70 {
71 .name = "help",
72 .has_arg = no_argument,
73 .flag = NULL,
74 .val = 'h'
75 },
21e47d90
ADB
76 {
77 .name = "input-file",
78 .has_arg = required_argument,
79 .flag = NULL,
80 .val = 'i'
81 },
82 {
83 .name = "iostat",
84 .has_arg = required_argument,
85 .flag = NULL,
86 .val = 'I'
87 },
b2ecdd0f
ADB
88 {
89 .name = "d2c-latencies",
90 .has_arg = required_argument,
91 .flag = NULL,
92 .val = 'l'
93 },
2baef508
AB
94 {
95 .name = "periodic-latencies",
96 .has_arg = required_argument,
97 .flag = NULL,
98 .val = 'L'
99 },
ccf6d55e
AB
100 {
101 .name = "seeks-per-second",
102 .has_arg = required_argument,
103 .flag = NULL,
104 .val = 'm'
105 },
63eba147
JA
106 {
107 .name = "dev-maps",
108 .has_arg = required_argument,
109 .flag = NULL,
110 .val = 'M'
111 },
63eba147
JA
112 {
113 .name = "output-file",
114 .has_arg = required_argument,
115 .flag = NULL,
116 .val = 'o'
117 },
095181f2
JA
118 {
119 .name = "per-io-dump",
120 .has_arg = required_argument,
121 .flag = NULL,
122 .val = 'p'
123 },
b2ecdd0f
ADB
124 {
125 .name = "q2c-latencies",
126 .has_arg = required_argument,
127 .flag = NULL,
128 .val = 'q'
129 },
4ae2c3c6
AB
130 {
131 .name = "active-queue-depth",
132 .has_arg = required_argument,
133 .flag = NULL,
134 .val = 'Q'
135 },
5225e788
AB
136 {
137 .name = "seeks",
138 .has_arg = required_argument,
139 .flag = NULL,
140 .val = 's'
141 },
21e47d90
ADB
142 {
143 .name = "iostat-interval",
144 .has_arg = required_argument,
145 .flag = NULL,
146 .val = 'S'
147 },
001b2633
JA
148 {
149 .name = "time-start",
150 .has_arg = required_argument,
151 .flag = NULL,
152 .val = 't'
153 },
154 {
155 .name = "time-end",
156 .has_arg = required_argument,
157 .flag = NULL,
158 .val = 'T'
159 },
fc16a815
AB
160 {
161 .name = "unplug-hist",
162 .has_arg = required_argument,
163 .flag = NULL,
164 .val = 'u'
165 },
63eba147
JA
166 {
167 .name = "version",
168 .has_arg = no_argument,
169 .flag = NULL,
170 .val = 'V'
171 },
172 {
173 .name = "verbose",
174 .has_arg = no_argument,
175 .flag = NULL,
176 .val = 'v'
177 },
f028c958
AB
178 {
179 .name = "easy-parse-avgs",
180 .has_arg = no_argument,
181 .flag = NULL,
182 .val = 'X'
183 },
63eba147
JA
184 {
185 .name = NULL,
186 }
187};
188
189static char usage_str[] = \
69040794
AB
190 "\n[ -a | --seek-absolute ]\n" \
191 "[ -A | --all-data ]\n" \
192 "[ -B <output name> | --dump-blocknos=<output name> ]\n" \
512566d4 193 "[ -d <seconds> | --range-delta=<seconds> ]\n" \
80c27cbe 194 "[ -D <dev;...> | --devices=<dev;...> ]\n" \
63eba147
JA
195 "[ -e <exe,...> | --exes=<exe,...> ]\n" \
196 "[ -h | --help ]\n" \
197 "[ -i <input name> | --input-file=<input name> ]\n" \
21e47d90 198 "[ -I <output name> | --iostat=<output name> ]\n" \
b2ecdd0f 199 "[ -l <output name> | --d2c-latencies=<output name> ]\n" \
2baef508 200 "[ -L <freq> | --periodic-latencies=<freq> ]\n" \
ccf6d55e 201 "[ -m <output name> | --seeks-per-second=<output name> ]\n" \
21e47d90 202 "[ -M <dev map> | --dev-maps=<dev map>\n" \
63eba147 203 "[ -o <output name> | --output-file=<output name> ]\n" \
095181f2 204 "[ -p <output name> | --per-io-dump=<output name> ]\n" \
b2ecdd0f 205 "[ -q <output name> | --q2c-latencies=<output name> ]\n" \
4ae2c3c6 206 "[ -Q <output name> | --active-queue-depth=<output name> ]\n" \
5225e788 207 "[ -s <output name> | --seeks=<output name> ]\n" \
21e47d90 208 "[ -S <interval> | --iostat-interval=<interval> ]\n" \
001b2633
JA
209 "[ -t <sec> | --time-start=<sec> ]\n" \
210 "[ -T <sec> | --time-end=<sec> ]\n" \
f028c958 211 "[ -u <output name> | --unplug-hist=<output name> ]\n" \
63eba147 212 "[ -V | --version ]\n" \
f028c958
AB
213 "[ -v | --verbose ]\n" \
214 "[ -X | --easy-parse-avgs ]\n" \
215 "\n";
63eba147 216
69040794
AB
217static struct file_info *arg_files = NULL;
218
63eba147
JA
219static void usage(char *prog)
220{
221 fprintf(stderr, "Usage: %s %s %s", prog, bt_timeline_version,
222 usage_str);
223}
224
69040794
AB
225static FILE *setup_ofile(char *fname)
226{
227 if (fname) {
228 char *buf;
229 FILE *ofp = fopen(fname, "w");
230
231 if (!ofp) {
232 perror(fname);
233 exit(1);
234 }
235
236 buf = malloc(SETBUFFER_SIZE);
69040794
AB
237
238 setbuffer(ofp, buf, SETBUFFER_SIZE);
239 add_file(&arg_files, ofp, fname);
240 add_buf(buf);
241 return ofp;
242 }
243
244 return NULL;
245}
246
247void clean_args(void)
248{
249 clean_files(&arg_files);
250}
251
63eba147
JA
252void handle_args(int argc, char *argv[])
253{
254 int c;
63eba147
JA
255
256 while ((c = getopt_long(argc, argv, S_OPTS, l_opts, NULL)) != -1) {
257 switch (c) {
69040794
AB
258 case 'a':
259 seek_absolute = 1;
260 break;
74dc9101
AB
261 case 'A':
262 output_all_data = 1;
263 break;
69040794
AB
264 case 'B':
265 bno_dump_name = strdup(optarg);
266 break;
63eba147
JA
267 case 'd':
268 sscanf(optarg, "%lf", &range_delta);
269 break;
270 case 'D':
6eb42155 271 devices = strdup(optarg);
63eba147
JA
272 break;
273 case 'e':
6eb42155 274 exes = strdup(optarg);
63eba147
JA
275 break;
276 case 'h':
277 usage(argv[0]);
278 exit(0);
279 case 'i':
6eb42155 280 input_name = strdup(optarg);
63eba147 281 break;
b2ecdd0f 282 case 'l':
6eb42155 283 d2c_name = strdup(optarg);
b2ecdd0f 284 break;
2baef508
AB
285 case 'L':
286 plat_freq = atof(optarg);
287 break;
21e47d90 288 case 'I':
6eb42155 289 iostat_name = strdup(optarg);
21e47d90 290 break;
ccf6d55e
AB
291 case 'm':
292 sps_name = strdup(optarg);
293 break;
63eba147 294 case 'M':
6eb42155
ADB
295 if (dev_map_read(optarg))
296 exit(1);
63eba147
JA
297 break;
298 case 'o':
6eb42155 299 output_name = strdup(optarg);
63eba147 300 break;
095181f2
JA
301 case 'p':
302 per_io_name = strdup(optarg);
303 break;
b2ecdd0f 304 case 'q':
6eb42155 305 q2c_name = strdup(optarg);
b2ecdd0f 306 break;
4ae2c3c6
AB
307 case 'Q':
308 aqd_name = strdup(optarg);
309 break;
5225e788 310 case 's':
6eb42155 311 seek_name = strdup(optarg);
5225e788 312 break;
21e47d90
ADB
313 case 'S': {
314 unsigned int interval;
315 sscanf(optarg, "%u", &interval);
6eb42155 316 iostat_interval = (__u64)interval * 1000000000LL;
21e47d90
ADB
317 break;
318 }
001b2633
JA
319 case 't':
320 sscanf(optarg, "%lf", &t_astart);
321 time_bounded = 1;
322 break;
323 case 'T':
324 sscanf(optarg, "%lf", &t_aend);
325 time_bounded = 1;
326 break;
fc16a815
AB
327 case 'u':
328 unplug_hist_name = strdup(optarg);
329 break;
63eba147
JA
330 case 'v':
331 verbose = 1;
332 break;
333 case 'V':
334 printf("%s version %s\n", argv[0], bt_timeline_version);
335 exit(0);
f028c958
AB
336 case 'X':
337 easy_parse_avgs++;
338 break;
63eba147
JA
339 default:
340 usage(argv[0]);
341 exit(1);
342 }
343 }
344
80c27cbe 345 if (input_name == NULL) {
63eba147
JA
346 usage(argv[0]);
347 exit(1);
348 }
349
ccf6d55e
AB
350 if (sps_name && !seek_name) {
351 fprintf(stderr, "FATAL: -m option requires -s options\n");
352 exit(1);
353 }
354
d76c5b81 355 setup_ifile(input_name);
63eba147 356
f028c958 357 if (output_name == NULL) {
84a26fcd 358 ranges_ofp = avgs_ofp = msgs_ofp = stdout;
f028c958
AB
359 easy_parse_avgs = 0;
360 }
63eba147 361 else {
6eb42155 362 char *fname = malloc(strlen(output_name) + 32);
63eba147
JA
363
364 sprintf(fname, "%s.dat", output_name);
365 ranges_ofp = fopen(fname, "w");
366 if (ranges_ofp == NULL) {
367 perror(fname);
368 exit(1);
369 }
370 if (verbose)
f028c958 371 printf("Sending range data to %s\n", fname);
63eba147
JA
372
373 sprintf(fname, "%s.avg", output_name);
374 avgs_ofp = fopen(fname, "w");
375 if (avgs_ofp == NULL) {
376 perror(fname);
377 exit(1);
378 }
379 if (verbose)
f028c958
AB
380 printf("Sending stats data to %s\n", fname);
381
84a26fcd
AB
382 sprintf(fname, "%s.msg", output_name);
383 msgs_ofp = fopen(fname, "w");
384 if (msgs_ofp == NULL) {
385 perror(fname);
386 exit(1);
387 }
388 if (verbose)
389 printf("Sending K messages to %s\n", fname);
390
f028c958
AB
391 if (easy_parse_avgs) {
392 sprintf(fname, "%s.xvg", output_name);
393 xavgs_ofp = fopen(fname, "w");
394 if (avgs_ofp == NULL) {
395 perror(fname);
396 exit(1);
397 }
398 if (verbose)
399 printf("Sending X stats data to %s\n", fname);
400 }
63eba147
JA
401
402 free(fname);
403 }
21e47d90 404
69040794
AB
405 iostat_ofp = setup_ofile(iostat_name);
406 per_io_ofp = setup_ofile(per_io_name);
63eba147 407}