Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mariux64
/
linux
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
1
Pull requests
0
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
d822a19
Documentation
arch
block
crypto
drivers
firmware
fs
include
init
ipc
kernel
lib
mm
net
samples
bpf
Makefile
bpf_helpers.h
bpf_load.c
bpf_load.h
libbpf.c
libbpf.h
sock_example.c
sockex1_kern.c
sockex1_user.c
sockex2_kern.c
sockex2_user.c
test_maps.c
test_verifier.c
tracex1_kern.c
tracex1_user.c
tracex2_kern.c
tracex2_user.c
hidraw
hw_breakpoint
kdb
kfifo
kobject
kprobes
livepatch
rpmsg
seccomp
trace_events
uhid
Kconfig
Makefile
scripts
security
sound
tools
usr
virt
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
REPORTING-BUGS
Breadcrumbs
linux
/
samples
/
bpf
/
tracex2_user.c
Copy path
Blame
Blame
Latest commit
History
History
95 lines (81 loc) · 1.95 KB
Breadcrumbs
linux
/
samples
/
bpf
/
tracex2_user.c
Top
File metadata and controls
Code
Blame
95 lines (81 loc) · 1.95 KB
Raw
#include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <signal.h> #include <linux/bpf.h> #include "libbpf.h" #include "bpf_load.h" #define MAX_INDEX 64 #define MAX_STARS 38 static void stars(char *str, long val, long max, int width) { int i; for (i = 0; i < (width * val / max) - 1 && i < width - 1; i++) str[i] = '*'; if (val > max) str[i - 1] = '+'; str[i] = '\0'; } static void print_hist(int fd) { int key; long value; long data[MAX_INDEX] = {}; char starstr[MAX_STARS]; int i; int max_ind = -1; long max_value = 0; for (key = 0; key < MAX_INDEX; key++) { bpf_lookup_elem(fd, &key, &value); data[key] = value; if (value && key > max_ind) max_ind = key; if (value > max_value) max_value = value; } printf(" syscall write() stats\n"); printf(" byte_size : count distribution\n"); for (i = 1; i <= max_ind + 1; i++) { stars(starstr, data[i - 1], max_value, MAX_STARS); printf("%8ld -> %-8ld : %-8ld |%-*s|\n", (1l << i) >> 1, (1l << i) - 1, data[i - 1], MAX_STARS, starstr); } } static void int_exit(int sig) { print_hist(map_fd[1]); exit(0); } int main(int ac, char **argv) { char filename[256]; long key, next_key, value; FILE *f; int i; snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); signal(SIGINT, int_exit); /* start 'ping' in the background to have some kfree_skb events */ f = popen("ping -c5 localhost", "r"); (void) f; /* start 'dd' in the background to have plenty of 'write' syscalls */ f = popen("dd if=/dev/zero of=/dev/null count=5000000", "r"); (void) f; if (load_bpf_file(filename)) { printf("%s", bpf_log_buf); return 1; } for (i = 0; i < 5; i++) { key = 0; while (bpf_get_next_key(map_fd[0], &key, &next_key) == 0) { bpf_lookup_elem(map_fd[0], &next_key, &value); printf("location 0x%lx count %ld\n", next_key, value); key = next_key; } if (key) printf("\n"); sleep(1); } print_hist(map_fd[1]); return 0; }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
You can’t perform that action at this time.