Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bcc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
bcc
Commits
734a3ecb
Commit
734a3ecb
authored
Jun 05, 2015
by
4ast
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #29 from iovisor/bblanco_dev
Add simple single file example
parents
6c0311eb
41d10e2b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
1 deletion
+24
-1
examples/hello_world.py
examples/hello_world.py
+23
-0
src/bpf.py
src/bpf.py
+1
-1
No files found.
examples/hello_world.py
0 → 100755
View file @
734a3ecb
#!/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"
])
src/bpf.py
View file @
734a3ecb
...
...
@@ -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
(
"+"
,
"_"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment