1 /* Copyright (c) 2013-2015 PLUMgrid, http://plumgrid.com
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of version 2 of the GNU General Public
5 * License as published by the Free Software Foundation.
13 #include <linux/bpf.h>
19 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
23 static void clear_stats(int fd
)
25 unsigned int nr_cpus
= bpf_num_possible_cpus();
26 __u64 values
[nr_cpus
];
29 memset(values
, 0, sizeof(values
));
30 for (key
= 0; key
< SLOTS
; key
++)
31 bpf_map_update_elem(fd
, &key
, values
, BPF_ANY
);
34 const char *color
[] = {
48 const int num_colors
= ARRAY_SIZE(color
);
50 const char nocolor
[] = "\033[00m";
67 bool full_range
= false;
68 bool text_only
= false;
70 static void print_banner(void)
73 printf("|1ns |10ns |100ns |1us |10us |100us"
74 " |1ms |10ms |100ms |1s |10s\n");
76 printf("|1us |10us |100us |1ms |10ms "
80 static void print_hist(int fd
)
82 unsigned int nr_cpus
= bpf_num_possible_cpus();
83 __u64 total_events
= 0;
91 for (key
= 0; key
< SLOTS
; key
++) {
92 bpf_map_lookup_elem(fd
, &key
, values
);
94 for (i
= 0; i
< nr_cpus
; i
++)
97 total_events
+= value
;
102 for (key
= full_range
? 0 : 29; key
< SLOTS
; key
++) {
103 int c
= num_colors
* cnt
[key
] / (max_cnt
+ 1);
106 printf("%s", sym
[c
]);
108 printf("%s %s", color
[c
], nocolor
);
110 printf(" # %lld\n", total_events
);
113 int main(int ac
, char **argv
)
118 snprintf(filename
, sizeof(filename
), "%s_kern.o", argv
[0]);
120 if (load_bpf_file(filename
)) {
121 printf("%s", bpf_log_buf
);
125 for (i
= 1; i
< ac
; i
++) {
126 if (strcmp(argv
[i
], "-a") == 0) {
128 } else if (strcmp(argv
[i
], "-t") == 0) {
130 } else if (strcmp(argv
[i
], "-h") == 0) {
132 " -a display wider latency range\n"
138 printf(" heatmap of IO latency\n");
140 printf(" %s", sym
[num_colors
- 1]);
142 printf(" %s %s", color
[num_colors
- 1], nocolor
);
143 printf(" - many events with this latency\n");
146 printf(" %s", sym
[0]);
148 printf(" %s %s", color
[0], nocolor
);
149 printf(" - few events\n");
154 print_hist(map_fd
[1]);