2 * thread-stack.h: Synthesize a thread's stack using call / return events
3 * Copyright (c) 2014, Intel Corporation.
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.
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
16 #ifndef __PERF_THREAD_STACK_H
17 #define __PERF_THREAD_STACK_H
19 #include <sys/types.h>
21 #include <linux/types.h>
22 #include <linux/rbtree.h>
29 struct call_return_processor
;
37 * CALL_RETURN_NO_CALL: 'return' but no matching 'call'
38 * CALL_RETURN_NO_RETURN: 'call' but no matching 'return'
41 CALL_RETURN_NO_CALL
= 1 << 0,
42 CALL_RETURN_NO_RETURN
= 1 << 1,
46 * struct call_return - paired call/return information.
47 * @thread: thread in which call/return occurred
48 * @comm: comm in which call/return occurred
50 * @call_time: timestamp of call (if known)
51 * @return_time: timestamp of return (if known)
52 * @branch_count: number of branches seen between call and return
53 * @call_ref: external reference to 'call' sample (e.g. db_id)
54 * @return_ref: external reference to 'return' sample (e.g. db_id)
55 * @db_id: id used for db-export
56 * @flags: Call/Return flags
59 struct thread
*thread
;
72 * struct call_path - node in list of calls leading to a function call.
73 * @parent: call path to the parent function call
74 * @sym: symbol of function called
75 * @ip: only if sym is null, the ip of the function
76 * @db_id: id used for db-export
77 * @in_kernel: whether function is a in the kernel
78 * @rb_node: node in parent's tree of called functions
79 * @children: tree of call paths of functions called
81 * In combination with the call_return structure, the call_path structure
82 * defines a context-sensitve call-graph.
85 struct call_path
*parent
;
90 struct rb_node rb_node
;
91 struct rb_root children
;
94 int thread_stack__event(struct thread
*thread
, u32 flags
, u64 from_ip
,
95 u64 to_ip
, u16 insn_len
, u64 trace_nr
);
96 void thread_stack__set_trace_nr(struct thread
*thread
, u64 trace_nr
);
97 void thread_stack__sample(struct thread
*thread
, struct ip_callchain
*chain
,
99 int thread_stack__flush(struct thread
*thread
);
100 void thread_stack__free(struct thread
*thread
);
102 struct call_return_processor
*
103 call_return_processor__new(int (*process
)(struct call_return
*cr
, void *data
),
105 void call_return_processor__free(struct call_return_processor
*crp
);
106 int thread_stack__process(struct thread
*thread
, struct comm
*comm
,
107 struct perf_sample
*sample
,
108 struct addr_location
*from_al
,
109 struct addr_location
*to_al
, u64 ref
,
110 struct call_return_processor
*crp
);