blob: fc1e4c786df848589272c73600b13840f489d29f [file] [log] [blame]
Jens Axboe42a80e32014-09-16 17:06:52 +02001#include <stdio.h>
2#include <stdio.h>
3#include <unistd.h>
4#include <inttypes.h>
Jens Axboe1a9b2932014-12-10 22:01:36 +01005#include <math.h>
Jens Axboe42a80e32014-09-16 17:06:52 +02006#include <assert.h>
7
8#include "../io_ddir.h"
9#include "../flist.h"
10#include "../hash.h"
11#include "../fifo.h"
12#include "../blktrace_api.h"
13#include "../os/os.h"
14#include "../log.h"
15#include "../lib/linux-dev-lookup.h"
16
17#define TRACE_FIFO_SIZE 8192
18
19static unsigned int rt_threshold = 1000000;
20static unsigned int ios_threshold = 10;
Jens Axboe183f3922014-09-18 17:23:55 +020021static unsigned int rate_threshold;
22static unsigned int set_rate;
Jens Axboea5d7a722014-11-10 08:52:23 -070023static unsigned int max_depth = 256;
Jens Axboe42a80e32014-09-16 17:06:52 +020024static int output_ascii = 1;
Jens Axboeb064a142014-09-16 17:40:03 +020025static char *filename;
Jens Axboe42a80e32014-09-16 17:06:52 +020026
Jens Axboe1a9b2932014-12-10 22:01:36 +010027/*
28 * Collapse defaults
29 */
30static unsigned int collapse_entries = 0;
31static unsigned int depth_diff = 1;
32static unsigned int random_diff = 5;
33
Jens Axboe42a80e32014-09-16 17:06:52 +020034struct bs {
35 unsigned int bs;
36 unsigned int nr;
37 int merges;
38};
39
40struct trace_file {
41 char *name;
42 int major, minor;
43};
44
45struct btrace_out {
46 unsigned long ios[DDIR_RWDIR_CNT];
Jens Axboe42a80e32014-09-16 17:06:52 +020047 unsigned long merges[DDIR_RWDIR_CNT];
48
49 uint64_t last_end[DDIR_RWDIR_CNT];
50 uint64_t seq[DDIR_RWDIR_CNT];
51
52 struct bs *bs[DDIR_RWDIR_CNT];
53 unsigned int nr_bs[DDIR_RWDIR_CNT];
54
55 int inflight;
56 unsigned int depth;
Jens Axboea5d7a722014-11-10 08:52:23 -070057 int depth_disabled;
58 int complete_seen;
59
Jens Axboe183f3922014-09-18 17:23:55 +020060 uint64_t first_ttime[DDIR_RWDIR_CNT];
61 uint64_t last_ttime[DDIR_RWDIR_CNT];
62 uint64_t kb[DDIR_RWDIR_CNT];
Jens Axboe42a80e32014-09-16 17:06:52 +020063
Jens Axboe42a80e32014-09-16 17:06:52 +020064 uint64_t start_delay;
65};
66
67struct btrace_pid {
68 struct flist_head hash_list;
69 struct flist_head pid_list;
70 pid_t pid;
Jens Axboed8943e12014-09-16 20:17:55 -060071
Jens Axboe1a9b2932014-12-10 22:01:36 +010072 pid_t *merge_pids;
73 unsigned int nr_merge_pids;
74
Jens Axboed8943e12014-09-16 20:17:55 -060075 struct trace_file *files;
76 int nr_files;
77 unsigned int last_major, last_minor;
Jens Axboe1a9b2932014-12-10 22:01:36 +010078 int numjobs;
79 int ignore;
Jens Axboed8943e12014-09-16 20:17:55 -060080
Jens Axboe42a80e32014-09-16 17:06:52 +020081 struct btrace_out o;
82};
83
84struct inflight {
85 struct flist_head list;
86 struct btrace_pid *p;
87 uint64_t end_sector;
88};
89
90#define PID_HASH_BITS 10
91#define PID_HASH_SIZE (1U << PID_HASH_BITS)
92
93static struct flist_head pid_hash[PID_HASH_SIZE];
94static FLIST_HEAD(pid_list);
95
Jens Axboe50331622014-09-16 18:28:42 +020096#define INFLIGHT_HASH_BITS 8
97#define INFLIGHT_HASH_SIZE (1U << INFLIGHT_HASH_BITS)
98static struct flist_head inflight_hash[INFLIGHT_HASH_SIZE];
Jens Axboe42a80e32014-09-16 17:06:52 +020099
100static uint64_t first_ttime = -1ULL;
101
102static struct inflight *inflight_find(uint64_t sector)
103{
Jens Axboe50331622014-09-16 18:28:42 +0200104 struct flist_head *inflight_list;
Jens Axboe42a80e32014-09-16 17:06:52 +0200105 struct flist_head *e;
106
Jens Axboe50331622014-09-16 18:28:42 +0200107 inflight_list = &inflight_hash[hash_long(sector, INFLIGHT_HASH_BITS)];
108
109 flist_for_each(e, inflight_list) {
Jens Axboe42a80e32014-09-16 17:06:52 +0200110 struct inflight *i = flist_entry(e, struct inflight, list);
111
112 if (i->end_sector == sector)
113 return i;
114 }
115
116 return NULL;
117}
118
119static void inflight_remove(struct inflight *i)
120{
121 struct btrace_out *o = &i->p->o;
122
123 o->inflight--;
124 assert(o->inflight >= 0);
125 flist_del(&i->list);
126 free(i);
127}
128
Jens Axboe50331622014-09-16 18:28:42 +0200129static void __inflight_add(struct inflight *i)
Jens Axboe42a80e32014-09-16 17:06:52 +0200130{
Jens Axboe50331622014-09-16 18:28:42 +0200131 struct flist_head *list;
132
133 list = &inflight_hash[hash_long(i->end_sector, INFLIGHT_HASH_BITS)];
134 flist_add_tail(&i->list, list);
Jens Axboe42a80e32014-09-16 17:06:52 +0200135}
136
137static void inflight_add(struct btrace_pid *p, uint64_t sector, uint32_t len)
138{
139 struct btrace_out *o = &p->o;
140 struct inflight *i;
141
142 i = calloc(1, sizeof(*i));
143 i->p = p;
144 o->inflight++;
Jens Axboea5d7a722014-11-10 08:52:23 -0700145 if (!o->depth_disabled) {
146 o->depth = max((int) o->depth, o->inflight);
147 if (o->depth >= max_depth && !o->complete_seen) {
148 o->depth_disabled = 1;
149 o->depth = max_depth;
150 }
151 }
Jens Axboe42a80e32014-09-16 17:06:52 +0200152 i->end_sector = sector + (len >> 9);
Jens Axboe50331622014-09-16 18:28:42 +0200153 __inflight_add(i);
154}
155
156static void inflight_merge(struct inflight *i, int rw, unsigned int size)
157{
158 i->p->o.merges[rw]++;
159 if (size) {
160 i->end_sector += (size >> 9);
161 flist_del(&i->list);
162 __inflight_add(i);
163 }
Jens Axboe42a80e32014-09-16 17:06:52 +0200164}
165
166/*
167 * fifo refill frontend, to avoid reading data in trace sized bites
168 */
169static int refill_fifo(struct fifo *fifo, int fd)
170{
171 char buf[TRACE_FIFO_SIZE];
172 unsigned int total;
173 int ret;
174
175 total = sizeof(buf);
176 if (total > fifo_room(fifo))
177 total = fifo_room(fifo);
178
179 ret = read(fd, buf, total);
180 if (ret < 0) {
181 perror("read refill");
182 return -1;
183 }
184
185 if (ret > 0)
186 ret = fifo_put(fifo, buf, ret);
187
188 return ret;
189}
190
191/*
192 * Retrieve 'len' bytes from the fifo, refilling if necessary.
193 */
194static int trace_fifo_get(struct fifo *fifo, int fd, void *buf,
195 unsigned int len)
196{
197 if (fifo_len(fifo) < len) {
198 int ret = refill_fifo(fifo, fd);
199
200 if (ret < 0)
201 return ret;
202 }
203
204 return fifo_get(fifo, buf, len);
205}
206
207/*
208 * Just discard the pdu by seeking past it.
209 */
210static int discard_pdu(struct fifo *fifo, int fd, struct blk_io_trace *t)
211{
212 if (t->pdu_len == 0)
213 return 0;
214
215 return trace_fifo_get(fifo, fd, NULL, t->pdu_len);
216}
217
Jens Axboe183f3922014-09-18 17:23:55 +0200218static int handle_trace_notify(struct blk_io_trace *t)
Jens Axboe42a80e32014-09-16 17:06:52 +0200219{
220 switch (t->action) {
221 case BLK_TN_PROCESS:
222 //printf("got process notify: %x, %d\n", t->action, t->pid);
223 break;
224 case BLK_TN_TIMESTAMP:
225 //printf("got timestamp notify: %x, %d\n", t->action, t->pid);
226 break;
227 case BLK_TN_MESSAGE:
228 break;
229 default:
Jens Axboe50331622014-09-16 18:28:42 +0200230 log_err("unknown trace act %x\n", t->action);
Jens Axboe183f3922014-09-18 17:23:55 +0200231 return 1;
Jens Axboe42a80e32014-09-16 17:06:52 +0200232 }
Jens Axboe183f3922014-09-18 17:23:55 +0200233
234 return 0;
Jens Axboe42a80e32014-09-16 17:06:52 +0200235}
236
237static void __add_bs(struct btrace_out *o, unsigned int len, int rw)
238{
239 o->bs[rw] = realloc(o->bs[rw], (o->nr_bs[rw] + 1) * sizeof(struct bs));
240 o->bs[rw][o->nr_bs[rw]].bs = len;
241 o->bs[rw][o->nr_bs[rw]].nr = 1;
242 o->nr_bs[rw]++;
243}
244
245static void add_bs(struct btrace_out *o, unsigned int len, int rw)
246{
247 struct bs *bs = o->bs[rw];
248 int i;
249
250 if (!o->nr_bs[rw]) {
251 __add_bs(o, len, rw);
252 return;
253 }
254
255 for (i = 0; i < o->nr_bs[rw]; i++) {
256 if (bs[i].bs == len) {
257 bs[i].nr++;
258 return;
259 }
260 }
261
262 __add_bs(o, len, rw);
263}
264
265#define FMINORBITS 20
266#define FMINORMASK ((1U << FMINORBITS) - 1)
267#define FMAJOR(dev) ((unsigned int) ((dev) >> FMINORBITS))
268#define FMINOR(dev) ((unsigned int) ((dev) & FMINORMASK))
269
Jens Axboe183f3922014-09-18 17:23:55 +0200270static int btrace_add_file(struct btrace_pid *p, uint32_t devno)
Jens Axboe42a80e32014-09-16 17:06:52 +0200271{
272 unsigned int maj = FMAJOR(devno);
273 unsigned int min = FMINOR(devno);
274 struct trace_file *f;
275 unsigned int i;
276 char dev[256];
277
Jens Axboeb064a142014-09-16 17:40:03 +0200278 if (filename)
Jens Axboe183f3922014-09-18 17:23:55 +0200279 return 0;
Jens Axboed8943e12014-09-16 20:17:55 -0600280 if (p->last_major == maj && p->last_minor == min)
Jens Axboe183f3922014-09-18 17:23:55 +0200281 return 0;
Jens Axboe42a80e32014-09-16 17:06:52 +0200282
Jens Axboed8943e12014-09-16 20:17:55 -0600283 p->last_major = maj;
284 p->last_minor = min;
Jens Axboe42a80e32014-09-16 17:06:52 +0200285
286 /*
287 * check for this file in our list
288 */
Jens Axboed8943e12014-09-16 20:17:55 -0600289 for (i = 0; i < p->nr_files; i++) {
290 f = &p->files[i];
Jens Axboe42a80e32014-09-16 17:06:52 +0200291
292 if (f->major == maj && f->minor == min)
Jens Axboe183f3922014-09-18 17:23:55 +0200293 return 0;
Jens Axboe42a80e32014-09-16 17:06:52 +0200294 }
295
296 strcpy(dev, "/dev");
297 if (!blktrace_lookup_device(NULL, dev, maj, min)) {
298 log_err("fio: failed to find device %u/%u\n", maj, min);
Jens Axboe183f3922014-09-18 17:23:55 +0200299 if (!output_ascii) {
300 log_err("fio: use -d to specify device\n");
301 return 1;
302 }
303 return 0;
Jens Axboe42a80e32014-09-16 17:06:52 +0200304 }
305
Jens Axboed8943e12014-09-16 20:17:55 -0600306 p->files = realloc(p->files, (p->nr_files + 1) * sizeof(*f));
307 f = &p->files[p->nr_files];
Jens Axboe42a80e32014-09-16 17:06:52 +0200308 f->name = strdup(dev);
309 f->major = maj;
310 f->minor = min;
Jens Axboed8943e12014-09-16 20:17:55 -0600311 p->nr_files++;
Jens Axboe183f3922014-09-18 17:23:55 +0200312 return 0;
Jens Axboe42a80e32014-09-16 17:06:52 +0200313}
314
Jens Axboe183f3922014-09-18 17:23:55 +0200315static int t_to_rwdir(struct blk_io_trace *t)
316{
317 if (t->action & BLK_TC_ACT(BLK_TC_DISCARD))
318 return DDIR_TRIM;
319
320 return (t->action & BLK_TC_ACT(BLK_TC_WRITE)) != 0;
321}
322
323static int handle_trace_discard(struct blk_io_trace *t, struct btrace_pid *p)
Jens Axboe42a80e32014-09-16 17:06:52 +0200324{
Jens Axboed8943e12014-09-16 20:17:55 -0600325 struct btrace_out *o = &p->o;
326
Jens Axboe183f3922014-09-18 17:23:55 +0200327 if (btrace_add_file(p, t->device))
328 return 1;
Jens Axboe42a80e32014-09-16 17:06:52 +0200329
Jens Axboe183f3922014-09-18 17:23:55 +0200330 if (o->first_ttime[2] == -1ULL)
331 o->first_ttime[2] = t->time;
Jens Axboe42a80e32014-09-16 17:06:52 +0200332
333 o->ios[DDIR_TRIM]++;
334 add_bs(o, t->bytes, DDIR_TRIM);
Jens Axboe183f3922014-09-18 17:23:55 +0200335 return 0;
Jens Axboe42a80e32014-09-16 17:06:52 +0200336}
337
Jens Axboe183f3922014-09-18 17:23:55 +0200338static int handle_trace_fs(struct blk_io_trace *t, struct btrace_pid *p)
Jens Axboe42a80e32014-09-16 17:06:52 +0200339{
Jens Axboed8943e12014-09-16 20:17:55 -0600340 struct btrace_out *o = &p->o;
Jens Axboe42a80e32014-09-16 17:06:52 +0200341 int rw;
342
Jens Axboe183f3922014-09-18 17:23:55 +0200343 if (btrace_add_file(p, t->device))
344 return 1;
Jens Axboe42a80e32014-09-16 17:06:52 +0200345
346 first_ttime = min(first_ttime, (uint64_t) t->time);
347
Jens Axboe42a80e32014-09-16 17:06:52 +0200348 rw = (t->action & BLK_TC_ACT(BLK_TC_WRITE)) != 0;
349
Jens Axboe183f3922014-09-18 17:23:55 +0200350 if (o->first_ttime[rw] == -1ULL)
351 o->first_ttime[rw] = t->time;
352
Jens Axboe42a80e32014-09-16 17:06:52 +0200353 add_bs(o, t->bytes, rw);
354 o->ios[rw]++;
355
356 if (t->sector == o->last_end[rw] || o->last_end[rw] == -1ULL)
357 o->seq[rw]++;
358
359 o->last_end[rw] = t->sector + (t->bytes >> 9);
Jens Axboe183f3922014-09-18 17:23:55 +0200360 return 0;
Jens Axboe42a80e32014-09-16 17:06:52 +0200361}
362
Jens Axboe183f3922014-09-18 17:23:55 +0200363static int handle_queue_trace(struct blk_io_trace *t, struct btrace_pid *p)
Jens Axboe42a80e32014-09-16 17:06:52 +0200364{
365 if (t->action & BLK_TC_ACT(BLK_TC_NOTIFY))
Jens Axboe183f3922014-09-18 17:23:55 +0200366 return handle_trace_notify(t);
Jens Axboe42a80e32014-09-16 17:06:52 +0200367 else if (t->action & BLK_TC_ACT(BLK_TC_DISCARD))
Jens Axboe183f3922014-09-18 17:23:55 +0200368 return handle_trace_discard(t, p);
Jens Axboe42a80e32014-09-16 17:06:52 +0200369 else
Jens Axboe183f3922014-09-18 17:23:55 +0200370 return handle_trace_fs(t, p);
Jens Axboe42a80e32014-09-16 17:06:52 +0200371}
372
Jens Axboe183f3922014-09-18 17:23:55 +0200373static int handle_trace(struct blk_io_trace *t, struct btrace_pid *p)
Jens Axboe42a80e32014-09-16 17:06:52 +0200374{
375 unsigned int act = t->action & 0xffff;
Jens Axboe183f3922014-09-18 17:23:55 +0200376 int ret = 0;
Jens Axboe42a80e32014-09-16 17:06:52 +0200377
378 if (act == __BLK_TA_QUEUE) {
379 inflight_add(p, t->sector, t->bytes);
Jens Axboe183f3922014-09-18 17:23:55 +0200380 ret = handle_queue_trace(t, p);
Jens Axboe42a80e32014-09-16 17:06:52 +0200381 } else if (act == __BLK_TA_BACKMERGE) {
382 struct inflight *i;
383
384 i = inflight_find(t->sector + (t->bytes >> 9));
385 if (i)
386 inflight_remove(i);
387
388 i = inflight_find(t->sector);
Jens Axboe183f3922014-09-18 17:23:55 +0200389 if (i)
390 inflight_merge(i, t_to_rwdir(t), t->bytes);
Jens Axboe42a80e32014-09-16 17:06:52 +0200391 } else if (act == __BLK_TA_FRONTMERGE) {
392 struct inflight *i;
393
394 i = inflight_find(t->sector + (t->bytes >> 9));
395 if (i)
396 inflight_remove(i);
397
398 i = inflight_find(t->sector);
Jens Axboe183f3922014-09-18 17:23:55 +0200399 if (i)
400 inflight_merge(i, t_to_rwdir(t), 0);
Jens Axboe42a80e32014-09-16 17:06:52 +0200401 } else if (act == __BLK_TA_COMPLETE) {
402 struct inflight *i;
403
404 i = inflight_find(t->sector + (t->bytes >> 9));
Jens Axboe047623b2014-09-17 17:58:31 +0200405 if (i) {
Jens Axboe183f3922014-09-18 17:23:55 +0200406 i->p->o.kb[t_to_rwdir(t)] += (t->bytes >> 10);
Jens Axboea5d7a722014-11-10 08:52:23 -0700407 i->p->o.complete_seen = 1;
Jens Axboe42a80e32014-09-16 17:06:52 +0200408 inflight_remove(i);
Jens Axboe047623b2014-09-17 17:58:31 +0200409 }
Jens Axboe42a80e32014-09-16 17:06:52 +0200410 }
Jens Axboe183f3922014-09-18 17:23:55 +0200411
412 return ret;
Jens Axboe42a80e32014-09-16 17:06:52 +0200413}
414
415static void byteswap_trace(struct blk_io_trace *t)
416{
417 t->magic = fio_swap32(t->magic);
418 t->sequence = fio_swap32(t->sequence);
419 t->time = fio_swap64(t->time);
420 t->sector = fio_swap64(t->sector);
421 t->bytes = fio_swap32(t->bytes);
422 t->action = fio_swap32(t->action);
423 t->pid = fio_swap32(t->pid);
424 t->device = fio_swap32(t->device);
425 t->cpu = fio_swap32(t->cpu);
426 t->error = fio_swap16(t->error);
427 t->pdu_len = fio_swap16(t->pdu_len);
428}
429
430static struct btrace_pid *pid_hash_find(pid_t pid, struct flist_head *list)
431{
432 struct flist_head *e;
433 struct btrace_pid *p;
434
435 flist_for_each(e, list) {
436 p = flist_entry(e, struct btrace_pid, hash_list);
437 if (p->pid == pid)
438 return p;
439 }
440
441 return NULL;
442}
443
444static struct btrace_pid *pid_hash_get(pid_t pid)
445{
446 struct flist_head *hash_list;
447 struct btrace_pid *p;
448
449 hash_list = &pid_hash[hash_long(pid, PID_HASH_BITS)];
450
451 p = pid_hash_find(pid, hash_list);
452 if (!p) {
453 int i;
454
455 p = calloc(1, sizeof(*p));
Jens Axboe42a80e32014-09-16 17:06:52 +0200456
Jens Axboe183f3922014-09-18 17:23:55 +0200457 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
458 p->o.first_ttime[i] = -1ULL;
459 p->o.last_ttime[i] = -1ULL;
Jens Axboe42a80e32014-09-16 17:06:52 +0200460 p->o.last_end[i] = -1ULL;
Jens Axboe183f3922014-09-18 17:23:55 +0200461 }
Jens Axboe42a80e32014-09-16 17:06:52 +0200462
463 p->pid = pid;
Jens Axboe1a9b2932014-12-10 22:01:36 +0100464 p->numjobs = 1;
Jens Axboe42a80e32014-09-16 17:06:52 +0200465 flist_add_tail(&p->hash_list, hash_list);
466 flist_add_tail(&p->pid_list, &pid_list);
467 }
468
469 return p;
470}
471
472/*
473 * Load a blktrace file by reading all the blk_io_trace entries, and storing
474 * them as io_pieces like the fio text version would do.
475 */
Jens Axboe0f7f9a92014-11-06 09:21:10 -0700476static int load_blktrace(const char *fname, int need_swap)
Jens Axboe42a80e32014-09-16 17:06:52 +0200477{
478 struct btrace_pid *p;
479 unsigned long traces;
480 struct blk_io_trace t;
481 struct fifo *fifo;
Jens Axboe183f3922014-09-18 17:23:55 +0200482 int fd, ret = 0;
Jens Axboe42a80e32014-09-16 17:06:52 +0200483
Jens Axboe0f7f9a92014-11-06 09:21:10 -0700484 fd = open(fname, O_RDONLY);
Jens Axboe42a80e32014-09-16 17:06:52 +0200485 if (fd < 0) {
486 perror("open trace file\n");
487 return 1;
488 }
489
490 fifo = fifo_alloc(TRACE_FIFO_SIZE);
491
492 traces = 0;
493 do {
Jens Axboe0f7f9a92014-11-06 09:21:10 -0700494 ret = trace_fifo_get(fifo, fd, &t, sizeof(t));
Jens Axboe42a80e32014-09-16 17:06:52 +0200495 if (ret < 0)
496 goto err;
497 else if (!ret)
498 break;
499 else if (ret < (int) sizeof(t)) {
Jens Axboe50331622014-09-16 18:28:42 +0200500 log_err("fio: short fifo get\n");
Jens Axboe42a80e32014-09-16 17:06:52 +0200501 break;
502 }
503
504 if (need_swap)
505 byteswap_trace(&t);
506
507 if ((t.magic & 0xffffff00) != BLK_IO_TRACE_MAGIC) {
Jens Axboe50331622014-09-16 18:28:42 +0200508 log_err("fio: bad magic in blktrace data: %x\n", t.magic);
Jens Axboe42a80e32014-09-16 17:06:52 +0200509 goto err;
510 }
511 if ((t.magic & 0xff) != BLK_IO_TRACE_VERSION) {
Jens Axboe50331622014-09-16 18:28:42 +0200512 log_err("fio: bad blktrace version %d\n", t.magic & 0xff);
Jens Axboe42a80e32014-09-16 17:06:52 +0200513 goto err;
514 }
515 ret = discard_pdu(fifo, fd, &t);
516 if (ret < 0) {
Jens Axboe50331622014-09-16 18:28:42 +0200517 log_err("blktrace lseek\n");
Jens Axboe42a80e32014-09-16 17:06:52 +0200518 goto err;
519 } else if (t.pdu_len != ret) {
Jens Axboe50331622014-09-16 18:28:42 +0200520 log_err("fio: discarded %d of %d\n", ret, t.pdu_len);
Jens Axboe42a80e32014-09-16 17:06:52 +0200521 goto err;
522 }
523
524 p = pid_hash_get(t.pid);
Jens Axboe183f3922014-09-18 17:23:55 +0200525 ret = handle_trace(&t, p);
526 if (ret)
527 break;
528 p->o.last_ttime[t_to_rwdir(&t)] = t.time;
Jens Axboe42a80e32014-09-16 17:06:52 +0200529 traces++;
530 } while (1);
531
532 fifo_free(fifo);
533 close(fd);
534
Jens Axboe183f3922014-09-18 17:23:55 +0200535 if (ret)
536 return ret;
537
Jens Axboe42a80e32014-09-16 17:06:52 +0200538 if (output_ascii)
539 printf("Traces loaded: %lu\n", traces);
540
541 return 0;
542err:
543 close(fd);
544 fifo_free(fifo);
545 return 1;
546}
547
548static int bs_cmp(const void *ba, const void *bb)
549{
550 const struct bs *bsa = ba;
551 const struct bs *bsb = bb;
552
553 return bsb->nr - bsa->nr;
554}
555
Jens Axboe183f3922014-09-18 17:23:55 +0200556static unsigned long o_to_kb_rate(struct btrace_out *o, int rw)
557{
558 uint64_t usec = (o->last_ttime[rw] - o->first_ttime[rw]) / 1000ULL;
559 uint64_t val;
560
561 if (!usec)
562 return 0;
563
Jens Axboe44aab352014-11-11 08:09:04 -0700564 usec /= 1000;
565 if (!usec)
566 return 0;
567
Jens Axboe183f3922014-09-18 17:23:55 +0200568 val = o->kb[rw] * 1000ULL;
Jens Axboe44aab352014-11-11 08:09:04 -0700569 return val / usec;
Jens Axboe183f3922014-09-18 17:23:55 +0200570}
571
572static uint64_t o_first_ttime(struct btrace_out *o)
573{
574 uint64_t first;
575
576 first = min(o->first_ttime[0], o->first_ttime[1]);
577 return min(first, o->first_ttime[2]);
578}
579
580static uint64_t o_longest_ttime(struct btrace_out *o)
581{
582 uint64_t ret = 0;
583 int i;
584
585 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
586 uint64_t diff;
587
588 diff = o->last_ttime[i] - o->first_ttime[i];
589 ret = max(diff, ret);
590 }
591
592 return ret;
593}
594
Jens Axboe42a80e32014-09-16 17:06:52 +0200595static void __output_p_ascii(struct btrace_pid *p, unsigned long *ios)
596{
597 const char *msg[] = { "reads", "writes", "trims" };
598 struct btrace_out *o = &p->o;
Jens Axboe047623b2014-09-17 17:58:31 +0200599 unsigned long total, usec;
Jens Axboe42a80e32014-09-16 17:06:52 +0200600 int i, j;
601
Jens Axboe1a9b2932014-12-10 22:01:36 +0100602 printf("[pid:\t%u", p->pid);
603 if (p->nr_merge_pids)
604 for (i = 0; i < p->nr_merge_pids; i++)
605 printf(", %u", p->merge_pids[i]);
606 printf("]\n");
Jens Axboe42a80e32014-09-16 17:06:52 +0200607
608 total = ddir_rw_sum(o->ios);
609 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
610 float perc;
611
612 if (!o->ios[i])
613 continue;
614
615 ios[i] += o->ios[i] + o->merges[i];
616 printf("%s\n", msg[i]);
617 perc = ((float) o->ios[i] * 100.0) / (float) total;
618 printf("\tios: %lu (perc=%3.2f%%)\n", o->ios[i], perc);
619 perc = ((float) o->merges[i] * 100.0) / (float) total;
620 printf("\tmerges: %lu (perc=%3.2f%%)\n", o->merges[i], perc);
621 perc = ((float) o->seq[i] * 100.0) / (float) o->ios[i];
Jens Axboeb2a657f2014-09-23 16:06:04 -0600622 printf("\tseq: %lu (perc=%3.2f%%)\n", (unsigned long) o->seq[i], perc);
Jens Axboe183f3922014-09-18 17:23:55 +0200623 printf("\trate: %lu KB/sec\n", o_to_kb_rate(o, i));
Jens Axboe42a80e32014-09-16 17:06:52 +0200624
625 for (j = 0; j < o->nr_bs[i]; j++) {
626 struct bs *bs = &o->bs[i][j];
627
628 perc = (((float) bs->nr * 100.0) / (float) o->ios[i]);
629 printf("\tbs=%u, perc=%3.2f%%\n", bs->bs, perc);
630 }
631 }
632
633 printf("depth:\t%u\n", o->depth);
Jens Axboe183f3922014-09-18 17:23:55 +0200634 usec = o_longest_ttime(o) / 1000ULL;
Jens Axboe047623b2014-09-17 17:58:31 +0200635 printf("usec:\t%lu (delay=%llu)\n", usec, (unsigned long long) o->start_delay);
Jens Axboe42a80e32014-09-16 17:06:52 +0200636
637 printf("files:\t");
Jens Axboed8943e12014-09-16 20:17:55 -0600638 for (i = 0; i < p->nr_files; i++)
639 printf("%s,", p->files[i].name);
Jens Axboe42a80e32014-09-16 17:06:52 +0200640 printf("\n");
641
642 printf("\n");
643}
644
645static int __output_p_fio(struct btrace_pid *p, unsigned long *ios)
646{
647 struct btrace_out *o = &p->o;
648 unsigned long total;
Jens Axboecdc4d672014-09-16 17:35:55 +0200649 unsigned long long time;
Jens Axboe42a80e32014-09-16 17:06:52 +0200650 float perc;
651 int i, j;
652
653 if ((o->ios[0] + o->ios[1]) && o->ios[2]) {
654 log_err("fio: trace has both read/write and trim\n");
655 return 1;
656 }
Jens Axboe183f3922014-09-18 17:23:55 +0200657 if (!p->nr_files) {
658 log_err("fio: no devices found\n");
659 return 1;
660 }
Jens Axboe42a80e32014-09-16 17:06:52 +0200661
Jens Axboe1a9b2932014-12-10 22:01:36 +0100662 printf("[pid%u", p->pid);
663 if (p->nr_merge_pids)
664 for (i = 0; i < p->nr_merge_pids; i++)
665 printf(",pid%u", p->merge_pids[i]);
666 printf("]\n");
667
668 printf("numjobs=%u\n", p->numjobs);
Jens Axboe42a80e32014-09-16 17:06:52 +0200669 printf("direct=1\n");
670 if (o->depth == 1)
671 printf("ioengine=sync\n");
672 else
673 printf("ioengine=libaio\niodepth=%u\n", o->depth);
674
675 if (o->ios[0] && !o->ios[1])
676 printf("rw=randread\n");
677 else if (!o->ios[0] && o->ios[1])
678 printf("rw=randwrite\n");
679 else if (o->ios[2])
680 printf("rw=randtrim\n");
681 else {
682 printf("rw=randrw\n");
683 total = ddir_rw_sum(o->ios);
684 perc = ((float) o->ios[0] * 100.0) / (float) total;
Jens Axboe1a9b2932014-12-10 22:01:36 +0100685 printf("rwmixread=%u\n", (int) floor(perc + 0.50));
Jens Axboe42a80e32014-09-16 17:06:52 +0200686 }
687
Jens Axboeb064a142014-09-16 17:40:03 +0200688 printf("percentage_random=");
Jens Axboe42a80e32014-09-16 17:06:52 +0200689 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
690 if (o->seq[i] && o->ios[i]) {
691 perc = ((float) o->seq[i] * 100.0) / (float) o->ios[i];
692 if (perc >= 99.0)
693 perc = 100.0;
694 } else
695 perc = 100.0;
696
697 if (i)
698 printf(",");
Jens Axboeb064a142014-09-16 17:40:03 +0200699 perc = 100.0 - perc;
Jens Axboe1a9b2932014-12-10 22:01:36 +0100700 printf("%u", (int) floor(perc + 0.5));
Jens Axboe42a80e32014-09-16 17:06:52 +0200701 }
702 printf("\n");
703
704 printf("filename=");
Jens Axboed8943e12014-09-16 20:17:55 -0600705 for (i = 0; i < p->nr_files; i++) {
Jens Axboe42a80e32014-09-16 17:06:52 +0200706 if (i)
707 printf(":");
Jens Axboed8943e12014-09-16 20:17:55 -0600708 printf("%s", p->files[i].name);
Jens Axboe42a80e32014-09-16 17:06:52 +0200709 }
710 printf("\n");
711
Jens Axboe1a9b2932014-12-10 22:01:36 +0100712 if (o->start_delay / 1000000ULL)
713 printf("startdelay=%llus\n", o->start_delay / 1000000ULL);
Jens Axboe42a80e32014-09-16 17:06:52 +0200714
Jens Axboe183f3922014-09-18 17:23:55 +0200715 time = o_longest_ttime(o);
Jens Axboecdc4d672014-09-16 17:35:55 +0200716 time = (time + 1000000000ULL - 1) / 1000000000ULL;
717 printf("runtime=%llus\n", time);
718
Jens Axboe42a80e32014-09-16 17:06:52 +0200719 printf("bssplit=");
720 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
721
722 if (i && o->nr_bs[i - 1] && o->nr_bs[i])
723 printf(",");
724
725 for (j = 0; j < o->nr_bs[i]; j++) {
726 struct bs *bs = &o->bs[i][j];
727
728 perc = (((float) bs->nr * 100.0) / (float) o->ios[i]);
729 if (perc < 1.00)
730 continue;
731 if (j)
732 printf(":");
733 if (j + 1 == o->nr_bs[i])
734 printf("%u/", bs->bs);
735 else
Jens Axboe1a9b2932014-12-10 22:01:36 +0100736 printf("%u/%u", bs->bs, (int) floor(perc + 0.5));
Jens Axboe42a80e32014-09-16 17:06:52 +0200737 }
738 }
Jens Axboe183f3922014-09-18 17:23:55 +0200739 printf("\n");
Jens Axboe42a80e32014-09-16 17:06:52 +0200740
Jens Axboe183f3922014-09-18 17:23:55 +0200741 if (set_rate) {
742 printf("rate=");
743 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
744 unsigned long rate;
745
746 rate = o_to_kb_rate(o, i);
747 if (i)
748 printf(",");
749 if (rate)
750 printf("%luk", rate);
751 }
752 printf("\n");
753 }
754
755 printf("\n");
Jens Axboe42a80e32014-09-16 17:06:52 +0200756 return 0;
757}
758
759static int __output_p(struct btrace_pid *p, unsigned long *ios)
760{
761 struct btrace_out *o = &p->o;
762 int i, ret = 0;
763
764 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
765 if (o->nr_bs[i] <= 1)
766 continue;
767 qsort(o->bs[i], o->nr_bs[i], sizeof(struct bs), bs_cmp);
768 }
769
Jens Axboeb064a142014-09-16 17:40:03 +0200770 if (filename) {
Jens Axboed8943e12014-09-16 20:17:55 -0600771 p->files = malloc(sizeof(struct trace_file));
772 p->nr_files++;
773 p->files[0].name = filename;
Jens Axboeb064a142014-09-16 17:40:03 +0200774 }
775
Jens Axboe42a80e32014-09-16 17:06:52 +0200776 if (output_ascii)
777 __output_p_ascii(p, ios);
778 else
779 ret = __output_p_fio(p, ios);
780
781 return ret;
782}
783
Jens Axboe183f3922014-09-18 17:23:55 +0200784static void remove_ddir(struct btrace_out *o, int rw)
785{
786 o->ios[rw] = 0;
787}
788
Jens Axboe42a80e32014-09-16 17:06:52 +0200789static int prune_entry(struct btrace_out *o)
790{
Jens Axboe183f3922014-09-18 17:23:55 +0200791 unsigned long rate;
Jens Axboe42a80e32014-09-16 17:06:52 +0200792 uint64_t time;
Jens Axboe183f3922014-09-18 17:23:55 +0200793 int i;
Jens Axboe42a80e32014-09-16 17:06:52 +0200794
795 if (ddir_rw_sum(o->ios) < ios_threshold)
796 return 1;
797
Jens Axboe183f3922014-09-18 17:23:55 +0200798 time = o_longest_ttime(o) / 1000ULL;
Jens Axboe42a80e32014-09-16 17:06:52 +0200799 if (time < rt_threshold)
800 return 1;
801
Jens Axboe183f3922014-09-18 17:23:55 +0200802 rate = 0;
803 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
804 unsigned long this_rate;
805
806 this_rate = o_to_kb_rate(o, i);
807 if (this_rate < rate_threshold) {
808 remove_ddir(o, i);
809 this_rate = 0;
810 }
811 rate += this_rate;
812 }
813
814 if (rate < rate_threshold)
815 return 1;
816
Jens Axboe42a80e32014-09-16 17:06:52 +0200817 return 0;
818}
819
820static int entry_cmp(void *priv, struct flist_head *a, struct flist_head *b)
821{
822 struct btrace_pid *pa = flist_entry(a, struct btrace_pid, pid_list);
823 struct btrace_pid *pb = flist_entry(b, struct btrace_pid, pid_list);
824
825 return ddir_rw_sum(pb->o.ios) - ddir_rw_sum(pa->o.ios);
826}
827
Jens Axboe50331622014-09-16 18:28:42 +0200828static void free_p(struct btrace_pid *p)
829{
830 struct btrace_out *o = &p->o;
831 int i;
832
Jens Axboed8943e12014-09-16 20:17:55 -0600833 for (i = 0; i < p->nr_files; i++) {
834 if (p->files[i].name && p->files[i].name != filename)
835 free(p->files[i].name);
Jens Axboe50331622014-09-16 18:28:42 +0200836 }
837
838 for (i = 0; i < DDIR_RWDIR_CNT; i++)
839 free(o->bs[i]);
840
Jens Axboed8943e12014-09-16 20:17:55 -0600841 free(p->files);
Jens Axboe50331622014-09-16 18:28:42 +0200842 flist_del(&p->pid_list);
843 flist_del(&p->hash_list);
844 free(p);
845}
846
Jens Axboe1a9b2932014-12-10 22:01:36 +0100847static int entries_close(struct btrace_pid *pida, struct btrace_pid *pidb)
848{
849 float perca, percb, fdiff;
850 int i, idiff;
851
852 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
853 if ((pida->o.ios[i] && !pidb->o.ios[i]) ||
854 (pidb->o.ios[i] && !pida->o.ios[i]))
855 return 0;
856 if (pida->o.ios[i] && pidb->o.ios[i]) {
857 perca = ((float) pida->o.seq[i] * 100.0) / (float) pida->o.ios[i];
858 percb = ((float) pidb->o.seq[i] * 100.0) / (float) pidb->o.ios[i];
859 fdiff = perca - percb;
860 if (fabs(fdiff) > random_diff)
861 return 0;
862 }
863
864 idiff = pida->o.depth - pidb->o.depth;
865 if (abs(idiff) > depth_diff)
866 return 0;
867 }
868
869 return 1;
870}
871
872static void merge_bs(struct bs **bsap, unsigned int *nr_bsap,
873 struct bs *bsb, unsigned int nr_bsb)
874{
875 struct bs *bsa = *bsap;
876 unsigned int nr_bsa = *nr_bsap;
877 int a, b;
878
879 for (b = 0; b < nr_bsb; b++) {
880 int next, found = 0;
881
882 for (a = 0; a < nr_bsa; a++) {
883 if (bsb[b].bs != bsa[a].bs)
884 continue;
885
886 bsa[a].nr += bsb[b].nr;
887 bsa[a].merges += bsb[b].merges;
888 found = 1;
889 break;
890 }
891
892 if (found)
893 continue;
894
895 next = *nr_bsap;
896 bsa = realloc(bsa, (next + 1) * sizeof(struct bs));
897 bsa[next].bs = bsb[b].bs;
898 bsa[next].nr = bsb[b].nr;
899 (*nr_bsap)++;
900 *bsap = bsa;
901 }
902}
903
904static int merge_entries(struct btrace_pid *pida, struct btrace_pid *pidb)
905{
906 int i;
907
908 if (!entries_close(pida, pidb))
909 return 0;
910
911 pida->nr_merge_pids++;
912 pida->merge_pids = realloc(pida->merge_pids, pida->nr_merge_pids * sizeof(pid_t));
913 pida->merge_pids[pida->nr_merge_pids - 1] = pidb->pid;
914
915 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
916 struct btrace_out *oa = &pida->o;
917 struct btrace_out *ob = &pidb->o;
918
919 oa->ios[i] += ob->ios[i];
920 oa->merges[i] += ob->merges[i];
921 oa->seq[i] += ob->seq[i];
922 oa->kb[i] += ob->kb[i];
923 oa->first_ttime[i] = min(oa->first_ttime[i], ob->first_ttime[i]);
924 oa->last_ttime[i] = max(oa->last_ttime[i], ob->last_ttime[i]);
925 merge_bs(&oa->bs[i], &oa->nr_bs[i], ob->bs[i], ob->nr_bs[i]);
926 }
927
928 pida->o.start_delay = min(pida->o.start_delay, pidb->o.start_delay);
929 pida->o.depth = (pida->o.depth + pidb->o.depth) / 2;
930 return 1;
931}
932
933static void check_merges(struct btrace_pid *p, struct flist_head *pid_list)
934{
935 struct flist_head *e, *tmp;
936
937 if (p->ignore)
938 return;
939
940 flist_for_each_safe(e, tmp, pid_list) {
941 struct btrace_pid *pidb;
942
943 pidb = flist_entry(e, struct btrace_pid, pid_list);
944 if (pidb == p)
945 continue;
946
947 if (merge_entries(p, pidb)) {
948 pidb->ignore = 1;
949 p->numjobs++;
950 }
951 }
952}
953
Jens Axboe42a80e32014-09-16 17:06:52 +0200954static int output_p(void)
955{
956 unsigned long ios[DDIR_RWDIR_CNT];
957 struct flist_head *e, *tmp;
Jens Axboea5d7a722014-11-10 08:52:23 -0700958 int depth_disabled = 0;
Jens Axboe42a80e32014-09-16 17:06:52 +0200959 int ret = 0;
960
961 flist_for_each_safe(e, tmp, &pid_list) {
962 struct btrace_pid *p;
963
964 p = flist_entry(e, struct btrace_pid, pid_list);
965 if (prune_entry(&p->o)) {
Jens Axboe50331622014-09-16 18:28:42 +0200966 free_p(p);
Jens Axboe42a80e32014-09-16 17:06:52 +0200967 continue;
968 }
Jens Axboe183f3922014-09-18 17:23:55 +0200969 p->o.start_delay = (o_first_ttime(&p->o) / 1000ULL) - first_ttime;
Jens Axboea5d7a722014-11-10 08:52:23 -0700970 depth_disabled += p->o.depth_disabled;
Jens Axboe42a80e32014-09-16 17:06:52 +0200971 }
972
Jens Axboe1a9b2932014-12-10 22:01:36 +0100973 if (collapse_entries) {
974 struct btrace_pid *p;
975
976 flist_for_each_safe(e, tmp, &pid_list) {
977 p = flist_entry(e, struct btrace_pid, pid_list);
978 check_merges(p, &pid_list);
979 }
980
981 flist_for_each_safe(e, tmp, &pid_list) {
982 p = flist_entry(e, struct btrace_pid, pid_list);
983 if (p->ignore)
984 free_p(p);
985 }
986 }
987
Jens Axboea5d7a722014-11-10 08:52:23 -0700988 if (depth_disabled)
989 log_err("fio: missing completion traces, depths capped at %u\n", max_depth);
990
Jens Axboe42a80e32014-09-16 17:06:52 +0200991 memset(ios, 0, sizeof(ios));
992
993 flist_sort(NULL, &pid_list, entry_cmp);
994
995 flist_for_each(e, &pid_list) {
996 struct btrace_pid *p;
997
998 p = flist_entry(e, struct btrace_pid, pid_list);
999 ret |= __output_p(p, ios);
Jens Axboe183f3922014-09-18 17:23:55 +02001000 if (ret && !output_ascii)
1001 break;
Jens Axboe42a80e32014-09-16 17:06:52 +02001002 }
1003
1004 if (output_ascii)
1005 printf("Total: reads=%lu, writes=%lu\n", ios[0], ios[1]);
1006
1007 return ret;
1008}
1009
1010static int usage(char *argv[])
1011{
Jens Axboe1a9b2932014-12-10 22:01:36 +01001012 log_err("%s: [options] <blktrace bin file>\n", argv[0]);
Jens Axboe50331622014-09-16 18:28:42 +02001013 log_err("\t-t\tUsec threshold to ignore task\n");
1014 log_err("\t-n\tNumber IOS threshold to ignore task\n");
1015 log_err("\t-f\tFio job file output\n");
1016 log_err("\t-d\tUse this file/device for replay\n");
Jens Axboe183f3922014-09-18 17:23:55 +02001017 log_err("\t-r\tIgnore jobs with less than this KB/sec rate\n");
Jens Axboe1a9b2932014-12-10 22:01:36 +01001018 log_err("\t-R\tSet rate in fio job (def=%u)\n", set_rate);
Jens Axboea5d7a722014-11-10 08:52:23 -07001019 log_err("\t-D\tCap queue depth at this value (def=%u)\n", max_depth);
Jens Axboe1a9b2932014-12-10 22:01:36 +01001020 log_err("\t-c\tCollapse \"identical\" jobs (def=%u)\n", collapse_entries);
1021 log_err("\t-u\tDepth difference for collapse (def=%u)\n", depth_diff);
1022 log_err("\t-x\tRandom difference for collapse (def=%u)\n", random_diff);
Jens Axboe42a80e32014-09-16 17:06:52 +02001023 return 1;
1024}
1025
Jens Axboe50331622014-09-16 18:28:42 +02001026static int trace_needs_swap(const char *trace_file, int *swap)
1027{
1028 struct blk_io_trace t;
1029 int fd, ret;
1030
1031 *swap = -1;
1032
1033 fd = open(trace_file, O_RDONLY);
1034 if (fd < 0) {
1035 perror("open");
1036 return 1;
1037 }
1038
1039 ret = read(fd, &t, sizeof(t));
1040 if (ret < 0) {
Jens Axboe31da12c2014-10-14 19:55:18 -06001041 close(fd);
Jens Axboe50331622014-09-16 18:28:42 +02001042 perror("read");
1043 return 1;
1044 } else if (ret != sizeof(t)) {
Jens Axboe31da12c2014-10-14 19:55:18 -06001045 close(fd);
Jens Axboe50331622014-09-16 18:28:42 +02001046 log_err("fio: short read on trace file\n");
1047 return 1;
1048 }
1049
1050 close(fd);
1051
1052 if ((t.magic & 0xffffff00) == BLK_IO_TRACE_MAGIC)
1053 *swap = 0;
1054 else {
1055 /*
1056 * Maybe it needs to be endian swapped...
1057 */
1058 t.magic = fio_swap32(t.magic);
1059 if ((t.magic & 0xffffff00) == BLK_IO_TRACE_MAGIC)
1060 *swap = 1;
1061 }
1062
1063 if (*swap == -1) {
1064 log_err("fio: blktrace appears corrupt\n");
1065 return 1;
1066 }
1067
1068 return 0;
1069}
1070
Jens Axboe42a80e32014-09-16 17:06:52 +02001071int main(int argc, char *argv[])
1072{
Jens Axboe50331622014-09-16 18:28:42 +02001073 int need_swap, i, c;
Jens Axboe42a80e32014-09-16 17:06:52 +02001074
1075 if (argc < 2)
1076 return usage(argv);
1077
Jens Axboe1a9b2932014-12-10 22:01:36 +01001078 while ((c = getopt(argc, argv, "t:n:fd:r:RD:c:u:x:")) != -1) {
Jens Axboe42a80e32014-09-16 17:06:52 +02001079 switch (c) {
Jens Axboe183f3922014-09-18 17:23:55 +02001080 case 'R':
1081 set_rate = 1;
1082 break;
1083 case 'r':
1084 rate_threshold = atoi(optarg);
1085 break;
Jens Axboe42a80e32014-09-16 17:06:52 +02001086 case 't':
1087 rt_threshold = atoi(optarg);
1088 break;
1089 case 'n':
1090 ios_threshold = atoi(optarg);
1091 break;
1092 case 'f':
1093 output_ascii = 0;
1094 break;
Jens Axboeb064a142014-09-16 17:40:03 +02001095 case 'd':
1096 filename = strdup(optarg);
1097 break;
Jens Axboea5d7a722014-11-10 08:52:23 -07001098 case 'D':
1099 max_depth = atoi(optarg);
1100 break;
Jens Axboe1a9b2932014-12-10 22:01:36 +01001101 case 'c':
1102 collapse_entries = atoi(optarg);
1103 break;
1104 case 'u':
1105 depth_diff = atoi(optarg);
1106 break;
1107 case 'x':
1108 random_diff = atoi(optarg);
1109 break;
Jens Axboe42a80e32014-09-16 17:06:52 +02001110 case '?':
1111 default:
1112 return usage(argv);
1113 }
1114 }
1115
1116 if (argc == optind)
1117 return usage(argv);
1118
Jens Axboe50331622014-09-16 18:28:42 +02001119 if (trace_needs_swap(argv[optind], &need_swap))
Jens Axboe42a80e32014-09-16 17:06:52 +02001120 return 1;
Jens Axboe42a80e32014-09-16 17:06:52 +02001121
1122 for (i = 0; i < PID_HASH_SIZE; i++)
1123 INIT_FLIST_HEAD(&pid_hash[i]);
Jens Axboe50331622014-09-16 18:28:42 +02001124 for (i = 0; i < INFLIGHT_HASH_SIZE; i++)
1125 INIT_FLIST_HEAD(&inflight_hash[i]);
Jens Axboe42a80e32014-09-16 17:06:52 +02001126
1127 load_blktrace(argv[optind], need_swap);
1128 first_ttime /= 1000ULL;
1129
1130 return output_p();
1131}