1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/unistd.h>
10 #include <arpa/inet.h>
18 static void stars(char *str, long val, long max, int width)
22 for (i = 0; i < (width * val / max) - 1 && i < width - 1; i++)
29 int main(int argc, char **argv)
31 unsigned int nr_cpus = bpf_num_possible_cpus();
32 const char *map_filename = "/sys/fs/bpf/tc/globals/lwt_len_hist_map";
33 uint64_t values[nr_cpus], sum, max_value = 0, data[MAX_INDEX] = {};
34 uint64_t key = 0, next_key, max_key = 0;
35 char starstr[MAX_STARS];
38 map_fd = bpf_obj_get(map_filename);
40 fprintf(stderr, "bpf_obj_get(%s): %s(%d)\n",
41 map_filename, strerror(errno), errno);
45 while (bpf_map_get_next_key(map_fd, &key, &next_key) == 0) {
46 if (next_key >= MAX_INDEX) {
47 fprintf(stderr, "Key %lu out of bounds\n", next_key);
51 bpf_map_lookup_elem(map_fd, &next_key, values);
54 for (i = 0; i < nr_cpus; i++)
58 if (sum && next_key > max_key)
67 for (i = 1; i <= max_key + 1; i++) {
68 stars(starstr, data[i - 1], max_value, MAX_STARS);
69 printf("%8ld -> %-8ld : %-8ld |%-*s|\n",
70 (1l << i) >> 1, (1l << i) - 1, data[i - 1],