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>
17 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
21 static void clear_stats(int fd)
26 for (key = 0; key < SLOTS; key++)
27 bpf_update_elem(fd, &key, &value, 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)
82 __u64 total_events = 0;
84 for (key = 0; key < SLOTS; key++) {
86 bpf_lookup_elem(fd, &key, &value);
88 total_events += value;
93 for (key = full_range ? 0 : 29; key < SLOTS; key++) {
94 int c = num_colors * cnt[key] / (max_cnt + 1);
99 printf("%s %s", color[c], nocolor);
101 printf(" # %lld\n", total_events);
104 int main(int ac, char **argv)
109 snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
111 if (load_bpf_file(filename)) {
112 printf("%s", bpf_log_buf);
116 for (i = 1; i < ac; i++) {
117 if (strcmp(argv[i], "-a") == 0) {
119 } else if (strcmp(argv[i], "-t") == 0) {
121 } else if (strcmp(argv[i], "-h") == 0) {
123 " -a display wider latency range\n"
129 printf(" heatmap of IO latency\n");
131 printf(" %s", sym[num_colors - 1]);
133 printf(" %s %s", color[num_colors - 1], nocolor);
134 printf(" - many events with this latency\n");
137 printf(" %s", sym[0]);
139 printf(" %s %s", color[0], nocolor);
140 printf(" - few events\n");
145 print_hist(map_fd[1]);