1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright (c) 2013-2015 PLUMgrid, http://plumgrid.com
10 #include <linux/bpf.h>
11 #include <sys/resource.h>
19 static void clear_stats(int fd
)
21 unsigned int nr_cpus
= bpf_num_possible_cpus();
22 __u64 values
[nr_cpus
];
25 memset(values
, 0, sizeof(values
));
26 for (key
= 0; key
< SLOTS
; key
++)
27 bpf_map_update_elem(fd
, &key
, values
, BPF_ANY
);
30 const char *color
[] = {
44 const int num_colors
= ARRAY_SIZE(color
);
46 const char nocolor
[] = "\033[00m";
63 bool full_range
= false;
64 bool text_only
= false;
66 static void print_banner(void)
69 printf("|1ns |10ns |100ns |1us |10us |100us"
70 " |1ms |10ms |100ms |1s |10s\n");
72 printf("|1us |10us |100us |1ms |10ms "
76 static void print_hist(int fd
)
78 unsigned int nr_cpus
= bpf_num_possible_cpus();
79 __u64 total_events
= 0;
87 for (key
= 0; key
< SLOTS
; key
++) {
88 bpf_map_lookup_elem(fd
, &key
, values
);
90 for (i
= 0; i
< nr_cpus
; i
++)
93 total_events
+= value
;
98 for (key
= full_range
? 0 : 29; key
< SLOTS
; key
++) {
99 int c
= num_colors
* cnt
[key
] / (max_cnt
+ 1);
102 printf("%s", sym
[c
]);
104 printf("%s %s", color
[c
], nocolor
);
106 printf(" # %lld\n", total_events
);
109 int main(int ac
, char **argv
)
111 struct rlimit r
= {1024*1024, RLIM_INFINITY
};
115 snprintf(filename
, sizeof(filename
), "%s_kern.o", argv
[0]);
117 if (setrlimit(RLIMIT_MEMLOCK
, &r
)) {
118 perror("setrlimit(RLIMIT_MEMLOCK)");
122 if (load_bpf_file(filename
)) {
123 printf("%s", bpf_log_buf
);
127 for (i
= 1; i
< ac
; i
++) {
128 if (strcmp(argv
[i
], "-a") == 0) {
130 } else if (strcmp(argv
[i
], "-t") == 0) {
132 } else if (strcmp(argv
[i
], "-h") == 0) {
134 " -a display wider latency range\n"
140 printf(" heatmap of IO latency\n");
142 printf(" %s", sym
[num_colors
- 1]);
144 printf(" %s %s", color
[num_colors
- 1], nocolor
);
145 printf(" - many events with this latency\n");
148 printf(" %s", sym
[0]);
150 printf(" %s %s", color
[0], nocolor
);
151 printf(" - few events\n");
156 print_hist(map_fd
[1]);