/
usr
/
share
/
doc
/
bpfcc-tools
/
examples
/
tracing
/
/usr/share/doc/bpfcc-tools/examples/tracing
mkdir
upload
Name
Size
Mode
Actions
biolatpcts.py
3312
0755
edit
dl
rm
biolatpcts_example.txt
650
0644
edit
dl
rm
bitehist.py
1397
0755
edit
dl
rm
bitehist_example.txt
1208
0644
edit
dl
rm
CMakeLists.txt
276
0644
edit
dl
rm
dddos.py
3818
0755
edit
dl
rm
dddos_example.txt
2112
0644
edit
dl
rm
disksnoop.py
1947
0755
edit
dl
rm
disksnoop_example.txt
1587
0644
edit
dl
rm
hello_fields.py
679
0755
edit
dl
rm
hello_perf_output.py
1270
0755
edit
dl
rm
hello_perf_output_using_ns.py
1843
0755
edit
dl
rm
kvm_hypercall.py
1520
0755
edit
dl
rm
kvm_hypercall.txt
1782
0644
edit
dl
rm
mallocstacks.py
1942
0755
edit
dl
rm
mysqld_query.py
1701
0755
edit
dl
rm
mysqld_query_example.txt
499
0644
edit
dl
rm
nflatency.py
6214
0755
edit
dl
rm
nodejs_http_server.py
1376
0755
edit
dl
rm
nodejs_http_server_example.txt
276
0644
edit
dl
rm
stacksnoop.py
3252
0755
edit
dl
rm
stacksnoop_example.txt
2871
0644
edit
dl
rm
stack_buildid_example.py
3106
0755
edit
dl
rm
strlen_count.py
1331
0755
edit
dl
rm
strlen_hist.py
1856
0755
edit
dl
rm
strlen_hist_ifunc.py
3800
0755
edit
dl
rm
strlen_snoop.py
1384
0755
edit
dl
rm
sync_timing.py
1390
0755
edit
dl
rm
task_switch.c
499
0644
edit
dl
rm
task_switch.py
486
0755
edit
dl
rm
tcpv4connect.py
2413
0755
edit
dl
rm
tcpv4connect_example.txt
1063
0644
edit
dl
rm
trace_fields.py
589
0755
edit
dl
rm
trace_perf_output.py
1600
0755
edit
dl
rm
undump.py
3602
0755
edit
dl
rm
undump_example.txt
886
0644
edit
dl
rm
urandomread-explicit.py
1511
0755
edit
dl
rm
urandomread.py
1032
0755
edit
dl
rm
urandomread_example.txt
675
0644
edit
dl
rm
vfsreadlat.c
896
0644
edit
dl
rm
vfsreadlat.py
1336
0755
edit
dl
rm
vfsreadlat_example.txt
3619
0644
edit
dl
rm
Edit:
/usr/share/doc/bpfcc-tools/examples/tracing/urandomread-explicit.py
(1511B)
#!/usr/bin/python # # urandomread-explicit Example of instrumenting a kernel tracepoint. # For Linux, uses BCC, BPF. Embedded C. # # This is an older example of instrumenting a tracepoint, which defines # the argument struct and makes an explicit call to attach_tracepoint(). # See urandomread for a newer version that uses TRACEPOINT_PROBE(). # # REQUIRES: Linux 4.7+ (BPF_PROG_TYPE_TRACEPOINT support). # # Test by running this, then in another shell, run: # dd if=/dev/urandom of=/dev/null bs=1k count=5 # # Copyright 2016 Netflix, Inc. # Licensed under the Apache License, Version 2.0 (the "License") from __future__ import print_function from bcc import BPF from bcc.utils import printb # define BPF program bpf_text = """ #include <uapi/linux/ptrace.h> struct urandom_read_args { // from /sys/kernel/debug/tracing/events/random/urandom_read/format u64 __unused__; u32 got_bits; u32 pool_left; u32 input_left; }; int printarg(struct urandom_read_args *args) { bpf_trace_printk("%d\\n", args->got_bits); return 0; } """ # load BPF program b = BPF(text=bpf_text) b.attach_tracepoint(tp="random:urandom_read", fn_name="printarg") # header print("%-18s %-16s %-6s %s" % ("TIME(s)", "COMM", "PID", "GOTBITS")) # format output while 1: try: (task, pid, cpu, flags, ts, msg) = b.trace_fields() except ValueError: continue except KeyboardInterrupt: exit() printb(b"%-18.9f %-16s %-6d %s" % (ts, task, pid, msg))
Save
cmd:
run