2 * block queue tracing parse application
4 * Copyright (C) 2005 Jens Axboe <axboe@suse.de>
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
21 #include <sys/types.h>
36 #define SECONDS(x) ((unsigned long long)(x) / 1000000000)
37 #define NANO_SECONDS(x) ((unsigned long long)(x) % 1000000000)
40 static unsigned long long genesis_time, last_reported_time;
43 unsigned long qreads, qwrites, creads, cwrites, mreads, mwrites;
44 unsigned long ireads, iwrites;
45 unsigned long long qread_kb, qwrite_kb, cread_kb, cwrite_kb;
46 unsigned long long iread_kb, iwrite_kb;
56 struct io_stats io_stats;
59 struct per_process_info {
62 struct io_stats io_stats;
63 struct per_process_info *hash_next, *list_next;
68 unsigned long long longest_allocation_wait[2];
69 unsigned long long longest_dispatch_wait[2];
70 unsigned long long longest_completion_wait[2];
73 #define PPI_HASH_SHIFT (8)
74 static struct per_process_info *ppi_hash[1 << PPI_HASH_SHIFT];
75 static struct per_process_info *ppi_list;
77 #define S_OPTS "i:o:b:st"
78 static struct option l_opts[] = {
98 .name = "per program stats",
117 static struct rb_root rb_sort_root;
118 static struct rb_root rb_track_root;
121 * for sorting the displayed output
124 struct blk_io_trace *bit;
125 struct rb_node rb_node;
129 * for tracking individual ios
132 struct rb_node rb_node;
136 unsigned long long allocation_time;
137 unsigned long long queue_time;
138 unsigned long long dispatch_time;
139 unsigned long long completion_time;
143 static struct per_cpu_info *per_cpu_info;
145 static unsigned long long events;
147 static char *dev, *output_name;
150 static int per_process_stats;
151 static int track_ios;
153 #define RB_BATCH_DEFAULT (1024)
154 static int rb_batch = RB_BATCH_DEFAULT;
156 #define is_done() (*(volatile int *)(&done))
157 static volatile int done;
159 static inline unsigned long hash_long(unsigned long val)
163 #elif __WORDSIZE == 64
164 val *= 0x9e37fffffffc0001UL;
166 #error unknown word size
169 return val >> (__WORDSIZE - PPI_HASH_SHIFT);
172 static inline void add_process_to_hash(struct per_process_info *ppi)
174 const int hash_idx = hash_long(ppi->pid);
176 ppi->hash_next = ppi_hash[hash_idx];
177 ppi_hash[hash_idx] = ppi;
180 static inline void add_process_to_list(struct per_process_info *ppi)
182 ppi->list_next = ppi_list;
186 static struct per_process_info *find_process_by_pid(__u32 pid)
188 const int hash_idx = hash_long(pid);
189 struct per_process_info *ppi;
191 ppi = ppi_hash[hash_idx];
196 ppi = ppi->hash_next;
202 static inline int trace_rb_insert(struct trace *t)
204 struct rb_node **p = &rb_sort_root.rb_node;
205 struct rb_node *parent = NULL;
210 __t = rb_entry(parent, struct trace, rb_node);
212 if (t->bit->sequence < __t->bit->sequence)
214 else if (t->bit->sequence > __t->bit->sequence)
217 fprintf(stderr, "sequence alias!\n");
222 rb_link_node(&t->rb_node, parent, p);
223 rb_insert_color(&t->rb_node, &rb_sort_root);
227 static inline int track_rb_insert(struct io_track *iot)
229 struct rb_node **p = &rb_track_root.rb_node;
230 struct rb_node *parent = NULL;
231 struct io_track *__iot;
236 __iot = rb_entry(parent, struct io_track, rb_node);
238 if (iot->sector < __iot->sector)
240 else if (iot->sector > __iot->sector)
243 fprintf(stderr, "sequence alias!\n");
248 rb_link_node(&iot->rb_node, parent, p);
249 rb_insert_color(&iot->rb_node, &rb_track_root);
253 static struct io_track *__find_track(__u64 sector)
255 struct rb_node **p = &rb_track_root.rb_node;
256 struct rb_node *parent = NULL;
257 struct io_track *__iot;
262 __iot = rb_entry(parent, struct io_track, rb_node);
264 if (sector < __iot->sector)
266 else if (sector > __iot->sector)
275 static struct io_track *find_track(__u32 pid, __u64 sector)
277 struct io_track *iot = __find_track(sector);
279 iot = __find_track(sector);
281 iot = malloc(sizeof(*iot));
283 iot->sector = sector;
284 track_rb_insert(iot);
290 static void log_track_merge(struct blk_io_trace *t)
292 struct io_track *iot;
296 if ((t->action & BLK_TC_ACT(BLK_TC_FS)) == 0)
299 iot = __find_track(t->sector - (t->bytes >> 10));
301 fprintf(stderr, "Trying to merge on non-existing request\n");
305 rb_erase(&iot->rb_node, &rb_track_root);
306 iot->sector -= t->bytes >> 10;
307 track_rb_insert(iot);
310 static void log_track_getrq(struct blk_io_trace *t)
312 struct io_track *iot;
317 iot = find_track(t->pid, t->sector);
318 iot->allocation_time = t->time;
323 * return time between rq allocation and queue
325 static unsigned long long log_track_queue(struct blk_io_trace *t)
327 unsigned long long elapsed;
328 struct io_track *iot;
333 iot = find_track(t->pid, t->sector);
334 iot->queue_time = t->time;
335 elapsed = iot->queue_time - iot->allocation_time;
337 if (per_process_stats) {
338 struct per_process_info *ppi = find_process_by_pid(iot->pid);
339 int w = (t->action & BLK_TC_ACT(BLK_TC_WRITE)) != 0;
341 if (ppi && elapsed > ppi->longest_allocation_wait[w])
342 ppi->longest_allocation_wait[w] = elapsed;
349 * return time between queue and issue
351 static unsigned long long log_track_issue(struct blk_io_trace *t)
353 unsigned long long elapsed;
354 struct io_track *iot;
358 if ((t->action & BLK_TC_ACT(BLK_TC_FS)) == 0)
361 iot = __find_track(t->sector);
363 fprintf(stderr, "Trying to issue on non-existing request\n");
367 iot->dispatch_time = t->time;
368 elapsed = iot->dispatch_time - iot->queue_time;
370 if (per_process_stats) {
371 struct per_process_info *ppi = find_process_by_pid(iot->pid);
372 int w = (t->action & BLK_TC_ACT(BLK_TC_WRITE)) != 0;
374 if (ppi && elapsed > ppi->longest_dispatch_wait[w])
375 ppi->longest_dispatch_wait[w] = elapsed;
382 * return time between dispatch and complete
384 static unsigned long long log_track_complete(struct blk_io_trace *t)
386 unsigned long long elapsed;
387 struct io_track *iot;
391 if ((t->action & BLK_TC_ACT(BLK_TC_FS)) == 0)
394 iot = __find_track(t->sector);
396 fprintf(stderr, "Trying to dispatch on non-existing request\n");
400 iot->completion_time = t->time;
401 elapsed = iot->completion_time - iot->dispatch_time;
403 if (per_process_stats) {
404 struct per_process_info *ppi = find_process_by_pid(iot->pid);
405 int w = (t->action & BLK_TC_ACT(BLK_TC_WRITE)) != 0;
407 if (ppi && elapsed > ppi->longest_completion_wait[w])
408 ppi->longest_completion_wait[w] = elapsed;
412 * kill the trace, we don't need it after completion
414 rb_erase(&iot->rb_node, &rb_track_root);
421 static struct io_stats *find_process_io_stats(__u32 pid, char *name)
423 struct per_process_info *ppi = find_process_by_pid(pid);
426 ppi = malloc(sizeof(*ppi));
427 memset(ppi, 0, sizeof(*ppi));
428 strncpy(ppi->name, name, sizeof(ppi->name));
430 add_process_to_hash(ppi);
431 add_process_to_list(ppi);
434 return &ppi->io_stats;
437 static void resize_cpu_info(int cpuid)
439 int new_space, new_max = cpuid + 1;
442 per_cpu_info = realloc(per_cpu_info, new_max * sizeof(*per_cpu_info));
444 fprintf(stderr, "Cannot allocate CPU info -- %d x %d bytes\n",
445 new_max, (int) sizeof(*per_cpu_info));
449 new_start = (char *)per_cpu_info + (max_cpus * sizeof(*per_cpu_info));
450 new_space = (new_max - max_cpus) * sizeof(*per_cpu_info);
451 memset(new_start, 0, new_space);
455 static struct per_cpu_info *get_cpu_info(int cpu)
457 struct per_cpu_info *pci;
460 resize_cpu_info(cpu);
463 * ->cpu might already be set, but just set it unconditionally
465 pci = &per_cpu_info[cpu];
471 static inline void check_time(struct blk_io_trace *bit)
473 unsigned long long this = bit->time;
474 unsigned long long last = last_reported_time;
476 backwards = (this < last) ? 'B' : ' ';
477 last_reported_time = this;
480 static inline void __account_m(struct io_stats *ios, struct blk_io_trace *t,
485 ios->qwrite_kb += t->bytes >> 10;
488 ios->qread_kb += t->bytes >> 10;
492 static inline void account_m(struct blk_io_trace *t, struct per_cpu_info *pci,
495 __account_m(&pci->io_stats, t, rw);
497 if (per_process_stats) {
498 struct io_stats *ios = find_process_io_stats(t->pid, t->comm);
500 __account_m(ios, t, rw);
504 static inline void __account_q(struct io_stats *ios, struct blk_io_trace *t,
509 ios->qwrite_kb += t->bytes >> 10;
512 ios->qread_kb += t->bytes >> 10;
516 static inline void account_q(struct blk_io_trace *t, struct per_cpu_info *pci,
519 __account_q(&pci->io_stats, t, rw);
521 if (per_process_stats) {
522 struct io_stats *ios = find_process_io_stats(t->pid, t->comm);
524 __account_q(ios, t, rw);
528 static inline void __account_c(struct io_stats *ios, int rw, unsigned int bytes)
532 ios->cwrite_kb += bytes >> 10;
535 ios->cread_kb += bytes >> 10;
539 static inline void account_c(struct blk_io_trace *t, struct per_cpu_info *pci,
542 __account_c(&pci->io_stats, rw, bytes);
544 if (per_process_stats) {
545 struct io_stats *ios = find_process_io_stats(t->pid, t->comm);
547 __account_c(ios, rw, bytes);
551 static inline void __account_i(struct io_stats *ios, int rw, unsigned int bytes)
555 ios->iwrite_kb += bytes >> 10;
558 ios->iread_kb += bytes >> 10;
562 static inline void account_i(struct blk_io_trace *t, struct per_cpu_info *pci,
565 __account_i(&pci->io_stats, rw, t->bytes);
567 if (per_process_stats) {
568 struct io_stats *ios = find_process_io_stats(t->pid, t->comm);
570 __account_i(ios, rw, t->bytes);
574 static void output(struct per_cpu_info *pci, char *s)
576 fprintf(ofp, "%s", s);
579 static char hstring[256];
580 static char tstring[256];
582 static inline char *setup_header(struct per_cpu_info *pci,
583 struct blk_io_trace *t, char act)
585 int w = t->action & BLK_TC_ACT(BLK_TC_WRITE);
586 int b = t->action & BLK_TC_ACT(BLK_TC_BARRIER);
587 int s = t->action & BLK_TC_ACT(BLK_TC_SYNC);
602 sprintf(hstring, "%2d %8ld %5Lu.%09Lu %5u %c %3s",
604 (unsigned long)t->sequence, SECONDS(t->time),
605 NANO_SECONDS(t->time), t->pid, act, rwbs);
610 static void log_complete(struct per_cpu_info *pci, struct blk_io_trace *t,
613 unsigned long long elapsed = log_track_complete(t);
615 if (elapsed != -1ULL) {
616 unsigned long usec = elapsed / 1000;
618 sprintf(tstring,"%s %Lu + %u (%8lu) [%d]\n",
619 setup_header(pci, t, act),
620 (unsigned long long)t->sector, t->bytes >> 9,
623 sprintf(tstring,"%s %Lu + %u [%d]\n", setup_header(pci, t, act),
624 (unsigned long long)t->sector, t->bytes >> 9, t->error);
627 output(pci, tstring);
630 static void log_queue(struct per_cpu_info *pci, struct blk_io_trace *t,
633 unsigned long long elapsed = log_track_queue(t);
635 if (elapsed != -1ULL) {
636 unsigned long usec = elapsed / 1000;
638 sprintf(tstring,"%s %Lu + %u (%8lu) [%s]\n",
639 setup_header(pci, t, act),
640 (unsigned long long)t->sector, t->bytes >> 9,
643 sprintf(tstring,"%s %Lu + %u [%s]\n", setup_header(pci, t, act),
644 (unsigned long long)t->sector, t->bytes >> 9, t->comm);
646 output(pci, tstring);
649 static void log_issue(struct per_cpu_info *pci, struct blk_io_trace *t,
652 unsigned long long elapsed = log_track_issue(t);
654 if (elapsed != -1ULL) {
655 double usec = (double) elapsed / 1000;
657 sprintf(tstring,"%s %Lu + %u (%8.2f) [%s]\n",
658 setup_header(pci, t, act),
659 (unsigned long long)t->sector, t->bytes >> 9,
662 sprintf(tstring,"%s %Lu + %u [%s]\n", setup_header(pci, t, act),
663 (unsigned long long)t->sector, t->bytes >> 9, t->comm);
666 output(pci, tstring);
669 static void log_merge(struct per_cpu_info *pci, struct blk_io_trace *t,
674 sprintf(tstring,"%s %Lu + %u [%s]\n", setup_header(pci, t, act),
675 (unsigned long long)t->sector, t->bytes >> 9, t->comm);
676 output(pci, tstring);
679 static void log_generic(struct per_cpu_info *pci, struct blk_io_trace *t,
682 sprintf(tstring,"%s %Lu + %u [%s]\n", setup_header(pci, t, act),
683 (unsigned long long)t->sector, t->bytes >> 9, t->comm);
684 output(pci, tstring);
687 static int log_pc(struct per_cpu_info *pci, struct blk_io_trace *t, char act)
692 sprintf(tstring,"%s ", setup_header(pci, t, act));
693 output(pci, tstring);
695 buf = (unsigned char *) t + sizeof(*t);
696 for (i = 0; i < t->pdu_len; i++) {
697 sprintf(tstring,"%02x ", buf[i]);
698 output(pci, tstring);
702 sprintf(tstring,"[%d]\n", t->error);
703 output(pci, tstring);
705 sprintf(tstring,"[%s]\n", t->comm);
706 output(pci, tstring);
711 static int dump_trace_pc(struct blk_io_trace *t, struct per_cpu_info *pci)
715 switch (t->action & 0xffff) {
717 log_generic(pci, t, 'Q');
720 log_generic(pci, t, 'G');
722 case __BLK_TA_SLEEPRQ:
723 log_generic(pci, t, 'S');
725 case __BLK_TA_REQUEUE:
726 log_generic(pci, t, 'R');
729 ret = log_pc(pci, t, 'D');
731 case __BLK_TA_COMPLETE:
735 fprintf(stderr, "Bad pc action %x\n", t->action);
743 static void dump_trace_fs(struct blk_io_trace *t, struct per_cpu_info *pci)
745 int w = t->action & BLK_TC_ACT(BLK_TC_WRITE);
746 int act = t->action & 0xffff;
750 account_q(t, pci, w);
751 log_queue(pci, t, 'Q');
753 case __BLK_TA_BACKMERGE:
754 account_m(t, pci, w);
755 log_merge(pci, t, 'M');
757 case __BLK_TA_FRONTMERGE:
758 account_m(t, pci, w);
759 log_merge(pci, t, 'F');
763 log_generic(pci, t, 'G');
765 case __BLK_TA_SLEEPRQ:
766 log_generic(pci, t, 'S');
768 case __BLK_TA_REQUEUE:
769 account_c(t, pci, w, -t->bytes);
770 log_queue(pci, t, 'R');
773 account_i(t, pci, w);
774 log_issue(pci, t, 'D');
776 case __BLK_TA_COMPLETE:
777 account_c(t, pci, w, t->bytes);
778 log_complete(pci, t, 'C');
781 fprintf(stderr, "Bad fs action %x\n", t->action);
786 static int dump_trace(struct blk_io_trace *t, struct per_cpu_info *pci)
790 if (t->action & BLK_TC_ACT(BLK_TC_PC))
791 ret = dump_trace_pc(t, pci);
793 dump_trace_fs(t, pci);
799 static void dump_io_stats(struct io_stats *ios, char *msg)
801 fprintf(ofp, "%s\n", msg);
803 fprintf(ofp, " Reads Queued: %'8lu, %'8LuKiB\t", ios->qreads, ios->qread_kb);
804 fprintf(ofp, " Writes Queued: %'8lu, %'8LuKiB\n", ios->qwrites,ios->qwrite_kb);
806 fprintf(ofp, " Read Dispatches: %'8lu, %'8LuKiB\t", ios->ireads, ios->iread_kb);
807 fprintf(ofp, " Write Dispatches: %'8lu, %'8LuKiB\n", ios->iwrites,ios->iwrite_kb);
808 fprintf(ofp, " Reads Completed: %'8lu, %'8LuKiB\t", ios->creads, ios->cread_kb);
809 fprintf(ofp, " Writes Completed: %'8lu, %'8LuKiB\n", ios->cwrites,ios->cwrite_kb);
810 fprintf(ofp, " Read Merges: %'8lu%8c\t", ios->mreads, ' ');
812 fprintf(ofp, " Write Merges: %'8lu\n", ios->mwrites);
815 static void dump_wait_stats(struct per_process_info *ppi)
817 unsigned long rawait = ppi->longest_allocation_wait[0] / 1000;
818 unsigned long rdwait = ppi->longest_dispatch_wait[0] / 1000;
819 unsigned long rcwait = ppi->longest_completion_wait[0] / 1000;
820 unsigned long wawait = ppi->longest_allocation_wait[1] / 1000;
821 unsigned long wdwait = ppi->longest_dispatch_wait[1] / 1000;
822 unsigned long wcwait = ppi->longest_completion_wait[1] / 1000;
824 fprintf(ofp, " Allocation wait: %'8lu%8c\t", rawait, ' ');
825 fprintf(ofp, " Allocation wait: %'8lu\n", wawait);
826 fprintf(ofp, " Dispatch wait: %'8lu%8c\t", rdwait, ' ');
827 fprintf(ofp, " Dispatch wait: %'8lu\n", wdwait);
828 fprintf(ofp, " Completion wait: %'8lu%8c\t", rcwait, ' ');
829 fprintf(ofp, " Completion wait: %'8lu\n", wcwait);
832 static void show_process_stats(void)
834 struct per_process_info *ppi;
838 dump_io_stats(&ppi->io_stats, ppi->name);
839 dump_wait_stats(ppi);
840 ppi = ppi->list_next;
846 static void show_cpu_stats(void)
848 struct per_cpu_info foo, *pci;
849 struct io_stats *ios;
850 int i, pci_events = 0;
852 memset(&foo, 0, sizeof(foo));
854 for (i = 0; i < max_cpus; i++) {
857 pci = &per_cpu_info[i];
858 ios = &pci->io_stats;
863 foo.io_stats.qreads += ios->qreads;
864 foo.io_stats.qwrites += ios->qwrites;
865 foo.io_stats.creads += ios->creads;
866 foo.io_stats.cwrites += ios->cwrites;
867 foo.io_stats.mreads += ios->mreads;
868 foo.io_stats.mwrites += ios->mwrites;
869 foo.io_stats.ireads += ios->ireads;
870 foo.io_stats.iwrites += ios->iwrites;
871 foo.io_stats.qread_kb += ios->qread_kb;
872 foo.io_stats.qwrite_kb += ios->qwrite_kb;
873 foo.io_stats.cread_kb += ios->cread_kb;
874 foo.io_stats.cwrite_kb += ios->cwrite_kb;
875 foo.io_stats.iread_kb += ios->iread_kb;
876 foo.io_stats.iwrite_kb += ios->iwrite_kb;
878 snprintf(cpu, sizeof(cpu) - 1, "CPU%d:", i);
879 dump_io_stats(ios, cpu);
883 if (pci_events > 1) {
885 dump_io_stats(&foo.io_stats, "Total:");
888 fprintf(ofp, "\nEvents: %'Lu\n", events);
891 #define min(a, b) ((a) < (b) ? (a) : (b))
893 static struct blk_io_trace *find_trace(void *p, unsigned long offset, int nr)
895 unsigned long max_offset = min(offset,nr * sizeof(struct blk_io_trace));
897 struct blk_io_trace *bit;
900 for (off = 0; off < max_offset; off++) {
903 magic = be32_to_cpu(bit->magic);
904 if ((magic & 0xffffff00) == BLK_IO_TRACE_MAGIC)
911 static int sort_entries(void *traces, unsigned long offset, int nr)
913 struct per_cpu_info *pci;
914 struct blk_io_trace *bit;
916 void *start = traces;
919 while (traces - start <= offset - sizeof(*bit)) {
923 bit = find_trace(traces, offset - (traces - start), nr);
927 t = malloc(sizeof(*t));
929 memset(&t->rb_node, 0, sizeof(t->rb_node));
933 if (verify_trace(bit))
936 pci = get_cpu_info(bit->cpu);
939 if (trace_rb_insert(t))
942 traces += sizeof(*bit) + bit->pdu_len;
950 static void free_entries_rb(void)
954 while ((n = rb_first(&rb_sort_root)) != NULL) {
955 struct trace *t = rb_entry(n, struct trace, rb_node);
957 rb_erase(&t->rb_node, &rb_sort_root);
962 static void show_entries_rb(void)
964 struct blk_io_trace *bit;
969 n = rb_first(&rb_sort_root);
974 t = rb_entry(n, struct trace, rb_node);
978 if (cpu > max_cpus) {
979 fprintf(stderr, "CPU number too large (%d)\n", cpu);
983 if (genesis_time == 0)
984 genesis_time = bit->time;
985 bit->time -= genesis_time;
989 if (dump_trace(bit, &per_cpu_info[cpu]))
992 } while ((n = rb_next(n)) != NULL);
995 static int read_data(int fd, void *buffer, int bytes, int block)
997 int ret, bytes_left, fl;
1000 fl = fcntl(fd, F_GETFL);
1003 fcntl(fd, F_SETFL, fl | O_NONBLOCK);
1005 fcntl(fd, F_SETFL, fl & ~O_NONBLOCK);
1009 while (bytes_left > 0) {
1010 ret = read(fd, p, bytes_left);
1014 if (errno != EAGAIN)
1026 static int do_file(void)
1030 for (i = 0, nfiles = 0;; i++, nfiles++) {
1031 struct per_cpu_info *pci;
1035 pci = get_cpu_info(i);
1037 snprintf(pci->fname, sizeof(pci->fname)-1,"%s_out.%d", dev, i);
1038 if (stat(pci->fname, &st) < 0)
1043 printf("Processing %s\n", pci->fname);
1045 tb = malloc(st.st_size);
1047 pci->fd = open(pci->fname, O_RDONLY);
1053 if (read_data(pci->fd, tb, st.st_size, 1))
1056 if (sort_entries(tb, st.st_size, ~0U) == -1)
1060 printf("\t%2d %10s %15d\n", i, pci->fname, pci->nelems);
1065 fprintf(stderr, "No files found\n");
1073 static void resize_buffer(void **buffer, long *size, long offset)
1075 long old_size = *size;
1078 *buffer = realloc(*buffer, *size);
1079 memset(*buffer + offset, 0, *size - old_size);
1082 static int read_sort_events(int fd, void **buffer, long *max_offset)
1087 if (*max_offset == 0) {
1088 *max_offset = 128 * sizeof(struct blk_io_trace);
1089 *buffer = malloc(*max_offset);
1096 struct blk_io_trace *t;
1099 if (*max_offset - offset < sizeof(*t))
1100 resize_buffer(buffer, max_offset, offset);
1102 if (read_data(fd, *buffer + offset, sizeof(*t), !events)) {
1110 t = *buffer + offset;
1111 offset += sizeof(*t);
1113 pdu_len = be16_to_cpu(t->pdu_len);
1115 if (*max_offset - offset < pdu_len)
1116 resize_buffer(buffer, max_offset, offset);
1118 if (read_data(fd, *buffer + offset, pdu_len, 1))
1125 } while (!is_done() && events < rb_batch);
1130 static int do_stdin(void)
1136 fd = dup(STDIN_FILENO);
1141 events = read_sort_events(fd, &ptr, &max_offset);
1145 if (sort_entries(ptr, ~0UL, events) == -1)
1157 static void flush_output(void)
1162 static void handle_sigint(int sig)
1168 static void usage(char *prog)
1170 fprintf(stderr, "Usage: %s -i <name> [-o <output>][-s]\n", prog);
1173 int main(int argc, char *argv[])
1178 while ((c = getopt_long(argc, argv, S_OPTS, l_opts, NULL)) != -1) {
1184 output_name = optarg;
1187 rb_batch = atoi(optarg);
1189 rb_batch = RB_BATCH_DEFAULT;
1192 per_process_stats = 1;
1208 memset(&rb_sort_root, 0, sizeof(rb_sort_root));
1209 memset(&rb_track_root, 0, sizeof(rb_track_root));
1211 signal(SIGINT, handle_sigint);
1212 signal(SIGHUP, handle_sigint);
1213 signal(SIGTERM, handle_sigint);
1215 setlocale(LC_NUMERIC, "en_US");
1218 ofp = fdopen(STDOUT_FILENO, "w");
1223 snprintf(ofname, sizeof(ofname) - 1, "%s.log", output_name);
1224 ofp = fopen(ofname, "w");
1233 ofp_buffer = malloc(4096);
1234 if (setvbuf(ofp, ofp_buffer, mode, 4096)) {
1239 if (!strcmp(dev, "-"))
1244 if (per_process_stats)
1245 show_process_stats();