Commit ac297c1e authored by Brendan Gregg's avatar Brendan Gregg Committed by 4ast

fix profile.py page_offset_base breakage (#768)

parent 5845ef9c
...@@ -18,20 +18,16 @@ kernel context, rather than passing each stack to user space for frequency ...@@ -18,20 +18,16 @@ kernel context, rather than passing each stack to user space for frequency
counting there. Only the unique stacks and counts are passed to user space counting there. Only the unique stacks and counts are passed to user space
at the end of the profile, greatly reducing the kernel<->user transfer. at the end of the profile, greatly reducing the kernel<->user transfer.
Note: if another perf-based sampling session is active, the output may become Note: if another perf-based sampling or tracing session is active, the output
polluted with their events. On older kernels, the ouptut may also become may become polluted with their events. This will be fixed for Linux 4.9.
polluted with tracing sessions (when the kprobe is used instead of the
tracepoint). This may be filtered in a future version if it becomes a problem.
.SH REQUIREMENTS .SH REQUIREMENTS
CONFIG_BPF and bcc. CONFIG_BPF and bcc.
This also requires Linux 4.6+ (BPF_MAP_TYPE_STACK_TRACE support), and the This also requires Linux 4.6+ (BPF_MAP_TYPE_STACK_TRACE support), and the
perf:perf_hrtimer tracepoint (currently a kernel patch). If the latter is perf_misc_flags() function symbol to exist. The latter may or may not
unavailable, this will try to use kprobes as a fallback (of perf_misc_flags()), exist depending on your kernel build, and if it doesn't exist, this tool
which may work or will not work. Linux 4.9 provides a proper solution to this (this tool will
may not, depending on your kernel build. If the kprobe doesn't work, this tool be updated).
will either error on instrumentation, or, instrument successfully but
generate no output.
.SH OPTIONS .SH OPTIONS
.TP .TP
\-h \-h
......
...@@ -24,9 +24,9 @@ ...@@ -24,9 +24,9 @@
# tracepoint). If this becomes a problem, logic can be added to filter events. # tracepoint). If this becomes a problem, logic can be added to filter events.
# #
# REQUIRES: Linux 4.6+ (BPF_MAP_TYPE_STACK_TRACE support), and the # REQUIRES: Linux 4.6+ (BPF_MAP_TYPE_STACK_TRACE support), and the
# perf:perf_hrtimer tracepoint (currently a kernel patch). If the latter is # perf_misc_flags() function symbol to exist. The latter may or may not
# unavailable, this will try to use kprobes as a fallback, which may work or # exist depending on your kernel build. Linux 4.9 provides a proper solution
# may instrument nothing, depending on your kernel build. # to this (this tool will be updated).
# #
# Copyright 2016 Netflix, Inc. # Copyright 2016 Netflix, Inc.
# Licensed under the Apache License, Version 2.0 (the "License") # Licensed under the Apache License, Version 2.0 (the "License")
...@@ -162,8 +162,13 @@ PERF_TRACE_EVENT { ...@@ -162,8 +162,13 @@ PERF_TRACE_EVENT {
struct pt_regs regs = {}; struct pt_regs regs = {};
bpf_probe_read(&regs, sizeof(regs), (void *)REGS_LOCATION); bpf_probe_read(&regs, sizeof(regs), (void *)REGS_LOCATION);
u64 ip = PT_REGS_IP(&regs); u64 ip = PT_REGS_IP(&regs);
// if ip isn't sane, leave key ips as zero for later checking // if ip isn't sane, leave key ips as zero for later checking
#ifdef CONFIG_RANDOMIZE_MEMORY
if (ip > __PAGE_OFFSET_BASE) {
#else
if (ip > PAGE_OFFSET) { if (ip > PAGE_OFFSET) {
#endif
key.kernel_ip = ip; key.kernel_ip = ip;
if (DO_KERNEL_RIP) { if (DO_KERNEL_RIP) {
/* /*
...@@ -232,23 +237,21 @@ if not args.folded: ...@@ -232,23 +237,21 @@ if not args.folded:
else: else:
print("... Hit Ctrl-C to end.") print("... Hit Ctrl-C to end.")
# use perf tracepoint if it exists, else kprobe # kprobe perf_misc_flags()
if os.path.exists("/sys/kernel/debug/tracing/events/perf/perf_hrtimer"): bpf_text = bpf_text.replace('PERF_TRACE_EVENT',
bpf_text = bpf_text.replace('PERF_TRACE_EVENT', 'int kprobe__perf_misc_flags(struct pt_regs *args)')
'TRACEPOINT_PROBE(perf, perf_hrtimer)') bpf_text = bpf_text.replace('REGS_LOCATION', 'PT_REGS_PARM1(args)')
bpf_text = bpf_text.replace('REGS_LOCATION', 'args->regs')
else:
if not args.folded:
print("Tracepoint perf:perf_hrtimer missing. "
"Trying kprobe of perf_misc_flags()...")
bpf_text = bpf_text.replace('PERF_TRACE_EVENT',
'int kprobe__perf_misc_flags(struct pt_regs *args)')
bpf_text = bpf_text.replace('REGS_LOCATION', 'PT_REGS_PARM1(args)')
if debug: if debug:
print(bpf_text) print(bpf_text)
# initialize BPF # initialize BPF
b = BPF(text=bpf_text) try:
b = BPF(text=bpf_text)
except:
print("BPF initialization failed. perf_misc_flags() may be inlined in " +
"your kernel build.\nThis tool will be updated in the future to " +
"support Linux 4.9, which has reliable profiling support. Exiting.")
exit()
# signal handler # signal handler
def signal_ignore(signal, frame): def signal_ignore(signal, frame):
......
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