xref: /haiku/headers/private/system/system_profiler_defs.h (revision 7eb6aafc307e7442d5b523d034870fd029d56aa5)
1e2ae69daSIngo Weinhold /*
2e2ae69daSIngo Weinhold  * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3e2ae69daSIngo Weinhold  * Distributed under the terms of the MIT License.
4e2ae69daSIngo Weinhold  */
5e2ae69daSIngo Weinhold #ifndef _SYSTEM_SYSTEM_PROFILER_DEFS_H
6e2ae69daSIngo Weinhold #define _SYSTEM_SYSTEM_PROFILER_DEFS_H
7e2ae69daSIngo Weinhold 
8d8d4b902SIngo Weinhold 
9e2ae69daSIngo Weinhold #include <image.h>
10e2ae69daSIngo Weinhold 
11e2ae69daSIngo Weinhold 
125b2f0f33SIngo Weinhold struct system_profiler_parameters {
135b2f0f33SIngo Weinhold 	// general
145b2f0f33SIngo Weinhold 	area_id		buffer_area;			// area the events will be written to
155b2f0f33SIngo Weinhold 	uint32		flags;					// flags selecting the events to receive
165b2f0f33SIngo Weinhold 
175b2f0f33SIngo Weinhold 	// scheduling
185b2f0f33SIngo Weinhold 	size_t		locking_lookup_size;	// size of the lookup table used for
195b2f0f33SIngo Weinhold 										// caching the locking primitive infos
205b2f0f33SIngo Weinhold 
215b2f0f33SIngo Weinhold 	// sampling
225b2f0f33SIngo Weinhold 	bigtime_t	interval;				// interval at which to take samples
235b2f0f33SIngo Weinhold 	uint32		stack_depth;			// maximum stack depth to sample
24*7eb6aafcSAugustin Cavalier 	bool		profile_kernel;			// sample kernel stack frames
255b2f0f33SIngo Weinhold };
265b2f0f33SIngo Weinhold 
275b2f0f33SIngo Weinhold 
285b2f0f33SIngo Weinhold // event flags
295b2f0f33SIngo Weinhold enum {
305b2f0f33SIngo Weinhold 	B_SYSTEM_PROFILER_TEAM_EVENTS			= 0x01,
315b2f0f33SIngo Weinhold 	B_SYSTEM_PROFILER_THREAD_EVENTS			= 0x02,
325b2f0f33SIngo Weinhold 	B_SYSTEM_PROFILER_IMAGE_EVENTS			= 0x04,
335b2f0f33SIngo Weinhold 	B_SYSTEM_PROFILER_SAMPLING_EVENTS		= 0x08,
34189010cbSIngo Weinhold 	B_SYSTEM_PROFILER_SCHEDULING_EVENTS		= 0x10,
35189010cbSIngo Weinhold 	B_SYSTEM_PROFILER_IO_SCHEDULING_EVENTS	= 0x20
365b2f0f33SIngo Weinhold };
375b2f0f33SIngo Weinhold 
385b2f0f33SIngo Weinhold 
39e2ae69daSIngo Weinhold // events
40e2ae69daSIngo Weinhold enum {
415b2f0f33SIngo Weinhold 	// reserved for the user application
425b2f0f33SIngo Weinhold 	B_SYSTEM_PROFILER_USER_EVENT = 0,
435b2f0f33SIngo Weinhold 
445b2f0f33SIngo Weinhold 	// ring buffer wrap-around marker
455b2f0f33SIngo Weinhold 	B_SYSTEM_PROFILER_BUFFER_END,
465b2f0f33SIngo Weinhold 
475b2f0f33SIngo Weinhold 	// team
485b2f0f33SIngo Weinhold 	B_SYSTEM_PROFILER_TEAM_ADDED,
49e2ae69daSIngo Weinhold 	B_SYSTEM_PROFILER_TEAM_REMOVED,
50e2ae69daSIngo Weinhold 	B_SYSTEM_PROFILER_TEAM_EXEC,
515b2f0f33SIngo Weinhold 
525b2f0f33SIngo Weinhold 	// thread
53e2ae69daSIngo Weinhold 	B_SYSTEM_PROFILER_THREAD_ADDED,
54e2ae69daSIngo Weinhold 	B_SYSTEM_PROFILER_THREAD_REMOVED,
555b2f0f33SIngo Weinhold 
565b2f0f33SIngo Weinhold 	// image
57e2ae69daSIngo Weinhold 	B_SYSTEM_PROFILER_IMAGE_ADDED,
58e2ae69daSIngo Weinhold 	B_SYSTEM_PROFILER_IMAGE_REMOVED,
595b2f0f33SIngo Weinhold 
605b2f0f33SIngo Weinhold 	// profiling samples
61e2ae69daSIngo Weinhold 	B_SYSTEM_PROFILER_SAMPLES,
625b2f0f33SIngo Weinhold 
635b2f0f33SIngo Weinhold 	// scheduling
645b2f0f33SIngo Weinhold 	B_SYSTEM_PROFILER_THREAD_SCHEDULED,
655b2f0f33SIngo Weinhold 	B_SYSTEM_PROFILER_THREAD_ENQUEUED_IN_RUN_QUEUE,
665b2f0f33SIngo Weinhold 	B_SYSTEM_PROFILER_THREAD_REMOVED_FROM_RUN_QUEUE,
67189010cbSIngo Weinhold 	B_SYSTEM_PROFILER_WAIT_OBJECT_INFO,
68189010cbSIngo Weinhold 
69189010cbSIngo Weinhold 	// I/O scheduling
70189010cbSIngo Weinhold 	B_SYSTEM_PROFILER_IO_SCHEDULER_ADDED,
71189010cbSIngo Weinhold 	B_SYSTEM_PROFILER_IO_SCHEDULER_REMOVED,
72189010cbSIngo Weinhold 	B_SYSTEM_PROFILER_IO_REQUEST_SCHEDULED,
73189010cbSIngo Weinhold 	B_SYSTEM_PROFILER_IO_REQUEST_FINISHED,
74189010cbSIngo Weinhold 	B_SYSTEM_PROFILER_IO_OPERATION_STARTED,
75189010cbSIngo Weinhold 	B_SYSTEM_PROFILER_IO_OPERATION_FINISHED
76e2ae69daSIngo Weinhold };
77e2ae69daSIngo Weinhold 
78e2ae69daSIngo Weinhold 
79e2ae69daSIngo Weinhold struct system_profiler_buffer_header {
80e2ae69daSIngo Weinhold 	size_t	start;
81e2ae69daSIngo Weinhold 	size_t	size;
82e2ae69daSIngo Weinhold };
83e2ae69daSIngo Weinhold 
84e2ae69daSIngo Weinhold 
85e2ae69daSIngo Weinhold struct system_profiler_event_header {
86e2ae69daSIngo Weinhold 	uint8	event;
87e2ae69daSIngo Weinhold 	uint8	cpu;	// only for B_SYSTEM_PROFILER_SAMPLES
88e2ae69daSIngo Weinhold 	uint16	size;	// size of the event structure excluding the header
89e2ae69daSIngo Weinhold };
90e2ae69daSIngo Weinhold 
91e2ae69daSIngo Weinhold 
92e2ae69daSIngo Weinhold // B_SYSTEM_PROFILER_TEAM_ADDED
93e2ae69daSIngo Weinhold struct system_profiler_team_added {
94e2ae69daSIngo Weinhold 	team_id		team;
95227fe7d3SIngo Weinhold 	uint16		args_offset;
96227fe7d3SIngo Weinhold 	char		name[1];
97e2ae69daSIngo Weinhold };
98e2ae69daSIngo Weinhold 
99e2ae69daSIngo Weinhold // B_SYSTEM_PROFILER_TEAM_REMOVED
100e2ae69daSIngo Weinhold struct system_profiler_team_removed {
101e2ae69daSIngo Weinhold 	team_id		team;
102e2ae69daSIngo Weinhold };
103e2ae69daSIngo Weinhold 
104e2ae69daSIngo Weinhold // B_SYSTEM_PROFILER_TEAM_EXEC
105e2ae69daSIngo Weinhold struct system_profiler_team_exec {
106e2ae69daSIngo Weinhold 	team_id		team;
1071b9d2885SIngo Weinhold 	char		thread_name[B_OS_NAME_LENGTH];
1081b9d2885SIngo Weinhold 	char		args[1];
109e2ae69daSIngo Weinhold };
110e2ae69daSIngo Weinhold 
111e2ae69daSIngo Weinhold // B_SYSTEM_PROFILER_THREAD_ADDED
112e2ae69daSIngo Weinhold struct system_profiler_thread_added {
113e2ae69daSIngo Weinhold 	team_id		team;
114e2ae69daSIngo Weinhold 	thread_id	thread;
1151b9d2885SIngo Weinhold 	char		name[B_OS_NAME_LENGTH];
1162813fd13SAugustin Cavalier 	bigtime_t	cpu_time;
117e2ae69daSIngo Weinhold };
118e2ae69daSIngo Weinhold 
119e2ae69daSIngo Weinhold // B_SYSTEM_PROFILER_THREAD_REMOVED
120e2ae69daSIngo Weinhold struct system_profiler_thread_removed {
121e2ae69daSIngo Weinhold 	team_id		team;
122e2ae69daSIngo Weinhold 	thread_id	thread;
1232813fd13SAugustin Cavalier 	bigtime_t	cpu_time;
124e2ae69daSIngo Weinhold };
125e2ae69daSIngo Weinhold 
126e2ae69daSIngo Weinhold // B_SYSTEM_PROFILER_IMAGE_ADDED
127e2ae69daSIngo Weinhold struct system_profiler_image_added {
128e2ae69daSIngo Weinhold 	team_id		team;
129e2ae69daSIngo Weinhold 	image_info	info;
130e2ae69daSIngo Weinhold };
131e2ae69daSIngo Weinhold 
132e2ae69daSIngo Weinhold // B_SYSTEM_PROFILER_IMAGE_REMOVED
133e2ae69daSIngo Weinhold struct system_profiler_image_removed {
134e2ae69daSIngo Weinhold 	team_id		team;
135e2ae69daSIngo Weinhold 	image_id	image;
136e2ae69daSIngo Weinhold };
137e2ae69daSIngo Weinhold 
138e2ae69daSIngo Weinhold // B_SYSTEM_PROFILER_SAMPLES
139e2ae69daSIngo Weinhold struct system_profiler_samples {
140e2ae69daSIngo Weinhold 	thread_id	thread;
141e2ae69daSIngo Weinhold 	addr_t		samples[0];
142e2ae69daSIngo Weinhold };
143e2ae69daSIngo Weinhold 
14422a332f0SIngo Weinhold // base structure for the following three
14522a332f0SIngo Weinhold struct system_profiler_thread_scheduling_event {
146d8d4b902SIngo Weinhold 	nanotime_t	time;
14722a332f0SIngo Weinhold 	thread_id	thread;
14822a332f0SIngo Weinhold };
14922a332f0SIngo Weinhold 
150227fe7d3SIngo Weinhold // B_SYSTEM_PROFILER_THREAD_SCHEDULED
1515b2f0f33SIngo Weinhold struct system_profiler_thread_scheduled {
152d8d4b902SIngo Weinhold 	nanotime_t	time;
1535b2f0f33SIngo Weinhold 	thread_id	thread;
1545b2f0f33SIngo Weinhold 	thread_id	previous_thread;
1555b2f0f33SIngo Weinhold 	uint16		previous_thread_state;
1565b2f0f33SIngo Weinhold 	uint16		previous_thread_wait_object_type;
1575b2f0f33SIngo Weinhold 	addr_t		previous_thread_wait_object;
1585b2f0f33SIngo Weinhold };
1595b2f0f33SIngo Weinhold 
160227fe7d3SIngo Weinhold // B_SYSTEM_PROFILER_THREAD_ENQUEUED_IN_RUN_QUEUE
1615b2f0f33SIngo Weinhold struct system_profiler_thread_enqueued_in_run_queue {
162d8d4b902SIngo Weinhold 	nanotime_t	time;
1635b2f0f33SIngo Weinhold 	thread_id	thread;
1645b2f0f33SIngo Weinhold 	uint8		priority;
1655b2f0f33SIngo Weinhold };
1665b2f0f33SIngo Weinhold 
167227fe7d3SIngo Weinhold // B_SYSTEM_PROFILER_THREAD_REMOVED_FROM_RUN_QUEUE
1685b2f0f33SIngo Weinhold struct system_profiler_thread_removed_from_run_queue {
169d8d4b902SIngo Weinhold 	nanotime_t	time;
1705b2f0f33SIngo Weinhold 	thread_id	thread;
1715b2f0f33SIngo Weinhold };
1725b2f0f33SIngo Weinhold 
1735b2f0f33SIngo Weinhold // B_SYSTEM_PROFILER_WAIT_OBJECT_INFO
1745b2f0f33SIngo Weinhold struct system_profiler_wait_object_info {
1755b2f0f33SIngo Weinhold 	uint32		type;
1765b2f0f33SIngo Weinhold 	addr_t		object;
1775b2f0f33SIngo Weinhold 	addr_t		referenced_object;
1785b2f0f33SIngo Weinhold 	char		name[1];
1795b2f0f33SIngo Weinhold };
1805b2f0f33SIngo Weinhold 
181189010cbSIngo Weinhold // B_SYSTEM_PROFILER_IO_SCHEDULER_ADDED
182189010cbSIngo Weinhold struct system_profiler_io_scheduler_added {
183189010cbSIngo Weinhold 	int32		scheduler;
184189010cbSIngo Weinhold 	char		name[1];
185189010cbSIngo Weinhold };
186189010cbSIngo Weinhold 
187189010cbSIngo Weinhold // B_SYSTEM_PROFILER_IO_SCHEDULER_REMOVED
188189010cbSIngo Weinhold struct system_profiler_io_scheduler_removed {
189189010cbSIngo Weinhold 	int32		scheduler;
190189010cbSIngo Weinhold };
191189010cbSIngo Weinhold 
192189010cbSIngo Weinhold // B_SYSTEM_PROFILER_IO_REQUEST_SCHEDULED
193189010cbSIngo Weinhold struct system_profiler_io_request_scheduled {
194189010cbSIngo Weinhold 	nanotime_t	time;
195189010cbSIngo Weinhold 	int32		scheduler;
196189010cbSIngo Weinhold 	team_id		team;
197189010cbSIngo Weinhold 	thread_id	thread;
198189010cbSIngo Weinhold 	void*		request;
199189010cbSIngo Weinhold 	off_t		offset;
200189010cbSIngo Weinhold 	size_t		length;
201189010cbSIngo Weinhold 	bool		write;
202189010cbSIngo Weinhold 	uint8		priority;
203189010cbSIngo Weinhold };
204189010cbSIngo Weinhold 
205189010cbSIngo Weinhold // B_SYSTEM_PROFILER_IO_REQUEST_FINISHED
206189010cbSIngo Weinhold struct system_profiler_io_request_finished {
207189010cbSIngo Weinhold 	nanotime_t	time;
208189010cbSIngo Weinhold 	int32		scheduler;
209189010cbSIngo Weinhold 	void*		request;
210189010cbSIngo Weinhold 	status_t	status;
211189010cbSIngo Weinhold 	size_t		transferred;
212189010cbSIngo Weinhold };
213189010cbSIngo Weinhold 
214189010cbSIngo Weinhold // B_SYSTEM_PROFILER_IO_OPERATION_STARTED
215189010cbSIngo Weinhold struct system_profiler_io_operation_started {
216189010cbSIngo Weinhold 	nanotime_t	time;
217189010cbSIngo Weinhold 	int32		scheduler;
218189010cbSIngo Weinhold 	void*		request;
219189010cbSIngo Weinhold 	void*		operation;
220189010cbSIngo Weinhold 	off_t		offset;
221189010cbSIngo Weinhold 	size_t		length;
222189010cbSIngo Weinhold 	bool		write;
223189010cbSIngo Weinhold };
224189010cbSIngo Weinhold 
225189010cbSIngo Weinhold // B_SYSTEM_PROFILER_IO_OPERATION_FINISHED
226189010cbSIngo Weinhold struct system_profiler_io_operation_finished {
227189010cbSIngo Weinhold 	nanotime_t	time;
228189010cbSIngo Weinhold 	int32		scheduler;
229189010cbSIngo Weinhold 	void*		request;
230189010cbSIngo Weinhold 	void*		operation;
231189010cbSIngo Weinhold 	status_t	status;
232189010cbSIngo Weinhold 	size_t		transferred;
233189010cbSIngo Weinhold };
234189010cbSIngo Weinhold 
235e2ae69daSIngo Weinhold 
236e2ae69daSIngo Weinhold #endif	/* _SYSTEM_SYSTEM_PROFILER_DEFS_H */
237