]>
git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blob - samples/bpf/tracex3_user.c
56466d010139477593b5f18b927a7c63e7777219
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>
14 #include <sys/resource.h>
22 static void clear_stats(int fd
)
24 unsigned int nr_cpus
= bpf_num_possible_cpus();
25 __u64 values
[nr_cpus
];
28 memset(values
, 0, sizeof(values
));
29 for (key
= 0; key
< SLOTS
; key
++)
30 bpf_map_update_elem(fd
, &key
, values
, BPF_ANY
);
33 const char *color
[] = {
47 const int num_colors
= ARRAY_SIZE(color
);
49 const char nocolor
[] = "\033[00m";
66 bool full_range
= false;
67 bool text_only
= false;
69 static void print_banner(void)
72 printf("|1ns |10ns |100ns |1us |10us |100us"
73 " |1ms |10ms |100ms |1s |10s\n");
75 printf("|1us |10us |100us |1ms |10ms "
79 static void print_hist(int fd
)
81 unsigned int nr_cpus
= bpf_num_possible_cpus();
82 __u64 total_events
= 0;
90 for (key
= 0; key
< SLOTS
; key
++) {
91 bpf_map_lookup_elem(fd
, &key
, values
);
93 for (i
= 0; i
< nr_cpus
; i
++)
96 total_events
+= value
;
101 for (key
= full_range
? 0 : 29; key
< SLOTS
; key
++) {
102 int c
= num_colors
* cnt
[key
] / (max_cnt
+ 1);
105 printf("%s", sym
[c
]);
107 printf("%s %s", color
[c
], nocolor
);
109 printf(" # %lld\n", total_events
);
112 int main(int ac
, char **argv
)
114 struct rlimit r
= {1024*1024, RLIM_INFINITY
};
118 snprintf(filename
, sizeof(filename
), "%s_kern.o", argv
[0]);
120 if (setrlimit(RLIMIT_MEMLOCK
, &r
)) {
121 perror("setrlimit(RLIMIT_MEMLOCK)");
125 if (load_bpf_file(filename
)) {
126 printf("%s", bpf_log_buf
);
130 for (i
= 1; i
< ac
; i
++) {
131 if (strcmp(argv
[i
], "-a") == 0) {
133 } else if (strcmp(argv
[i
], "-t") == 0) {
135 } else if (strcmp(argv
[i
], "-h") == 0) {
137 " -a display wider latency range\n"
143 printf(" heatmap of IO latency\n");
145 printf(" %s", sym
[num_colors
- 1]);
147 printf(" %s %s", color
[num_colors
- 1], nocolor
);
148 printf(" - many events with this latency\n");
151 printf(" %s", sym
[0]);
153 printf(" %s %s", color
[0], nocolor
);
154 printf(" - few events\n");
159 print_hist(map_fd
[1]);