Skip to content

Instantly share code, notes, and snippets.

@raffysommy
Created August 6, 2018 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raffysommy/1dabe5bf9487d974f3acd1f7a32ed01c to your computer and use it in GitHub Desktop.
Save raffysommy/1dabe5bf9487d974f3acd1f7a32ed01c to your computer and use it in GitHub Desktop.
#!/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