Debian Codegraph @

src/libsysprof/sysprof-perf-event-stream-private.h

raw
1 /* sysprof-perf-event-stream-private.h
2 *
3 * Copyright 2023 Christian Hergert <[email protected]>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * SPDX-License-Identifier: GPL-3.0-or-later
19 */
20
21 #pragma once
22
23 #include <gio/gio.h>
24 #include <libdex.h>
25 #include <linux/perf_event.h>
26
27 #include <sysprof-capture.h>
28
29 G_BEGIN_DECLS
30
31 SYSPROF_ALIGNED_BEGIN(1)
32 typedef struct _SysprofPerfEventFork
33 {
34 struct perf_event_header header;
35 guint32 pid;
36 guint32 ppid;
37 guint32 tid;
38 guint32 ptid;
39 guint64 time;
40 } SysprofPerfEventFork
41 SYSPROF_ALIGNED_END(1);
42
43 SYSPROF_ALIGNED_BEGIN(1)
44 typedef struct _SysprofPerfEventComm
45 {
46 struct perf_event_header header;
47 guint32 pid;
48 guint32 tid;
49 gchar comm[0];
50 } SysprofPerfEventComm
51 SYSPROF_ALIGNED_END(1);
52
53 SYSPROF_ALIGNED_BEGIN(1)
54 typedef struct _SysprofPerfEventExit
55 {
56 struct perf_event_header header;
57 guint32 pid;
58 guint32 ppid;
59 guint32 tid;
60 guint32 ptid;
61 guint64 time;
62 } SysprofPerfEventExit
63 SYSPROF_ALIGNED_END(1);
64
65 SYSPROF_ALIGNED_BEGIN(1)
66 typedef struct _SysprofPerfEventMmap
67 {
68 struct perf_event_header header;
69 guint32 pid;
70 guint32 tid;
71 guint64 addr;
72 guint64 len;
73 guint64 pgoff;
74 char filename[0];
75 } SysprofPerfEventMmap
76 SYSPROF_ALIGNED_END(1);
77
78 SYSPROF_ALIGNED_BEGIN(1)
79 typedef struct _SysprofPerfEventMmap2
80 {
81 struct perf_event_header header;
82 guint32 pid;
83 guint32 tid;
84 guint64 addr;
85 guint64 len;
86 guint64 pgoff;
87 union {
88 struct {
89 guint32 maj;
90 guint32 min;
91 guint64 ino;
92 guint64 ino_generation;
93 };
94 struct {
95 guint8 build_id_size;
96 guint8 __reserved_1;
97 guint16 __reserved_2;
98 guint8 build_id[20];
99 };
100 };
101 guint32 prot;
102 guint32 flags;
103 char filename[0];
104 } SysprofPerfEventMmap2
105 SYSPROF_ALIGNED_END(1);
106
107 SYSPROF_ALIGNED_BEGIN(1)
108 typedef struct _SysprofPerfEventCallchain
109 {
110 struct perf_event_header header;
111 guint64 identifier;
112 guint64 ip;
113 guint32 pid;
114 guint32 tid;
115 guint64 time;
116 guint64 n_ips;
117 guint64 ips[0];
118 } SysprofPerfEventCallchain
119 SYSPROF_ALIGNED_END(1);
120
121 SYSPROF_ALIGNED_BEGIN(1)
122 typedef struct _SysprofPerfEventTracepoint
123 {
124 struct perf_event_header header;
125 guint64 identifier;
126 guint64 ip;
127 guint32 pid;
128 guint32 tid;
129 guint64 time;
130 guint32 raw_size;
131 guchar raw[];
132 } SysprofPerfEventTracepoint
133 SYSPROF_ALIGNED_END(1);
134
135 SYSPROF_ALIGNED_BEGIN(1)
136 typedef struct _SysprofPerfEventLost
137 {
138 struct perf_event_header header;
139 guint64 identifier;
140 guint64 lost;
141 } SysprofPerfEventLost
142 SYSPROF_ALIGNED_END(1);
143
144 SYSPROF_ALIGNED_BEGIN(1)
145 typedef union _SysprofPerfEvent
146 {
147 struct perf_event_header header;
148 SysprofPerfEventFork fork;
149 SysprofPerfEventComm comm;
150 SysprofPerfEventExit exit;
151 SysprofPerfEventMmap mmap;
152 SysprofPerfEventMmap2 mmap2;
153 SysprofPerfEventCallchain callchain;
154 SysprofPerfEventTracepoint tracepoint;
155 SysprofPerfEventLost lost;
156 guint8 raw[0];
157 } SysprofPerfEvent
158 SYSPROF_ALIGNED_END(1);
159
160 typedef void (*SysprofPerfEventCallback) (const SysprofPerfEvent *event,
161 guint cpu,
162 gpointer user_data);
163
164 #define SYSPROF_TYPE_PERF_EVENT_STREAM (sysprof_perf_event_stream_get_type())
165
166 G_DECLARE_FINAL_TYPE (SysprofPerfEventStream, sysprof_perf_event_stream, SYSPROF, PERF_EVENT_STREAM, GObject)
167
168 DexFuture *sysprof_perf_event_stream_new (GDBusConnection *connection,
169 struct perf_event_attr *attr,
170 int cpu,
171 int group_fd,
172 guint64 flags,
173 SysprofPerfEventCallback callback,
174 gpointer callback_data,
175 GDestroyNotify callback_data_destroy);
176 gboolean sysprof_perf_event_stream_enable (SysprofPerfEventStream *self,
177 GError **error);
178 gboolean sysprof_perf_event_stream_disable (SysprofPerfEventStream *self,
179 GError **error);
180 GVariant *_sysprof_perf_event_attr_to_variant (const struct perf_event_attr *attr);
181
182 G_END_DECLS