blob: 9c45f947f5a9e2532bb9e8f214cd6955f07e80e9 [file] [log] [blame]
Adrian Hunter00447cc2014-10-30 16:09:42 +02001/*
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
23struct thread;
Adrian Hunter92a9e4f2014-10-30 16:09:45 +020024struct comm;
Adrian Hunter00447cc2014-10-30 16:09:42 +020025struct ip_callchain;
Adrian Hunter92a9e4f2014-10-30 16:09:45 +020026struct symbol;
27struct dso;
Adrian Hunter92a9e4f2014-10-30 16:09:45 +020028struct comm;
29struct perf_sample;
30struct addr_location;
Chris Phlipot451db122016-04-28 01:19:07 -070031struct call_path;
Adrian Hunter92a9e4f2014-10-30 16:09:45 +020032
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'
Adrian Hunterf08046c2019-01-09 11:18:33 +020038 * CALL_RETURN_NON_CALL: a branch but not a 'call' to the start of a different
39 * symbol
Adrian Hunter92a9e4f2014-10-30 16:09:45 +020040 */
41enum {
42 CALL_RETURN_NO_CALL = 1 << 0,
43 CALL_RETURN_NO_RETURN = 1 << 1,
Adrian Hunterf08046c2019-01-09 11:18:33 +020044 CALL_RETURN_NON_CALL = 1 << 2,
Adrian Hunter92a9e4f2014-10-30 16:09:45 +020045};
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 * @call_ref: external reference to 'call' sample (e.g. db_id)
56 * @return_ref: external reference to 'return' sample (e.g. db_id)
57 * @db_id: id used for db-export
Adrian Hunterf4358872019-02-28 15:00:24 +020058 * @parent_db_id: id of parent call used for db-export
Adrian Hunter92a9e4f2014-10-30 16:09:45 +020059 * @flags: Call/Return flags
60 */
61struct call_return {
62 struct thread *thread;
63 struct comm *comm;
64 struct call_path *cp;
65 u64 call_time;
66 u64 return_time;
67 u64 branch_count;
68 u64 call_ref;
69 u64 return_ref;
70 u64 db_id;
Adrian Hunterf4358872019-02-28 15:00:24 +020071 u64 parent_db_id;
Adrian Hunter92a9e4f2014-10-30 16:09:45 +020072 u32 flags;
73};
74
Chris Phlipot2c15f5e2016-04-28 01:19:10 -070075/**
76 * struct call_return_processor - provides a call-back to consume call-return
77 * information.
78 * @cpr: call path root
79 * @process: call-back that accepts call/return information
80 * @data: anonymous data for call-back
81 */
82struct call_return_processor {
83 struct call_path_root *cpr;
Adrian Hunterf4358872019-02-28 15:00:24 +020084 int (*process)(struct call_return *cr, u64 *parent_db_id, void *data);
Chris Phlipot2c15f5e2016-04-28 01:19:10 -070085 void *data;
86};
87
Adrian Hunter256d92b2018-12-21 14:06:19 +020088int thread_stack__event(struct thread *thread, int cpu, u32 flags, u64 from_ip,
Adrian Hunter00447cc2014-10-30 16:09:42 +020089 u64 to_ip, u16 insn_len, u64 trace_nr);
Adrian Hunter256d92b2018-12-21 14:06:19 +020090void thread_stack__set_trace_nr(struct thread *thread, int cpu, u64 trace_nr);
91void thread_stack__sample(struct thread *thread, int cpu, struct ip_callchain *chain,
Adrian Hunter24248302018-10-31 11:10:42 +020092 size_t sz, u64 ip, u64 kernel_start);
Adrian Huntera5499b32015-05-29 16:33:30 +030093int thread_stack__flush(struct thread *thread);
Adrian Hunter00447cc2014-10-30 16:09:42 +020094void thread_stack__free(struct thread *thread);
Adrian Hunter256d92b2018-12-21 14:06:19 +020095size_t thread_stack__depth(struct thread *thread, int cpu);
Adrian Hunter00447cc2014-10-30 16:09:42 +020096
Adrian Hunter92a9e4f2014-10-30 16:09:45 +020097struct call_return_processor *
Adrian Hunterf4358872019-02-28 15:00:24 +020098call_return_processor__new(int (*process)(struct call_return *cr, u64 *parent_db_id, void *data),
Adrian Hunter92a9e4f2014-10-30 16:09:45 +020099 void *data);
100void call_return_processor__free(struct call_return_processor *crp);
101int thread_stack__process(struct thread *thread, struct comm *comm,
102 struct perf_sample *sample,
103 struct addr_location *from_al,
104 struct addr_location *to_al, u64 ref,
105 struct call_return_processor *crp);
106
Adrian Hunter00447cc2014-10-30 16:09:42 +0200107#endif