forked from iovisor/bcc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add perf_output support for high rate events
This adds support for the bpf_perf_event_output command. This is intended for per-process events from bpf to userspace at high rate. The events from the bpf program can be completely customized. Signed-off-by: Brenden Blanco <[email protected]>
- Loading branch information
Brenden Blanco
committed
Nov 6, 2015
1 parent
33d0003
commit d0daf6a
Showing
8 changed files
with
237 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/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" | ||
|
||
import atexit | ||
from bcc import BPF | ||
import ctypes | ||
|
||
counter = 0 | ||
def cb(foo, data, size): | ||
global counter | ||
counter += 1 | ||
|
||
prog = """ | ||
BPF_PERF_ARRAY(events, 2); | ||
BPF_TABLE("array", int, u64, counters, 10); | ||
int kprobe__sys_write(void *ctx) { | ||
struct { | ||
u64 ts; | ||
} data = {bpf_ktime_get_ns()}; | ||
if (events.perf_output(ctx, 0, &data, sizeof(data)) < 0) | ||
bpf_trace_printk("perf_output failed\\n"); | ||
int zero = 0; | ||
u64 *val = counters.lookup(&zero); | ||
if (val) lock_xadd(val, 1); | ||
return 0; | ||
} | ||
""" | ||
b = BPF(text=prog) | ||
b["events"].open_perf_buffer(0, cb, None) | ||
|
||
@atexit.register | ||
def print_counter(): | ||
global counter | ||
global b | ||
print("counter = %d vs %d" % (counter, b["counters"][ctypes.c_int(0)].value)) | ||
|
||
while 1: | ||
b.kprobe_poll() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.