Commit 41d10e2b authored by Brenden Blanco's avatar Brenden Blanco

Add simple single file example

Signed-off-by: default avatarBrenden Blanco <bblanco@plumgrid.com>
parent 6c0311eb
#!/usr/bin/env python
# Copyright (c) PLUMgrid, Inc.
# Licensed under the Apache License, Version 2.0 (the "License")
# run in project directory with:
# sudo bash -c "PYTHONPATH=$PWD/src LD_LIBRARY_PATH=$PWD/build/src/cc examples/hello_world.py"
from bpf import BPF
from subprocess import call
prog = """
#include "src/cc/bpf_helpers.h"
BPF_EXPORT(hello)
int hello(void *ctx) {
char fmt[] = "Hello, World!\\n";
bpf_trace_printk(fmt, sizeof(fmt));
return 0;
};
"""
b = BPF(text=prog)
fn = b.load_func("hello", BPF.KPROBE)
BPF.attach_kprobe(fn, "sys_clone")
call(["cat", "/sys/kernel/debug/tracing/trace_pipe"])
......@@ -176,7 +176,7 @@ class BPF(object):
fn.sock = sock
@staticmethod
def attach_kprobe(fn, event, pid=-1, cpu=0, group_fd=-1):
def attach_kprobe(fn, event, pid=0, cpu=-1, group_fd=-1):
if not isinstance(fn, BPF.Function):
raise Exception("arg 1 must be of type BPF.Function")
ev_name = "p_" + event.replace("+", "_")
......
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