diff --git a/README.md b/README.md index 6345134443f7..3eb9ce5b66cb 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ detail of how this all works. First, we should include the BPF class from the bpf module: ```python -from bpf import BPF +from bcc import BPF ``` Since the C code is so short, we will embed it inside the python script. @@ -158,7 +158,7 @@ argument). The `get_table` API returns an object that gives dict-style access to the stats BPF map. The python program could use that handle to modify the kernel table as well. ```python -from bpf import BPF +from bcc import BPF from time import sleep b = BPF(src_file="task_switch.c") diff --git a/SPECS/bcc.el6.spec.in b/SPECS/bcc.el6.spec.in index f37a57bfada7..3c4df2b04546 100644 --- a/SPECS/bcc.el6.spec.in +++ b/SPECS/bcc.el6.spec.in @@ -96,15 +96,14 @@ Summary: Examples for BPF Compiler Collection (BCC) %description -n libbcc-examples Examples for BPF Compiler Collection (BCC) -%package -n python-bpf +%package -n python-bcc Summary: Python bindings for BPF Compiler Collection (BCC) -%description -n python-bpf +%description -n python-bcc Python bindings for BPF Compiler Collection (BCC) -%files -n python-bpf -%{python_sitelib}/bpf* +%files -n python-bcc +%{python_sitelib}/bcc* %exclude %{python_sitelib}/*.egg-info -/usr/bin/bpf-run %files -n libbcc /usr/lib64/* diff --git a/SPECS/bcc.el7.spec.in b/SPECS/bcc.el7.spec.in index fa173d499aff..c3c0dfe6f548 100644 --- a/SPECS/bcc.el7.spec.in +++ b/SPECS/bcc.el7.spec.in @@ -65,15 +65,14 @@ Summary: Examples for BPF Compiler Collection (BCC) %description -n libbcc-examples Examples for BPF Compiler Collection (BCC) -%package -n python-bpf +%package -n python-bcc Summary: Python bindings for BPF Compiler Collection (BCC) -%description -n python-bpf +%description -n python-bcc Python bindings for BPF Compiler Collection (BCC) -%files -n python-bpf -%{python_sitelib}/bpf* +%files -n python-bcc +%{python_sitelib}/bcc* %exclude %{python_sitelib}/*.egg-info -/usr/bin/bpf-run %files -n libbcc /usr/lib64/* diff --git a/SPECS/bcc.f22.spec.in b/SPECS/bcc.f22.spec.in index fa173d499aff..c3c0dfe6f548 100644 --- a/SPECS/bcc.f22.spec.in +++ b/SPECS/bcc.f22.spec.in @@ -65,15 +65,14 @@ Summary: Examples for BPF Compiler Collection (BCC) %description -n libbcc-examples Examples for BPF Compiler Collection (BCC) -%package -n python-bpf +%package -n python-bcc Summary: Python bindings for BPF Compiler Collection (BCC) -%description -n python-bpf +%description -n python-bcc Python bindings for BPF Compiler Collection (BCC) -%files -n python-bpf -%{python_sitelib}/bpf* +%files -n python-bcc +%{python_sitelib}/bcc* %exclude %{python_sitelib}/*.egg-info -/usr/bin/bpf-run %files -n libbcc /usr/lib64/* diff --git a/debian/control b/debian/control index b94e0d4a4a2d..40bfe6bed02d 100644 --- a/debian/control +++ b/debian/control @@ -18,7 +18,7 @@ Architecture: any Depends: libbcc Description: Shared Library for BPF Compiler Collection (BCC) -Package: python-bpf +Package: python-bcc Architecture: all Depends: libbcc, python Description: Python wrappers for BPF Compiler Collection (BCC) diff --git a/examples/bitehist.py b/examples/bitehist.py index eb0518ad4be6..9bcfb5d4e5fa 100755 --- a/examples/bitehist.py +++ b/examples/bitehist.py @@ -15,7 +15,7 @@ # # 15-Aug-2015 Brendan Gregg Created this. -from bpf import BPF +from bcc import BPF from ctypes import c_ushort, c_int, c_ulonglong from time import sleep from sys import argv diff --git a/examples/disksnoop.py b/examples/disksnoop.py index f65e524320d4..c73bab9d3c49 100755 --- a/examples/disksnoop.py +++ b/examples/disksnoop.py @@ -11,7 +11,7 @@ # 11-Aug-2015 Brendan Gregg Created this. from __future__ import print_function -from bpf import BPF +from bcc import BPF import sys REQ_WRITE = 1 # from include/linux/blk_types.h diff --git a/examples/distributed_bridge/tunnel.py b/examples/distributed_bridge/tunnel.py index 84dfaabb42ca..06ebbf1ba51f 100755 --- a/examples/distributed_bridge/tunnel.py +++ b/examples/distributed_bridge/tunnel.py @@ -3,7 +3,7 @@ # Licensed under the Apache License, Version 2.0 (the "License") from sys import argv -from bpf import BPF +from bcc import BPF from builtins import input from ctypes import c_int, c_uint from http.server import HTTPServer, SimpleHTTPRequestHandler diff --git a/examples/distributed_bridge/tunnel_mesh.py b/examples/distributed_bridge/tunnel_mesh.py index 64700a176412..ad5c5c6ebaeb 100644 --- a/examples/distributed_bridge/tunnel_mesh.py +++ b/examples/distributed_bridge/tunnel_mesh.py @@ -3,7 +3,7 @@ # Licensed under the Apache License, Version 2.0 (the "License") from sys import argv -from bpf import BPF +from bcc import BPF from builtins import input from ctypes import c_int, c_uint from http.server import HTTPServer, SimpleHTTPRequestHandler diff --git a/examples/hello_world.py b/examples/hello_world.py index 2ad21c6905ff..77b2c2b877a0 100755 --- a/examples/hello_world.py +++ b/examples/hello_world.py @@ -5,7 +5,7 @@ # run in project examples directory with: # sudo ./hello_world.py" -from bpf import BPF +from bcc import BPF prog = """ int hello(void *ctx) { diff --git a/examples/simple_tc.py b/examples/simple_tc.py index f0258e504826..4dd8aa5ca9d4 100755 --- a/examples/simple_tc.py +++ b/examples/simple_tc.py @@ -2,7 +2,7 @@ # Copyright (c) PLUMgrid, Inc. # Licensed under the Apache License, Version 2.0 (the "License") -from bpf import BPF +from bcc import BPF from pyroute2 import IPRoute ipr = IPRoute() diff --git a/examples/task_switch.py b/examples/task_switch.py index c42d6377cb16..43a4f3f8d0b2 100755 --- a/examples/task_switch.py +++ b/examples/task_switch.py @@ -2,7 +2,7 @@ # Copyright (c) PLUMgrid, Inc. # Licensed under the Apache License, Version 2.0 (the "License") -from bpf import BPF +from bcc import BPF from time import sleep b = BPF(src_file="task_switch.c") diff --git a/examples/tc_neighbor_sharing.py b/examples/tc_neighbor_sharing.py index da2877c9b58c..f2ec8a859586 100755 --- a/examples/tc_neighbor_sharing.py +++ b/examples/tc_neighbor_sharing.py @@ -25,7 +25,7 @@ # pass() | -from bpf import BPF +from bcc import BPF from pyroute2 import IPRoute, NetNS, IPDB, NSPopen from simulation import Simulation import sys diff --git a/examples/tunnel_monitor/monitor.py b/examples/tunnel_monitor/monitor.py index 057d6c42a60a..bac3420ec494 100644 --- a/examples/tunnel_monitor/monitor.py +++ b/examples/tunnel_monitor/monitor.py @@ -2,7 +2,7 @@ # Copyright (c) PLUMgrid, Inc. # Licensed under the Apache License, Version 2.0 (the "License") -from bpf import BPF +from bcc import BPF from ctypes import c_uint, c_int, c_ulonglong, Structure import json from netaddr import IPAddress diff --git a/examples/vfsreadlat.py b/examples/vfsreadlat.py index 6c61c22551ea..784b6095462b 100755 --- a/examples/vfsreadlat.py +++ b/examples/vfsreadlat.py @@ -15,7 +15,7 @@ # # 15-Aug-2015 Brendan Gregg Created this. -from bpf import BPF +from bcc import BPF from ctypes import c_ushort, c_int, c_ulonglong from time import sleep from sys import argv diff --git a/examples/vlan_learning.py b/examples/vlan_learning.py index a9bef1130c77..200062f10528 100644 --- a/examples/vlan_learning.py +++ b/examples/vlan_learning.py @@ -23,7 +23,7 @@ # phys | veth | # switch | | -from bpf import BPF +from bcc import BPF from builtins import input from pyroute2 import IPRoute, NetNS, IPDB, NSPopen from random import shuffle diff --git a/src/python/CMakeLists.txt b/src/python/CMakeLists.txt index 0e0476430fdd..9f76137df361 100644 --- a/src/python/CMakeLists.txt +++ b/src/python/CMakeLists.txt @@ -5,18 +5,17 @@ macro(symlink_file SRC DST) execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${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) +symlink_file(${CMAKE_CURRENT_SOURCE_DIR}/bcc ${CMAKE_CURRENT_BINARY_DIR}/bcc) -set(PIP_INSTALLABLE "${CMAKE_CURRENT_BINARY_DIR}/dist/bpf-${REVISION}.tar.gz") +set(PIP_INSTALLABLE "${CMAKE_CURRENT_BINARY_DIR}/dist/bcc-${REVISION}.tar.gz") configure_file(setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/setup.py @ONLY) # build the pip installable add_custom_command(OUTPUT ${PIP_INSTALLABLE} COMMAND python setup.py sdist WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bpf/__init__.py ${CMAKE_CURRENT_BINARY_DIR}/setup.py + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bcc/__init__.py ${CMAKE_CURRENT_BINARY_DIR}/setup.py ) -add_custom_target(bpf_py ALL DEPENDS ${PIP_INSTALLABLE}) +add_custom_target(bcc_py ALL DEPENDS ${PIP_INSTALLABLE}) if(EXISTS "/etc/debian_version") set(PYTHON_FLAGS "${PYTHON_FLAGS} --install-layout deb") diff --git a/src/python/MANIFEST b/src/python/MANIFEST index 79f8a3152aac..e72a5376fd12 100644 --- a/src/python/MANIFEST +++ b/src/python/MANIFEST @@ -1,4 +1,3 @@ # file GENERATED by distutils, do NOT edit setup.py -bpf/__init__.py -bpf-run +bcc/__init__.py diff --git a/src/python/bpf/__init__.py b/src/python/bcc/__init__.py similarity index 100% rename from src/python/bpf/__init__.py rename to src/python/bcc/__init__.py diff --git a/src/python/bpf-run b/src/python/bpf-run deleted file mode 100755 index b97cdb7689bd..000000000000 --- a/src/python/bpf-run +++ /dev/null @@ -1,96 +0,0 @@ -#!/usr/bin/env python - -import sys - -USAGE = """\ -usage: {argv0} -p probe_func -c cmd - -c cmd contents of the program to run, omitting prototype (required) - -d name dump table upon exit - -f format format string to apply to trace output (see python str.format()) - -n sec run for 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, World!\\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:f: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 - format_str = None - - for o, a in opts: - if o == "-c": runcmd = a - if o == "-d": dump_tables.append(a) - if o == "-f": format_str = a - if o == "-h": print_usage_and_exit(0) - if o == "-n": nsec = int(a) - if o == "-p": probe_fn = a - if o == "-t": trace = 1 - if o == "-v": verbose += 1 - - 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) - line = line.rstrip() - if format_str: - args=line.split(None, 5) - line = format_str.format(*args) - print(line) - sys.stdout.flush() - elif nsec: - signal.pause() - except KeyboardInterrupt: - pass - - if dump_tables: - print("Table dump not yet implemented") - -if __name__ == "__main__": - main() diff --git a/src/python/setup.py.in b/src/python/setup.py.in index 40afa0515dc2..8e05d4fe9aa7 100644 --- a/src/python/setup.py.in +++ b/src/python/setup.py.in @@ -7,12 +7,11 @@ import sys if os.environ.get('DESTDIR'): sys.argv += ['--root', os.environ['DESTDIR']] -setup(name='bpf', +setup(name='bcc', version='@REVISION@', description='BPF Loader Library', author='Brenden Blanco', author_email='bblanco@plumgrid.com', - url='http://plumgrid.com', - packages=['bpf'], - scripts=['bpf-run'], + url='https://github.com/iovisor/bcc', + packages=['bcc'], platforms=['Linux']) diff --git a/tests/cc/test_brb.py b/tests/cc/test_brb.py index 8362286e3edf..005158d8410e 100755 --- a/tests/cc/test_brb.py +++ b/tests/cc/test_brb.py @@ -63,7 +63,7 @@ from ctypes import c_uint from netaddr import IPAddress, EUI -from bpf import BPF +from bcc import BPF from pyroute2 import IPRoute, NetNS, IPDB, NSPopen import sys from time import sleep diff --git a/tests/cc/test_brb2.py b/tests/cc/test_brb2.py index 69ce6040f99f..e4d3b200a9f5 100755 --- a/tests/cc/test_brb2.py +++ b/tests/cc/test_brb2.py @@ -55,7 +55,7 @@ # 9: OK from ctypes import c_uint -from bpf import BPF +from bcc import BPF from pyroute2 import IPRoute, NetNS, IPDB, NSPopen import sys from time import sleep diff --git a/tests/cc/test_call1.py b/tests/cc/test_call1.py index eea364a6fac3..68d68de5b0ae 100755 --- a/tests/cc/test_call1.py +++ b/tests/cc/test_call1.py @@ -4,7 +4,7 @@ from ctypes import c_ushort, c_int, c_ulonglong from netaddr import IPAddress -from bpf import BPF +from bcc import BPF from pyroute2 import IPRoute from socket import socket, AF_INET, SOCK_DGRAM import sys diff --git a/tests/cc/test_clang.py b/tests/cc/test_clang.py index b41e40843d06..276f5eb86a59 100755 --- a/tests/cc/test_clang.py +++ b/tests/cc/test_clang.py @@ -2,7 +2,7 @@ # Copyright (c) PLUMgrid, Inc. # Licensed under the Apache License, Version 2.0 (the "License") -from bpf import BPF +from bcc import BPF from unittest import main, TestCase class TestClang(TestCase): diff --git a/tests/cc/test_stat1.py b/tests/cc/test_stat1.py index 7e9415f328be..98ff756ea25c 100755 --- a/tests/cc/test_stat1.py +++ b/tests/cc/test_stat1.py @@ -7,7 +7,7 @@ from ctypes import c_uint, c_ulong, Structure from netaddr import IPAddress -from bpf import BPF +from bcc import BPF from subprocess import check_call import sys from unittest import main, TestCase diff --git a/tests/cc/test_trace1.py b/tests/cc/test_trace1.py index a009bb6a5d4e..685c9468c482 100755 --- a/tests/cc/test_trace1.py +++ b/tests/cc/test_trace1.py @@ -3,7 +3,7 @@ # Licensed under the Apache License, Version 2.0 (the "License") from ctypes import c_uint, c_ulong, Structure -from bpf import BPF +from bcc import BPF import os from time import sleep import sys diff --git a/tests/cc/test_trace2.py b/tests/cc/test_trace2.py index dbd06e2b7cb2..3d38d0217d0a 100755 --- a/tests/cc/test_trace2.py +++ b/tests/cc/test_trace2.py @@ -3,7 +3,7 @@ # Licensed under the Apache License, Version 2.0 (the "License") from ctypes import c_uint, c_ulong, Structure -from bpf import BPF +from bcc import BPF from time import sleep import sys from unittest import main, TestCase diff --git a/tests/cc/test_trace3.py b/tests/cc/test_trace3.py index 2f05f3a931c0..d14b089e317b 100755 --- a/tests/cc/test_trace3.py +++ b/tests/cc/test_trace3.py @@ -3,7 +3,7 @@ # Licensed under the Apache License, Version 2.0 (the "License") from ctypes import c_uint, c_ulong, Structure -from bpf import BPF +from bcc import BPF from time import sleep import sys from unittest import main, TestCase diff --git a/tests/cc/test_trace4.py b/tests/cc/test_trace4.py index 2cb94c06025b..bcfbfdabd6b8 100755 --- a/tests/cc/test_trace4.py +++ b/tests/cc/test_trace4.py @@ -2,7 +2,7 @@ # Copyright (c) PLUMgrid, Inc. # Licensed under the Apache License, Version 2.0 (the "License") -from bpf import BPF +from bcc import BPF import os import sys from unittest import main, TestCase diff --git a/tests/cc/test_xlate1.py b/tests/cc/test_xlate1.py index a5f3fa8b820e..4e1eb7887a5a 100755 --- a/tests/cc/test_xlate1.py +++ b/tests/cc/test_xlate1.py @@ -3,7 +3,7 @@ # Licensed under the Apache License, Version 2.0 (the "License") from netaddr import IPAddress -from bpf import BPF +from bcc import BPF from pyroute2 import IPRoute from socket import socket, AF_INET, SOCK_DGRAM from subprocess import call diff --git a/tools/pidpersec b/tools/pidpersec index 75ceaa754f6a..7e23fbbde7db 100755 --- a/tools/pidpersec +++ b/tools/pidpersec @@ -13,7 +13,7 @@ # # 11-Aug-2015 Brendan Gregg Created this. -from bpf import BPF +from bcc import BPF from ctypes import c_ushort, c_int, c_ulonglong from time import sleep, strftime diff --git a/tools/syncsnoop b/tools/syncsnoop index 869ca7dfc0ab..4df1931a4be2 100755 --- a/tools/syncsnoop +++ b/tools/syncsnoop @@ -12,7 +12,7 @@ # 13-Aug-2015 Brendan Gregg Created this. from __future__ import print_function -from bpf import BPF +from bcc import BPF import sys # load BPF program diff --git a/tools/vfscount b/tools/vfscount index 70f2f3ac4552..9d06d7e85382 100755 --- a/tools/vfscount +++ b/tools/vfscount @@ -11,7 +11,7 @@ # 14-Aug-2015 Brendan Gregg Created this. from __future__ import print_function -from bpf import BPF +from bcc import BPF from ctypes import c_ushort, c_int, c_ulonglong from time import sleep, strftime from sys import stderr diff --git a/tools/vfsstat b/tools/vfsstat index d074faf607f1..59255162bff7 100755 --- a/tools/vfsstat +++ b/tools/vfsstat @@ -13,7 +13,7 @@ # 14-Aug-2015 Brendan Gregg Created this. from __future__ import print_function -from bpf import BPF +from bcc import BPF from ctypes import c_ushort, c_int, c_ulonglong from time import sleep, strftime from sys import argv