xref: /linux/tools/perf/util/thread-stack.h (revision b0f84a84fff180718995b1269da2988e5b28be42)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * thread-stack.h: Synthesize a thread's stack using call / return events
4  * Copyright (c) 2014, Intel Corporation.
5  */
6 
7 #ifndef __PERF_THREAD_STACK_H
8 #define __PERF_THREAD_STACK_H
9 
10 #include <sys/types.h>
11 
12 #include <linux/types.h>
13 
14 struct thread;
15 struct comm;
16 struct ip_callchain;
17 struct symbol;
18 struct dso;
19 struct comm;
20 struct perf_sample;
21 struct addr_location;
22 struct call_path;
23 
24 /*
25  * Call/Return flags.
26  *
27  * CALL_RETURN_NO_CALL: 'return' but no matching 'call'
28  * CALL_RETURN_NO_RETURN: 'call' but no matching 'return'
29  * CALL_RETURN_NON_CALL: a branch but not a 'call' to the start of a different
30  *                       symbol
31  */
32 enum {
33 	CALL_RETURN_NO_CALL	= 1 << 0,
34 	CALL_RETURN_NO_RETURN	= 1 << 1,
35 	CALL_RETURN_NON_CALL	= 1 << 2,
36 };
37 
38 /**
39  * struct call_return - paired call/return information.
40  * @thread: thread in which call/return occurred
41  * @comm: comm in which call/return occurred
42  * @cp: call path
43  * @call_time: timestamp of call (if known)
44  * @return_time: timestamp of return (if known)
45  * @branch_count: number of branches seen between call and return
46  * @call_ref: external reference to 'call' sample (e.g. db_id)
47  * @return_ref:  external reference to 'return' sample (e.g. db_id)
48  * @db_id: id used for db-export
49  * @parent_db_id: id of parent call used for db-export
50  * @flags: Call/Return flags
51  */
52 struct call_return {
53 	struct thread *thread;
54 	struct comm *comm;
55 	struct call_path *cp;
56 	u64 call_time;
57 	u64 return_time;
58 	u64 branch_count;
59 	u64 call_ref;
60 	u64 return_ref;
61 	u64 db_id;
62 	u64 parent_db_id;
63 	u32 flags;
64 };
65 
66 /**
67  * struct call_return_processor - provides a call-back to consume call-return
68  *                                information.
69  * @cpr: call path root
70  * @process: call-back that accepts call/return information
71  * @data: anonymous data for call-back
72  */
73 struct call_return_processor {
74 	struct call_path_root *cpr;
75 	int (*process)(struct call_return *cr, u64 *parent_db_id, void *data);
76 	void *data;
77 };
78 
79 int thread_stack__event(struct thread *thread, int cpu, u32 flags, u64 from_ip,
80 			u64 to_ip, u16 insn_len, u64 trace_nr);
81 void thread_stack__set_trace_nr(struct thread *thread, int cpu, u64 trace_nr);
82 void thread_stack__sample(struct thread *thread, int cpu, struct ip_callchain *chain,
83 			  size_t sz, u64 ip, u64 kernel_start);
84 int thread_stack__flush(struct thread *thread);
85 void thread_stack__free(struct thread *thread);
86 size_t thread_stack__depth(struct thread *thread, int cpu);
87 
88 struct call_return_processor *
89 call_return_processor__new(int (*process)(struct call_return *cr, u64 *parent_db_id, void *data),
90 			   void *data);
91 void call_return_processor__free(struct call_return_processor *crp);
92 int thread_stack__process(struct thread *thread, struct comm *comm,
93 			  struct perf_sample *sample,
94 			  struct addr_location *from_al,
95 			  struct addr_location *to_al, u64 ref,
96 			  struct call_return_processor *crp);
97 
98 #endif
99