1 /* Copyright (c) 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.
14 #include <linux/bpf.h>
15 #include <sys/resource.h>
25 static __u64
time_get_ns(void)
29 clock_gettime(CLOCK_MONOTONIC
, &ts
);
30 return ts
.tv_sec
* 1000000000ull + ts
.tv_nsec
;
33 static void print_old_objects(int fd
)
35 long long val
= time_get_ns();
39 key
= write(1, "\e[1;1H\e[2J", 12); /* clear screen */
42 while (bpf_map_get_next_key(map_fd
[0], &key
, &next_key
) == 0) {
43 bpf_map_lookup_elem(map_fd
[0], &next_key
, &v
);
45 if (val
- v
.val
< 1000000000ll)
46 /* object was allocated more then 1 sec ago */
48 printf("obj 0x%llx is %2lldsec old was allocated at ip %llx\n",
49 next_key
, (val
- v
.val
) / 1000000000ll, v
.ip
);
53 int main(int ac
, char **argv
)
55 struct rlimit r
= {RLIM_INFINITY
, RLIM_INFINITY
};
59 snprintf(filename
, sizeof(filename
), "%s_kern.o", argv
[0]);
61 if (setrlimit(RLIMIT_MEMLOCK
, &r
)) {
62 perror("setrlimit(RLIMIT_MEMLOCK, RLIM_INFINITY)");
66 if (load_bpf_file(filename
)) {
67 printf("%s", bpf_log_buf
);
72 print_old_objects(map_fd
[1]);