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
615db324
Commit
615db324
authored
Aug 17, 2015
by
4ast
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #133 from iovisor/bblanco_dev
Add bpf-run command line tool
parents
ada05c25
f1edfe43
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
92 additions
and
0 deletions
+92
-0
src/python/CMakeLists.txt
src/python/CMakeLists.txt
+1
-0
src/python/MANIFEST
src/python/MANIFEST
+1
-0
src/python/bpf-run
src/python/bpf-run
+89
-0
src/python/setup.py.in
src/python/setup.py.in
+1
-0
No files found.
src/python/CMakeLists.txt
View file @
615db324
...
...
@@ -6,6 +6,7 @@ macro(symlink_file SRC DST)
endmacro
()
symlink_file
(
${
CMAKE_CURRENT_SOURCE_DIR
}
/bpf
${
CMAKE_CURRENT_BINARY_DIR
}
/bpf
)
symlink_file
(
${
CMAKE_CURRENT_SOURCE_DIR
}
/bpf-run
${
CMAKE_CURRENT_BINARY_DIR
}
/bpf-run
)
set
(
PIP_INSTALLABLE
"
${
CMAKE_CURRENT_BINARY_DIR
}
/dist/bpf-
${
REVISION
}
.tar.gz"
)
configure_file
(
setup.py.in
${
CMAKE_CURRENT_BINARY_DIR
}
/setup.py @ONLY
)
...
...
src/python/MANIFEST
View file @
615db324
# file GENERATED by distutils, do NOT edit
setup.py
bpf/__init__.py
bpf-run
src/python/bpf-run
0 → 100755
View file @
615db324
#!/usr/bin/env python
import
sys
USAGE
=
"""
\
usage: {argv0} <opts> -p probe_func -c cmd
-c cmd contents of the program to run, omitting prototype
-d name dump table <name> upon exit
-n sec run for <sec> seconds and then exit (default=-1)
-p probe kernel entry point to trace (required)
-t attach to kernel trace output
-v increase verbosity
example:
{argv0} -p sys_clone -c 'bpf_trace_printk("hello
\
\
n");' -t
\
"""
wrapper
=
"""
int run(void *ctx) {
%s
return 0;
}
"""
def
print_usage_and_exit
(
rc
,
msg
=
None
):
if
rc
!=
0
:
sys
.
stdout
=
sys
.
stderr
if
msg
:
print
(
msg
)
print
(
USAGE
.
format
(
argv0
=
sys
.
argv
[
0
]))
sys
.
exit
(
rc
)
def
main
():
import
getopt
import
os
import
signal
try
:
opts
,
args
=
getopt
.
getopt
(
sys
.
argv
[
1
:],
"c:d:hn:p:tv"
)
except
getopt
.
error
,
msg
:
print_usage_and_exit
(
2
,
msg
)
runcmd
=
None
probe_fn
=
None
trace
=
0
dump_tables
=
[]
verbose
=
0
nsec
=
0
for
o
,
a
in
opts
:
if
o
==
"-d"
:
dump_tables
.
append
(
a
)
if
o
==
"-n"
:
nsec
=
int
(
a
)
if
o
==
"-t"
:
trace
=
1
if
o
==
"-v"
:
verbose
+=
1
if
o
==
"-c"
:
runcmd
=
a
if
o
==
"-p"
:
probe_fn
=
a
if
o
==
"-h"
:
print_usage_and_exit
(
0
)
if
not
runcmd
or
not
probe_fn
:
print_usage_and_exit
(
2
,
"Error: -p and -c arguments are required"
)
from
bpf
import
BPF
b
=
BPF
(
text
=
wrapper
%
runcmd
,
debug
=
verbose
)
fn
=
b
.
load_func
(
"run"
,
BPF
.
KPROBE
)
BPF
.
attach_kprobe
(
fn
,
probe_fn
)
if
nsec
:
def
receive_alarm
(
signo
,
stack
):
os
.
kill
(
os
.
getpid
(),
signal
.
SIGINT
)
signal
.
signal
(
signal
.
SIGALRM
,
receive_alarm
)
signal
.
alarm
(
nsec
)
try
:
if
trace
:
with
open
(
"/sys/kernel/debug/tracing/trace_pipe"
)
as
f
:
while
True
:
line
=
f
.
readline
(
128
)
print
(
line
.
rstrip
())
sys
.
stdout
.
flush
()
elif
nsec
:
signal
.
pause
()
except
KeyboardInterrupt
:
pass
if
dump_tables
:
print
(
"Table dump not yet implemented"
)
if
__name__
==
"__main__"
:
main
()
src/python/setup.py.in
View file @
615db324
...
...
@@ -14,4 +14,5 @@ setup(name='bpf',
author_email='bblanco@plumgrid.com',
url='http://plumgrid.com',
packages=['bpf'],
scripts=['bpf-run'],
platforms=['Linux'])
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