Commit 919d30a0 authored by Brenden Blanco's avatar Brenden Blanco

Merge pull request #249 from brendangregg/master

use BPF_HISTOGRAM and num_open_kprobes
parents 6ee90d08 3736885c
......@@ -24,7 +24,7 @@ summary is returned to user-level.
# ./bitehist.py
Tracing... Hit Ctrl-C to end.
^C
value : count distribution
kbytes : count distribution
0 -> 1 : 3 | |
2 -> 3 : 0 | |
4 -> 7 : 211 |********** |
......
......@@ -13,13 +13,10 @@
#include <uapi/linux/ptrace.h>
#include <linux/blkdev.h>
BPF_TABLE("array", int, u64, dist, 64);
BPF_HISTOGRAM(dist);
int kprobe__blk_account_io_completion(struct pt_regs *ctx, struct request *req)
{
int index = bpf_log2l(req->__data_len / 1024);
u64 *leaf = dist.lookup(&index);
if (leaf) (*leaf)++;
dist.increment(bpf_log2l(req->__data_len / 1024));
return 0;
}
......@@ -22,10 +22,11 @@ b = BPF(src_file = "bitehist.c")
# header
print("Tracing... Hit Ctrl-C to end.")
# output
# trace until Ctrl-C
try:
sleep(99999999)
except KeyboardInterrupt:
print
# output
b["dist"].print_log2_hist("kbytes")
......@@ -13,7 +13,7 @@
#include <uapi/linux/ptrace.h>
BPF_HASH(start, u32);
BPF_TABLE("array", int, u64, dist, 64);
BPF_HISTOGRAM(dist);
int do_entry(struct pt_regs *ctx)
{
......@@ -36,9 +36,7 @@ int do_return(struct pt_regs *ctx)
if (tsp != 0) {
delta = bpf_ktime_get_ns() - *tsp;
int index = bpf_log2l(delta / 1000);
u64 *leaf = dist.lookup(&index);
if (leaf) (*leaf)++;
dist.increment(bpf_log2l(delta / 1000));
start.delete(&pid);
}
......
......@@ -81,9 +81,14 @@ if debug:
print(bpf_text)
b = BPF(text=bpf_text)
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... Ctrl-C to end.")
print("Tracing %d functions for \"%s\"... Hit Ctrl-C to end." %
(matched, args.pattern))
# output
exiting = 0 if args.interval else 1
......
......@@ -62,8 +62,8 @@ bpf_text = """
#include <uapi/linux/ptrace.h>
#include <linux/blkdev.h>
BPF_TABLE(\"array\", int, u64, dist, 64);
BPF_HASH(start, u32);
BPF_HISTOGRAM(dist);
int trace_func_entry(struct pt_regs *ctx)
{
......@@ -86,14 +86,12 @@ int trace_func_return(struct pt_regs *ctx)
if (tsp == 0) {
return 0; // missed start
}
start.delete(&pid);
delta = bpf_ktime_get_ns() - *tsp;
start.delete(&pid);
FACTOR
// store as histogram
int index = bpf_log2l(delta);
u64 *leaf = dist.lookup(&index);
if (leaf) (*leaf)++;
dist.increment(bpf_log2l(delta));
return 0;
}
......@@ -123,9 +121,14 @@ def signal_ignore(signal, frame):
b = BPF(text=bpf_text)
b.attach_kprobe(event_re=pattern, fn_name="trace_func_entry")
b.attach_kretprobe(event_re=pattern, fn_name="trace_func_return")
matched = b.num_open_kprobes()
if matched == 0:
print("0 functions matched by \"%s\". Exiting." % args.pattern)
exit()
# header
print("Tracing %s... Hit Ctrl-C to end." % args.pattern)
print("Tracing %d functions for \"%s\"... Hit Ctrl-C to end." %
(matched / 2, args.pattern))
# output
exiting = 0 if args.interval else 1
......
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