blob: d0b7e091aa9bbff6dd2d61bc220e265d72d52c6e [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 Axboe32e9adb2014-12-18 10:18:30 -070027static char **add_opts;
28static int n_add_opts;
29
Jens Axboe1a9b2932014-12-10 22:01:36 +010030/*
31 * Collapse defaults
32 */
33static unsigned int collapse_entries = 0;
34static unsigned int depth_diff = 1;
35static unsigned int random_diff = 5;
36
Jens Axboe42a80e32014-09-16 17:06:52 +020037struct bs {
38 unsigned int bs;
39 unsigned int nr;
40 int merges;
41};
42
43struct trace_file {
44 char *name;
45 int major, minor;
46};
47
48struct btrace_out {
49 unsigned long ios[DDIR_RWDIR_CNT];
Jens Axboe42a80e32014-09-16 17:06:52 +020050 unsigned long merges[DDIR_RWDIR_CNT];
51
52 uint64_t last_end[DDIR_RWDIR_CNT];
53 uint64_t seq[DDIR_RWDIR_CNT];
54
55 struct bs *bs[DDIR_RWDIR_CNT];
56 unsigned int nr_bs[DDIR_RWDIR_CNT];
57
58 int inflight;
59 unsigned int depth;
Jens Axboea5d7a722014-11-10 08:52:23 -070060 int depth_disabled;
61 int complete_seen;
62
Jens Axboe183f3922014-09-18 17:23:55 +020063 uint64_t first_ttime[DDIR_RWDIR_CNT];
64 uint64_t last_ttime[DDIR_RWDIR_CNT];
65 uint64_t kb[DDIR_RWDIR_CNT];
Jens Axboe42a80e32014-09-16 17:06:52 +020066
Jens Axboe42a80e32014-09-16 17:06:52 +020067 uint64_t start_delay;
68};
69
70struct btrace_pid {
71 struct flist_head hash_list;
72 struct flist_head pid_list;
73 pid_t pid;
Jens Axboed8943e12014-09-16 20:17:55 -060074
Jens Axboe1a9b2932014-12-10 22:01:36 +010075 pid_t *merge_pids;
76 unsigned int nr_merge_pids;
77
Jens Axboed8943e12014-09-16 20:17:55 -060078 struct trace_file *files;
79 int nr_files;
80 unsigned int last_major, last_minor;
Jens Axboe1a9b2932014-12-10 22:01:36 +010081 int numjobs;
82 int ignore;
Jens Axboed8943e12014-09-16 20:17:55 -060083
Jens Axboe42a80e32014-09-16 17:06:52 +020084 struct btrace_out o;
85};
86
87struct inflight {
88 struct flist_head list;
89 struct btrace_pid *p;
90 uint64_t end_sector;
91};
92
93#define PID_HASH_BITS 10
94#define PID_HASH_SIZE (1U << PID_HASH_BITS)
95
96static struct flist_head pid_hash[PID_HASH_SIZE];
97static FLIST_HEAD(pid_list);
98
Jens Axboe50331622014-09-16 18:28:42 +020099#define INFLIGHT_HASH_BITS 8
100#define INFLIGHT_HASH_SIZE (1U << INFLIGHT_HASH_BITS)
101static struct flist_head inflight_hash[INFLIGHT_HASH_SIZE];
Jens Axboe42a80e32014-09-16 17:06:52 +0200102
103static uint64_t first_ttime = -1ULL;
104
105static struct inflight *inflight_find(uint64_t sector)
106{
Jens Axboe50331622014-09-16 18:28:42 +0200107 struct flist_head *inflight_list;
Jens Axboe42a80e32014-09-16 17:06:52 +0200108 struct flist_head *e;
109
Jens Axboe50331622014-09-16 18:28:42 +0200110 inflight_list = &inflight_hash[hash_long(sector, INFLIGHT_HASH_BITS)];
111
112 flist_for_each(e, inflight_list) {
Jens Axboe42a80e32014-09-16 17:06:52 +0200113 struct inflight *i = flist_entry(e, struct inflight, list);
114
115 if (i->end_sector == sector)
116 return i;
117 }
118
119 return NULL;
120}
121
122static void inflight_remove(struct inflight *i)
123{
124 struct btrace_out *o = &i->p->o;
125
126 o->inflight--;
127 assert(o->inflight >= 0);
128 flist_del(&i->list);
129 free(i);
130}
131
Jens Axboe50331622014-09-16 18:28:42 +0200132static void __inflight_add(struct inflight *i)
Jens Axboe42a80e32014-09-16 17:06:52 +0200133{
Jens Axboe50331622014-09-16 18:28:42 +0200134 struct flist_head *list;
135
136 list = &inflight_hash[hash_long(i->end_sector, INFLIGHT_HASH_BITS)];
137 flist_add_tail(&i->list, list);
Jens Axboe42a80e32014-09-16 17:06:52 +0200138}
139
140static void inflight_add(struct btrace_pid *p, uint64_t sector, uint32_t len)
141{
142 struct btrace_out *o = &p->o;
143 struct inflight *i;
144
145 i = calloc(1, sizeof(*i));
146 i->p = p;
147 o->inflight++;
Jens Axboea5d7a722014-11-10 08:52:23 -0700148 if (!o->depth_disabled) {
149 o->depth = max((int) o->depth, o->inflight);
150 if (o->depth >= max_depth && !o->complete_seen) {
151 o->depth_disabled = 1;
152 o->depth = max_depth;
153 }
154 }
Jens Axboe42a80e32014-09-16 17:06:52 +0200155 i->end_sector = sector + (len >> 9);
Jens Axboe50331622014-09-16 18:28:42 +0200156 __inflight_add(i);
157}
158
159static void inflight_merge(struct inflight *i, int rw, unsigned int size)
160{
161 i->p->o.merges[rw]++;
162 if (size) {
163 i->end_sector += (size >> 9);
164 flist_del(&i->list);
165 __inflight_add(i);
166 }
Jens Axboe42a80e32014-09-16 17:06:52 +0200167}
168
169/*
170 * fifo refill frontend, to avoid reading data in trace sized bites
171 */
172static int refill_fifo(struct fifo *fifo, int fd)
173{
174 char buf[TRACE_FIFO_SIZE];
175 unsigned int total;
176 int ret;
177
178 total = sizeof(buf);
179 if (total > fifo_room(fifo))
180 total = fifo_room(fifo);
181
182 ret = read(fd, buf, total);
183 if (ret < 0) {
184 perror("read refill");
185 return -1;
186 }
187
188 if (ret > 0)
189 ret = fifo_put(fifo, buf, ret);
190
191 return ret;
192}
193
194/*
195 * Retrieve 'len' bytes from the fifo, refilling if necessary.
196 */
197static int trace_fifo_get(struct fifo *fifo, int fd, void *buf,
198 unsigned int len)
199{
200 if (fifo_len(fifo) < len) {
201 int ret = refill_fifo(fifo, fd);
202
203 if (ret < 0)
204 return ret;
205 }
206
207 return fifo_get(fifo, buf, len);
208}
209
210/*
211 * Just discard the pdu by seeking past it.
212 */
213static int discard_pdu(struct fifo *fifo, int fd, struct blk_io_trace *t)
214{
215 if (t->pdu_len == 0)
216 return 0;
217
218 return trace_fifo_get(fifo, fd, NULL, t->pdu_len);
219}
220
Jens Axboe183f3922014-09-18 17:23:55 +0200221static int handle_trace_notify(struct blk_io_trace *t)
Jens Axboe42a80e32014-09-16 17:06:52 +0200222{
223 switch (t->action) {
224 case BLK_TN_PROCESS:
225 //printf("got process notify: %x, %d\n", t->action, t->pid);
226 break;
227 case BLK_TN_TIMESTAMP:
228 //printf("got timestamp notify: %x, %d\n", t->action, t->pid);
229 break;
230 case BLK_TN_MESSAGE:
231 break;
232 default:
Jens Axboe50331622014-09-16 18:28:42 +0200233 log_err("unknown trace act %x\n", t->action);
Jens Axboe183f3922014-09-18 17:23:55 +0200234 return 1;
Jens Axboe42a80e32014-09-16 17:06:52 +0200235 }
Jens Axboe183f3922014-09-18 17:23:55 +0200236
237 return 0;
Jens Axboe42a80e32014-09-16 17:06:52 +0200238}
239
240static void __add_bs(struct btrace_out *o, unsigned int len, int rw)
241{
242 o->bs[rw] = realloc(o->bs[rw], (o->nr_bs[rw] + 1) * sizeof(struct bs));
243 o->bs[rw][o->nr_bs[rw]].bs = len;
244 o->bs[rw][o->nr_bs[rw]].nr = 1;
245 o->nr_bs[rw]++;
246}
247
248static void add_bs(struct btrace_out *o, unsigned int len, int rw)
249{
250 struct bs *bs = o->bs[rw];
251 int i;
252
253 if (!o->nr_bs[rw]) {
254 __add_bs(o, len, rw);
255 return;
256 }
257
258 for (i = 0; i < o->nr_bs[rw]; i++) {
259 if (bs[i].bs == len) {
260 bs[i].nr++;
261 return;
262 }
263 }
264
265 __add_bs(o, len, rw);
266}
267
268#define FMINORBITS 20
269#define FMINORMASK ((1U << FMINORBITS) - 1)
270#define FMAJOR(dev) ((unsigned int) ((dev) >> FMINORBITS))
271#define FMINOR(dev) ((unsigned int) ((dev) & FMINORMASK))
272
Jens Axboe183f3922014-09-18 17:23:55 +0200273static int btrace_add_file(struct btrace_pid *p, uint32_t devno)
Jens Axboe42a80e32014-09-16 17:06:52 +0200274{
275 unsigned int maj = FMAJOR(devno);
276 unsigned int min = FMINOR(devno);
277 struct trace_file *f;
278 unsigned int i;
279 char dev[256];
280
Jens Axboeb064a142014-09-16 17:40:03 +0200281 if (filename)
Jens Axboe183f3922014-09-18 17:23:55 +0200282 return 0;
Jens Axboed8943e12014-09-16 20:17:55 -0600283 if (p->last_major == maj && p->last_minor == min)
Jens Axboe183f3922014-09-18 17:23:55 +0200284 return 0;
Jens Axboe42a80e32014-09-16 17:06:52 +0200285
Jens Axboed8943e12014-09-16 20:17:55 -0600286 p->last_major = maj;
287 p->last_minor = min;
Jens Axboe42a80e32014-09-16 17:06:52 +0200288
289 /*
290 * check for this file in our list
291 */
Jens Axboed8943e12014-09-16 20:17:55 -0600292 for (i = 0; i < p->nr_files; i++) {
293 f = &p->files[i];
Jens Axboe42a80e32014-09-16 17:06:52 +0200294
295 if (f->major == maj && f->minor == min)
Jens Axboe183f3922014-09-18 17:23:55 +0200296 return 0;
Jens Axboe42a80e32014-09-16 17:06:52 +0200297 }
298
299 strcpy(dev, "/dev");
300 if (!blktrace_lookup_device(NULL, dev, maj, min)) {
301 log_err("fio: failed to find device %u/%u\n", maj, min);
Jens Axboe183f3922014-09-18 17:23:55 +0200302 if (!output_ascii) {
303 log_err("fio: use -d to specify device\n");
304 return 1;
305 }
306 return 0;
Jens Axboe42a80e32014-09-16 17:06:52 +0200307 }
308
Jens Axboed8943e12014-09-16 20:17:55 -0600309 p->files = realloc(p->files, (p->nr_files + 1) * sizeof(*f));
310 f = &p->files[p->nr_files];
Jens Axboe42a80e32014-09-16 17:06:52 +0200311 f->name = strdup(dev);
312 f->major = maj;
313 f->minor = min;
Jens Axboed8943e12014-09-16 20:17:55 -0600314 p->nr_files++;
Jens Axboe183f3922014-09-18 17:23:55 +0200315 return 0;
Jens Axboe42a80e32014-09-16 17:06:52 +0200316}
317
Jens Axboe183f3922014-09-18 17:23:55 +0200318static int t_to_rwdir(struct blk_io_trace *t)
319{
320 if (t->action & BLK_TC_ACT(BLK_TC_DISCARD))
321 return DDIR_TRIM;
322
323 return (t->action & BLK_TC_ACT(BLK_TC_WRITE)) != 0;
324}
325
326static int handle_trace_discard(struct blk_io_trace *t, struct btrace_pid *p)
Jens Axboe42a80e32014-09-16 17:06:52 +0200327{
Jens Axboed8943e12014-09-16 20:17:55 -0600328 struct btrace_out *o = &p->o;
329
Jens Axboe183f3922014-09-18 17:23:55 +0200330 if (btrace_add_file(p, t->device))
331 return 1;
Jens Axboe42a80e32014-09-16 17:06:52 +0200332
Jens Axboe183f3922014-09-18 17:23:55 +0200333 if (o->first_ttime[2] == -1ULL)
334 o->first_ttime[2] = t->time;
Jens Axboe42a80e32014-09-16 17:06:52 +0200335
336 o->ios[DDIR_TRIM]++;
337 add_bs(o, t->bytes, DDIR_TRIM);
Jens Axboe183f3922014-09-18 17:23:55 +0200338 return 0;
Jens Axboe42a80e32014-09-16 17:06:52 +0200339}
340
Jens Axboe183f3922014-09-18 17:23:55 +0200341static int handle_trace_fs(struct blk_io_trace *t, struct btrace_pid *p)
Jens Axboe42a80e32014-09-16 17:06:52 +0200342{
Jens Axboed8943e12014-09-16 20:17:55 -0600343 struct btrace_out *o = &p->o;
Jens Axboe42a80e32014-09-16 17:06:52 +0200344 int rw;
345
Jens Axboe183f3922014-09-18 17:23:55 +0200346 if (btrace_add_file(p, t->device))
347 return 1;
Jens Axboe42a80e32014-09-16 17:06:52 +0200348
349 first_ttime = min(first_ttime, (uint64_t) t->time);
350
Jens Axboe42a80e32014-09-16 17:06:52 +0200351 rw = (t->action & BLK_TC_ACT(BLK_TC_WRITE)) != 0;
352
Jens Axboe183f3922014-09-18 17:23:55 +0200353 if (o->first_ttime[rw] == -1ULL)
354 o->first_ttime[rw] = t->time;
355
Jens Axboe42a80e32014-09-16 17:06:52 +0200356 add_bs(o, t->bytes, rw);
357 o->ios[rw]++;
358
359 if (t->sector == o->last_end[rw] || o->last_end[rw] == -1ULL)
360 o->seq[rw]++;
361
362 o->last_end[rw] = t->sector + (t->bytes >> 9);
Jens Axboe183f3922014-09-18 17:23:55 +0200363 return 0;
Jens Axboe42a80e32014-09-16 17:06:52 +0200364}
365
Jens Axboe183f3922014-09-18 17:23:55 +0200366static int handle_queue_trace(struct blk_io_trace *t, struct btrace_pid *p)
Jens Axboe42a80e32014-09-16 17:06:52 +0200367{
368 if (t->action & BLK_TC_ACT(BLK_TC_NOTIFY))
Jens Axboe183f3922014-09-18 17:23:55 +0200369 return handle_trace_notify(t);
Jens Axboe42a80e32014-09-16 17:06:52 +0200370 else if (t->action & BLK_TC_ACT(BLK_TC_DISCARD))
Jens Axboe183f3922014-09-18 17:23:55 +0200371 return handle_trace_discard(t, p);
Jens Axboe42a80e32014-09-16 17:06:52 +0200372 else
Jens Axboe183f3922014-09-18 17:23:55 +0200373 return handle_trace_fs(t, p);
Jens Axboe42a80e32014-09-16 17:06:52 +0200374}
375
Jens Axboe183f3922014-09-18 17:23:55 +0200376static int handle_trace(struct blk_io_trace *t, struct btrace_pid *p)
Jens Axboe42a80e32014-09-16 17:06:52 +0200377{
378 unsigned int act = t->action & 0xffff;
Jens Axboe183f3922014-09-18 17:23:55 +0200379 int ret = 0;
Jens Axboe42a80e32014-09-16 17:06:52 +0200380
381 if (act == __BLK_TA_QUEUE) {
382 inflight_add(p, t->sector, t->bytes);
Jens Axboe183f3922014-09-18 17:23:55 +0200383 ret = handle_queue_trace(t, p);
Jens Axboe42a80e32014-09-16 17:06:52 +0200384 } else if (act == __BLK_TA_BACKMERGE) {
385 struct inflight *i;
386
387 i = inflight_find(t->sector + (t->bytes >> 9));
388 if (i)
389 inflight_remove(i);
390
391 i = inflight_find(t->sector);
Jens Axboe183f3922014-09-18 17:23:55 +0200392 if (i)
393 inflight_merge(i, t_to_rwdir(t), t->bytes);
Jens Axboe42a80e32014-09-16 17:06:52 +0200394 } else if (act == __BLK_TA_FRONTMERGE) {
395 struct inflight *i;
396
397 i = inflight_find(t->sector + (t->bytes >> 9));
398 if (i)
399 inflight_remove(i);
400
401 i = inflight_find(t->sector);
Jens Axboe183f3922014-09-18 17:23:55 +0200402 if (i)
403 inflight_merge(i, t_to_rwdir(t), 0);
Jens Axboe42a80e32014-09-16 17:06:52 +0200404 } else if (act == __BLK_TA_COMPLETE) {
405 struct inflight *i;
406
407 i = inflight_find(t->sector + (t->bytes >> 9));
Jens Axboe047623b2014-09-17 17:58:31 +0200408 if (i) {
Jens Axboe183f3922014-09-18 17:23:55 +0200409 i->p->o.kb[t_to_rwdir(t)] += (t->bytes >> 10);
Jens Axboea5d7a722014-11-10 08:52:23 -0700410 i->p->o.complete_seen = 1;
Jens Axboe42a80e32014-09-16 17:06:52 +0200411 inflight_remove(i);
Jens Axboe047623b2014-09-17 17:58:31 +0200412 }
Jens Axboe42a80e32014-09-16 17:06:52 +0200413 }
Jens Axboe183f3922014-09-18 17:23:55 +0200414
415 return ret;
Jens Axboe42a80e32014-09-16 17:06:52 +0200416}
417
418static void byteswap_trace(struct blk_io_trace *t)
419{
420 t->magic = fio_swap32(t->magic);
421 t->sequence = fio_swap32(t->sequence);
422 t->time = fio_swap64(t->time);
423 t->sector = fio_swap64(t->sector);
424 t->bytes = fio_swap32(t->bytes);
425 t->action = fio_swap32(t->action);
426 t->pid = fio_swap32(t->pid);
427 t->device = fio_swap32(t->device);
428 t->cpu = fio_swap32(t->cpu);
429 t->error = fio_swap16(t->error);
430 t->pdu_len = fio_swap16(t->pdu_len);
431}
432
433static struct btrace_pid *pid_hash_find(pid_t pid, struct flist_head *list)
434{
435 struct flist_head *e;
436 struct btrace_pid *p;
437
438 flist_for_each(e, list) {
439 p = flist_entry(e, struct btrace_pid, hash_list);
440 if (p->pid == pid)
441 return p;
442 }
443
444 return NULL;
445}
446
447static struct btrace_pid *pid_hash_get(pid_t pid)
448{
449 struct flist_head *hash_list;
450 struct btrace_pid *p;
451
452 hash_list = &pid_hash[hash_long(pid, PID_HASH_BITS)];
453
454 p = pid_hash_find(pid, hash_list);
455 if (!p) {
456 int i;
457
458 p = calloc(1, sizeof(*p));
Jens Axboe42a80e32014-09-16 17:06:52 +0200459
Jens Axboe183f3922014-09-18 17:23:55 +0200460 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
461 p->o.first_ttime[i] = -1ULL;
462 p->o.last_ttime[i] = -1ULL;
Jens Axboe42a80e32014-09-16 17:06:52 +0200463 p->o.last_end[i] = -1ULL;
Jens Axboe183f3922014-09-18 17:23:55 +0200464 }
Jens Axboe42a80e32014-09-16 17:06:52 +0200465
466 p->pid = pid;
Jens Axboe1a9b2932014-12-10 22:01:36 +0100467 p->numjobs = 1;
Jens Axboe42a80e32014-09-16 17:06:52 +0200468 flist_add_tail(&p->hash_list, hash_list);
469 flist_add_tail(&p->pid_list, &pid_list);
470 }
471
472 return p;
473}
474
475/*
476 * Load a blktrace file by reading all the blk_io_trace entries, and storing
477 * them as io_pieces like the fio text version would do.
478 */
Jens Axboe0f7f9a92014-11-06 09:21:10 -0700479static int load_blktrace(const char *fname, int need_swap)
Jens Axboe42a80e32014-09-16 17:06:52 +0200480{
481 struct btrace_pid *p;
482 unsigned long traces;
483 struct blk_io_trace t;
484 struct fifo *fifo;
Jens Axboe183f3922014-09-18 17:23:55 +0200485 int fd, ret = 0;
Jens Axboe42a80e32014-09-16 17:06:52 +0200486
Jens Axboe0f7f9a92014-11-06 09:21:10 -0700487 fd = open(fname, O_RDONLY);
Jens Axboe42a80e32014-09-16 17:06:52 +0200488 if (fd < 0) {
489 perror("open trace file\n");
490 return 1;
491 }
492
493 fifo = fifo_alloc(TRACE_FIFO_SIZE);
494
495 traces = 0;
496 do {
Jens Axboe0f7f9a92014-11-06 09:21:10 -0700497 ret = trace_fifo_get(fifo, fd, &t, sizeof(t));
Jens Axboe42a80e32014-09-16 17:06:52 +0200498 if (ret < 0)
499 goto err;
500 else if (!ret)
501 break;
502 else if (ret < (int) sizeof(t)) {
Jens Axboe50331622014-09-16 18:28:42 +0200503 log_err("fio: short fifo get\n");
Jens Axboe42a80e32014-09-16 17:06:52 +0200504 break;
505 }
506
507 if (need_swap)
508 byteswap_trace(&t);
509
510 if ((t.magic & 0xffffff00) != BLK_IO_TRACE_MAGIC) {
Jens Axboe50331622014-09-16 18:28:42 +0200511 log_err("fio: bad magic in blktrace data: %x\n", t.magic);
Jens Axboe42a80e32014-09-16 17:06:52 +0200512 goto err;
513 }
514 if ((t.magic & 0xff) != BLK_IO_TRACE_VERSION) {
Jens Axboe50331622014-09-16 18:28:42 +0200515 log_err("fio: bad blktrace version %d\n", t.magic & 0xff);
Jens Axboe42a80e32014-09-16 17:06:52 +0200516 goto err;
517 }
518 ret = discard_pdu(fifo, fd, &t);
519 if (ret < 0) {
Jens Axboe50331622014-09-16 18:28:42 +0200520 log_err("blktrace lseek\n");
Jens Axboe42a80e32014-09-16 17:06:52 +0200521 goto err;
522 } else if (t.pdu_len != ret) {
Jens Axboe50331622014-09-16 18:28:42 +0200523 log_err("fio: discarded %d of %d\n", ret, t.pdu_len);
Jens Axboe42a80e32014-09-16 17:06:52 +0200524 goto err;
525 }
526
527 p = pid_hash_get(t.pid);
Jens Axboe183f3922014-09-18 17:23:55 +0200528 ret = handle_trace(&t, p);
529 if (ret)
530 break;
531 p->o.last_ttime[t_to_rwdir(&t)] = t.time;
Jens Axboe42a80e32014-09-16 17:06:52 +0200532 traces++;
533 } while (1);
534
535 fifo_free(fifo);
536 close(fd);
537
Jens Axboe183f3922014-09-18 17:23:55 +0200538 if (ret)
539 return ret;
540
Jens Axboe42a80e32014-09-16 17:06:52 +0200541 if (output_ascii)
542 printf("Traces loaded: %lu\n", traces);
543
544 return 0;
545err:
546 close(fd);
547 fifo_free(fifo);
548 return 1;
549}
550
551static int bs_cmp(const void *ba, const void *bb)
552{
553 const struct bs *bsa = ba;
554 const struct bs *bsb = bb;
555
556 return bsb->nr - bsa->nr;
557}
558
Jens Axboe183f3922014-09-18 17:23:55 +0200559static unsigned long o_to_kb_rate(struct btrace_out *o, int rw)
560{
561 uint64_t usec = (o->last_ttime[rw] - o->first_ttime[rw]) / 1000ULL;
562 uint64_t val;
563
564 if (!usec)
565 return 0;
566
Jens Axboe44aab352014-11-11 08:09:04 -0700567 usec /= 1000;
568 if (!usec)
569 return 0;
570
Jens Axboe183f3922014-09-18 17:23:55 +0200571 val = o->kb[rw] * 1000ULL;
Jens Axboe44aab352014-11-11 08:09:04 -0700572 return val / usec;
Jens Axboe183f3922014-09-18 17:23:55 +0200573}
574
575static uint64_t o_first_ttime(struct btrace_out *o)
576{
577 uint64_t first;
578
579 first = min(o->first_ttime[0], o->first_ttime[1]);
580 return min(first, o->first_ttime[2]);
581}
582
583static uint64_t o_longest_ttime(struct btrace_out *o)
584{
585 uint64_t ret = 0;
586 int i;
587
588 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
589 uint64_t diff;
590
591 diff = o->last_ttime[i] - o->first_ttime[i];
592 ret = max(diff, ret);
593 }
594
595 return ret;
596}
597
Jens Axboe42a80e32014-09-16 17:06:52 +0200598static void __output_p_ascii(struct btrace_pid *p, unsigned long *ios)
599{
600 const char *msg[] = { "reads", "writes", "trims" };
601 struct btrace_out *o = &p->o;
Jens Axboe047623b2014-09-17 17:58:31 +0200602 unsigned long total, usec;
Jens Axboe42a80e32014-09-16 17:06:52 +0200603 int i, j;
604
Jens Axboe1a9b2932014-12-10 22:01:36 +0100605 printf("[pid:\t%u", p->pid);
606 if (p->nr_merge_pids)
607 for (i = 0; i < p->nr_merge_pids; i++)
608 printf(", %u", p->merge_pids[i]);
609 printf("]\n");
Jens Axboe42a80e32014-09-16 17:06:52 +0200610
611 total = ddir_rw_sum(o->ios);
612 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
613 float perc;
614
615 if (!o->ios[i])
616 continue;
617
618 ios[i] += o->ios[i] + o->merges[i];
619 printf("%s\n", msg[i]);
620 perc = ((float) o->ios[i] * 100.0) / (float) total;
621 printf("\tios: %lu (perc=%3.2f%%)\n", o->ios[i], perc);
622 perc = ((float) o->merges[i] * 100.0) / (float) total;
623 printf("\tmerges: %lu (perc=%3.2f%%)\n", o->merges[i], perc);
624 perc = ((float) o->seq[i] * 100.0) / (float) o->ios[i];
Jens Axboeb2a657f2014-09-23 16:06:04 -0600625 printf("\tseq: %lu (perc=%3.2f%%)\n", (unsigned long) o->seq[i], perc);
Jens Axboe183f3922014-09-18 17:23:55 +0200626 printf("\trate: %lu KB/sec\n", o_to_kb_rate(o, i));
Jens Axboe42a80e32014-09-16 17:06:52 +0200627
628 for (j = 0; j < o->nr_bs[i]; j++) {
629 struct bs *bs = &o->bs[i][j];
630
631 perc = (((float) bs->nr * 100.0) / (float) o->ios[i]);
632 printf("\tbs=%u, perc=%3.2f%%\n", bs->bs, perc);
633 }
634 }
635
636 printf("depth:\t%u\n", o->depth);
Jens Axboe183f3922014-09-18 17:23:55 +0200637 usec = o_longest_ttime(o) / 1000ULL;
Jens Axboe047623b2014-09-17 17:58:31 +0200638 printf("usec:\t%lu (delay=%llu)\n", usec, (unsigned long long) o->start_delay);
Jens Axboe42a80e32014-09-16 17:06:52 +0200639
640 printf("files:\t");
Jens Axboed8943e12014-09-16 20:17:55 -0600641 for (i = 0; i < p->nr_files; i++)
642 printf("%s,", p->files[i].name);
Jens Axboe42a80e32014-09-16 17:06:52 +0200643 printf("\n");
644
645 printf("\n");
646}
647
648static int __output_p_fio(struct btrace_pid *p, unsigned long *ios)
649{
650 struct btrace_out *o = &p->o;
651 unsigned long total;
Jens Axboecdc4d672014-09-16 17:35:55 +0200652 unsigned long long time;
Jens Axboe42a80e32014-09-16 17:06:52 +0200653 float perc;
654 int i, j;
655
656 if ((o->ios[0] + o->ios[1]) && o->ios[2]) {
657 log_err("fio: trace has both read/write and trim\n");
658 return 1;
659 }
Jens Axboe183f3922014-09-18 17:23:55 +0200660 if (!p->nr_files) {
661 log_err("fio: no devices found\n");
662 return 1;
663 }
Jens Axboe42a80e32014-09-16 17:06:52 +0200664
Jens Axboe1a9b2932014-12-10 22:01:36 +0100665 printf("[pid%u", p->pid);
666 if (p->nr_merge_pids)
667 for (i = 0; i < p->nr_merge_pids; i++)
668 printf(",pid%u", p->merge_pids[i]);
669 printf("]\n");
670
671 printf("numjobs=%u\n", p->numjobs);
Jens Axboe42a80e32014-09-16 17:06:52 +0200672 printf("direct=1\n");
673 if (o->depth == 1)
674 printf("ioengine=sync\n");
675 else
676 printf("ioengine=libaio\niodepth=%u\n", o->depth);
677
678 if (o->ios[0] && !o->ios[1])
679 printf("rw=randread\n");
680 else if (!o->ios[0] && o->ios[1])
681 printf("rw=randwrite\n");
682 else if (o->ios[2])
683 printf("rw=randtrim\n");
684 else {
685 printf("rw=randrw\n");
686 total = ddir_rw_sum(o->ios);
687 perc = ((float) o->ios[0] * 100.0) / (float) total;
Jens Axboe1a9b2932014-12-10 22:01:36 +0100688 printf("rwmixread=%u\n", (int) floor(perc + 0.50));
Jens Axboe42a80e32014-09-16 17:06:52 +0200689 }
690
Jens Axboeb064a142014-09-16 17:40:03 +0200691 printf("percentage_random=");
Jens Axboe42a80e32014-09-16 17:06:52 +0200692 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
693 if (o->seq[i] && o->ios[i]) {
694 perc = ((float) o->seq[i] * 100.0) / (float) o->ios[i];
695 if (perc >= 99.0)
696 perc = 100.0;
697 } else
698 perc = 100.0;
699
700 if (i)
701 printf(",");
Jens Axboeb064a142014-09-16 17:40:03 +0200702 perc = 100.0 - perc;
Jens Axboe1a9b2932014-12-10 22:01:36 +0100703 printf("%u", (int) floor(perc + 0.5));
Jens Axboe42a80e32014-09-16 17:06:52 +0200704 }
705 printf("\n");
706
707 printf("filename=");
Jens Axboed8943e12014-09-16 20:17:55 -0600708 for (i = 0; i < p->nr_files; i++) {
Jens Axboe42a80e32014-09-16 17:06:52 +0200709 if (i)
710 printf(":");
Jens Axboed8943e12014-09-16 20:17:55 -0600711 printf("%s", p->files[i].name);
Jens Axboe42a80e32014-09-16 17:06:52 +0200712 }
713 printf("\n");
714
Jens Axboe1a9b2932014-12-10 22:01:36 +0100715 if (o->start_delay / 1000000ULL)
716 printf("startdelay=%llus\n", o->start_delay / 1000000ULL);
Jens Axboe42a80e32014-09-16 17:06:52 +0200717
Jens Axboe183f3922014-09-18 17:23:55 +0200718 time = o_longest_ttime(o);
Jens Axboecdc4d672014-09-16 17:35:55 +0200719 time = (time + 1000000000ULL - 1) / 1000000000ULL;
720 printf("runtime=%llus\n", time);
721
Jens Axboe42a80e32014-09-16 17:06:52 +0200722 printf("bssplit=");
723 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
724
725 if (i && o->nr_bs[i - 1] && o->nr_bs[i])
726 printf(",");
727
728 for (j = 0; j < o->nr_bs[i]; j++) {
729 struct bs *bs = &o->bs[i][j];
730
731 perc = (((float) bs->nr * 100.0) / (float) o->ios[i]);
732 if (perc < 1.00)
733 continue;
734 if (j)
735 printf(":");
736 if (j + 1 == o->nr_bs[i])
737 printf("%u/", bs->bs);
738 else
Jens Axboe1a9b2932014-12-10 22:01:36 +0100739 printf("%u/%u", bs->bs, (int) floor(perc + 0.5));
Jens Axboe42a80e32014-09-16 17:06:52 +0200740 }
741 }
Jens Axboe183f3922014-09-18 17:23:55 +0200742 printf("\n");
Jens Axboe42a80e32014-09-16 17:06:52 +0200743
Jens Axboe183f3922014-09-18 17:23:55 +0200744 if (set_rate) {
745 printf("rate=");
746 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
747 unsigned long rate;
748
749 rate = o_to_kb_rate(o, i);
750 if (i)
751 printf(",");
752 if (rate)
753 printf("%luk", rate);
754 }
755 printf("\n");
756 }
757
Jens Axboe32e9adb2014-12-18 10:18:30 -0700758 if (n_add_opts)
759 for (i = 0; i < n_add_opts; i++)
760 printf("%s\n", add_opts[i]);
761
Jens Axboe183f3922014-09-18 17:23:55 +0200762 printf("\n");
Jens Axboe42a80e32014-09-16 17:06:52 +0200763 return 0;
764}
765
766static int __output_p(struct btrace_pid *p, unsigned long *ios)
767{
768 struct btrace_out *o = &p->o;
769 int i, ret = 0;
770
771 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
772 if (o->nr_bs[i] <= 1)
773 continue;
774 qsort(o->bs[i], o->nr_bs[i], sizeof(struct bs), bs_cmp);
775 }
776
Jens Axboeb064a142014-09-16 17:40:03 +0200777 if (filename) {
Jens Axboed8943e12014-09-16 20:17:55 -0600778 p->files = malloc(sizeof(struct trace_file));
779 p->nr_files++;
780 p->files[0].name = filename;
Jens Axboeb064a142014-09-16 17:40:03 +0200781 }
782
Jens Axboe42a80e32014-09-16 17:06:52 +0200783 if (output_ascii)
784 __output_p_ascii(p, ios);
785 else
786 ret = __output_p_fio(p, ios);
787
788 return ret;
789}
790
Jens Axboe183f3922014-09-18 17:23:55 +0200791static void remove_ddir(struct btrace_out *o, int rw)
792{
793 o->ios[rw] = 0;
794}
795
Jens Axboe42a80e32014-09-16 17:06:52 +0200796static int prune_entry(struct btrace_out *o)
797{
Jens Axboe183f3922014-09-18 17:23:55 +0200798 unsigned long rate;
Jens Axboe42a80e32014-09-16 17:06:52 +0200799 uint64_t time;
Jens Axboe183f3922014-09-18 17:23:55 +0200800 int i;
Jens Axboe42a80e32014-09-16 17:06:52 +0200801
802 if (ddir_rw_sum(o->ios) < ios_threshold)
803 return 1;
804
Jens Axboe183f3922014-09-18 17:23:55 +0200805 time = o_longest_ttime(o) / 1000ULL;
Jens Axboe42a80e32014-09-16 17:06:52 +0200806 if (time < rt_threshold)
807 return 1;
808
Jens Axboe183f3922014-09-18 17:23:55 +0200809 rate = 0;
810 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
811 unsigned long this_rate;
812
813 this_rate = o_to_kb_rate(o, i);
814 if (this_rate < rate_threshold) {
815 remove_ddir(o, i);
816 this_rate = 0;
817 }
818 rate += this_rate;
819 }
820
821 if (rate < rate_threshold)
822 return 1;
823
Jens Axboe42a80e32014-09-16 17:06:52 +0200824 return 0;
825}
826
827static int entry_cmp(void *priv, struct flist_head *a, struct flist_head *b)
828{
829 struct btrace_pid *pa = flist_entry(a, struct btrace_pid, pid_list);
830 struct btrace_pid *pb = flist_entry(b, struct btrace_pid, pid_list);
831
832 return ddir_rw_sum(pb->o.ios) - ddir_rw_sum(pa->o.ios);
833}
834
Jens Axboe50331622014-09-16 18:28:42 +0200835static void free_p(struct btrace_pid *p)
836{
837 struct btrace_out *o = &p->o;
838 int i;
839
Jens Axboed8943e12014-09-16 20:17:55 -0600840 for (i = 0; i < p->nr_files; i++) {
841 if (p->files[i].name && p->files[i].name != filename)
842 free(p->files[i].name);
Jens Axboe50331622014-09-16 18:28:42 +0200843 }
844
845 for (i = 0; i < DDIR_RWDIR_CNT; i++)
846 free(o->bs[i]);
847
Jens Axboed8943e12014-09-16 20:17:55 -0600848 free(p->files);
Jens Axboe50331622014-09-16 18:28:42 +0200849 flist_del(&p->pid_list);
850 flist_del(&p->hash_list);
851 free(p);
852}
853
Jens Axboe1a9b2932014-12-10 22:01:36 +0100854static int entries_close(struct btrace_pid *pida, struct btrace_pid *pidb)
855{
856 float perca, percb, fdiff;
857 int i, idiff;
858
859 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
860 if ((pida->o.ios[i] && !pidb->o.ios[i]) ||
861 (pidb->o.ios[i] && !pida->o.ios[i]))
862 return 0;
863 if (pida->o.ios[i] && pidb->o.ios[i]) {
864 perca = ((float) pida->o.seq[i] * 100.0) / (float) pida->o.ios[i];
865 percb = ((float) pidb->o.seq[i] * 100.0) / (float) pidb->o.ios[i];
866 fdiff = perca - percb;
867 if (fabs(fdiff) > random_diff)
868 return 0;
869 }
870
871 idiff = pida->o.depth - pidb->o.depth;
872 if (abs(idiff) > depth_diff)
873 return 0;
874 }
875
876 return 1;
877}
878
879static void merge_bs(struct bs **bsap, unsigned int *nr_bsap,
880 struct bs *bsb, unsigned int nr_bsb)
881{
882 struct bs *bsa = *bsap;
883 unsigned int nr_bsa = *nr_bsap;
884 int a, b;
885
886 for (b = 0; b < nr_bsb; b++) {
887 int next, found = 0;
888
889 for (a = 0; a < nr_bsa; a++) {
890 if (bsb[b].bs != bsa[a].bs)
891 continue;
892
893 bsa[a].nr += bsb[b].nr;
894 bsa[a].merges += bsb[b].merges;
895 found = 1;
896 break;
897 }
898
899 if (found)
900 continue;
901
902 next = *nr_bsap;
903 bsa = realloc(bsa, (next + 1) * sizeof(struct bs));
904 bsa[next].bs = bsb[b].bs;
905 bsa[next].nr = bsb[b].nr;
906 (*nr_bsap)++;
907 *bsap = bsa;
908 }
909}
910
911static int merge_entries(struct btrace_pid *pida, struct btrace_pid *pidb)
912{
913 int i;
914
915 if (!entries_close(pida, pidb))
916 return 0;
917
918 pida->nr_merge_pids++;
919 pida->merge_pids = realloc(pida->merge_pids, pida->nr_merge_pids * sizeof(pid_t));
920 pida->merge_pids[pida->nr_merge_pids - 1] = pidb->pid;
921
922 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
923 struct btrace_out *oa = &pida->o;
924 struct btrace_out *ob = &pidb->o;
925
926 oa->ios[i] += ob->ios[i];
927 oa->merges[i] += ob->merges[i];
928 oa->seq[i] += ob->seq[i];
929 oa->kb[i] += ob->kb[i];
930 oa->first_ttime[i] = min(oa->first_ttime[i], ob->first_ttime[i]);
931 oa->last_ttime[i] = max(oa->last_ttime[i], ob->last_ttime[i]);
932 merge_bs(&oa->bs[i], &oa->nr_bs[i], ob->bs[i], ob->nr_bs[i]);
933 }
934
935 pida->o.start_delay = min(pida->o.start_delay, pidb->o.start_delay);
936 pida->o.depth = (pida->o.depth + pidb->o.depth) / 2;
937 return 1;
938}
939
940static void check_merges(struct btrace_pid *p, struct flist_head *pid_list)
941{
942 struct flist_head *e, *tmp;
943
944 if (p->ignore)
945 return;
946
947 flist_for_each_safe(e, tmp, pid_list) {
948 struct btrace_pid *pidb;
949
950 pidb = flist_entry(e, struct btrace_pid, pid_list);
951 if (pidb == p)
952 continue;
953
954 if (merge_entries(p, pidb)) {
955 pidb->ignore = 1;
956 p->numjobs++;
957 }
958 }
959}
960
Jens Axboe42a80e32014-09-16 17:06:52 +0200961static int output_p(void)
962{
963 unsigned long ios[DDIR_RWDIR_CNT];
964 struct flist_head *e, *tmp;
Jens Axboea5d7a722014-11-10 08:52:23 -0700965 int depth_disabled = 0;
Jens Axboe42a80e32014-09-16 17:06:52 +0200966 int ret = 0;
967
968 flist_for_each_safe(e, tmp, &pid_list) {
969 struct btrace_pid *p;
970
971 p = flist_entry(e, struct btrace_pid, pid_list);
972 if (prune_entry(&p->o)) {
Jens Axboe50331622014-09-16 18:28:42 +0200973 free_p(p);
Jens Axboe42a80e32014-09-16 17:06:52 +0200974 continue;
975 }
Jens Axboe183f3922014-09-18 17:23:55 +0200976 p->o.start_delay = (o_first_ttime(&p->o) / 1000ULL) - first_ttime;
Jens Axboea5d7a722014-11-10 08:52:23 -0700977 depth_disabled += p->o.depth_disabled;
Jens Axboe42a80e32014-09-16 17:06:52 +0200978 }
979
Jens Axboe1a9b2932014-12-10 22:01:36 +0100980 if (collapse_entries) {
981 struct btrace_pid *p;
982
983 flist_for_each_safe(e, tmp, &pid_list) {
984 p = flist_entry(e, struct btrace_pid, pid_list);
985 check_merges(p, &pid_list);
986 }
987
988 flist_for_each_safe(e, tmp, &pid_list) {
989 p = flist_entry(e, struct btrace_pid, pid_list);
990 if (p->ignore)
991 free_p(p);
992 }
993 }
994
Jens Axboea5d7a722014-11-10 08:52:23 -0700995 if (depth_disabled)
996 log_err("fio: missing completion traces, depths capped at %u\n", max_depth);
997
Jens Axboe42a80e32014-09-16 17:06:52 +0200998 memset(ios, 0, sizeof(ios));
999
1000 flist_sort(NULL, &pid_list, entry_cmp);
1001
1002 flist_for_each(e, &pid_list) {
1003 struct btrace_pid *p;
1004
1005 p = flist_entry(e, struct btrace_pid, pid_list);
1006 ret |= __output_p(p, ios);
Jens Axboe183f3922014-09-18 17:23:55 +02001007 if (ret && !output_ascii)
1008 break;
Jens Axboe42a80e32014-09-16 17:06:52 +02001009 }
1010
1011 if (output_ascii)
1012 printf("Total: reads=%lu, writes=%lu\n", ios[0], ios[1]);
1013
1014 return ret;
1015}
1016
1017static int usage(char *argv[])
1018{
Jens Axboe1a9b2932014-12-10 22:01:36 +01001019 log_err("%s: [options] <blktrace bin file>\n", argv[0]);
Jens Axboe50331622014-09-16 18:28:42 +02001020 log_err("\t-t\tUsec threshold to ignore task\n");
1021 log_err("\t-n\tNumber IOS threshold to ignore task\n");
1022 log_err("\t-f\tFio job file output\n");
1023 log_err("\t-d\tUse this file/device for replay\n");
Jens Axboe183f3922014-09-18 17:23:55 +02001024 log_err("\t-r\tIgnore jobs with less than this KB/sec rate\n");
Jens Axboe1a9b2932014-12-10 22:01:36 +01001025 log_err("\t-R\tSet rate in fio job (def=%u)\n", set_rate);
Jens Axboea5d7a722014-11-10 08:52:23 -07001026 log_err("\t-D\tCap queue depth at this value (def=%u)\n", max_depth);
Jens Axboe1a9b2932014-12-10 22:01:36 +01001027 log_err("\t-c\tCollapse \"identical\" jobs (def=%u)\n", collapse_entries);
1028 log_err("\t-u\tDepth difference for collapse (def=%u)\n", depth_diff);
1029 log_err("\t-x\tRandom difference for collapse (def=%u)\n", random_diff);
Jens Axboe32e9adb2014-12-18 10:18:30 -07001030 log_err("\t-a\tAdditional fio option to add to job file\n");
Jens Axboe42a80e32014-09-16 17:06:52 +02001031 return 1;
1032}
1033
Jens Axboe50331622014-09-16 18:28:42 +02001034static int trace_needs_swap(const char *trace_file, int *swap)
1035{
1036 struct blk_io_trace t;
1037 int fd, ret;
1038
1039 *swap = -1;
1040
1041 fd = open(trace_file, O_RDONLY);
1042 if (fd < 0) {
1043 perror("open");
1044 return 1;
1045 }
1046
1047 ret = read(fd, &t, sizeof(t));
1048 if (ret < 0) {
Jens Axboe31da12c2014-10-14 19:55:18 -06001049 close(fd);
Jens Axboe50331622014-09-16 18:28:42 +02001050 perror("read");
1051 return 1;
1052 } else if (ret != sizeof(t)) {
Jens Axboe31da12c2014-10-14 19:55:18 -06001053 close(fd);
Jens Axboe50331622014-09-16 18:28:42 +02001054 log_err("fio: short read on trace file\n");
1055 return 1;
1056 }
1057
1058 close(fd);
1059
1060 if ((t.magic & 0xffffff00) == BLK_IO_TRACE_MAGIC)
1061 *swap = 0;
1062 else {
1063 /*
1064 * Maybe it needs to be endian swapped...
1065 */
1066 t.magic = fio_swap32(t.magic);
1067 if ((t.magic & 0xffffff00) == BLK_IO_TRACE_MAGIC)
1068 *swap = 1;
1069 }
1070
1071 if (*swap == -1) {
1072 log_err("fio: blktrace appears corrupt\n");
1073 return 1;
1074 }
1075
1076 return 0;
1077}
1078
Jens Axboe42a80e32014-09-16 17:06:52 +02001079int main(int argc, char *argv[])
1080{
Jens Axboe50331622014-09-16 18:28:42 +02001081 int need_swap, i, c;
Jens Axboe42a80e32014-09-16 17:06:52 +02001082
1083 if (argc < 2)
1084 return usage(argv);
1085
Jens Axboe32e9adb2014-12-18 10:18:30 -07001086 while ((c = getopt(argc, argv, "t:n:fd:r:RD:c:u:x:a:")) != -1) {
Jens Axboe42a80e32014-09-16 17:06:52 +02001087 switch (c) {
Jens Axboe183f3922014-09-18 17:23:55 +02001088 case 'R':
1089 set_rate = 1;
1090 break;
1091 case 'r':
1092 rate_threshold = atoi(optarg);
1093 break;
Jens Axboe42a80e32014-09-16 17:06:52 +02001094 case 't':
1095 rt_threshold = atoi(optarg);
1096 break;
1097 case 'n':
1098 ios_threshold = atoi(optarg);
1099 break;
1100 case 'f':
1101 output_ascii = 0;
1102 break;
Jens Axboeb064a142014-09-16 17:40:03 +02001103 case 'd':
1104 filename = strdup(optarg);
1105 break;
Jens Axboea5d7a722014-11-10 08:52:23 -07001106 case 'D':
1107 max_depth = atoi(optarg);
1108 break;
Jens Axboe1a9b2932014-12-10 22:01:36 +01001109 case 'c':
1110 collapse_entries = atoi(optarg);
1111 break;
1112 case 'u':
1113 depth_diff = atoi(optarg);
1114 break;
1115 case 'x':
1116 random_diff = atoi(optarg);
1117 break;
Jens Axboe32e9adb2014-12-18 10:18:30 -07001118 case 'a':
1119 add_opts = realloc(add_opts, (n_add_opts + 1) * sizeof(char *));
1120 add_opts[n_add_opts] = strdup(optarg);
1121 n_add_opts++;
1122 break;
Jens Axboe42a80e32014-09-16 17:06:52 +02001123 case '?':
1124 default:
1125 return usage(argv);
1126 }
1127 }
1128
1129 if (argc == optind)
1130 return usage(argv);
1131
Jens Axboe50331622014-09-16 18:28:42 +02001132 if (trace_needs_swap(argv[optind], &need_swap))
Jens Axboe42a80e32014-09-16 17:06:52 +02001133 return 1;
Jens Axboe42a80e32014-09-16 17:06:52 +02001134
1135 for (i = 0; i < PID_HASH_SIZE; i++)
1136 INIT_FLIST_HEAD(&pid_hash[i]);
Jens Axboe50331622014-09-16 18:28:42 +02001137 for (i = 0; i < INFLIGHT_HASH_SIZE; i++)
1138 INIT_FLIST_HEAD(&inflight_hash[i]);
Jens Axboe42a80e32014-09-16 17:06:52 +02001139
1140 load_blktrace(argv[optind], need_swap);
1141 first_ttime /= 1000ULL;
1142
1143 return output_p();
1144}