clk: rockchip: mark rk3399 GIC clocks as critical
[linux/fpc-iii.git] / samples / bpf / tracex4_user.c
blobbc4a3bdea6ed4cbceed4478899702b8ee04dd8eb
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.
6 */
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <signal.h>
10 #include <unistd.h>
11 #include <stdbool.h>
12 #include <string.h>
13 #include <time.h>
14 #include <linux/bpf.h>
15 #include "libbpf.h"
16 #include "bpf_load.h"
18 struct pair {
19 long long val;
20 __u64 ip;
23 static __u64 time_get_ns(void)
25 struct timespec ts;
27 clock_gettime(CLOCK_MONOTONIC, &ts);
28 return ts.tv_sec * 1000000000ull + ts.tv_nsec;
31 static void print_old_objects(int fd)
33 long long val = time_get_ns();
34 __u64 key, next_key;
35 struct pair v;
37 key = write(1, "\e[1;1H\e[2J", 12); /* clear screen */
39 key = -1;
40 while (bpf_get_next_key(map_fd[0], &key, &next_key) == 0) {
41 bpf_lookup_elem(map_fd[0], &next_key, &v);
42 key = next_key;
43 if (val - v.val < 1000000000ll)
44 /* object was allocated more then 1 sec ago */
45 continue;
46 printf("obj 0x%llx is %2lldsec old was allocated at ip %llx\n",
47 next_key, (val - v.val) / 1000000000ll, v.ip);
51 int main(int ac, char **argv)
53 char filename[256];
54 int i;
56 snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
58 if (load_bpf_file(filename)) {
59 printf("%s", bpf_log_buf);
60 return 1;
63 for (i = 0; ; i++) {
64 print_old_objects(map_fd[1]);
65 sleep(1);
68 return 0;