2014-10-30 22:09:42 +08:00
|
|
|
/*
|
|
|
|
* thread-stack.h: Synthesize a thread's stack using call / return events
|
|
|
|
* Copyright (c) 2014, Intel Corporation.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __PERF_THREAD_STACK_H
|
|
|
|
#define __PERF_THREAD_STACK_H
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
|
|
|
|
struct thread;
|
2014-10-30 22:09:45 +08:00
|
|
|
struct comm;
|
2014-10-30 22:09:42 +08:00
|
|
|
struct ip_callchain;
|
2014-10-30 22:09:45 +08:00
|
|
|
struct symbol;
|
|
|
|
struct dso;
|
|
|
|
struct comm;
|
|
|
|
struct perf_sample;
|
|
|
|
struct addr_location;
|
2016-04-28 16:19:07 +08:00
|
|
|
struct call_path;
|
2014-10-30 22:09:45 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Call/Return flags.
|
|
|
|
*
|
|
|
|
* CALL_RETURN_NO_CALL: 'return' but no matching 'call'
|
|
|
|
* CALL_RETURN_NO_RETURN: 'call' but no matching 'return'
|
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
CALL_RETURN_NO_CALL = 1 << 0,
|
|
|
|
CALL_RETURN_NO_RETURN = 1 << 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct call_return - paired call/return information.
|
|
|
|
* @thread: thread in which call/return occurred
|
|
|
|
* @comm: comm in which call/return occurred
|
|
|
|
* @cp: call path
|
|
|
|
* @call_time: timestamp of call (if known)
|
|
|
|
* @return_time: timestamp of return (if known)
|
|
|
|
* @branch_count: number of branches seen between call and return
|
|
|
|
* @call_ref: external reference to 'call' sample (e.g. db_id)
|
|
|
|
* @return_ref: external reference to 'return' sample (e.g. db_id)
|
|
|
|
* @db_id: id used for db-export
|
|
|
|
* @flags: Call/Return flags
|
|
|
|
*/
|
|
|
|
struct call_return {
|
|
|
|
struct thread *thread;
|
|
|
|
struct comm *comm;
|
|
|
|
struct call_path *cp;
|
|
|
|
u64 call_time;
|
|
|
|
u64 return_time;
|
|
|
|
u64 branch_count;
|
|
|
|
u64 call_ref;
|
|
|
|
u64 return_ref;
|
|
|
|
u64 db_id;
|
|
|
|
u32 flags;
|
|
|
|
};
|
|
|
|
|
2016-04-28 16:19:10 +08:00
|
|
|
/**
|
|
|
|
* struct call_return_processor - provides a call-back to consume call-return
|
|
|
|
* information.
|
|
|
|
* @cpr: call path root
|
|
|
|
* @process: call-back that accepts call/return information
|
|
|
|
* @data: anonymous data for call-back
|
|
|
|
*/
|
|
|
|
struct call_return_processor {
|
|
|
|
struct call_path_root *cpr;
|
|
|
|
int (*process)(struct call_return *cr, void *data);
|
|
|
|
void *data;
|
|
|
|
};
|
|
|
|
|
2014-10-30 22:09:42 +08:00
|
|
|
int thread_stack__event(struct thread *thread, u32 flags, u64 from_ip,
|
|
|
|
u64 to_ip, u16 insn_len, u64 trace_nr);
|
2014-10-30 22:09:45 +08:00
|
|
|
void thread_stack__set_trace_nr(struct thread *thread, u64 trace_nr);
|
2014-10-30 22:09:42 +08:00
|
|
|
void thread_stack__sample(struct thread *thread, struct ip_callchain *chain,
|
2018-10-31 17:10:42 +08:00
|
|
|
size_t sz, u64 ip, u64 kernel_start);
|
2015-05-29 21:33:30 +08:00
|
|
|
int thread_stack__flush(struct thread *thread);
|
2014-10-30 22:09:42 +08:00
|
|
|
void thread_stack__free(struct thread *thread);
|
perf script: Add callindent option
Based on patches from Andi Kleen.
When printing PT instruction traces with perf script it is rather useful
to see some indentation for the call tree. This patch adds a new
callindent field to perf script that prints spaces for the function call
stack depth.
We already have code to track the function call stack for PT, that we
can reuse with minor modifications.
The resulting output is not quite as nice as ftrace yet, but a lot
better than what was there before.
Note there are some corner cases when the thread stack gets code
confused and prints incorrect indentation. Even with that it is fairly
useful.
When displaying kernel code traces it is recommended to run as root, as
otherwise perf doesn't understand the kernel addresses properly, and may
not reset the call stack correctly on kernel boundaries.
Example output:
sudo perf-with-kcore record eg2 -a -e intel_pt// -- sleep 1
sudo perf-with-kcore script eg2 --ns -F callindent,time,comm,pid,sym,ip,addr,flags,cpu --itrace=cre | less
...
swapper 0 [000] 5830.389116586: call irq_exit ffffffff8104d620 smp_call_function_single_interrupt+0x30 => ffffffff8107e720 irq_exit
swapper 0 [000] 5830.389116586: call idle_cpu ffffffff8107e769 irq_exit+0x49 => ffffffff810a3970 idle_cpu
swapper 0 [000] 5830.389116586: return idle_cpu ffffffff810a39b7 idle_cpu+0x47 => ffffffff8107e76e irq_exit
swapper 0 [000] 5830.389116586: call tick_nohz_irq_exit ffffffff8107e7bd irq_exit+0x9d => ffffffff810f2fc0 tick_nohz_irq_exit
swapper 0 [000] 5830.389116919: call __tick_nohz_idle_enter ffffffff810f2fe0 tick_nohz_irq_exit+0x20 => ffffffff810f28d0 __tick_nohz_idle_enter
swapper 0 [000] 5830.389116919: call ktime_get ffffffff810f28f1 __tick_nohz_idle_enter+0x21 => ffffffff810e9ec0 ktime_get
swapper 0 [000] 5830.389116919: call read_tsc ffffffff810e9ef6 ktime_get+0x36 => ffffffff81035070 read_tsc
swapper 0 [000] 5830.389116919: return read_tsc ffffffff81035084 read_tsc+0x14 => ffffffff810e9efc ktime_get
swapper 0 [000] 5830.389116919: return ktime_get ffffffff810e9f46 ktime_get+0x86 => ffffffff810f28f6 __tick_nohz_idle_enter
swapper 0 [000] 5830.389116919: call sched_clock_idle_sleep_event ffffffff810f290b __tick_nohz_idle_enter+0x3b => ffffffff810a7380 sched_clock_idle_sleep_event
swapper 0 [000] 5830.389116919: call sched_clock_cpu ffffffff810a738b sched_clock_idle_sleep_event+0xb => ffffffff810a72e0 sched_clock_cpu
swapper 0 [000] 5830.389116919: call sched_clock ffffffff810a734d sched_clock_cpu+0x6d => ffffffff81035750 sched_clock
swapper 0 [000] 5830.389116919: call native_sched_clock ffffffff81035754 sched_clock+0x4 => ffffffff81035640 native_sched_clock
swapper 0 [000] 5830.389116919: return native_sched_clock ffffffff8103568c native_sched_clock+0x4c => ffffffff81035759 sched_clock
swapper 0 [000] 5830.389116919: return sched_clock ffffffff8103575c sched_clock+0xc => ffffffff810a7352 sched_clock_cpu
swapper 0 [000] 5830.389116919: return sched_clock_cpu ffffffff810a7356 sched_clock_cpu+0x76 => ffffffff810a7390 sched_clock_idle_sleep_event
swapper 0 [000] 5830.389116919: return sched_clock_idle_sleep_event ffffffff810a7391 sched_clock_idle_sleep_event+0x11 => ffffffff810f2910 __tick_nohz_idle_enter
...
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Link: http://lkml.kernel.org/r/1466689258-28493-4-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-06-23 21:40:58 +08:00
|
|
|
size_t thread_stack__depth(struct thread *thread);
|
2014-10-30 22:09:42 +08:00
|
|
|
|
2014-10-30 22:09:45 +08:00
|
|
|
struct call_return_processor *
|
|
|
|
call_return_processor__new(int (*process)(struct call_return *cr, void *data),
|
|
|
|
void *data);
|
|
|
|
void call_return_processor__free(struct call_return_processor *crp);
|
|
|
|
int thread_stack__process(struct thread *thread, struct comm *comm,
|
|
|
|
struct perf_sample *sample,
|
|
|
|
struct addr_location *from_al,
|
|
|
|
struct addr_location *to_al, u64 ref,
|
|
|
|
struct call_return_processor *crp);
|
|
|
|
|
2014-10-30 22:09:42 +08:00
|
|
|
#endif
|