Skip to content

Commit

Permalink
Merge pull request iovisor#1531 from natoscott/master
Browse files Browse the repository at this point in the history
Allow for sharing of python tools/ scripts
  • Loading branch information
yonghong-song committed Jan 22, 2018
2 parents fb8bbfe + 1a197db commit bb95ef2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/python/bcc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ def __init__(self, src_file="", hdr_file="", text=None, cb=None, debug=0,
if text:
self.module = lib.bpf_module_create_c_from_string(text.encode("ascii"),
self.debug, cflags_array, len(cflags_array))
if not self.module:
raise Exception("Failed to compile BPF text:\n%s" % text)
else:
src_file = BPF._find_file(src_file)
hdr_file = BPF._find_file(hdr_file)
Expand All @@ -296,9 +298,8 @@ def __init__(self, src_file="", hdr_file="", text=None, cb=None, debug=0,
else:
self.module = lib.bpf_module_create_c(src_file.encode("ascii"),
self.debug, cflags_array, len(cflags_array))

if not self.module:
raise Exception("Failed to compile BPF module %s" % src_file)
if not self.module:
raise Exception("Failed to compile BPF module %s" % src_file)

for usdt_context in usdt_contexts:
usdt_context.attach_uprobes(self)
Expand Down
6 changes: 5 additions & 1 deletion tools/biolatency.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
help="output interval, in seconds")
parser.add_argument("count", nargs="?", default=99999999,
help="number of outputs")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args()
countdown = int(args.count)
debug = 0
Expand Down Expand Up @@ -103,8 +105,10 @@
bpf_text = bpf_text.replace('STORAGE', 'BPF_HISTOGRAM(dist);')
bpf_text = bpf_text.replace('STORE',
'dist.increment(bpf_log2l(delta));')
if debug:
if debug or args.ebpf:
print(bpf_text)
if args.ebpf:
exit()

# load BPF program
b = BPF(text=bpf_text)
Expand Down
12 changes: 10 additions & 2 deletions tools/biotop.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
help="output interval, in seconds")
parser.add_argument("count", nargs="?", default=99999999,
help="number of outputs")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args()
interval = int(args.interval)
countdown = int(args.count)
Expand All @@ -55,7 +57,7 @@ def signal_ignore(signal, frame):
print()

# load BPF program
b = BPF(text="""
bpf_text = """
#include <uapi/linux/ptrace.h>
#include <linux/blkdev.h>
Expand Down Expand Up @@ -163,7 +165,13 @@ def signal_ignore(signal, frame):
return 0;
}
""", debug=0)
"""

if args.ebpf:
print(bpf_text)
exit()

b = BPF(text=bpf_text)
b.attach_kprobe(event="blk_account_io_start", fn_name="trace_pid_start")
b.attach_kprobe(event="blk_start_request", fn_name="trace_req_start")
b.attach_kprobe(event="blk_mq_start_request", fn_name="trace_req_start")
Expand Down
6 changes: 5 additions & 1 deletion tools/tcplife.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
help="comma-separated list of local ports to trace.")
parser.add_argument("-D", "--remoteport",
help="comma-separated list of remote ports to trace.")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args()
debug = 0

Expand Down Expand Up @@ -375,8 +377,10 @@
bpf_text = bpf_text.replace('FILTER_DPORT', '')
bpf_text = bpf_text.replace('FILTER_LPORT', '')

if debug:
if debug or args.ebpf:
print(bpf_text)
if args.ebpf:
exit()

# event data
TASK_COMM_LEN = 16 # linux/sched.h
Expand Down

0 comments on commit bb95ef2

Please sign in to comment.