Beispiel #1
0
    return 0;
}
"""
filter_text = "u32 pid; pid = bpf_get_current_pid_tgid(); "
if args.pid:
    filter_text += "if (pid != %s) { return 0; }" % args.pid
else:
    filter_text += "if (pid == %s) { return 0; }" % os.getpid()
bpf_text = bpf_text.replace('FILTER', filter_text)
if debug:
    print(bpf_text)
b = BPF(text=bpf_text)
counts = b.get_table("counts")

# pre-insert the function addresses into the counts table
fns = b._get_kprobe_functions(pattern)
for fn in fns:
    addr = b.ksymname(fn)
    if addr == -1:
        raise Exception("Unknown symbol name %s" % fn)
    counts[counts.Key(addr)] = counts.Leaf()

b.attach_kprobe(event_re=pattern, fn_name="trace_count")
matched = b.num_open_kprobes()
if matched == 0:
    print("0 functions matched by \"%s\". Exiting." % args.pattern)
    exit()

# header
print("Tracing %d functions for \"%s\"... Hit Ctrl-C to end." %
    (matched, args.pattern))
Beispiel #2
0
    return 0;
}
"""
if args.pid:
    bpf_text = bpf_text.replace(
        'FILTER', ('u32 pid; pid = bpf_get_current_pid_tgid(); ' +
                   'if (pid != %s) { return 0; }') % (args.pid))
else:
    bpf_text = bpf_text.replace('FILTER', '')
if debug:
    print(bpf_text)
b = BPF(text=bpf_text)
counts = b.get_table("counts")

# pre-insert the function addresses into the counts table
fns = b._get_kprobe_functions(pattern)
for fn in fns:
    addr = b.ksymname(fn)
    if addr == -1:
        raise Exception("Unknown symbol name %s" % fn)
    counts[counts.Key(addr)] = counts.Leaf()

b.attach_kprobe(event_re=pattern, fn_name="trace_count")
matched = b.num_open_kprobes()
if matched == 0:
    print("0 functions matched by \"%s\". Exiting." % args.pattern)
    exit()

# header
print("Tracing %d functions for \"%s\"... Hit Ctrl-C to end." %
      (matched, args.pattern))