xref: /haiku/headers/private/system/system_profiler_defs.h (revision 909af08f4328301fbdef1ffb41f566c3b5bec0c7)
1 /*
2  * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _SYSTEM_SYSTEM_PROFILER_DEFS_H
6 #define _SYSTEM_SYSTEM_PROFILER_DEFS_H
7 
8 
9 #include <image.h>
10 
11 
12 struct system_profiler_parameters {
13 	// general
14 	area_id		buffer_area;			// area the events will be written to
15 	uint32		flags;					// flags selecting the events to receive
16 
17 	// scheduling
18 	size_t		locking_lookup_size;	// size of the lookup table used for
19 										// caching the locking primitive infos
20 
21 	// sampling
22 	bigtime_t	interval;				// interval at which to take samples
23 	uint32		stack_depth;			// maximum stack depth to sample
24 	bool		profile_kernel;			// sample kernel stack frames
25 };
26 
27 
28 // event flags
29 enum {
30 	B_SYSTEM_PROFILER_TEAM_EVENTS			= 0x01,
31 	B_SYSTEM_PROFILER_THREAD_EVENTS			= 0x02,
32 	B_SYSTEM_PROFILER_IMAGE_EVENTS			= 0x04,
33 	B_SYSTEM_PROFILER_SAMPLING_EVENTS		= 0x08,
34 	B_SYSTEM_PROFILER_SCHEDULING_EVENTS		= 0x10,
35 	B_SYSTEM_PROFILER_IO_SCHEDULING_EVENTS	= 0x20
36 };
37 
38 
39 // events
40 enum {
41 	// reserved for the user application
42 	B_SYSTEM_PROFILER_USER_EVENT = 0,
43 
44 	// ring buffer wrap-around marker
45 	B_SYSTEM_PROFILER_BUFFER_END,
46 
47 	// team
48 	B_SYSTEM_PROFILER_TEAM_ADDED,
49 	B_SYSTEM_PROFILER_TEAM_REMOVED,
50 	B_SYSTEM_PROFILER_TEAM_EXEC,
51 
52 	// thread
53 	B_SYSTEM_PROFILER_THREAD_ADDED,
54 	B_SYSTEM_PROFILER_THREAD_REMOVED,
55 
56 	// image
57 	B_SYSTEM_PROFILER_IMAGE_ADDED,
58 	B_SYSTEM_PROFILER_IMAGE_REMOVED,
59 
60 	// profiling samples
61 	B_SYSTEM_PROFILER_SAMPLES,
62 
63 	// scheduling
64 	B_SYSTEM_PROFILER_THREAD_SCHEDULED,
65 	B_SYSTEM_PROFILER_THREAD_ENQUEUED_IN_RUN_QUEUE,
66 	B_SYSTEM_PROFILER_THREAD_REMOVED_FROM_RUN_QUEUE,
67 	B_SYSTEM_PROFILER_WAIT_OBJECT_INFO,
68 
69 	// I/O scheduling
70 	B_SYSTEM_PROFILER_IO_SCHEDULER_ADDED,
71 	B_SYSTEM_PROFILER_IO_SCHEDULER_REMOVED,
72 	B_SYSTEM_PROFILER_IO_REQUEST_SCHEDULED,
73 	B_SYSTEM_PROFILER_IO_REQUEST_FINISHED,
74 	B_SYSTEM_PROFILER_IO_OPERATION_STARTED,
75 	B_SYSTEM_PROFILER_IO_OPERATION_FINISHED
76 };
77 
78 
79 struct system_profiler_buffer_header {
80 	size_t	start;
81 	size_t	size;
82 };
83 
84 
85 struct system_profiler_event_header {
86 	uint8	event;
87 	uint8	cpu;	// only for B_SYSTEM_PROFILER_SAMPLES
88 	uint16	size;	// size of the event structure excluding the header
89 };
90 
91 
92 // B_SYSTEM_PROFILER_TEAM_ADDED
93 struct system_profiler_team_added {
94 	team_id		team;
95 	uint16		args_offset;
96 	char		name[1];
97 };
98 
99 // B_SYSTEM_PROFILER_TEAM_REMOVED
100 struct system_profiler_team_removed {
101 	team_id		team;
102 };
103 
104 // B_SYSTEM_PROFILER_TEAM_EXEC
105 struct system_profiler_team_exec {
106 	team_id		team;
107 	char		thread_name[B_OS_NAME_LENGTH];
108 	char		args[1];
109 };
110 
111 // B_SYSTEM_PROFILER_THREAD_ADDED
112 struct system_profiler_thread_added {
113 	team_id		team;
114 	thread_id	thread;
115 	char		name[B_OS_NAME_LENGTH];
116 	bigtime_t	cpu_time;
117 };
118 
119 // B_SYSTEM_PROFILER_THREAD_REMOVED
120 struct system_profiler_thread_removed {
121 	team_id		team;
122 	thread_id	thread;
123 	bigtime_t	cpu_time;
124 };
125 
126 // B_SYSTEM_PROFILER_IMAGE_ADDED
127 struct system_profiler_image_added {
128 	team_id		team;
129 	image_info	info;
130 };
131 
132 // B_SYSTEM_PROFILER_IMAGE_REMOVED
133 struct system_profiler_image_removed {
134 	team_id		team;
135 	image_id	image;
136 };
137 
138 // B_SYSTEM_PROFILER_SAMPLES
139 struct system_profiler_samples {
140 	thread_id	thread;
141 	addr_t		samples[0];
142 };
143 
144 // base structure for the following three
145 struct system_profiler_thread_scheduling_event {
146 	nanotime_t	time;
147 	thread_id	thread;
148 };
149 
150 // B_SYSTEM_PROFILER_THREAD_SCHEDULED
151 struct system_profiler_thread_scheduled {
152 	nanotime_t	time;
153 	thread_id	thread;
154 	thread_id	previous_thread;
155 	uint16		previous_thread_state;
156 	uint16		previous_thread_wait_object_type;
157 	addr_t		previous_thread_wait_object;
158 };
159 
160 // B_SYSTEM_PROFILER_THREAD_ENQUEUED_IN_RUN_QUEUE
161 struct system_profiler_thread_enqueued_in_run_queue {
162 	nanotime_t	time;
163 	thread_id	thread;
164 	uint8		priority;
165 };
166 
167 // B_SYSTEM_PROFILER_THREAD_REMOVED_FROM_RUN_QUEUE
168 struct system_profiler_thread_removed_from_run_queue {
169 	nanotime_t	time;
170 	thread_id	thread;
171 };
172 
173 // B_SYSTEM_PROFILER_WAIT_OBJECT_INFO
174 struct system_profiler_wait_object_info {
175 	uint32		type;
176 	addr_t		object;
177 	addr_t		referenced_object;
178 	char		name[1];
179 };
180 
181 // B_SYSTEM_PROFILER_IO_SCHEDULER_ADDED
182 struct system_profiler_io_scheduler_added {
183 	int32		scheduler;
184 	char		name[1];
185 };
186 
187 // B_SYSTEM_PROFILER_IO_SCHEDULER_REMOVED
188 struct system_profiler_io_scheduler_removed {
189 	int32		scheduler;
190 };
191 
192 // B_SYSTEM_PROFILER_IO_REQUEST_SCHEDULED
193 struct system_profiler_io_request_scheduled {
194 	nanotime_t	time;
195 	int32		scheduler;
196 	team_id		team;
197 	thread_id	thread;
198 	void*		request;
199 	off_t		offset;
200 	size_t		length;
201 	bool		write;
202 	uint8		priority;
203 };
204 
205 // B_SYSTEM_PROFILER_IO_REQUEST_FINISHED
206 struct system_profiler_io_request_finished {
207 	nanotime_t	time;
208 	int32		scheduler;
209 	void*		request;
210 	status_t	status;
211 	size_t		transferred;
212 };
213 
214 // B_SYSTEM_PROFILER_IO_OPERATION_STARTED
215 struct system_profiler_io_operation_started {
216 	nanotime_t	time;
217 	int32		scheduler;
218 	void*		request;
219 	void*		operation;
220 	off_t		offset;
221 	size_t		length;
222 	bool		write;
223 };
224 
225 // B_SYSTEM_PROFILER_IO_OPERATION_FINISHED
226 struct system_profiler_io_operation_finished {
227 	nanotime_t	time;
228 	int32		scheduler;
229 	void*		request;
230 	void*		operation;
231 	status_t	status;
232 	size_t		transferred;
233 };
234 
235 
236 #endif	/* _SYSTEM_SYSTEM_PROFILER_DEFS_H */
237