Skip to content

Instantly share code, notes, and snippets.

@raffysommy
Created August 6, 2018 18:48
Embed
What would you like to do?
#!/usr/bin/env python
# Copyright (c) PLUMgrid, Inc.
# Licensed under the Apache License, Version 2.0 (the "License")
# This is an example of tracing an event and printing custom fields.
# run in project examples directory with:
# sudo ./trace_fields.py"
from time import sleep
from bcc import BPF
import ctypes as ct
prog = """
BPF_HASH(start, u64);
BPF_HASH(start1, u64);
BPF_HASH(start2, u64);
int hello(void *ctx) {
bpf_trace_printk("Hello, World!\\n");
return 0;
}
"""
b = BPF(text=prog)
#b.attach_kprobe(event=b.get_syscall_fnname("clone"), fn_name="hello")
counts = b.get_table("start")
counts[ct.c_uint(0)]=ct.c_ulonglong(0)
counts = b.get_table("start1")
counts[ct.c_uint(4)]=ct.c_ulonglong(3)
counts = b.get_table("start2")
counts[ct.c_uint(6)]=ct.c_ulonglong(3)
val=counts[ct.c_uint(6)]
while 1:
sleep(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment