Loading...
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#include <linux/rbtree.h>
23
24struct thread;
25struct comm;
26struct ip_callchain;
27struct symbol;
28struct dso;
29struct call_return_processor;
30struct comm;
31struct perf_sample;
32struct addr_location;
33
34/*
35 * Call/Return flags.
36 *
37 * CALL_RETURN_NO_CALL: 'return' but no matching 'call'
38 * CALL_RETURN_NO_RETURN: 'call' but no matching 'return'
39 */
40enum {
41 CALL_RETURN_NO_CALL = 1 << 0,
42 CALL_RETURN_NO_RETURN = 1 << 1,
43};
44
45/**
46 * struct call_return - paired call/return information.
47 * @thread: thread in which call/return occurred
48 * @comm: comm in which call/return occurred
49 * @cp: call path
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
57 */
58struct call_return {
59 struct thread *thread;
60 struct comm *comm;
61 struct call_path *cp;
62 u64 call_time;
63 u64 return_time;
64 u64 branch_count;
65 u64 call_ref;
66 u64 return_ref;
67 u64 db_id;
68 u32 flags;
69};
70
71/**
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
80 *
81 * In combination with the call_return structure, the call_path structure
82 * defines a context-sensitve call-graph.
83 */
84struct call_path {
85 struct call_path *parent;
86 struct symbol *sym;
87 u64 ip;
88 u64 db_id;
89 bool in_kernel;
90 struct rb_node rb_node;
91 struct rb_root children;
92};
93
94int thread_stack__event(struct thread *thread, u32 flags, u64 from_ip,
95 u64 to_ip, u16 insn_len, u64 trace_nr);
96void thread_stack__set_trace_nr(struct thread *thread, u64 trace_nr);
97void thread_stack__sample(struct thread *thread, struct ip_callchain *chain,
98 size_t sz, u64 ip);
99int thread_stack__flush(struct thread *thread);
100void thread_stack__free(struct thread *thread);
101
102struct call_return_processor *
103call_return_processor__new(int (*process)(struct call_return *cr, void *data),
104 void *data);
105void call_return_processor__free(struct call_return_processor *crp);
106int 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);
111
112#endif
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
14struct thread;
15struct comm;
16struct ip_callchain;
17struct symbol;
18struct dso;
19struct perf_sample;
20struct addr_location;
21struct call_path;
22
23/*
24 * Call/Return flags.
25 *
26 * CALL_RETURN_NO_CALL: 'return' but no matching 'call'
27 * CALL_RETURN_NO_RETURN: 'call' but no matching 'return'
28 * CALL_RETURN_NON_CALL: a branch but not a 'call' to the start of a different
29 * symbol
30 */
31enum {
32 CALL_RETURN_NO_CALL = 1 << 0,
33 CALL_RETURN_NO_RETURN = 1 << 1,
34 CALL_RETURN_NON_CALL = 1 << 2,
35};
36
37/**
38 * struct call_return - paired call/return information.
39 * @thread: thread in which call/return occurred
40 * @comm: comm in which call/return occurred
41 * @cp: call path
42 * @call_time: timestamp of call (if known)
43 * @return_time: timestamp of return (if known)
44 * @branch_count: number of branches seen between call and return
45 * @insn_count: approx. number of instructions between call and return
46 * @cyc_count: approx. number of cycles between call and return
47 * @call_ref: external reference to 'call' sample (e.g. db_id)
48 * @return_ref: external reference to 'return' sample (e.g. db_id)
49 * @db_id: id used for db-export
50 * @parent_db_id: id of parent call used for db-export
51 * @flags: Call/Return flags
52 */
53struct call_return {
54 struct thread *thread;
55 struct comm *comm;
56 struct call_path *cp;
57 u64 call_time;
58 u64 return_time;
59 u64 branch_count;
60 u64 insn_count;
61 u64 cyc_count;
62 u64 call_ref;
63 u64 return_ref;
64 u64 db_id;
65 u64 parent_db_id;
66 u32 flags;
67};
68
69/**
70 * struct call_return_processor - provides a call-back to consume call-return
71 * information.
72 * @cpr: call path root
73 * @process: call-back that accepts call/return information
74 * @data: anonymous data for call-back
75 */
76struct call_return_processor {
77 struct call_path_root *cpr;
78 int (*process)(struct call_return *cr, u64 *parent_db_id, void *data);
79 void *data;
80};
81
82int thread_stack__event(struct thread *thread, int cpu, u32 flags, u64 from_ip,
83 u64 to_ip, u16 insn_len, u64 trace_nr, bool callstack,
84 unsigned int br_stack_sz, bool mispred_all);
85void thread_stack__set_trace_nr(struct thread *thread, int cpu, u64 trace_nr);
86void thread_stack__sample(struct thread *thread, int cpu, struct ip_callchain *chain,
87 size_t sz, u64 ip, u64 kernel_start);
88void thread_stack__sample_late(struct thread *thread, int cpu,
89 struct ip_callchain *chain, size_t sz, u64 ip,
90 u64 kernel_start);
91void thread_stack__br_sample(struct thread *thread, int cpu,
92 struct branch_stack *dst, unsigned int sz);
93void thread_stack__br_sample_late(struct thread *thread, int cpu,
94 struct branch_stack *dst, unsigned int sz,
95 u64 sample_ip, u64 kernel_start);
96int thread_stack__flush(struct thread *thread);
97void thread_stack__free(struct thread *thread);
98size_t thread_stack__depth(struct thread *thread, int cpu);
99
100struct call_return_processor *
101call_return_processor__new(int (*process)(struct call_return *cr, u64 *parent_db_id, void *data),
102 void *data);
103void call_return_processor__free(struct call_return_processor *crp);
104int thread_stack__process(struct thread *thread, struct comm *comm,
105 struct perf_sample *sample,
106 struct addr_location *from_al,
107 struct addr_location *to_al, u64 ref,
108 struct call_return_processor *crp);
109
110#endif