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>
38 static char blkparse_version[] = "0.99";
41 unsigned long start, end;
42 struct skip_info *prev, *next;
50 unsigned long long events;
51 unsigned long long first_reported_time;
52 unsigned long long last_reported_time;
53 unsigned long long last_read_time;
54 struct io_stats io_stats;
55 unsigned long skips, nskips;
56 unsigned long long seq_skips, seq_nskips;
57 unsigned int max_depth[2];
58 unsigned int cur_depth[2];
60 struct rb_root rb_track;
65 unsigned long *cpu_map;
66 unsigned int cpu_map_max;
68 struct per_cpu_info *cpus;
71 struct per_process_info {
74 struct io_stats io_stats;
75 struct per_process_info *hash_next, *list_next;
81 unsigned long long longest_allocation_wait[2];
82 unsigned long long longest_dispatch_wait[2];
83 unsigned long long longest_completion_wait[2];
86 #define PPI_HASH_SHIFT (8)
87 #define PPI_HASH_SIZE (1 << PPI_HASH_SHIFT)
88 #define PPI_HASH_MASK (PPI_HASH_SIZE - 1)
89 static struct per_process_info *ppi_hash_table[PPI_HASH_SIZE];
90 static struct per_process_info *ppi_list;
91 static int ppi_list_entries;
93 #define S_OPTS "a:A:i:o:b:stqw:f:F:vVhD:"
94 static struct option l_opts[] = {
97 .has_arg = required_argument,
103 .has_arg = required_argument,
109 .has_arg = required_argument,
115 .has_arg = required_argument,
121 .has_arg = required_argument,
126 .name = "per-program-stats",
127 .has_arg = no_argument,
133 .has_arg = no_argument,
139 .has_arg = no_argument,
145 .has_arg = required_argument,
151 .has_arg = required_argument,
156 .name = "format-spec",
157 .has_arg = required_argument,
162 .name = "hash-by-name",
163 .has_arg = no_argument,
169 .has_arg = no_argument,
175 .has_arg = no_argument,
180 .name = "input-directory",
181 .has_arg = required_argument,
191 * for sorting the displayed output
194 struct blk_io_trace *bit;
195 struct rb_node rb_node;
197 unsigned long read_sequence;
200 static struct rb_root rb_sort_root;
201 static unsigned long rb_sort_entries;
203 static struct trace *trace_list;
208 static struct blk_io_trace *bit_alloc_list;
209 static struct trace *t_alloc_list;
212 * for tracking individual ios
215 struct rb_node rb_node;
220 unsigned long long allocation_time;
221 unsigned long long queue_time;
222 unsigned long long dispatch_time;
223 unsigned long long completion_time;
227 static struct per_dev_info *devices;
228 static char *get_dev_name(struct per_dev_info *, char *, int);
229 static int trace_rb_insert_last(struct per_dev_info *, struct trace *);
232 static char *output_name;
233 static char *input_dir;
235 static unsigned long long genesis_time;
236 static unsigned long long last_allowed_time;
237 static unsigned long long stopwatch_start; /* start from zero by default */
238 static unsigned long long stopwatch_end = -1ULL; /* "infinity" */
239 static unsigned long read_sequence;
241 static int per_process_stats;
242 static int per_device_and_cpu_stats = 1;
243 static int track_ios;
244 static int ppi_hash_by_pid = 1;
246 static unsigned int act_mask = -1U;
247 static int stats_printed;
248 int data_is_native = -1;
250 static unsigned int t_alloc_cache;
251 static unsigned int bit_alloc_cache;
253 #define RB_BATCH_DEFAULT (512)
254 static unsigned int rb_batch = RB_BATCH_DEFAULT;
258 #define is_done() (*(volatile int *)(&done))
259 static volatile int done;
261 #define JHASH_RANDOM (0x3af5f2ee)
263 #define CPUS_PER_LONG (8 * sizeof(unsigned long))
264 #define CPU_IDX(cpu) ((cpu) / CPUS_PER_LONG)
265 #define CPU_BIT(cpu) ((cpu) & (CPUS_PER_LONG - 1))
267 static void resize_cpu_info(struct per_dev_info *pdi, int cpu)
269 struct per_cpu_info *cpus = pdi->cpus;
270 int ncpus = pdi->ncpus;
271 int new_count = cpu + 1;
275 size = new_count * sizeof(struct per_cpu_info);
276 cpus = realloc(cpus, size);
279 fprintf(stderr, "Out of memory, CPU info for device %s (%d)\n",
280 get_dev_name(pdi, name, sizeof(name)), size);
284 new_start = (char *)cpus + (ncpus * sizeof(struct per_cpu_info));
285 new_space = (new_count - ncpus) * sizeof(struct per_cpu_info);
286 memset(new_start, 0, new_space);
288 pdi->ncpus = new_count;
291 for (new_count = 0; new_count < pdi->ncpus; new_count++) {
292 struct per_cpu_info *pci = &pdi->cpus[new_count];
296 memset(&pci->rb_last, 0, sizeof(pci->rb_last));
297 pci->rb_last_entries = 0;
298 pci->last_sequence = -1;
303 static struct per_cpu_info *get_cpu_info(struct per_dev_info *pdi, int cpu)
305 struct per_cpu_info *pci;
307 if (cpu >= pdi->ncpus)
308 resize_cpu_info(pdi, cpu);
310 pci = &pdi->cpus[cpu];
316 static int resize_devices(char *name)
318 int size = (ndevices + 1) * sizeof(struct per_dev_info);
320 devices = realloc(devices, size);
322 fprintf(stderr, "Out of memory, device %s (%d)\n", name, size);
325 memset(&devices[ndevices], 0, sizeof(struct per_dev_info));
326 devices[ndevices].name = name;
331 static struct per_dev_info *get_dev_info(dev_t dev)
333 struct per_dev_info *pdi;
336 for (i = 0; i < ndevices; i++) {
338 devices[i].dev = dev;
339 if (devices[i].dev == dev)
343 if (resize_devices(NULL))
346 pdi = &devices[ndevices - 1];
348 pdi->first_reported_time = 0;
349 pdi->last_read_time = 0;
354 static void insert_skip(struct per_cpu_info *pci, unsigned long start,
357 struct skip_info *sip;
359 for (sip = pci->skips_tail; sip != NULL; sip = sip->prev) {
360 if (end == (sip->start - 1)) {
363 } else if (start == (sip->end + 1)) {
369 sip = malloc(sizeof(struct skip_info));
372 sip->prev = sip->next = NULL;
373 if (pci->skips_tail == NULL)
374 pci->skips_head = pci->skips_tail = sip;
376 sip->prev = pci->skips_tail;
377 pci->skips_tail->next = sip;
378 pci->skips_tail = sip;
382 static void remove_sip(struct per_cpu_info *pci, struct skip_info *sip)
384 if (sip->prev == NULL) {
385 if (sip->next == NULL)
386 pci->skips_head = pci->skips_tail = NULL;
388 pci->skips_head = sip->next;
389 sip->next->prev = NULL;
391 } else if (sip->next == NULL) {
392 pci->skips_tail = sip->prev;
393 sip->prev->next = NULL;
395 sip->prev->next = sip->next;
396 sip->next->prev = sip->prev;
399 sip->prev = sip->next = NULL;
403 #define IN_SKIP(sip,seq) (((sip)->start <= (seq)) && ((seq) <= sip->end))
404 static int check_current_skips(struct per_cpu_info *pci, unsigned long seq)
406 struct skip_info *sip;
408 for (sip = pci->skips_tail; sip != NULL; sip = sip->prev) {
409 if (IN_SKIP(sip, seq)) {
410 if (sip->start == seq) {
412 remove_sip(pci, sip);
415 } else if (sip->end == seq)
419 insert_skip(pci, seq + 1, sip->end);
428 static void collect_pdi_skips(struct per_dev_info *pdi)
430 struct skip_info *sip;
436 for (cpu = 0; cpu < pdi->ncpus; cpu++) {
437 struct per_cpu_info *pci = &pdi->cpus[cpu];
439 for (sip = pci->skips_head; sip != NULL; sip = sip->next) {
441 pdi->seq_skips += (sip->end - sip->start + 1);
443 fprintf(stderr,"(%d,%d): skipping %lu -> %lu\n",
444 MAJOR(pdi->dev), MINOR(pdi->dev),
445 sip->start, sip->end);
450 static void cpu_mark_online(struct per_dev_info *pdi, unsigned int cpu)
452 if (cpu >= pdi->cpu_map_max || !pdi->cpu_map) {
453 int new_max = (cpu + CPUS_PER_LONG) & ~(CPUS_PER_LONG - 1);
454 unsigned long *map = malloc(new_max / sizeof(long));
456 memset(map, 0, new_max / sizeof(long));
459 memcpy(map, pdi->cpu_map, pdi->cpu_map_max / sizeof(long));
464 pdi->cpu_map_max = new_max;
467 pdi->cpu_map[CPU_IDX(cpu)] |= (1UL << CPU_BIT(cpu));
470 static inline void cpu_mark_offline(struct per_dev_info *pdi, int cpu)
472 pdi->cpu_map[CPU_IDX(cpu)] &= ~(1UL << CPU_BIT(cpu));
475 static inline int cpu_is_online(struct per_dev_info *pdi, int cpu)
477 return (pdi->cpu_map[CPU_IDX(cpu)] & (1UL << CPU_BIT(cpu))) != 0;
480 static inline int ppi_hash_pid(__u32 pid)
482 return jhash_1word(pid, JHASH_RANDOM) & PPI_HASH_MASK;
485 static inline int ppi_hash_name(const char *name)
487 return jhash(name, 16, JHASH_RANDOM) & PPI_HASH_MASK;
490 static inline int ppi_hash(struct per_process_info *ppi)
493 return ppi_hash_pid(ppi->pid);
495 return ppi_hash_name(ppi->name);
498 static inline void add_process_to_hash(struct per_process_info *ppi)
500 const int hash_idx = ppi_hash(ppi);
502 ppi->hash_next = ppi_hash_table[hash_idx];
503 ppi_hash_table[hash_idx] = ppi;
506 static inline void add_process_to_list(struct per_process_info *ppi)
508 ppi->list_next = ppi_list;
513 static struct per_process_info *find_process_by_name(char *name)
515 const int hash_idx = ppi_hash_name(name);
516 struct per_process_info *ppi;
518 ppi = ppi_hash_table[hash_idx];
520 if (!strcmp(ppi->name, name))
523 ppi = ppi->hash_next;
529 static struct per_process_info *find_process_by_pid(__u32 pid)
531 const int hash_idx = ppi_hash_pid(pid);
532 struct per_process_info *ppi;
534 ppi = ppi_hash_table[hash_idx];
539 ppi = ppi->hash_next;
545 static struct per_process_info *find_process(__u32 pid, char *name)
547 struct per_process_info *ppi;
550 return find_process_by_pid(pid);
552 ppi = find_process_by_name(name);
553 if (ppi && ppi->pid != pid)
554 ppi->more_than_one = 1;
560 * struct trace and blktrace allocation cache, we do potentially
561 * millions of mallocs for these structures while only using at most
562 * a few thousand at the time
564 static inline void t_free(struct trace *t)
566 if (t_alloc_cache < 1024) {
567 t->next = t_alloc_list;
574 static inline struct trace *t_alloc(void)
576 struct trace *t = t_alloc_list;
579 t_alloc_list = t->next;
584 return malloc(sizeof(*t));
587 static inline void bit_free(struct blk_io_trace *bit)
589 if (bit_alloc_cache < 1024 && !bit->pdu_len) {
591 * abuse a 64-bit field for a next pointer for the free item
593 bit->time = (__u64) (unsigned long) bit_alloc_list;
594 bit_alloc_list = (struct blk_io_trace *) bit;
600 static inline struct blk_io_trace *bit_alloc(void)
602 struct blk_io_trace *bit = bit_alloc_list;
605 bit_alloc_list = (struct blk_io_trace *) (unsigned long) \
611 return malloc(sizeof(*bit));
614 static inline void __put_trace_last(struct per_dev_info *pdi, struct trace *t)
616 struct per_cpu_info *pci = get_cpu_info(pdi, t->bit->cpu);
618 rb_erase(&t->rb_node, &pci->rb_last);
619 pci->rb_last_entries--;
625 static void put_trace(struct per_dev_info *pdi, struct trace *t)
627 rb_erase(&t->rb_node, &rb_sort_root);
630 trace_rb_insert_last(pdi, t);
633 static inline int trace_rb_insert(struct trace *t, struct rb_root *root)
635 struct rb_node **p = &root->rb_node;
636 struct rb_node *parent = NULL;
642 __t = rb_entry(parent, struct trace, rb_node);
644 if (t->bit->time < __t->bit->time)
646 else if (t->bit->time > __t->bit->time)
648 else if (t->bit->device < __t->bit->device)
650 else if (t->bit->device > __t->bit->device)
652 else if (t->bit->sequence < __t->bit->sequence)
654 else /* >= sequence */
658 rb_link_node(&t->rb_node, parent, p);
659 rb_insert_color(&t->rb_node, root);
663 static inline int trace_rb_insert_sort(struct trace *t)
665 if (!trace_rb_insert(t, &rb_sort_root)) {
673 static int trace_rb_insert_last(struct per_dev_info *pdi, struct trace *t)
675 struct per_cpu_info *pci = get_cpu_info(pdi, t->bit->cpu);
677 if (trace_rb_insert(t, &pci->rb_last))
680 pci->rb_last_entries++;
682 if (pci->rb_last_entries > rb_batch * pdi->nfiles) {
683 struct rb_node *n = rb_first(&pci->rb_last);
685 t = rb_entry(n, struct trace, rb_node);
686 __put_trace_last(pdi, t);
692 static struct trace *trace_rb_find(dev_t device, unsigned long sequence,
693 struct rb_root *root, int order)
695 struct rb_node *n = root->rb_node;
696 struct rb_node *prev = NULL;
700 __t = rb_entry(n, struct trace, rb_node);
703 if (device < __t->bit->device)
705 else if (device > __t->bit->device)
707 else if (sequence < __t->bit->sequence)
709 else if (sequence > __t->bit->sequence)
716 * hack - the list may not be sequence ordered because some
717 * events don't have sequence and time matched. so we end up
718 * being a little off in the rb lookup here, because we don't
719 * know the time we are looking for. compensate by browsing
720 * a little ahead from the last entry to find the match
725 while (((n = rb_next(prev)) != NULL) && max--) {
726 __t = rb_entry(n, struct trace, rb_node);
728 if (__t->bit->device == device &&
729 __t->bit->sequence == sequence)
739 static inline struct trace *trace_rb_find_last(struct per_dev_info *pdi,
740 struct per_cpu_info *pci,
743 return trace_rb_find(pdi->dev, seq, &pci->rb_last, 0);
746 static inline int track_rb_insert(struct per_dev_info *pdi,struct io_track *iot)
748 struct rb_node **p = &pdi->rb_track.rb_node;
749 struct rb_node *parent = NULL;
750 struct io_track *__iot;
754 __iot = rb_entry(parent, struct io_track, rb_node);
756 if (iot->sector < __iot->sector)
758 else if (iot->sector > __iot->sector)
762 "sector alias (%Lu) on device %d,%d!\n",
763 (unsigned long long) iot->sector,
764 MAJOR(pdi->dev), MINOR(pdi->dev));
769 rb_link_node(&iot->rb_node, parent, p);
770 rb_insert_color(&iot->rb_node, &pdi->rb_track);
774 static struct io_track *__find_track(struct per_dev_info *pdi, __u64 sector)
776 struct rb_node *n = pdi->rb_track.rb_node;
777 struct io_track *__iot;
780 __iot = rb_entry(n, struct io_track, rb_node);
782 if (sector < __iot->sector)
784 else if (sector > __iot->sector)
793 static struct io_track *find_track(struct per_dev_info *pdi, __u32 pid,
794 char *comm, __u64 sector)
796 struct io_track *iot;
798 iot = __find_track(pdi, sector);
800 iot = malloc(sizeof(*iot));
802 memcpy(iot->comm, comm, sizeof(iot->comm));
803 iot->sector = sector;
804 track_rb_insert(pdi, iot);
810 static void log_track_frontmerge(struct per_dev_info *pdi,
811 struct blk_io_trace *t)
813 struct io_track *iot;
818 iot = __find_track(pdi, t->sector + t_sec(t));
821 fprintf(stderr, "merge not found for (%d,%d): %llu\n",
822 MAJOR(pdi->dev), MINOR(pdi->dev),
823 (unsigned long long) t->sector + t_sec(t));
827 rb_erase(&iot->rb_node, &pdi->rb_track);
828 iot->sector -= t_sec(t);
829 track_rb_insert(pdi, iot);
832 static void log_track_getrq(struct per_dev_info *pdi, struct blk_io_trace *t)
834 struct io_track *iot;
839 iot = find_track(pdi, t->pid, t->comm, t->sector);
840 iot->allocation_time = t->time;
844 * return time between rq allocation and insertion
846 static unsigned long long log_track_insert(struct per_dev_info *pdi,
847 struct blk_io_trace *t)
849 unsigned long long elapsed;
850 struct io_track *iot;
855 iot = find_track(pdi, t->pid, t->comm, t->sector);
856 iot->queue_time = t->time;
858 if (!iot->allocation_time)
861 elapsed = iot->queue_time - iot->allocation_time;
863 if (per_process_stats) {
864 struct per_process_info *ppi = find_process(iot->pid,iot->comm);
865 int w = (t->action & BLK_TC_ACT(BLK_TC_WRITE)) != 0;
867 if (ppi && elapsed > ppi->longest_allocation_wait[w])
868 ppi->longest_allocation_wait[w] = elapsed;
875 * return time between queue and issue
877 static unsigned long long log_track_issue(struct per_dev_info *pdi,
878 struct blk_io_trace *t)
880 unsigned long long elapsed;
881 struct io_track *iot;
885 if ((t->action & BLK_TC_ACT(BLK_TC_FS)) == 0)
888 iot = __find_track(pdi, t->sector);
891 fprintf(stderr, "issue not found for (%d,%d): %llu\n",
892 MAJOR(pdi->dev), MINOR(pdi->dev),
893 (unsigned long long) t->sector);
897 iot->dispatch_time = t->time;
898 elapsed = iot->dispatch_time - iot->queue_time;
900 if (per_process_stats) {
901 struct per_process_info *ppi = find_process(iot->pid,iot->comm);
902 int w = (t->action & BLK_TC_ACT(BLK_TC_WRITE)) != 0;
904 if (ppi && elapsed > ppi->longest_dispatch_wait[w])
905 ppi->longest_dispatch_wait[w] = elapsed;
912 * return time between dispatch and complete
914 static unsigned long long log_track_complete(struct per_dev_info *pdi,
915 struct blk_io_trace *t)
917 unsigned long long elapsed;
918 struct io_track *iot;
922 if ((t->action & BLK_TC_ACT(BLK_TC_FS)) == 0)
925 iot = __find_track(pdi, t->sector);
928 fprintf(stderr,"complete not found for (%d,%d): %llu\n",
929 MAJOR(pdi->dev), MINOR(pdi->dev),
930 (unsigned long long) t->sector);
934 iot->completion_time = t->time;
935 elapsed = iot->completion_time - iot->dispatch_time;
937 if (per_process_stats) {
938 struct per_process_info *ppi = find_process(iot->pid,iot->comm);
939 int w = (t->action & BLK_TC_ACT(BLK_TC_WRITE)) != 0;
941 if (ppi && elapsed > ppi->longest_completion_wait[w])
942 ppi->longest_completion_wait[w] = elapsed;
946 * kill the trace, we don't need it after completion
948 rb_erase(&iot->rb_node, &pdi->rb_track);
955 static struct io_stats *find_process_io_stats(__u32 pid, char *name)
957 struct per_process_info *ppi = find_process(pid, name);
960 ppi = malloc(sizeof(*ppi));
961 memset(ppi, 0, sizeof(*ppi));
962 memcpy(ppi->name, name, 16);
964 add_process_to_hash(ppi);
965 add_process_to_list(ppi);
968 return &ppi->io_stats;
971 static char *get_dev_name(struct per_dev_info *pdi, char *buffer, int size)
974 snprintf(buffer, size, "%s", pdi->name);
976 snprintf(buffer, size, "%d,%d",MAJOR(pdi->dev),MINOR(pdi->dev));
980 static void check_time(struct per_dev_info *pdi, struct blk_io_trace *bit)
982 unsigned long long this = bit->time;
983 unsigned long long last = pdi->last_reported_time;
985 pdi->backwards = (this < last) ? 'B' : ' ';
986 pdi->last_reported_time = this;
989 static inline void __account_m(struct io_stats *ios, struct blk_io_trace *t,
994 ios->qwrite_kb += t_kb(t);
997 ios->qread_kb += t_kb(t);
1001 static inline void account_m(struct blk_io_trace *t, struct per_cpu_info *pci,
1004 __account_m(&pci->io_stats, t, rw);
1006 if (per_process_stats) {
1007 struct io_stats *ios = find_process_io_stats(t->pid, t->comm);
1009 __account_m(ios, t, rw);
1013 static inline void __account_queue(struct io_stats *ios, struct blk_io_trace *t,
1018 ios->qwrite_kb += t_kb(t);
1021 ios->qread_kb += t_kb(t);
1025 static inline void account_queue(struct blk_io_trace *t,
1026 struct per_cpu_info *pci, int rw)
1028 __account_queue(&pci->io_stats, t, rw);
1030 if (per_process_stats) {
1031 struct io_stats *ios = find_process_io_stats(t->pid, t->comm);
1033 __account_queue(ios, t, rw);
1037 static inline void __account_c(struct io_stats *ios, int rw, int bytes)
1041 ios->cwrite_kb += bytes >> 10;
1044 ios->cread_kb += bytes >> 10;
1048 static inline void account_c(struct blk_io_trace *t, struct per_cpu_info *pci,
1051 __account_c(&pci->io_stats, rw, bytes);
1053 if (per_process_stats) {
1054 struct io_stats *ios = find_process_io_stats(t->pid, t->comm);
1056 __account_c(ios, rw, bytes);
1060 static inline void __account_issue(struct io_stats *ios, int rw,
1065 ios->iwrite_kb += bytes >> 10;
1068 ios->iread_kb += bytes >> 10;
1072 static inline void account_issue(struct blk_io_trace *t,
1073 struct per_cpu_info *pci, int rw)
1075 __account_issue(&pci->io_stats, rw, t->bytes);
1077 if (per_process_stats) {
1078 struct io_stats *ios = find_process_io_stats(t->pid, t->comm);
1080 __account_issue(ios, rw, t->bytes);
1084 static inline void __account_unplug(struct io_stats *ios, int timer)
1087 ios->timer_unplugs++;
1092 static inline void account_unplug(struct blk_io_trace *t,
1093 struct per_cpu_info *pci, int timer)
1095 __account_unplug(&pci->io_stats, timer);
1097 if (per_process_stats) {
1098 struct io_stats *ios = find_process_io_stats(t->pid, t->comm);
1100 __account_unplug(ios, timer);
1104 static inline void __account_requeue(struct io_stats *ios,
1105 struct blk_io_trace *t, int rw)
1109 ios->iwrite_kb -= t_kb(t);
1112 ios->iread_kb -= t_kb(t);
1116 static inline void account_requeue(struct blk_io_trace *t,
1117 struct per_cpu_info *pci, int rw)
1119 __account_requeue(&pci->io_stats, t, rw);
1121 if (per_process_stats) {
1122 struct io_stats *ios = find_process_io_stats(t->pid, t->comm);
1124 __account_requeue(ios, t, rw);
1128 static void log_complete(struct per_dev_info *pdi, struct per_cpu_info *pci,
1129 struct blk_io_trace *t, char *act)
1131 process_fmt(act, pci, t, log_track_complete(pdi, t), 0, NULL);
1134 static void log_insert(struct per_dev_info *pdi, struct per_cpu_info *pci,
1135 struct blk_io_trace *t, char *act)
1137 process_fmt(act, pci, t, log_track_insert(pdi, t), 0, NULL);
1140 static void log_queue(struct per_cpu_info *pci, struct blk_io_trace *t,
1143 process_fmt(act, pci, t, -1, 0, NULL);
1146 static void log_issue(struct per_dev_info *pdi, struct per_cpu_info *pci,
1147 struct blk_io_trace *t, char *act)
1149 process_fmt(act, pci, t, log_track_issue(pdi, t), 0, NULL);
1152 static void log_merge(struct per_dev_info *pdi, struct per_cpu_info *pci,
1153 struct blk_io_trace *t, char *act)
1156 log_track_frontmerge(pdi, t);
1158 process_fmt(act, pci, t, -1ULL, 0, NULL);
1161 static void log_action(struct per_cpu_info *pci, struct blk_io_trace *t,
1164 process_fmt(act, pci, t, -1ULL, 0, NULL);
1167 static void log_generic(struct per_cpu_info *pci, struct blk_io_trace *t,
1170 process_fmt(act, pci, t, -1ULL, 0, NULL);
1173 static void log_unplug(struct per_cpu_info *pci, struct blk_io_trace *t,
1176 process_fmt(act, pci, t, -1ULL, 0, NULL);
1179 static void log_split(struct per_cpu_info *pci, struct blk_io_trace *t,
1182 process_fmt(act, pci, t, -1ULL, 0, NULL);
1185 static void log_pc(struct per_cpu_info *pci, struct blk_io_trace *t, char *act)
1187 unsigned char *buf = (unsigned char *) t + sizeof(*t);
1189 process_fmt(act, pci, t, -1ULL, t->pdu_len, buf);
1192 static void dump_trace_pc(struct blk_io_trace *t, struct per_cpu_info *pci)
1194 int act = t->action & 0xffff;
1197 case __BLK_TA_QUEUE:
1198 log_generic(pci, t, "Q");
1200 case __BLK_TA_GETRQ:
1201 log_generic(pci, t, "G");
1203 case __BLK_TA_SLEEPRQ:
1204 log_generic(pci, t, "S");
1206 case __BLK_TA_REQUEUE:
1207 log_generic(pci, t, "R");
1209 case __BLK_TA_ISSUE:
1210 log_pc(pci, t, "D");
1212 case __BLK_TA_COMPLETE:
1213 log_pc(pci, t, "C");
1215 case __BLK_TA_INSERT:
1216 log_pc(pci, t, "I");
1219 fprintf(stderr, "Bad pc action %x\n", act);
1224 static void dump_trace_fs(struct blk_io_trace *t, struct per_dev_info *pdi,
1225 struct per_cpu_info *pci)
1227 int w = (t->action & BLK_TC_ACT(BLK_TC_WRITE)) != 0;
1228 int act = t->action & 0xffff;
1231 case __BLK_TA_QUEUE:
1232 account_queue(t, pci, w);
1233 log_queue(pci, t, "Q");
1235 case __BLK_TA_INSERT:
1236 log_insert(pdi, pci, t, "I");
1238 case __BLK_TA_BACKMERGE:
1239 account_m(t, pci, w);
1240 log_merge(pdi, pci, t, "M");
1242 case __BLK_TA_FRONTMERGE:
1243 account_m(t, pci, w);
1244 log_merge(pdi, pci, t, "F");
1246 case __BLK_TA_GETRQ:
1247 log_track_getrq(pdi, t);
1248 log_generic(pci, t, "G");
1250 case __BLK_TA_SLEEPRQ:
1251 log_generic(pci, t, "S");
1253 case __BLK_TA_REQUEUE:
1255 * can happen if we miss traces, don't let it go
1258 if (pdi->cur_depth[w])
1259 pdi->cur_depth[w]--;
1260 account_requeue(t, pci, w);
1261 log_queue(pci, t, "R");
1263 case __BLK_TA_ISSUE:
1264 account_issue(t, pci, w);
1265 pdi->cur_depth[w]++;
1266 if (pdi->cur_depth[w] > pdi->max_depth[w])
1267 pdi->max_depth[w] = pdi->cur_depth[w];
1268 log_issue(pdi, pci, t, "D");
1270 case __BLK_TA_COMPLETE:
1271 if (pdi->cur_depth[w])
1272 pdi->cur_depth[w]--;
1273 account_c(t, pci, w, t->bytes);
1274 log_complete(pdi, pci, t, "C");
1277 log_action(pci, t, "P");
1279 case __BLK_TA_UNPLUG_IO:
1280 account_unplug(t, pci, 0);
1281 log_unplug(pci, t, "U");
1283 case __BLK_TA_UNPLUG_TIMER:
1284 account_unplug(t, pci, 1);
1285 log_unplug(pci, t, "UT");
1287 case __BLK_TA_SPLIT:
1288 log_split(pci, t, "X");
1290 case __BLK_TA_BOUNCE:
1291 log_generic(pci, t, "B");
1293 case __BLK_TA_REMAP:
1294 log_generic(pci, t, "A");
1297 fprintf(stderr, "Bad fs action %x\n", t->action);
1302 static void dump_trace(struct blk_io_trace *t, struct per_cpu_info *pci,
1303 struct per_dev_info *pdi)
1305 if (t->action & BLK_TC_ACT(BLK_TC_PC))
1306 dump_trace_pc(t, pci);
1308 dump_trace_fs(t, pdi, pci);
1311 pdi->first_reported_time = t->time;
1317 * print in a proper way, not too small and not too big. if more than
1318 * 1000,000K, turn into M and so on
1320 static char *size_cnv(char *dst, unsigned long long num, int in_kb)
1322 char suff[] = { '\0', 'K', 'M', 'G', 'P' };
1328 while (num > 1000 * 1000ULL && (i < sizeof(suff) - 1)) {
1333 sprintf(dst, "%'8Lu%c", num, suff[i]);
1337 static void dump_io_stats(struct per_dev_info *pdi, struct io_stats *ios,
1340 static char x[256], y[256];
1342 fprintf(ofp, "%s\n", msg);
1344 fprintf(ofp, " Reads Queued: %s, %siB\t", size_cnv(x, ios->qreads, 0), size_cnv(y, ios->qread_kb, 1));
1345 fprintf(ofp, " Writes Queued: %s, %siB\n", size_cnv(x, ios->qwrites, 0), size_cnv(y, ios->qwrite_kb, 1));
1347 fprintf(ofp, " Read Dispatches: %s, %siB\t", size_cnv(x, ios->ireads, 0), size_cnv(y, ios->iread_kb, 1));
1348 fprintf(ofp, " Write Dispatches: %s, %siB\n", size_cnv(x, ios->iwrites, 0), size_cnv(y, ios->iwrite_kb, 1));
1349 fprintf(ofp, " Reads Requeued: %s\t\t", size_cnv(x, ios->rrqueue, 0));
1350 fprintf(ofp, " Writes Requeued: %s\n", size_cnv(x, ios->wrqueue, 0));
1351 fprintf(ofp, " Reads Completed: %s, %siB\t", size_cnv(x, ios->creads, 0), size_cnv(y, ios->cread_kb, 1));
1352 fprintf(ofp, " Writes Completed: %s, %siB\n", size_cnv(x, ios->cwrites, 0), size_cnv(y, ios->cwrite_kb, 1));
1353 fprintf(ofp, " Read Merges: %'8lu%8c\t", ios->mreads, ' ');
1354 fprintf(ofp, " Write Merges: %'8lu\n", ios->mwrites);
1356 fprintf(ofp, " Read depth: %'8u%8c\t", pdi->max_depth[0], ' ');
1357 fprintf(ofp, " Write depth: %'8u\n", pdi->max_depth[1]);
1359 fprintf(ofp, " IO unplugs: %'8lu%8c\t", ios->io_unplugs, ' ');
1360 fprintf(ofp, " Timer unplugs: %'8lu\n", ios->timer_unplugs);
1363 static void dump_wait_stats(struct per_process_info *ppi)
1365 unsigned long rawait = ppi->longest_allocation_wait[0] / 1000;
1366 unsigned long rdwait = ppi->longest_dispatch_wait[0] / 1000;
1367 unsigned long rcwait = ppi->longest_completion_wait[0] / 1000;
1368 unsigned long wawait = ppi->longest_allocation_wait[1] / 1000;
1369 unsigned long wdwait = ppi->longest_dispatch_wait[1] / 1000;
1370 unsigned long wcwait = ppi->longest_completion_wait[1] / 1000;
1372 fprintf(ofp, " Allocation wait: %'8lu%8c\t", rawait, ' ');
1373 fprintf(ofp, " Allocation wait: %'8lu\n", wawait);
1374 fprintf(ofp, " Dispatch wait: %'8lu%8c\t", rdwait, ' ');
1375 fprintf(ofp, " Dispatch wait: %'8lu\n", wdwait);
1376 fprintf(ofp, " Completion wait: %'8lu%8c\t", rcwait, ' ');
1377 fprintf(ofp, " Completion wait: %'8lu\n", wcwait);
1380 static int ppi_name_compare(const void *p1, const void *p2)
1382 struct per_process_info *ppi1 = *((struct per_process_info **) p1);
1383 struct per_process_info *ppi2 = *((struct per_process_info **) p2);
1386 res = strverscmp(ppi1->name, ppi2->name);
1388 res = ppi1->pid > ppi2->pid;
1393 static void sort_process_list(void)
1395 struct per_process_info **ppis;
1396 struct per_process_info *ppi;
1399 ppis = malloc(ppi_list_entries * sizeof(struct per_process_info *));
1404 ppi = ppi->list_next;
1407 qsort(ppis, ppi_list_entries, sizeof(ppi), ppi_name_compare);
1409 i = ppi_list_entries - 1;
1414 ppi->list_next = ppi_list;
1422 static void show_process_stats(void)
1424 struct per_process_info *ppi;
1426 sort_process_list();
1432 if (ppi->more_than_one)
1433 sprintf(name, "%s (%u, ...)", ppi->name, ppi->pid);
1435 sprintf(name, "%s (%u)", ppi->name, ppi->pid);
1437 dump_io_stats(NULL, &ppi->io_stats, name);
1438 dump_wait_stats(ppi);
1439 ppi = ppi->list_next;
1445 static void show_device_and_cpu_stats(void)
1447 struct per_dev_info *pdi;
1448 struct per_cpu_info *pci;
1449 struct io_stats total, *ios;
1450 unsigned long long rrate, wrate, msec;
1451 int i, j, pci_events;
1452 char line[3 + 8/*cpu*/ + 2 + 32/*dev*/ + 3];
1455 for (pdi = devices, i = 0; i < ndevices; i++, pdi++) {
1457 memset(&total, 0, sizeof(total));
1463 for (pci = pdi->cpus, j = 0; j < pdi->ncpus; j++, pci++) {
1467 ios = &pci->io_stats;
1468 total.qreads += ios->qreads;
1469 total.qwrites += ios->qwrites;
1470 total.creads += ios->creads;
1471 total.cwrites += ios->cwrites;
1472 total.mreads += ios->mreads;
1473 total.mwrites += ios->mwrites;
1474 total.ireads += ios->ireads;
1475 total.iwrites += ios->iwrites;
1476 total.rrqueue += ios->rrqueue;
1477 total.wrqueue += ios->wrqueue;
1478 total.qread_kb += ios->qread_kb;
1479 total.qwrite_kb += ios->qwrite_kb;
1480 total.cread_kb += ios->cread_kb;
1481 total.cwrite_kb += ios->cwrite_kb;
1482 total.iread_kb += ios->iread_kb;
1483 total.iwrite_kb += ios->iwrite_kb;
1484 total.timer_unplugs += ios->timer_unplugs;
1485 total.io_unplugs += ios->io_unplugs;
1487 snprintf(line, sizeof(line) - 1, "CPU%d (%s):",
1488 j, get_dev_name(pdi, name, sizeof(name)));
1489 dump_io_stats(pdi, ios, line);
1493 if (pci_events > 1) {
1495 snprintf(line, sizeof(line) - 1, "Total (%s):",
1496 get_dev_name(pdi, name, sizeof(name)));
1497 dump_io_stats(NULL, &total, line);
1501 msec = (pdi->last_reported_time - pdi->first_reported_time) / 1000000;
1503 rrate = 1000 * total.cread_kb / msec;
1504 wrate = 1000 * total.cwrite_kb / msec;
1507 fprintf(ofp, "\nThroughput (R/W): %'LuKiB/s / %'LuKiB/s\n",
1509 fprintf(ofp, "Events (%s): %'Lu entries\n",
1510 get_dev_name(pdi, line, sizeof(line)), pdi->events);
1512 collect_pdi_skips(pdi);
1513 fprintf(ofp, "Skips: %'lu forward (%'llu - %5.1lf%%)\n",
1514 pdi->skips,pdi->seq_skips,
1515 100.0 * ((double)pdi->seq_skips /
1516 (double)(pdi->events + pdi->seq_skips)));
1520 static void find_genesis(void)
1522 struct trace *t = trace_list;
1524 genesis_time = -1ULL;
1526 if (t->bit->time < genesis_time)
1527 genesis_time = t->bit->time;
1533 static inline int check_stopwatch(struct blk_io_trace *bit)
1535 if (bit->time < stopwatch_end &&
1536 bit->time >= stopwatch_start)
1543 * return youngest entry read
1545 static int sort_entries(unsigned long long *youngest)
1547 struct per_dev_info *pdi = NULL;
1548 struct per_cpu_info *pci = NULL;
1555 while ((t = trace_list) != NULL) {
1556 struct blk_io_trace *bit = t->bit;
1558 trace_list = t->next;
1560 bit->time -= genesis_time;
1562 if (bit->time < *youngest || !*youngest)
1563 *youngest = bit->time;
1565 if (!pdi || pdi->dev != bit->device) {
1566 pdi = get_dev_info(bit->device);
1570 if (!pci || pci->cpu != bit->cpu)
1571 pci = get_cpu_info(pdi, bit->cpu);
1573 if (bit->sequence < pci->smallest_seq_read)
1574 pci->smallest_seq_read = bit->sequence;
1576 if (check_stopwatch(bit)) {
1582 if (trace_rb_insert_sort(t))
1590 * to continue, we must have traces from all online cpus in the tree
1592 static int check_cpu_map(struct per_dev_info *pdi)
1594 unsigned long *cpu_map;
1601 * create a map of the cpus we have traces for
1603 cpu_map = malloc(pdi->cpu_map_max / sizeof(long));
1604 n = rb_first(&rb_sort_root);
1606 __t = rb_entry(n, struct trace, rb_node);
1607 cpu = __t->bit->cpu;
1609 cpu_map[CPU_IDX(cpu)] |= (1UL << CPU_BIT(cpu));
1614 * we can't continue if pdi->cpu_map has entries set that we don't
1615 * have in the sort rbtree. the opposite is not a problem, though
1618 for (i = 0; i < pdi->cpu_map_max / CPUS_PER_LONG; i++) {
1619 if (pdi->cpu_map[i] & ~(cpu_map[i])) {
1629 static int check_sequence(struct per_dev_info *pdi, struct trace *t, int force)
1631 struct blk_io_trace *bit = t->bit;
1632 unsigned long expected_sequence;
1633 struct per_cpu_info *pci;
1636 pci = get_cpu_info(pdi, bit->cpu);
1637 expected_sequence = pci->last_sequence + 1;
1639 if (!expected_sequence) {
1641 * 1 should be the first entry, just allow it
1643 if (bit->sequence == 1)
1645 if (bit->sequence == pci->smallest_seq_read)
1648 return check_cpu_map(pdi);
1651 if (bit->sequence == expected_sequence)
1655 * we may not have seen that sequence yet. if we are not doing
1656 * the final run, break and wait for more entries.
1658 if (expected_sequence < pci->smallest_seq_read) {
1659 __t = trace_rb_find_last(pdi, pci, expected_sequence);
1663 __put_trace_last(pdi, __t);
1665 } else if (!force) {
1669 if (check_current_skips(pci, bit->sequence))
1672 if (expected_sequence < bit->sequence)
1673 insert_skip(pci, expected_sequence, bit->sequence - 1);
1678 static void show_entries_rb(int force)
1680 struct per_dev_info *pdi = NULL;
1681 struct per_cpu_info *pci = NULL;
1682 struct blk_io_trace *bit;
1686 while ((n = rb_first(&rb_sort_root)) != NULL) {
1687 if (is_done() && !force && !pipeline)
1690 t = rb_entry(n, struct trace, rb_node);
1693 if (read_sequence - t->read_sequence < 1 && !force)
1696 if (!pdi || pdi->dev != bit->device) {
1697 pdi = get_dev_info(bit->device);
1702 fprintf(stderr, "Unknown device ID? (%d,%d)\n",
1703 MAJOR(bit->device), MINOR(bit->device));
1707 if (check_sequence(pdi, t, force))
1710 if (!force && bit->time > last_allowed_time)
1713 check_time(pdi, bit);
1715 if (!pci || pci->cpu != bit->cpu)
1716 pci = get_cpu_info(pdi, bit->cpu);
1718 pci->last_sequence = bit->sequence;
1722 if (bit->action & (act_mask << BLK_TC_SHIFT))
1723 dump_trace(bit, pci, pdi);
1729 static int read_data(int fd, void *buffer, int bytes, int block, int *fdblock)
1731 int ret, bytes_left, fl;
1734 if (block != *fdblock) {
1735 fl = fcntl(fd, F_GETFL);
1739 fcntl(fd, F_SETFL, fl | O_NONBLOCK);
1742 fcntl(fd, F_SETFL, fl & ~O_NONBLOCK);
1748 while (bytes_left > 0) {
1749 ret = read(fd, p, bytes_left);
1753 if (errno != EAGAIN) {
1759 * never do partial reads. we can return if we
1760 * didn't read anything and we should not block,
1761 * otherwise wait for data
1763 if ((bytes_left == bytes) && !block)
1777 static inline __u16 get_pdulen(struct blk_io_trace *bit)
1780 return bit->pdu_len;
1782 return __bswap_16(bit->pdu_len);
1785 static inline __u32 get_magic(struct blk_io_trace *bit)
1790 return __bswap_32(bit->magic);
1793 static int read_events(int fd, int always_block, int *fdblock)
1795 struct per_dev_info *pdi = NULL;
1796 unsigned int events = 0;
1798 while (!is_done() && events < rb_batch) {
1799 struct blk_io_trace *bit;
1801 int pdu_len, should_block, ret;
1806 should_block = !events || always_block;
1808 ret = read_data(fd, bit, sizeof(*bit), should_block, fdblock);
1811 if (!events && ret < 0)
1817 * look at first trace to check whether we need to convert
1818 * data in the future
1820 if (data_is_native == -1 && check_data_endianness(bit))
1823 magic = get_magic(bit);
1824 if ((magic & 0xffffff00) != BLK_IO_TRACE_MAGIC) {
1825 fprintf(stderr, "Bad magic %x\n", magic);
1829 pdu_len = get_pdulen(bit);
1831 void *ptr = realloc(bit, sizeof(*bit) + pdu_len);
1833 if (read_data(fd, ptr + sizeof(*bit), pdu_len, 1, fdblock)) {
1843 if (verify_trace(bit)) {
1849 memset(t, 0, sizeof(*t));
1851 t->read_sequence = read_sequence;
1853 t->next = trace_list;
1856 if (!pdi || pdi->dev != bit->device)
1857 pdi = get_dev_info(bit->device);
1859 if (bit->time > pdi->last_read_time)
1860 pdi->last_read_time = bit->time;
1868 static int do_file(void)
1870 struct per_cpu_info *pci;
1871 struct per_dev_info *pdi;
1872 int i, j, events, events_added;
1875 * first prepare all files for reading
1877 for (i = 0; i < ndevices; i++) {
1886 pci = get_cpu_info(pdi, j);
1891 p = strdup(pdi->name);
1893 if (strcmp(dname, ".")) {
1895 p = strdup(pdi->name);
1896 strcpy(pdi->name, basename(p));
1901 len = sprintf(pci->fname, "%s/", input_dir);
1903 snprintf(pci->fname + len, sizeof(pci->fname)-1-len,
1904 "%s.blktrace.%d", pdi->name, pci->cpu);
1905 if (stat(pci->fname, &st) < 0)
1908 pci->fd = open(pci->fname, O_RDONLY);
1915 printf("Input file %s added\n", pci->fname);
1917 cpu_mark_online(pdi, pci->cpu);
1922 * now loop over the files reading in the data
1925 unsigned long long youngest;
1928 last_allowed_time = -1ULL;
1931 for (i = 0; i < ndevices; i++) {
1933 pdi->last_read_time = -1ULL;
1935 for (j = 0; j < pdi->nfiles; j++) {
1937 pci = get_cpu_info(pdi, j);
1942 pci->smallest_seq_read = -1;
1944 events = read_events(pci->fd, 1, &pci->fdblock);
1946 cpu_mark_offline(pdi, pci->cpu);
1952 if (pdi->last_read_time < last_allowed_time)
1953 last_allowed_time = pdi->last_read_time;
1955 events_added += events;
1959 if (sort_entries(&youngest))
1962 if (youngest > stopwatch_end)
1967 } while (events_added);
1969 if (rb_sort_entries)
1975 static int do_stdin(void)
1977 unsigned long long youngest;
1978 int fd, events, fdblock;
1980 last_allowed_time = -1ULL;
1981 fd = dup(STDIN_FILENO);
1983 perror("dup stdin");
1988 while ((events = read_events(fd, 0, &fdblock)) > 0) {
1992 smallest_seq_read = -1U;
1995 if (sort_entries(&youngest))
1998 if (youngest > stopwatch_end)
2004 if (rb_sort_entries)
2011 static void show_stats(void)
2020 if (per_process_stats)
2021 show_process_stats();
2023 if (per_device_and_cpu_stats)
2024 show_device_and_cpu_stats();
2029 static void handle_sigint(__attribute__((__unused__)) int sig)
2035 * Extract start and duration times from a string, allowing
2036 * us to specify a time interval of interest within a trace.
2037 * Format: "duration" (start is zero) or "start:duration".
2039 static int find_stopwatch_interval(char *string)
2044 value = strtod(string, &sp);
2046 fprintf(stderr,"Invalid stopwatch timer: %s\n", string);
2050 stopwatch_start = DOUBLE_TO_NANO_ULL(value);
2052 value = strtod(string, &sp);
2053 if (sp == string || *sp != '\0') {
2054 fprintf(stderr,"Invalid stopwatch duration time: %s\n",
2058 } else if (*sp != '\0') {
2059 fprintf(stderr,"Invalid stopwatch start timer: %s\n", string);
2062 stopwatch_end = DOUBLE_TO_NANO_ULL(value);
2063 if (stopwatch_end <= stopwatch_start) {
2064 fprintf(stderr, "Invalid stopwatch interval: %Lu -> %Lu\n",
2065 stopwatch_start, stopwatch_end);
2072 static char usage_str[] = \
2073 "[ -i <input name> ] [-o <output name> [ -s ] [ -t ] [ -q ]\n" \
2074 "[ -w start:stop ] [ -f output format ] [ -F format spec ] [ -v] \n\n" \
2075 "\t-i Input file containing trace data, or '-' for stdin\n" \
2076 "\t-D Directory to prepend to input file names\n" \
2077 "\t-o Output file. If not given, output is stdout\n" \
2078 "\t-b stdin read batching\n" \
2079 "\t-s Show per-program io statistics\n" \
2080 "\t-h Hash processes by name, not pid\n" \
2081 "\t-t Track individual ios. Will tell you the time a request took\n" \
2082 "\t to get queued, to get dispatched, and to get completed\n" \
2083 "\t-q Quiet. Don't display any stats at the end of the trace\n" \
2084 "\t-w Only parse data between the given time interval in seconds.\n" \
2085 "\t If 'start' isn't given, blkparse defaults the start time to 0\n" \
2086 "\t-f Output format. Customize the output format. The format field\n" \
2087 "\t identifies can be found in the documentation\n" \
2088 "\t-F Format specification. Can be found in the documentation\n" \
2089 "\t-v More verbose for marginal errors\n" \
2090 "\t-V Print program version info\n\n";
2092 static void usage(char *prog)
2094 fprintf(stderr, "Usage: %s %s %s", prog, blkparse_version, usage_str);
2097 int main(int argc, char *argv[])
2100 int i, c, ret, mode;
2101 int act_mask_tmp = 0;
2103 while ((c = getopt_long(argc, argv, S_OPTS, l_opts, NULL)) != -1) {
2106 i = find_mask_map(optarg);
2108 fprintf(stderr,"Invalid action mask %s\n",
2116 if ((sscanf(optarg, "%x", &i) != 1) ||
2117 !valid_act_opt(i)) {
2119 "Invalid set action mask %s/0x%x\n",
2126 if (!strcmp(optarg, "-") && !pipeline)
2128 else if (resize_devices(optarg) != 0)
2135 output_name = optarg;
2138 rb_batch = atoi(optarg);
2140 rb_batch = RB_BATCH_DEFAULT;
2143 per_process_stats = 1;
2149 per_device_and_cpu_stats = 0;
2152 if (find_stopwatch_interval(optarg) != 0)
2156 set_all_format_specs(optarg);
2159 if (add_format_spec(optarg) != 0)
2163 ppi_hash_by_pid = 0;
2169 printf("%s version %s\n", argv[0], blkparse_version);
2177 while (optind < argc) {
2178 if (!strcmp(argv[optind], "-") && !pipeline)
2180 else if (resize_devices(argv[optind]) != 0)
2185 if (!pipeline && !ndevices) {
2190 if (act_mask_tmp != 0)
2191 act_mask = act_mask_tmp;
2193 memset(&rb_sort_root, 0, sizeof(rb_sort_root));
2195 signal(SIGINT, handle_sigint);
2196 signal(SIGHUP, handle_sigint);
2197 signal(SIGTERM, handle_sigint);
2199 setlocale(LC_NUMERIC, "en_US");
2202 ofp = fdopen(STDOUT_FILENO, "w");
2207 snprintf(ofname, sizeof(ofname) - 1, "%s", output_name);
2208 ofp = fopen(ofname, "w");
2217 ofp_buffer = malloc(4096);
2218 if (setvbuf(ofp, ofp_buffer, mode, 4096)) {