Commit 98d0bebb authored by Brenden Blanco's avatar Brenden Blanco

Update trace perf output with struct deserialize example

Signed-off-by: default avatarBrenden Blanco <bblanco@plumgrid.com>
parent 1d75282c
......@@ -8,20 +8,28 @@
import atexit
from bcc import BPF
import ctypes
import ctypes as ct
class Data(ct.Structure):
_fields_ = [("ts", ct.c_ulonglong),
("magic", ct.c_ulonglong)]
counter = 0
def cb(cpu, data, size):
assert size >= ct.sizeof(Data)
event = ct.cast(data, ct.POINTER(Data)).contents
print("[%0d] %f: %x" % (cpu, float(event.ts) / 1000000, event.magic))
global counter
counter += 1
prog = """
BPF_PERF_OUTPUT(events);
BPF_TABLE("array", int, u64, counters, 10);
int kprobe__sys_write(void *ctx) {
int kprobe__sys_clone(void *ctx) {
struct {
u64 ts;
} data = {bpf_ktime_get_ns()};
u64 magic;
} data = {bpf_ktime_get_ns(), 0x12345678};
int rc;
if ((rc = events.perf_submit(ctx, &data, sizeof(data))) < 0)
bpf_trace_printk("perf_output failed: %d\\n", rc);
......@@ -38,7 +46,7 @@ b["events"].open_perf_buffer(cb)
def print_counter():
global counter
global b
print("counter = %d vs %d" % (counter, b["counters"][ctypes.c_int(0)].value))
print("counter = %d vs %d" % (counter, b["counters"][ct.c_int(0)].value))
print("Tracing sys_write, try `dd if=/dev/zero of=/dev/null`")
print("Tracing... Hit Ctrl-C to end.")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment