Commit b334f110 authored by yonghong-song's avatar yonghong-song Committed by GitHub

Merge pull request #1570 from natoscott/master

continue adding --ebpf option to the python tools/ scripts
parents e6c75684 f13107a3
...@@ -40,6 +40,8 @@ parser.add_argument("interval", nargs="?", ...@@ -40,6 +40,8 @@ parser.add_argument("interval", nargs="?",
help="output interval, in seconds") help="output interval, in seconds")
parser.add_argument("count", nargs="?", default=99999999, parser.add_argument("count", nargs="?", default=99999999,
help="number of outputs") help="number of outputs")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
pid = args.pid pid = args.pid
countdown = int(args.count) countdown = int(args.count)
...@@ -183,8 +185,10 @@ if args.pid: ...@@ -183,8 +185,10 @@ if args.pid:
bpf_text = bpf_text.replace('FILTER_PID', 'pid != %s' % pid) bpf_text = bpf_text.replace('FILTER_PID', 'pid != %s' % pid)
else: else:
bpf_text = bpf_text.replace('FILTER_PID', '0') bpf_text = bpf_text.replace('FILTER_PID', '0')
if debug: if debug or args.ebpf:
print(bpf_text) print(bpf_text)
if args.ebpf:
exit()
# load BPF program # load BPF program
b = BPF(text=bpf_text) b = BPF(text=bpf_text)
......
...@@ -51,6 +51,8 @@ parser.add_argument("-p", "--pid", ...@@ -51,6 +51,8 @@ parser.add_argument("-p", "--pid",
help="trace this PID only") help="trace this PID only")
parser.add_argument("min_ms", nargs="?", default='10', parser.add_argument("min_ms", nargs="?", default='10',
help="minimum I/O duration to trace, in ms (default 10)") help="minimum I/O duration to trace, in ms (default 10)")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
min_ms = int(args.min_ms) min_ms = int(args.min_ms)
pid = args.pid pid = args.pid
...@@ -280,8 +282,10 @@ if args.pid: ...@@ -280,8 +282,10 @@ if args.pid:
bpf_text = bpf_text.replace('FILTER_PID', 'pid != %s' % pid) bpf_text = bpf_text.replace('FILTER_PID', 'pid != %s' % pid)
else: else:
bpf_text = bpf_text.replace('FILTER_PID', '0') bpf_text = bpf_text.replace('FILTER_PID', '0')
if debug: if debug or args.ebpf:
print(bpf_text) print(bpf_text)
if args.ebpf:
exit()
# kernel->user event data: struct data_t # kernel->user event data: struct data_t
DNAME_INLINE_LEN = 32 # linux/dcache.h DNAME_INLINE_LEN = 32 # linux/dcache.h
......
...@@ -44,6 +44,8 @@ parser.add_argument("interval", nargs="?", default=99999999, ...@@ -44,6 +44,8 @@ parser.add_argument("interval", nargs="?", default=99999999,
help="output interval, in seconds") help="output interval, in seconds")
parser.add_argument("count", nargs="?", default=99999999, parser.add_argument("count", nargs="?", default=99999999,
help="number of outputs") help="number of outputs")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
countdown = int(args.count) countdown = int(args.count)
debug = 0 debug = 0
...@@ -149,8 +151,10 @@ else: ...@@ -149,8 +151,10 @@ else:
bpf_text = bpf_text.replace('STORAGE', 'BPF_HISTOGRAM(dist);') bpf_text = bpf_text.replace('STORAGE', 'BPF_HISTOGRAM(dist);')
bpf_text = bpf_text.replace('STORE', bpf_text = bpf_text.replace('STORE',
'dist.increment(bpf_log2l(delta));') 'dist.increment(bpf_log2l(delta));')
if debug: if debug or args.ebpf:
print(bpf_text) print(bpf_text)
if args.ebpf:
exit()
b = BPF(text=bpf_text) b = BPF(text=bpf_text)
b.attach_kprobe(event="finish_task_switch", fn_name="sched_switch") b.attach_kprobe(event="finish_task_switch", fn_name="sched_switch")
......
...@@ -87,6 +87,8 @@ parser.add_argument("interval", nargs="?", default=-1, ...@@ -87,6 +87,8 @@ parser.add_argument("interval", nargs="?", default=-1,
help="output interval, in seconds") help="output interval, in seconds")
parser.add_argument("count", nargs="?", default=99999999, parser.add_argument("count", nargs="?", default=99999999,
help="number of outputs") help="number of outputs")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
countdown = int(args.count) countdown = int(args.count)
frequency = 99 frequency = 99
...@@ -155,8 +157,10 @@ int do_perf_event(struct bpf_perf_event_data *ctx) ...@@ -155,8 +157,10 @@ int do_perf_event(struct bpf_perf_event_data *ctx)
""" """
# code substitutions # code substitutions
if debug: if debug or args.ebpf:
print(bpf_text) print(bpf_text)
if args.ebpf:
exit()
# initialize BPF & perf_events # initialize BPF & perf_events
b = BPF(text=bpf_text) b = BPF(text=bpf_text)
......
...@@ -51,6 +51,8 @@ parser.add_argument("-x", "--exe", type=str, ...@@ -51,6 +51,8 @@ parser.add_argument("-x", "--exe", type=str,
dest="path", metavar="PATH", help="path to binary") dest="path", metavar="PATH", help="path to binary")
parser.add_argument("-m", "--threshold", type=int, default=1, parser.add_argument("-m", "--threshold", type=int, default=1,
help="trace queries slower than this threshold (ms)") help="trace queries slower than this threshold (ms)")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
threshold_ns = args.threshold * 1000000 threshold_ns = args.threshold * 1000000
...@@ -196,8 +198,10 @@ else: ...@@ -196,8 +198,10 @@ else:
bpf = BPF(text=program, usdt_contexts=usdts) bpf = BPF(text=program, usdt_contexts=usdts)
if args.verbose: if args.verbose or args.ebpf:
print(program) print(program)
if args.ebpf:
exit()
class Data(ct.Structure): class Data(ct.Structure):
_fields_ = [ _fields_ = [
......
...@@ -38,6 +38,8 @@ parser = argparse.ArgumentParser( ...@@ -38,6 +38,8 @@ parser = argparse.ArgumentParser(
epilog=examples) epilog=examples)
parser.add_argument("-a", "--all", action="store_true", parser.add_argument("-a", "--all", action="store_true",
help="trace all lookups (default is fails only)") help="trace all lookups (default is fails only)")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
# define BPF program # define BPF program
...@@ -132,6 +134,10 @@ class Data(ct.Structure): ...@@ -132,6 +134,10 @@ class Data(ct.Structure):
("filename", ct.c_char * MAX_FILE_LEN), ("filename", ct.c_char * MAX_FILE_LEN),
] ]
if args.ebpf:
print(bpf_text)
exit()
# initialize BPF # initialize BPF
b = BPF(text=bpf_text) b = BPF(text=bpf_text)
if args.all: if args.all:
......
...@@ -46,6 +46,8 @@ parser.add_argument("-l", "--line", ...@@ -46,6 +46,8 @@ parser.add_argument("-l", "--line",
help="only print commands where arg contains this line (regex)") help="only print commands where arg contains this line (regex)")
parser.add_argument("--max-args", default="20", parser.add_argument("--max-args", default="20",
help="maximum number of arguments parsed and displayed, defaults to 20") help="maximum number of arguments parsed and displayed, defaults to 20")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
# define BPF program # define BPF program
...@@ -128,8 +130,13 @@ int kretprobe__sys_execve(struct pt_regs *ctx) ...@@ -128,8 +130,13 @@ int kretprobe__sys_execve(struct pt_regs *ctx)
} }
""" """
bpf_text = bpf_text.replace("MAXARG", args.max_args)
if args.ebpf:
print(bpf_text)
exit()
# initialize BPF # initialize BPF
b = BPF(text=bpf_text.replace("MAXARG", args.max_args)) b = BPF(text=bpf_text)
# header # header
if args.timestamp: if args.timestamp:
......
...@@ -40,6 +40,8 @@ parser.add_argument("interval", nargs="?", ...@@ -40,6 +40,8 @@ parser.add_argument("interval", nargs="?",
help="output interval, in seconds") help="output interval, in seconds")
parser.add_argument("count", nargs="?", default=99999999, parser.add_argument("count", nargs="?", default=99999999,
help="number of outputs") help="number of outputs")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
pid = args.pid pid = args.pid
countdown = int(args.count) countdown = int(args.count)
...@@ -163,8 +165,10 @@ if args.pid: ...@@ -163,8 +165,10 @@ if args.pid:
bpf_text = bpf_text.replace('FILTER_PID', 'pid != %s' % pid) bpf_text = bpf_text.replace('FILTER_PID', 'pid != %s' % pid)
else: else:
bpf_text = bpf_text.replace('FILTER_PID', '0') bpf_text = bpf_text.replace('FILTER_PID', '0')
if debug: if debug or args.ebpf:
print(bpf_text) print(bpf_text)
if args.ebpf:
exit()
# load BPF program # load BPF program
b = BPF(text=bpf_text) b = BPF(text=bpf_text)
......
...@@ -51,6 +51,8 @@ parser.add_argument("-p", "--pid", ...@@ -51,6 +51,8 @@ parser.add_argument("-p", "--pid",
help="trace this PID only") help="trace this PID only")
parser.add_argument("min_ms", nargs="?", default='10', parser.add_argument("min_ms", nargs="?", default='10',
help="minimum I/O duration to trace, in ms (default 10)") help="minimum I/O duration to trace, in ms (default 10)")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
min_ms = int(args.min_ms) min_ms = int(args.min_ms)
pid = args.pid pid = args.pid
...@@ -274,8 +276,10 @@ if args.pid: ...@@ -274,8 +276,10 @@ if args.pid:
bpf_text = bpf_text.replace('FILTER_PID', 'pid != %s' % pid) bpf_text = bpf_text.replace('FILTER_PID', 'pid != %s' % pid)
else: else:
bpf_text = bpf_text.replace('FILTER_PID', '0') bpf_text = bpf_text.replace('FILTER_PID', '0')
if debug: if debug or args.ebpf:
print(bpf_text) print(bpf_text)
if args.ebpf:
exit()
# kernel->user event data: struct data_t # kernel->user event data: struct data_t
DNAME_INLINE_LEN = 32 # linux/dcache.h DNAME_INLINE_LEN = 32 # linux/dcache.h
......
...@@ -34,6 +34,8 @@ parser = argparse.ArgumentParser( ...@@ -34,6 +34,8 @@ parser = argparse.ArgumentParser(
epilog=examples) epilog=examples)
parser.add_argument("-p", "--pid", parser.add_argument("-p", "--pid",
help="trace this PID only") help="trace this PID only")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
debug = 0 debug = 0
...@@ -114,8 +116,10 @@ if args.pid: ...@@ -114,8 +116,10 @@ if args.pid:
'if (pid != %s) { return 0; }' % args.pid) 'if (pid != %s) { return 0; }' % args.pid)
else: else:
bpf_text = bpf_text.replace('FILTER', '') bpf_text = bpf_text.replace('FILTER', '')
if debug: if debug or args.ebpf:
print(bpf_text) print(bpf_text)
if args.ebpf:
exit()
# initialize BPF # initialize BPF
b = BPF(text=bpf_text) b = BPF(text=bpf_text)
......
...@@ -50,6 +50,8 @@ parser.add_argument("-a", "--all-files", action="store_true", ...@@ -50,6 +50,8 @@ parser.add_argument("-a", "--all-files", action="store_true",
help="include non-regular file types (sockets, FIFOs, etc)") help="include non-regular file types (sockets, FIFOs, etc)")
parser.add_argument("min_ms", nargs="?", default='10', parser.add_argument("min_ms", nargs="?", default='10',
help="minimum I/O duration to trace, in ms (default 10)") help="minimum I/O duration to trace, in ms (default 10)")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
min_ms = int(args.min_ms) min_ms = int(args.min_ms)
tgid = args.tgid tgid = args.tgid
...@@ -185,11 +187,13 @@ if args.all_files: ...@@ -185,11 +187,13 @@ if args.all_files:
else: else:
bpf_text = bpf_text.replace('TYPE_FILTER', '!S_ISREG(mode)') bpf_text = bpf_text.replace('TYPE_FILTER', '!S_ISREG(mode)')
if debug: if debug or args.ebpf:
print(bpf_text) print(bpf_text)
if args.ebpf:
exit()
# initialize BPF # initialize BPF
b = BPF(text=bpf_text,) b = BPF(text=bpf_text)
# I'd rather trace these via new_sync_read/new_sync_write (which used to be # I'd rather trace these via new_sync_read/new_sync_write (which used to be
# do_sync_read/do_sync_write), but those became static. So trace these from # do_sync_read/do_sync_write), but those became static. So trace these from
......
...@@ -47,6 +47,8 @@ parser.add_argument("interval", nargs="?", default=1, ...@@ -47,6 +47,8 @@ parser.add_argument("interval", nargs="?", default=1,
help="output interval, in seconds") help="output interval, in seconds")
parser.add_argument("count", nargs="?", default=99999999, parser.add_argument("count", nargs="?", default=99999999,
help="number of outputs") help="number of outputs")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
interval = int(args.interval) interval = int(args.interval)
countdown = int(args.count) countdown = int(args.count)
...@@ -149,8 +151,10 @@ if args.all_files: ...@@ -149,8 +151,10 @@ if args.all_files:
else: else:
bpf_text = bpf_text.replace('TYPE_FILTER', '!S_ISREG(mode)') bpf_text = bpf_text.replace('TYPE_FILTER', '!S_ISREG(mode)')
if debug: if debug or args.ebpf:
print(bpf_text) print(bpf_text)
if args.ebpf:
exit()
# initialize BPF # initialize BPF
b = BPF(text=bpf_text) b = BPF(text=bpf_text)
......
...@@ -63,6 +63,8 @@ parser.add_argument("-v", "--verbose", action="store_true", ...@@ -63,6 +63,8 @@ parser.add_argument("-v", "--verbose", action="store_true",
help="print the BPF program (for debugging purposes)") help="print the BPF program (for debugging purposes)")
parser.add_argument("pattern", parser.add_argument("pattern",
help="search expression for functions") help="search expression for functions")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
def bail(error): def bail(error):
...@@ -184,8 +186,10 @@ else: ...@@ -184,8 +186,10 @@ else:
bpf_text = bpf_text.replace('ENTRYSTORE', '') bpf_text = bpf_text.replace('ENTRYSTORE', '')
bpf_text = bpf_text.replace('STORE', bpf_text = bpf_text.replace('STORE',
'dist.increment(bpf_log2l(delta));') 'dist.increment(bpf_log2l(delta));')
if args.verbose: if args.verbose or args.ebpf:
print(bpf_text) print(bpf_text)
if args.ebpf:
exit()
# signal handler # signal handler
def signal_ignore(signal, frame): def signal_ignore(signal, frame):
......
...@@ -55,6 +55,8 @@ parser.add_argument("-v", "--verbose", action="store_true", ...@@ -55,6 +55,8 @@ parser.add_argument("-v", "--verbose", action="store_true",
help="print the BPF program for debugging purposes") help="print the BPF program for debugging purposes")
parser.add_argument(metavar="function", nargs="+", dest="functions", parser.add_argument(metavar="function", nargs="+", dest="functions",
help="function(s) to trace") help="function(s) to trace")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
# fractions are allowed, but rounded to an integer nanosecond # fractions are allowed, but rounded to an integer nanosecond
...@@ -165,8 +167,10 @@ int trace_%d(struct pt_regs *ctx) { ...@@ -165,8 +167,10 @@ int trace_%d(struct pt_regs *ctx) {
} }
""" % (i, i) """ % (i, i)
if args.verbose: if args.verbose or args.ebpf:
print(bpf_text) print(bpf_text)
if args.ebpf:
exit()
b = BPF(text=bpf_text) b = BPF(text=bpf_text)
......
...@@ -31,6 +31,8 @@ parser = argparse.ArgumentParser( ...@@ -31,6 +31,8 @@ parser = argparse.ArgumentParser(
epilog=examples) epilog=examples)
parser.add_argument("-p", "--pid", help="trace this PID only", type=int, parser.add_argument("-p", "--pid", help="trace this PID only", type=int,
default=-1) default=-1)
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
# load BPF program # load BPF program
...@@ -94,6 +96,10 @@ int do_return(struct pt_regs *ctx) { ...@@ -94,6 +96,10 @@ int do_return(struct pt_regs *ctx) {
return 0; return 0;
} }
""" """
if args.ebpf:
print(bpf_text)
exit()
b = BPF(text=bpf_text) b = BPF(text=bpf_text)
b.attach_uprobe(name="c", sym="getaddrinfo", fn_name="do_entry", pid=args.pid) b.attach_uprobe(name="c", sym="getaddrinfo", fn_name="do_entry", pid=args.pid)
b.attach_uprobe(name="c", sym="gethostbyname", fn_name="do_entry", b.attach_uprobe(name="c", sym="gethostbyname", fn_name="do_entry",
......
...@@ -41,6 +41,8 @@ parser.add_argument("interval", nargs="?", default=99999999, ...@@ -41,6 +41,8 @@ parser.add_argument("interval", nargs="?", default=99999999,
help="output interval, in seconds") help="output interval, in seconds")
parser.add_argument("outputs", nargs="?", default=99999999, parser.add_argument("outputs", nargs="?", default=99999999,
help="number of outputs") help="number of outputs")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
countdown = int(args.outputs) countdown = int(args.outputs)
if args.count and (args.dist or args.nanoseconds): if args.count and (args.dist or args.nanoseconds):
...@@ -136,8 +138,10 @@ else: ...@@ -136,8 +138,10 @@ else:
'bpf_probe_read(&key.name, sizeof(key.name), name);' + 'bpf_probe_read(&key.name, sizeof(key.name), name);' +
'u64 zero = 0, *vp = dist.lookup_or_init(&key, &zero);' + 'u64 zero = 0, *vp = dist.lookup_or_init(&key, &zero);' +
'(*vp) += delta;') '(*vp) += delta;')
if debug: if debug or args.ebpf:
print(bpf_text) print(bpf_text)
if args.ebpf:
exit()
# load BPF program # load BPF program
b = BPF(text=bpf_text) b = BPF(text=bpf_text)
......
...@@ -32,6 +32,8 @@ parser.add_argument("-x", "--failed", action="store_true", ...@@ -32,6 +32,8 @@ parser.add_argument("-x", "--failed", action="store_true",
help="only show failed kill syscalls") help="only show failed kill syscalls")
parser.add_argument("-p", "--pid", parser.add_argument("-p", "--pid",
help="trace this PID only") help="trace this PID only")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
debug = 0 debug = 0
...@@ -102,8 +104,10 @@ if args.pid: ...@@ -102,8 +104,10 @@ if args.pid:
'if (pid != %s) { return 0; }' % args.pid) 'if (pid != %s) { return 0; }' % args.pid)
else: else:
bpf_text = bpf_text.replace('FILTER', '') bpf_text = bpf_text.replace('FILTER', '')
if debug: if debug or args.ebpf:
print(bpf_text) print(bpf_text)
if args.ebpf:
exit()
# initialize BPF # initialize BPF
b = BPF(text=bpf_text) b = BPF(text=bpf_text)
......
...@@ -28,10 +28,12 @@ parser.add_argument( ...@@ -28,10 +28,12 @@ parser.add_argument(
help="Sample one in this many number of cache reference / miss events") help="Sample one in this many number of cache reference / miss events")
parser.add_argument( parser.add_argument(
"duration", nargs="?", default=10, help="Duration, in seconds, to run") "duration", nargs="?", default=10, help="Duration, in seconds, to run")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
# load BPF program # load BPF program
b = BPF(text=""" bpf_text="""
#include <linux/ptrace.h> #include <linux/ptrace.h>
#include <uapi/linux/bpf_perf_event.h> #include <uapi/linux/bpf_perf_event.h>
...@@ -71,8 +73,13 @@ int on_cache_ref(struct bpf_perf_event_data *ctx) { ...@@ -71,8 +73,13 @@ int on_cache_ref(struct bpf_perf_event_data *ctx) {
return 0; return 0;
} }
""") """
if args.ebpf:
print(bpf_text)
exit()
b = BPF(text=bpf_text)
b.attach_perf_event( b.attach_perf_event(
ev_type=PerfType.HARDWARE, ev_config=PerfHWConfig.CACHE_MISSES, ev_type=PerfType.HARDWARE, ev_config=PerfHWConfig.CACHE_MISSES,
fn_name="on_cache_miss", sample_period=args.sample_period) fn_name="on_cache_miss", sample_period=args.sample_period)
......
...@@ -97,6 +97,8 @@ parser.add_argument("-Z", "--max-size", type=int, ...@@ -97,6 +97,8 @@ parser.add_argument("-Z", "--max-size", type=int,
help="capture only allocations smaller than this size") help="capture only allocations smaller than this size")
parser.add_argument("-O", "--obj", type=str, default="c", parser.add_argument("-O", "--obj", type=str, default="c",
help="attach to allocator functions in the specified object") help="attach to allocator functions in the specified object")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
...@@ -384,6 +386,10 @@ if not kernel_trace: ...@@ -384,6 +386,10 @@ if not kernel_trace:
stack_flags += "|BPF_F_USER_STACK" stack_flags += "|BPF_F_USER_STACK"
bpf_source = bpf_source.replace("STACK_FLAGS", stack_flags) bpf_source = bpf_source.replace("STACK_FLAGS", stack_flags)
if args.ebpf:
print(bpf_source)
exit()
bpf = BPF(text=bpf_source) bpf = BPF(text=bpf_source)
if not kernel_trace: if not kernel_trace:
......
...@@ -393,10 +393,15 @@ def main(): ...@@ -393,10 +393,15 @@ def main():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description='trace mount() and umount() syscalls' description='trace mount() and umount() syscalls'
) )
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
mounts = {} mounts = {}
umounts = {} umounts = {}
if args.ebpf:
print(bpf_text)
exit()
b = bcc.BPF(text=bpf_text) b = bcc.BPF(text=bpf_text)
b['events'].open_perf_buffer( b['events'].open_perf_buffer(
functools.partial(print_event, mounts, umounts)) functools.partial(print_event, mounts, umounts))
......
...@@ -34,6 +34,8 @@ parser.add_argument("interval", nargs="?", ...@@ -34,6 +34,8 @@ parser.add_argument("interval", nargs="?",
help="output interval, in seconds") help="output interval, in seconds")
parser.add_argument("count", nargs="?", default=99999999, parser.add_argument("count", nargs="?", default=99999999,
help="number of outputs") help="number of outputs")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
pid = args.pid pid = args.pid
countdown = int(args.count) countdown = int(args.count)
...@@ -124,8 +126,10 @@ if args.pid: ...@@ -124,8 +126,10 @@ if args.pid:
bpf_text = bpf_text.replace('FILTER_PID', 'pid != %s' % pid) bpf_text = bpf_text.replace('FILTER_PID', 'pid != %s' % pid)
else: else:
bpf_text = bpf_text.replace('FILTER_PID', '0') bpf_text = bpf_text.replace('FILTER_PID', '0')
if debug: if debug or args.ebpf:
print(bpf_text) print(bpf_text)
if args.ebpf:
exit()
# load BPF program # load BPF program
b = BPF(text=bpf_text) b = BPF(text=bpf_text)
......
...@@ -53,6 +53,8 @@ parser.add_argument("-j", "--csv", action="store_true", ...@@ -53,6 +53,8 @@ parser.add_argument("-j", "--csv", action="store_true",
parser.add_argument("-p", "--pid", help="Trace this pid only") parser.add_argument("-p", "--pid", help="Trace this pid only")
parser.add_argument("min_ms", nargs="?", default='10', parser.add_argument("min_ms", nargs="?", default='10',
help="Minimum IO duration to trace in ms (default=10ms)") help="Minimum IO duration to trace in ms (default=10ms)")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
min_ms = int(args.min_ms) min_ms = int(args.min_ms)
pid = args.pid pid = args.pid
...@@ -236,8 +238,10 @@ if args.pid: ...@@ -236,8 +238,10 @@ if args.pid:
bpf_text = bpf_text.replace('FILTER_PID', 'pid != %s' % pid) bpf_text = bpf_text.replace('FILTER_PID', 'pid != %s' % pid)
else: else:
bpf_text = bpf_text.replace('FILTER_PID', '0') bpf_text = bpf_text.replace('FILTER_PID', '0')
if debug: if debug or args.ebpf:
print(bpf_text) print(bpf_text)
if args.ebpf:
exit()
# kernel->user event data: struct data_t # kernel->user event data: struct data_t
DNAME_INLINE_LEN = 32 # linux/dcache.h DNAME_INLINE_LEN = 32 # linux/dcache.h
......
...@@ -91,6 +91,8 @@ parser.add_argument("-M", "--max-block-time", default=(1 << 64) - 1, ...@@ -91,6 +91,8 @@ parser.add_argument("-M", "--max-block-time", default=(1 << 64) - 1,
parser.add_argument("--state", type=positive_int, parser.add_argument("--state", type=positive_int,
help="filter on this thread state bitmask (eg, 2 == TASK_UNINTERRUPTIBLE" + help="filter on this thread state bitmask (eg, 2 == TASK_UNINTERRUPTIBLE" +
") see include/linux/sched.h") ") see include/linux/sched.h")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
if args.pid and args.tgid: if args.pid and args.tgid:
parser.error("specify only one of -p and -t") parser.error("specify only one of -p and -t")
...@@ -222,8 +224,10 @@ if args.kernel_threads_only and args.user_stacks_only: ...@@ -222,8 +224,10 @@ if args.kernel_threads_only and args.user_stacks_only:
"doesn't make sense.", file=stderr) "doesn't make sense.", file=stderr)
exit(1) exit(1)
if (debug): if debug or args.ebpf:
print(bpf_text) print(bpf_text)
if args.ebpf:
exit()
# initialize BPF # initialize BPF
b = BPF(text=bpf_text) b = BPF(text=bpf_text)
......
...@@ -88,6 +88,8 @@ parser.add_argument("-M", "--max-block-time", default=(1 << 64) - 1, ...@@ -88,6 +88,8 @@ parser.add_argument("-M", "--max-block-time", default=(1 << 64) - 1,
type=positive_nonzero_int, type=positive_nonzero_int,
help="the amount of time in microseconds under which we " + help="the amount of time in microseconds under which we " +
"store traces (default U64_MAX)") "store traces (default U64_MAX)")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
folded = args.folded folded = args.folded
duration = int(args.duration) duration = int(args.duration)
...@@ -235,6 +237,9 @@ else: ...@@ -235,6 +237,9 @@ else:
stack_context = "user + kernel" stack_context = "user + kernel"
bpf_text = bpf_text.replace('USER_STACK_GET', user_stack_get) bpf_text = bpf_text.replace('USER_STACK_GET', user_stack_get)
bpf_text = bpf_text.replace('KERNEL_STACK_GET', kernel_stack_get) bpf_text = bpf_text.replace('KERNEL_STACK_GET', kernel_stack_get)
if args.ebpf:
print(bpf_text)
exit()
# initialize BPF # initialize BPF
b = BPF(text=bpf_text) b = BPF(text=bpf_text)
......
...@@ -45,6 +45,8 @@ parser.add_argument("-d", "--duration", ...@@ -45,6 +45,8 @@ parser.add_argument("-d", "--duration",
help="total duration of trace in seconds") help="total duration of trace in seconds")
parser.add_argument("-n", "--name", parser.add_argument("-n", "--name",
help="only print process names containing this name") help="only print process names containing this name")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
debug = 0 debug = 0
if args.duration: if args.duration:
...@@ -125,8 +127,10 @@ elif args.pid: ...@@ -125,8 +127,10 @@ elif args.pid:
'if (pid != %s) { return 0; }' % args.pid) 'if (pid != %s) { return 0; }' % args.pid)
else: else:
bpf_text = bpf_text.replace('FILTER', '') bpf_text = bpf_text.replace('FILTER', '')
if debug: if debug or args.ebpf:
print(bpf_text) print(bpf_text)
if args.ebpf:
exit()
# initialize BPF # initialize BPF
b = BPF(text=bpf_text) b = BPF(text=bpf_text)
......
...@@ -97,6 +97,8 @@ parser.add_argument("--stack-storage-size", default=10240, ...@@ -97,6 +97,8 @@ parser.add_argument("--stack-storage-size", default=10240,
parser.add_argument("duration", nargs="?", default=99999999, parser.add_argument("duration", nargs="?", default=99999999,
type=positive_nonzero_int, type=positive_nonzero_int,
help="duration of trace, in seconds") help="duration of trace, in seconds")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
# option logic # option logic
args = parser.parse_args() args = parser.parse_args()
...@@ -208,8 +210,10 @@ if not args.folded: ...@@ -208,8 +210,10 @@ if not args.folded:
else: else:
print("... Hit Ctrl-C to end.") print("... Hit Ctrl-C to end.")
if debug: if debug or args.ebpf:
print(bpf_text) print(bpf_text)
if args.ebpf:
exit()
# initialize BPF & perf_events # initialize BPF & perf_events
b = BPF(text=bpf_text) b = BPF(text=bpf_text)
......
...@@ -58,6 +58,8 @@ parser.add_argument("interval", nargs="?", default=99999999, ...@@ -58,6 +58,8 @@ parser.add_argument("interval", nargs="?", default=99999999,
help="output interval, in seconds") help="output interval, in seconds")
parser.add_argument("count", nargs="?", default=99999999, parser.add_argument("count", nargs="?", default=99999999,
help="number of outputs") help="number of outputs")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
countdown = int(args.count) countdown = int(args.count)
debug = 0 debug = 0
...@@ -169,8 +171,10 @@ else: ...@@ -169,8 +171,10 @@ else:
bpf_text = bpf_text.replace('STORAGE', 'BPF_HISTOGRAM(dist);') bpf_text = bpf_text.replace('STORAGE', 'BPF_HISTOGRAM(dist);')
bpf_text = bpf_text.replace('STORE', bpf_text = bpf_text.replace('STORE',
'dist.increment(bpf_log2l(delta));') 'dist.increment(bpf_log2l(delta));')
if debug: if debug or args.ebpf:
print(bpf_text) print(bpf_text)
if args.ebpf:
exit()
# load BPF program # load BPF program
b = BPF(text=bpf_text) b = BPF(text=bpf_text)
......
...@@ -48,6 +48,8 @@ parser.add_argument("interval", nargs="?", default=99999999, ...@@ -48,6 +48,8 @@ parser.add_argument("interval", nargs="?", default=99999999,
help="output interval, in seconds") help="output interval, in seconds")
parser.add_argument("count", nargs="?", default=99999999, parser.add_argument("count", nargs="?", default=99999999,
help="number of outputs") help="number of outputs")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
countdown = int(args.count) countdown = int(args.count)
debug = 0 debug = 0
...@@ -158,6 +160,7 @@ int do_perf_event() ...@@ -158,6 +160,7 @@ int do_perf_event()
} }
""" """
# code substitutions
if args.cpus: if args.cpus:
bpf_text = bpf_text.replace('STORAGE', bpf_text = bpf_text.replace('STORAGE',
'BPF_HISTOGRAM(dist, cpu_key_t);') 'BPF_HISTOGRAM(dist, cpu_key_t);')
...@@ -174,9 +177,10 @@ if check_runnable_weight_field(): ...@@ -174,9 +177,10 @@ if check_runnable_weight_field():
else: else:
bpf_text = bpf_text.replace('RUNNABLE_WEIGHT_FIELD', '') bpf_text = bpf_text.replace('RUNNABLE_WEIGHT_FIELD', '')
# code substitutions if debug or args.ebpf:
if debug:
print(bpf_text) print(bpf_text)
if args.ebpf:
exit()
# load BPF program # load BPF program
b = BPF(text=bpf_text) b = BPF(text=bpf_text)
......
...@@ -41,6 +41,8 @@ parser.add_argument("interval", nargs="?", default=1, ...@@ -41,6 +41,8 @@ parser.add_argument("interval", nargs="?", default=1,
help="output interval, in seconds") help="output interval, in seconds")
parser.add_argument("count", nargs="?", default=99999999, parser.add_argument("count", nargs="?", default=99999999,
help="number of outputs") help="number of outputs")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
interval = int(args.interval) interval = int(args.interval)
countdown = int(args.count) countdown = int(args.count)
...@@ -90,8 +92,10 @@ int kprobe__kmem_cache_alloc(struct pt_regs *ctx, struct kmem_cache *cachep) ...@@ -90,8 +92,10 @@ int kprobe__kmem_cache_alloc(struct pt_regs *ctx, struct kmem_cache *cachep)
return 0; return 0;
} }
""" """
if debug: if debug or args.ebpf:
print(bpf_text) print(bpf_text)
if args.ebpf:
exit()
# initialize BPF # initialize BPF
b = BPF(text=bpf_text) b = BPF(text=bpf_text)
......
...@@ -38,6 +38,8 @@ parser.add_argument("interval", nargs="?", default=99999999, ...@@ -38,6 +38,8 @@ parser.add_argument("interval", nargs="?", default=99999999,
help="output interval, in seconds") help="output interval, in seconds")
parser.add_argument("count", nargs="?", default=99999999, parser.add_argument("count", nargs="?", default=99999999,
help="number of outputs") help="number of outputs")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
countdown = int(args.count) countdown = int(args.count)
if args.nanoseconds: if args.nanoseconds:
...@@ -110,8 +112,10 @@ else: ...@@ -110,8 +112,10 @@ else:
'key.vec = valp->vec; ' + 'key.vec = valp->vec; ' +
'u64 zero = 0, *vp = dist.lookup_or_init(&key, &zero); ' + 'u64 zero = 0, *vp = dist.lookup_or_init(&key, &zero); ' +
'(*vp) += delta;') '(*vp) += delta;')
if debug: if debug or args.ebpf:
print(bpf_text) print(bpf_text)
if args.ebpf:
exit()
# load BPF program # load BPF program
b = BPF(text=bpf_text) b = BPF(text=bpf_text)
......
...@@ -42,6 +42,8 @@ parser.add_argument("-p", "--pid", default=0, type=int, ...@@ -42,6 +42,8 @@ parser.add_argument("-p", "--pid", default=0, type=int,
help="trace this PID only") help="trace this PID only")
parser.add_argument("-n", "--netns", default=0, type=int, parser.add_argument("-n", "--netns", default=0, type=int,
help="trace this Network Namespace only") help="trace this Network Namespace only")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
# BPF Program # BPF Program
...@@ -190,6 +192,10 @@ if __name__ == "__main__": ...@@ -190,6 +192,10 @@ if __name__ == "__main__":
bpf_text = bpf_text.replace("##FILTER_PID##", pid_filter) bpf_text = bpf_text.replace("##FILTER_PID##", pid_filter)
bpf_text = bpf_text.replace("##FILTER_NETNS##", netns_filter) bpf_text = bpf_text.replace("##FILTER_NETNS##", netns_filter)
if args.ebpf:
print(bpf_text)
exit()
# Initialize BPF # Initialize BPF
b = BPF(text=bpf_text) b = BPF(text=bpf_text)
b["listen_evt"].open_perf_buffer(event_printer(args.show_netns)) b["listen_evt"].open_perf_buffer(event_printer(args.show_netns))
......
...@@ -39,6 +39,8 @@ parser.add_argument("-g", "--no-gnutls", action="store_false", dest="gnutls", ...@@ -39,6 +39,8 @@ parser.add_argument("-g", "--no-gnutls", action="store_false", dest="gnutls",
help="do not show GnuTLS calls.") help="do not show GnuTLS calls.")
parser.add_argument('-d', '--debug', dest='debug', action='count', default=0, parser.add_argument('-d', '--debug', dest='debug', action='count', default=0,
help='debug mode.') help='debug mode.')
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
...@@ -119,8 +121,10 @@ if args.pid: ...@@ -119,8 +121,10 @@ if args.pid:
else: else:
prog = prog.replace('FILTER', '') prog = prog.replace('FILTER', '')
if args.debug: if args.debug or args.ebpf:
print(prog) print(prog)
if args.ebpf:
exit()
b = BPF(text=prog) b = BPF(text=prog)
......
...@@ -34,6 +34,8 @@ parser.add_argument("-x", "--failed", action="store_true", ...@@ -34,6 +34,8 @@ parser.add_argument("-x", "--failed", action="store_true",
help="only show failed stats") help="only show failed stats")
parser.add_argument("-p", "--pid", parser.add_argument("-p", "--pid",
help="trace this PID only") help="trace this PID only")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
debug = 0 debug = 0
...@@ -100,8 +102,10 @@ if args.pid: ...@@ -100,8 +102,10 @@ if args.pid:
'if (pid != %s) { return 0; }' % args.pid) 'if (pid != %s) { return 0; }' % args.pid)
else: else:
bpf_text = bpf_text.replace('FILTER', '') bpf_text = bpf_text.replace('FILTER', '')
if debug: if debug or args.ebpf:
print(bpf_text) print(bpf_text)
if args.ebpf:
exit()
# initialize BPF # initialize BPF
b = BPF(text=bpf_text) b = BPF(text=bpf_text)
......
...@@ -401,6 +401,8 @@ parser.add_argument("-P", "--process", action="store_true", ...@@ -401,6 +401,8 @@ parser.add_argument("-P", "--process", action="store_true",
help="count by process and not by syscall") help="count by process and not by syscall")
parser.add_argument("-l", "--list", action="store_true", parser.add_argument("-l", "--list", action="store_true",
help="print list of recognized syscalls and exit") help="print list of recognized syscalls and exit")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
if args.list: if args.list:
...@@ -488,6 +490,9 @@ if args.latency: ...@@ -488,6 +490,9 @@ if args.latency:
text = "#define LATENCY\n" + text text = "#define LATENCY\n" + text
if args.process: if args.process:
text = "#define BY_PROCESS\n" + text text = "#define BY_PROCESS\n" + text
if args.ebpf:
print(text)
exit()
bpf = BPF(text=text) bpf = BPF(text=text)
......
...@@ -36,6 +36,8 @@ parser.add_argument("-t", "--timestamp", action="store_true", ...@@ -36,6 +36,8 @@ parser.add_argument("-t", "--timestamp", action="store_true",
help="include timestamp on output") help="include timestamp on output")
parser.add_argument("-p", "--pid", parser.add_argument("-p", "--pid",
help="trace this PID only") help="trace this PID only")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
debug = 0 debug = 0
...@@ -123,8 +125,10 @@ if args.pid: ...@@ -123,8 +125,10 @@ if args.pid:
'if (pid != %s) { return 0; }' % args.pid) 'if (pid != %s) { return 0; }' % args.pid)
else: else:
bpf_text = bpf_text.replace('FILTER', '') bpf_text = bpf_text.replace('FILTER', '')
if debug: if debug or args.ebpf:
print(bpf_text) print(bpf_text)
if args.ebpf:
exit()
# event data # event data
TASK_COMM_LEN = 16 # linux/sched.h TASK_COMM_LEN = 16 # linux/sched.h
......
...@@ -42,6 +42,8 @@ parser.add_argument("-p", "--pid", ...@@ -42,6 +42,8 @@ parser.add_argument("-p", "--pid",
help="trace this PID only") help="trace this PID only")
parser.add_argument("-P", "--port", parser.add_argument("-P", "--port",
help="comma-separated list of destination ports to trace.") help="comma-separated list of destination ports to trace.")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
debug = 0 debug = 0
...@@ -162,8 +164,10 @@ if args.port: ...@@ -162,8 +164,10 @@ if args.port:
bpf_text = bpf_text.replace('FILTER_PID', '') bpf_text = bpf_text.replace('FILTER_PID', '')
bpf_text = bpf_text.replace('FILTER_PORT', '') bpf_text = bpf_text.replace('FILTER_PORT', '')
if debug: if debug or args.ebpf:
print(bpf_text) print(bpf_text)
if args.ebpf:
exit()
# event data # event data
TASK_COMM_LEN = 16 # linux/sched.h TASK_COMM_LEN = 16 # linux/sched.h
......
...@@ -53,6 +53,8 @@ parser.add_argument("duration_ms", nargs="?", default=0, ...@@ -53,6 +53,8 @@ parser.add_argument("duration_ms", nargs="?", default=0,
help="minimum duration to trace (ms)") help="minimum duration to trace (ms)")
parser.add_argument("-v", "--verbose", action="store_true", parser.add_argument("-v", "--verbose", action="store_true",
help="print the BPF program for debugging purposes") help="print the BPF program for debugging purposes")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
if args.duration_ms: if args.duration_ms:
...@@ -186,8 +188,10 @@ if args.pid: ...@@ -186,8 +188,10 @@ if args.pid:
'if (pid != %s) { return 0; }' % args.pid) 'if (pid != %s) { return 0; }' % args.pid)
else: else:
bpf_text = bpf_text.replace('FILTER', '') bpf_text = bpf_text.replace('FILTER', '')
if debug or args.verbose: if debug or args.verbose or args.ebpf:
print(bpf_text) print(bpf_text)
if args.ebpf:
exit()
# initialize BPF # initialize BPF
b = BPF(text=bpf_text) b = BPF(text=bpf_text)
......
...@@ -37,6 +37,8 @@ parser.add_argument("-l", "--lossprobe", action="store_true", ...@@ -37,6 +37,8 @@ parser.add_argument("-l", "--lossprobe", action="store_true",
help="include tail loss probe attempts") help="include tail loss probe attempts")
parser.add_argument("-c", "--count", action="store_true", parser.add_argument("-c", "--count", action="store_true",
help="count occurred retransmits per flow") help="count occurred retransmits per flow")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
debug = 0 debug = 0
...@@ -189,8 +191,10 @@ else: ...@@ -189,8 +191,10 @@ else:
bpf_text = bpf_text.replace("IPV4_CORE", "ipv4_events.perf_submit(ctx, &data4, sizeof(data4));") bpf_text = bpf_text.replace("IPV4_CORE", "ipv4_events.perf_submit(ctx, &data4, sizeof(data4));")
bpf_text = bpf_text.replace("IPV6_CORE", "ipv6_events.perf_submit(ctx, &data6, sizeof(data6));") bpf_text = bpf_text.replace("IPV6_CORE", "ipv6_events.perf_submit(ctx, &data6, sizeof(data6));")
if debug: if debug or args.ebpf:
print(bpf_text) print(bpf_text)
if args.ebpf:
exit()
# event data # event data
class Data_ipv4(ct.Structure): class Data_ipv4(ct.Structure):
......
...@@ -60,6 +60,8 @@ parser.add_argument("interval", nargs="?", default=1, type=range_check, ...@@ -60,6 +60,8 @@ parser.add_argument("interval", nargs="?", default=1, type=range_check,
help="output interval, in seconds (default 1)") help="output interval, in seconds (default 1)")
parser.add_argument("count", nargs="?", default=-1, type=range_check, parser.add_argument("count", nargs="?", default=-1, type=range_check,
help="number of outputs") help="number of outputs")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
debug = 0 debug = 0
...@@ -189,8 +191,10 @@ if args.pid: ...@@ -189,8 +191,10 @@ if args.pid:
'if (pid != %s) { return 0; }' % args.pid) 'if (pid != %s) { return 0; }' % args.pid)
else: else:
bpf_text = bpf_text.replace('FILTER', '') bpf_text = bpf_text.replace('FILTER', '')
if debug: if debug or args.ebpf:
print(bpf_text) print(bpf_text)
if args.ebpf:
exit()
def pid_to_comm(pid): def pid_to_comm(pid):
try: try:
......
...@@ -32,6 +32,8 @@ parser.add_argument("-N", "--netns", default=0, type=int, ...@@ -32,6 +32,8 @@ parser.add_argument("-N", "--netns", default=0, type=int,
help="trace this Network Namespace only") help="trace this Network Namespace only")
parser.add_argument("-v", "--verbose", action="store_true", parser.add_argument("-v", "--verbose", action="store_true",
help="include Network Namespace in the output") help="include Network Namespace in the output")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
bpf_text = """ bpf_text = """
...@@ -622,6 +624,10 @@ if args.netns: ...@@ -622,6 +624,10 @@ if args.netns:
bpf_text = bpf_text.replace('##FILTER_PID##', pid_filter) bpf_text = bpf_text.replace('##FILTER_PID##', pid_filter)
bpf_text = bpf_text.replace('##FILTER_NETNS##', netns_filter) bpf_text = bpf_text.replace('##FILTER_NETNS##', netns_filter)
if args.ebpf:
print(bpf_text)
exit()
# initialize BPF # initialize BPF
b = BPF(text=bpf_text) b = BPF(text=bpf_text)
b.attach_kprobe(event="tcp_v4_connect", fn_name="trace_connect_v4_entry") b.attach_kprobe(event="tcp_v4_connect", fn_name="trace_connect_v4_entry")
......
...@@ -660,6 +660,8 @@ trace -I 'linux/fs_struct.h' 'mntns_install "users = %d", $task->fs->users' ...@@ -660,6 +660,8 @@ trace -I 'linux/fs_struct.h' 'mntns_install "users = %d", $task->fs->users'
"as either full path, " "as either full path, "
"or relative to current working directory, " "or relative to current working directory, "
"or relative to default kernel header search path") "or relative to default kernel header search path")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
self.args = parser.parse_args() self.args = parser.parse_args()
if self.args.tgid and self.args.pid: if self.args.tgid and self.args.pid:
parser.error("only one of -p and -L may be specified") parser.error("only one of -p and -L may be specified")
...@@ -690,8 +692,10 @@ trace -I 'linux/fs_struct.h' 'mntns_install "users = %d", $task->fs->users' ...@@ -690,8 +692,10 @@ trace -I 'linux/fs_struct.h' 'mntns_install "users = %d", $task->fs->users'
self.program += probe.generate_program( self.program += probe.generate_program(
self.args.include_self) self.args.include_self)
if self.args.verbose: if self.args.verbose or self.args.ebpf:
print(self.program) print(self.program)
if self.args.ebpf:
exit()
def _attach_probes(self): def _attach_probes(self):
usdt_contexts = [] usdt_contexts = []
......
...@@ -42,6 +42,8 @@ parser.add_argument("-C", "--noclear", action="store_true", ...@@ -42,6 +42,8 @@ parser.add_argument("-C", "--noclear", action="store_true",
help="don't clear the screen") help="don't clear the screen")
parser.add_argument("device", default="-1", parser.add_argument("device", default="-1",
help="path to a tty device (eg, /dev/tty0) or pts number") help="path to a tty device (eg, /dev/tty0) or pts number")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
debug = 0 debug = 0
...@@ -91,8 +93,10 @@ int kprobe__tty_write(struct pt_regs *ctx, struct file *file, ...@@ -91,8 +93,10 @@ int kprobe__tty_write(struct pt_regs *ctx, struct file *file,
""" """
bpf_text = bpf_text.replace('PTS', str(pi.st_ino)) bpf_text = bpf_text.replace('PTS', str(pi.st_ino))
if debug: if debug or args.ebpf:
print(bpf_text) print(bpf_text)
if args.ebpf:
exit()
# initialize BPF # initialize BPF
b = BPF(text=bpf_text) b = BPF(text=bpf_text)
......
...@@ -71,6 +71,8 @@ parser.add_argument("-M", "--max-block-time", default=(1 << 64) - 1, ...@@ -71,6 +71,8 @@ parser.add_argument("-M", "--max-block-time", default=(1 << 64) - 1,
type=positive_nonzero_int, type=positive_nonzero_int,
help="the amount of time in microseconds under which we " + help="the amount of time in microseconds under which we " +
"store traces (default U64_MAX)") "store traces (default U64_MAX)")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
folded = args.folded folded = args.folded
duration = int(args.duration) duration = int(args.duration)
...@@ -155,8 +157,10 @@ bpf_text = bpf_text.replace('STACK_STORAGE_SIZE', str(args.stack_storage_size)) ...@@ -155,8 +157,10 @@ bpf_text = bpf_text.replace('STACK_STORAGE_SIZE', str(args.stack_storage_size))
bpf_text = bpf_text.replace('MINBLOCK_US_VALUE', str(args.min_block_time)) bpf_text = bpf_text.replace('MINBLOCK_US_VALUE', str(args.min_block_time))
bpf_text = bpf_text.replace('MAXBLOCK_US_VALUE', str(args.max_block_time)) bpf_text = bpf_text.replace('MAXBLOCK_US_VALUE', str(args.max_block_time))
if debug: if debug or args.ebpf:
print(bpf_text) print(bpf_text)
if args.ebpf:
exit()
# initialize BPF # initialize BPF
b = BPF(text=bpf_text) b = BPF(text=bpf_text)
......
...@@ -37,6 +37,8 @@ parser.add_argument("interval", nargs="?", ...@@ -37,6 +37,8 @@ parser.add_argument("interval", nargs="?",
help="output interval, in seconds") help="output interval, in seconds")
parser.add_argument("count", nargs="?", default=99999999, parser.add_argument("count", nargs="?", default=99999999,
help="number of outputs") help="number of outputs")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
pid = args.pid pid = args.pid
countdown = int(args.count) countdown = int(args.count)
...@@ -126,8 +128,10 @@ if args.pid: ...@@ -126,8 +128,10 @@ if args.pid:
bpf_text = bpf_text.replace('FILTER_PID', 'pid != %s' % pid) bpf_text = bpf_text.replace('FILTER_PID', 'pid != %s' % pid)
else: else:
bpf_text = bpf_text.replace('FILTER_PID', '0') bpf_text = bpf_text.replace('FILTER_PID', '0')
if debug: if debug or args.ebpf:
print(bpf_text) print(bpf_text)
if args.ebpf:
exit()
# load BPF program # load BPF program
b = BPF(text=bpf_text) b = BPF(text=bpf_text)
......
...@@ -48,6 +48,8 @@ parser.add_argument("-p", "--pid", ...@@ -48,6 +48,8 @@ parser.add_argument("-p", "--pid",
help="trace this PID only") help="trace this PID only")
parser.add_argument("min_ms", nargs="?", default='10', parser.add_argument("min_ms", nargs="?", default='10',
help="minimum I/O duration to trace, in ms (default 10)") help="minimum I/O duration to trace, in ms (default 10)")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
min_ms = int(args.min_ms) min_ms = int(args.min_ms)
pid = args.pid pid = args.pid
...@@ -229,8 +231,10 @@ if args.pid: ...@@ -229,8 +231,10 @@ if args.pid:
bpf_text = bpf_text.replace('FILTER_PID', 'pid != %s' % pid) bpf_text = bpf_text.replace('FILTER_PID', 'pid != %s' % pid)
else: else:
bpf_text = bpf_text.replace('FILTER_PID', '0') bpf_text = bpf_text.replace('FILTER_PID', '0')
if debug: if debug or args.ebpf:
print(bpf_text) print(bpf_text)
if args.ebpf:
exit()
# kernel->user event data: struct data_t # kernel->user event data: struct data_t
DNAME_INLINE_LEN = 32 # linux/dcache.h DNAME_INLINE_LEN = 32 # linux/dcache.h
......
...@@ -37,6 +37,8 @@ parser.add_argument("interval", nargs="?", ...@@ -37,6 +37,8 @@ parser.add_argument("interval", nargs="?",
help="output interval, in seconds") help="output interval, in seconds")
parser.add_argument("count", nargs="?", default=99999999, parser.add_argument("count", nargs="?", default=99999999,
help="number of outputs") help="number of outputs")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
pid = args.pid pid = args.pid
countdown = int(args.count) countdown = int(args.count)
...@@ -126,8 +128,10 @@ if args.pid: ...@@ -126,8 +128,10 @@ if args.pid:
bpf_text = bpf_text.replace('FILTER_PID', 'pid != %s' % pid) bpf_text = bpf_text.replace('FILTER_PID', 'pid != %s' % pid)
else: else:
bpf_text = bpf_text.replace('FILTER_PID', '0') bpf_text = bpf_text.replace('FILTER_PID', '0')
if debug: if debug or args.ebpf:
print(bpf_text) print(bpf_text)
if args.ebpf:
exit()
# load BPF program # load BPF program
b = BPF(text=bpf_text) b = BPF(text=bpf_text)
......
...@@ -51,6 +51,8 @@ parser.add_argument("-p", "--pid", ...@@ -51,6 +51,8 @@ parser.add_argument("-p", "--pid",
help="trace this PID only") help="trace this PID only")
parser.add_argument("min_ms", nargs="?", default='10', parser.add_argument("min_ms", nargs="?", default='10',
help="minimum I/O duration to trace, in ms (default 10)") help="minimum I/O duration to trace, in ms (default 10)")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
min_ms = int(args.min_ms) min_ms = int(args.min_ms)
pid = args.pid pid = args.pid
...@@ -233,8 +235,10 @@ if args.pid: ...@@ -233,8 +235,10 @@ if args.pid:
bpf_text = bpf_text.replace('FILTER_PID', 'pid != %s' % pid) bpf_text = bpf_text.replace('FILTER_PID', 'pid != %s' % pid)
else: else:
bpf_text = bpf_text.replace('FILTER_PID', '0') bpf_text = bpf_text.replace('FILTER_PID', '0')
if debug: if debug or args.ebpf:
print(bpf_text) print(bpf_text)
if args.ebpf:
exit()
# kernel->user event data: struct data_t # kernel->user event data: struct data_t
DNAME_INLINE_LEN = 32 # linux/dcache.h DNAME_INLINE_LEN = 32 # linux/dcache.h
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment