1 /* 2 * thread-stack.h: Synthesize a thread's stack using call / return events 3 * Copyright (c) 2014, Intel Corporation. 4 * 5 * This program is free software; you can redistribute it and/or modify it 6 * under the terms and conditions of the GNU General Public License, 7 * version 2, as published by the Free Software Foundation. 8 * 9 * This program is distributed in the hope it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 * more details. 13 * 14 */ 15 16 #ifndef __PERF_THREAD_STACK_H 17 #define __PERF_THREAD_STACK_H 18 19 #include <sys/types.h> 20 21 #include <linux/types.h> 22 23 struct thread; 24 struct comm; 25 struct ip_callchain; 26 struct symbol; 27 struct dso; 28 struct comm; 29 struct perf_sample; 30 struct addr_location; 31 struct call_path; 32 33 /* 34 * Call/Return flags. 35 * 36 * CALL_RETURN_NO_CALL: 'return' but no matching 'call' 37 * CALL_RETURN_NO_RETURN: 'call' but no matching 'return' 38 * CALL_RETURN_NON_CALL: a branch but not a 'call' to the start of a different 39 * symbol 40 */ 41 enum { 42 CALL_RETURN_NO_CALL = 1 << 0, 43 CALL_RETURN_NO_RETURN = 1 << 1, 44 CALL_RETURN_NON_CALL = 1 << 2, 45 }; 46 47 /** 48 * struct call_return - paired call/return information. 49 * @thread: thread in which call/return occurred 50 * @comm: comm in which call/return occurred 51 * @cp: call path 52 * @call_time: timestamp of call (if known) 53 * @return_time: timestamp of return (if known) 54 * @branch_count: number of branches seen between call and return 55 * @insn_count: approx. number of instructions between call and return 56 * @cyc_count: approx. number of cycles between call and return 57 * @call_ref: external reference to 'call' sample (e.g. db_id) 58 * @return_ref: external reference to 'return' sample (e.g. db_id) 59 * @db_id: id used for db-export 60 * @parent_db_id: id of parent call used for db-export 61 * @flags: Call/Return flags 62 */ 63 struct call_return { 64 struct thread *thread; 65 struct comm *comm; 66 struct call_path *cp; 67 u64 call_time; 68 u64 return_time; 69 u64 branch_count; 70 u64 insn_count; 71 u64 cyc_count; 72 u64 call_ref; 73 u64 return_ref; 74 u64 db_id; 75 u64 parent_db_id; 76 u32 flags; 77 }; 78 79 /** 80 * struct call_return_processor - provides a call-back to consume call-return 81 * information. 82 * @cpr: call path root 83 * @process: call-back that accepts call/return information 84 * @data: anonymous data for call-back 85 */ 86 struct call_return_processor { 87 struct call_path_root *cpr; 88 int (*process)(struct call_return *cr, u64 *parent_db_id, void *data); 89 void *data; 90 }; 91 92 int thread_stack__event(struct thread *thread, int cpu, u32 flags, u64 from_ip, 93 u64 to_ip, u16 insn_len, u64 trace_nr); 94 void thread_stack__set_trace_nr(struct thread *thread, int cpu, u64 trace_nr); 95 void thread_stack__sample(struct thread *thread, int cpu, struct ip_callchain *chain, 96 size_t sz, u64 ip, u64 kernel_start); 97 int thread_stack__flush(struct thread *thread); 98 void thread_stack__free(struct thread *thread); 99 size_t thread_stack__depth(struct thread *thread, int cpu); 100 101 struct call_return_processor * 102 call_return_processor__new(int (*process)(struct call_return *cr, u64 *parent_db_id, void *data), 103 void *data); 104 void call_return_processor__free(struct call_return_processor *crp); 105 int thread_stack__process(struct thread *thread, struct comm *comm, 106 struct perf_sample *sample, 107 struct addr_location *from_al, 108 struct addr_location *to_al, u64 ref, 109 struct call_return_processor *crp); 110 111 #endif 112