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