13dc9bfd1SIngo Weinhold/*
23dc9bfd1SIngo Weinhold * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
33dc9bfd1SIngo Weinhold * Distributed under the terms of the MIT License.
43dc9bfd1SIngo Weinhold */
54f1804a1SIngo Weinhold#ifndef MODEL_H
64f1804a1SIngo Weinhold#define MODEL_H
73dc9bfd1SIngo Weinhold
8d4d63490SIngo Weinhold
9d4d63490SIngo Weinhold#include <stdlib.h>
10d4d63490SIngo Weinhold
1108e34e27SIngo Weinhold#include <OS.h>
1231391fedSIngo Weinhold#include <String.h>
1308e34e27SIngo Weinhold
1431391fedSIngo Weinhold#include <ObjectList.h>
15df540b50SIngo Weinhold#include <Referenceable.h>
16d4d63490SIngo Weinhold#include <util/OpenHashTable.h>
17df540b50SIngo Weinhold
1808e34e27SIngo Weinhold#include <system_profiler_defs.h>
191e336ebaSIngo Weinhold#include <util/SinglyLinkedList.h>
2008e34e27SIngo Weinhold
213dc9bfd1SIngo Weinhold
22d4d63490SIngo Weinholdenum ThreadState {
23d4d63490SIngo Weinhold	RUNNING,
24d4d63490SIngo Weinhold	STILL_RUNNING,
25d4d63490SIngo Weinhold	PREEMPTED,
26d4d63490SIngo Weinhold	READY,
27d4d63490SIngo Weinhold	WAITING,
28d4d63490SIngo Weinhold	UNKNOWN
29d4d63490SIngo Weinhold};
30d4d63490SIngo Weinhold
316d5e661dSIngo Weinholdconst char* thread_state_name(ThreadState state);
326d5e661dSIngo Weinholdconst char* wait_object_type_name(uint32 type);
336d5e661dSIngo Weinhold
34d4d63490SIngo Weinhold
35c3e066cfSIngo Weinholdclass Model : public BReferenceable {
363dc9bfd1SIngo Weinholdpublic:
3708e34e27SIngo Weinhold			struct creation_time_id;
381e336ebaSIngo Weinhold			struct type_and_object;
39bea40bcdSIngo Weinhold			class CPU;
40c2354448SIngo Weinhold			struct IOOperation;
41c2354448SIngo Weinhold			struct IORequest;
42934a8d01SIngo Weinhold			class IOScheduler;
431e336ebaSIngo Weinhold			class WaitObjectGroup;
441e336ebaSIngo Weinhold			class WaitObject;
451e336ebaSIngo Weinhold			class ThreadWaitObject;
461e336ebaSIngo Weinhold			class ThreadWaitObjectGroup;
4708e34e27SIngo Weinhold			class Team;
4808e34e27SIngo Weinhold			class Thread;
49d4d63490SIngo Weinhold			struct CompactThreadSchedulingState;
50d4d63490SIngo Weinhold			struct ThreadSchedulingState;
51d4d63490SIngo Weinhold			struct ThreadSchedulingStateDefinition;
52d4d63490SIngo Weinhold			typedef BOpenHashTable<ThreadSchedulingStateDefinition>
53d4d63490SIngo Weinhold				ThreadSchedulingStateTable;
54d4d63490SIngo Weinhold			class SchedulingState;
55d4d63490SIngo Weinhold			class CompactSchedulingState;
5608e34e27SIngo Weinhold
5708e34e27SIngo Weinholdpublic:
5831391fedSIngo Weinhold								Model(const char* dataSourceName,
596d5e661dSIngo Weinhold									void* eventData, size_t eventDataSize,
606d5e661dSIngo Weinhold									system_profiler_event_header** events,
616d5e661dSIngo Weinhold									size_t eventCount);
624f1804a1SIngo Weinhold								~Model();
633dc9bfd1SIngo Weinhold
6431391fedSIngo Weinhold	inline	const char*			DataSourceName() const;
65e8e86a50SIngo Weinhold	inline	void*				EventData() const;
66e8e86a50SIngo Weinhold	inline	size_t				EventDataSize() const;
676d5e661dSIngo Weinhold	inline	system_profiler_event_header** Events() const;
686d5e661dSIngo Weinhold	inline	size_t				CountEvents() const;
696d5e661dSIngo Weinhold			size_t				ClosestEventIndex(nanotime_t eventTime) const;
706d5e661dSIngo Weinhold									// finds the greatest event with event
716d5e661dSIngo Weinhold									// time >= eventTime; may return
726d5e661dSIngo Weinhold									// CountEvents()
7331391fedSIngo Weinhold
74e3bd3d83SIngo Weinhold			bool				AddAssociatedData(void* data);
75e3bd3d83SIngo Weinhold			void				RemoveAssociatedData(void* data);
76e3bd3d83SIngo Weinhold
77d4d63490SIngo Weinhold			void				LoadingFinished();
78d4d63490SIngo Weinhold
79d8d4b902SIngo Weinhold	inline	nanotime_t			BaseTime() const;
80d8d4b902SIngo Weinhold			void				SetBaseTime(nanotime_t time);
8131391fedSIngo Weinhold
82d8d4b902SIngo Weinhold	inline	nanotime_t			LastEventTime() const;
83d8d4b902SIngo Weinhold			void				SetLastEventTime(nanotime_t time);
8431391fedSIngo Weinhold
85bea40bcdSIngo Weinhold	inline	nanotime_t			IdleTime() const;
86bea40bcdSIngo Weinhold
87bea40bcdSIngo Weinhold	inline	int32				CountCPUs() const;
88bea40bcdSIngo Weinhold			bool				SetCPUCount(int32 count);
89bea40bcdSIngo Weinhold	inline	CPU*				CPUAt(int32 index) const;
90bea40bcdSIngo Weinhold
9108e34e27SIngo Weinhold			int32				CountTeams() const;
9208e34e27SIngo Weinhold			Team*				TeamAt(int32 index) const;
9308e34e27SIngo Weinhold			Team*				TeamByID(team_id id) const;
9408e34e27SIngo Weinhold			Team*				AddTeam(
9508e34e27SIngo Weinhold									const system_profiler_team_added* event,
96d8d4b902SIngo Weinhold									nanotime_t time);
9708e34e27SIngo Weinhold
9808e34e27SIngo Weinhold			int32				CountThreads() const;
9908e34e27SIngo Weinhold			Thread*				ThreadAt(int32 index) const;
10008e34e27SIngo Weinhold			Thread*				ThreadByID(thread_id id) const;
10108e34e27SIngo Weinhold			Thread*				AddThread(
10208e34e27SIngo Weinhold									const system_profiler_thread_added* event,
103d8d4b902SIngo Weinhold									nanotime_t time);
10408e34e27SIngo Weinhold
1051e336ebaSIngo Weinhold			WaitObject*			AddWaitObject(
1061e336ebaSIngo Weinhold									const system_profiler_wait_object_info*
1071e336ebaSIngo Weinhold										event,
1081e336ebaSIngo Weinhold									WaitObjectGroup** _waitObjectGroup);
1094e890d34SAxel Dörfler
1104e890d34SAxel Dörfler			int32				CountWaitObjectGroups() const;
1114e890d34SAxel Dörfler			WaitObjectGroup*	WaitObjectGroupAt(int32 index) const;
1121e336ebaSIngo Weinhold			WaitObjectGroup*	WaitObjectGroupFor(uint32 type,
1131e336ebaSIngo Weinhold									addr_t object) const;
1141e336ebaSIngo Weinhold
1151e336ebaSIngo Weinhold			ThreadWaitObject*	AddThreadWaitObject(thread_id threadID,
1161e336ebaSIngo Weinhold									WaitObject* waitObject,
1171e336ebaSIngo Weinhold									ThreadWaitObjectGroup**
1181e336ebaSIngo Weinhold										_threadWaitObjectGroup);
1191e336ebaSIngo Weinhold			ThreadWaitObjectGroup* ThreadWaitObjectGroupFor(
1201e336ebaSIngo Weinhold									thread_id threadID, uint32 type,
1211e336ebaSIngo Weinhold									addr_t object) const;
1221e336ebaSIngo Weinhold
123934a8d01SIngo Weinhold			int32				CountIOSchedulers() const;
124934a8d01SIngo Weinhold			IOScheduler*		IOSchedulerAt(int32 index) const;
125934a8d01SIngo Weinhold			IOScheduler*		IOSchedulerByID(int32 id) const;
126934a8d01SIngo Weinhold			IOScheduler*		AddIOScheduler(
127934a8d01SIngo Weinhold									system_profiler_io_scheduler_added* event);
128934a8d01SIngo Weinhold
129d4d63490SIngo Weinhold			bool				AddSchedulingStateSnapshot(
130d4d63490SIngo Weinhold									const SchedulingState& state,
131d4d63490SIngo Weinhold									off_t eventOffset);
132d4d63490SIngo Weinhold									// must be added in order (of time)
133d4d63490SIngo Weinhold			const CompactSchedulingState* ClosestSchedulingState(
134d8d4b902SIngo Weinhold									nanotime_t eventTime) const;
135d4d63490SIngo Weinhold									// returns the closest previous state
136d4d63490SIngo Weinhold
13708e34e27SIngo Weinholdprivate:
138bea40bcdSIngo Weinhold			typedef BObjectList<CPU> CPUList;
13908e34e27SIngo Weinhold			typedef BObjectList<Team> TeamList;
14008e34e27SIngo Weinhold			typedef BObjectList<Thread> ThreadList;
1411e336ebaSIngo Weinhold			typedef BObjectList<WaitObjectGroup> WaitObjectGroupList;
142934a8d01SIngo Weinhold			typedef BObjectList<IOScheduler> IOSchedulerList;
143d4d63490SIngo Weinhold			typedef BObjectList<CompactSchedulingState> SchedulingStateList;
144d4d63490SIngo Weinhold
145d4d63490SIngo Weinholdprivate:
1466d5e661dSIngo Weinhold	static	int					_CompareEventTimeSchedulingState(
1476d5e661dSIngo Weinhold									const nanotime_t* time,
1486d5e661dSIngo Weinhold									const CompactSchedulingState* state);
14908e34e27SIngo Weinhold
15008e34e27SIngo Weinholdprivate:
15131391fedSIngo Weinhold			BString				fDataSourceName;
15208e34e27SIngo Weinhold			void*				fEventData;
1536d5e661dSIngo Weinhold			system_profiler_event_header** fEvents;
15408e34e27SIngo Weinhold			size_t				fEventDataSize;
1556d5e661dSIngo Weinhold			size_t				fEventCount;
156bea40bcdSIngo Weinhold			int32				fCPUCount;
157d8d4b902SIngo Weinhold			nanotime_t			fBaseTime;
158d8d4b902SIngo Weinhold			nanotime_t			fLastEventTime;
159bea40bcdSIngo Weinhold			nanotime_t			fIdleTime;
160bea40bcdSIngo Weinhold			CPUList				fCPUs;
16108e34e27SIngo Weinhold			TeamList			fTeams;		// sorted by ID
16208e34e27SIngo Weinhold			ThreadList			fThreads;	// sorted by ID
1631e336ebaSIngo Weinhold			WaitObjectGroupList	fWaitObjectGroups;
164934a8d01SIngo Weinhold			IOSchedulerList		fIOSchedulers;
165d4d63490SIngo Weinhold			SchedulingStateList	fSchedulingStates;
166e3bd3d83SIngo Weinhold			BList				fAssociatedData;
16708e34e27SIngo Weinhold};
16808e34e27SIngo Weinhold
16908e34e27SIngo Weinhold
17008e34e27SIngo Weinholdstruct Model::creation_time_id {
171d8d4b902SIngo Weinhold	nanotime_t	time;
17208e34e27SIngo Weinhold	thread_id	id;
17308e34e27SIngo Weinhold};
17408e34e27SIngo Weinhold
17508e34e27SIngo Weinhold
1761e336ebaSIngo Weinholdstruct Model::type_and_object {
1771e336ebaSIngo Weinhold	uint32		type;
1781e336ebaSIngo Weinhold	addr_t		object;
1791e336ebaSIngo Weinhold};
1801e336ebaSIngo Weinhold
1811e336ebaSIngo Weinhold
182bea40bcdSIngo Weinholdclass Model::CPU {
183bea40bcdSIngo Weinholdpublic:
184bea40bcdSIngo Weinhold								CPU();
185bea40bcdSIngo Weinhold
186bea40bcdSIngo Weinhold	inline	nanotime_t			IdleTime() const;
187bea40bcdSIngo Weinhold			void				SetIdleTime(nanotime_t time);
188bea40bcdSIngo Weinhold
189bea40bcdSIngo Weinholdprivate:
190bea40bcdSIngo Weinhold			nanotime_t			fIdleTime;
191bea40bcdSIngo Weinhold};
192bea40bcdSIngo Weinhold
193bea40bcdSIngo Weinhold
194c2354448SIngo Weinholdstruct Model::IOOperation {
195c2354448SIngo Weinhold	system_profiler_io_operation_started*	startedEvent;
196c2354448SIngo Weinhold	system_profiler_io_operation_finished*	finishedEvent;
197934a8d01SIngo Weinhold
198934a8d01SIngo Weinhold	static inline int			CompareByTime(const IOOperation* a,
199934a8d01SIngo Weinhold									const IOOperation* b);
200f0a592fdSIngo Weinhold
201f0a592fdSIngo Weinhold	inline	nanotime_t			StartedTime() const;
202f0a592fdSIngo Weinhold	inline	nanotime_t			FinishedTime() const;
203f0a592fdSIngo Weinhold	inline	bool				IsFinished() const;
204f0a592fdSIngo Weinhold	inline	off_t				Offset() const;
205f0a592fdSIngo Weinhold	inline	size_t				Length() const;
206f0a592fdSIngo Weinhold	inline	bool				IsWrite() const;
207f0a592fdSIngo Weinhold	inline	status_t			Status() const;
208f0a592fdSIngo Weinhold	inline	size_t				BytesTransferred() const;
209c2354448SIngo Weinhold};
210c2354448SIngo Weinhold
211c2354448SIngo Weinhold
212c2354448SIngo Weinholdstruct Model::IORequest {
213c2354448SIngo Weinhold	system_profiler_io_request_scheduled*	scheduledEvent;
214c2354448SIngo Weinhold	system_profiler_io_request_finished*	finishedEvent;
215c2354448SIngo Weinhold	size_t									operationCount;
216c2354448SIngo Weinhold	IOOperation								operations[0];
217c2354448SIngo Weinhold
218f0a592fdSIngo Weinhold								IORequest(
219f0a592fdSIngo Weinhold									system_profiler_io_request_scheduled*
220f0a592fdSIngo Weinhold										scheduledEvent,
221f0a592fdSIngo Weinhold									system_profiler_io_request_finished*
222f0a592fdSIngo Weinhold										finishedEvent,
223f0a592fdSIngo Weinhold									size_t operationCount);
224f0a592fdSIngo Weinhold								~IORequest();
225f0a592fdSIngo Weinhold
226c2354448SIngo Weinhold	static	IORequest*			Create(
227c2354448SIngo Weinhold									system_profiler_io_request_scheduled*
228c2354448SIngo Weinhold										scheduledEvent,
229c2354448SIngo Weinhold									system_profiler_io_request_finished*
230c2354448SIngo Weinhold									finishedEvent,
231c2354448SIngo Weinhold									size_t operationCount);
232c2354448SIngo Weinhold			void				Delete();
233c2354448SIngo Weinhold
234f0a592fdSIngo Weinhold	inline	nanotime_t			ScheduledTime() const;
235f0a592fdSIngo Weinhold	inline	nanotime_t			FinishedTime() const;
236f0a592fdSIngo Weinhold	inline	bool				IsFinished() const;
237f0a592fdSIngo Weinhold	inline	int32				Scheduler() const;
238f0a592fdSIngo Weinhold	inline	off_t				Offset() const;
239f0a592fdSIngo Weinhold	inline	size_t				Length() const;
240f0a592fdSIngo Weinhold	inline	bool				IsWrite() const;
241f0a592fdSIngo Weinhold	inline	uint8				Priority() const;
242f0a592fdSIngo Weinhold	inline	status_t			Status() const;
243f0a592fdSIngo Weinhold	inline	size_t				BytesTransferred() const;
244f0a592fdSIngo Weinhold
245f0a592fdSIngo Weinhold
246934a8d01SIngo Weinhold	static inline bool			TimeLess(const IORequest* a,
247934a8d01SIngo Weinhold									const IORequest* b);
248c2354448SIngo Weinhold	static inline bool			SchedulerTimeLess(const IORequest* a,
249c2354448SIngo Weinhold									const IORequest* b);
250f0a592fdSIngo Weinhold	static inline int			CompareSchedulerTime(const IORequest* a,
251f0a592fdSIngo Weinhold									const IORequest* b);
252c2354448SIngo Weinhold};
253c2354448SIngo Weinhold
254c2354448SIngo Weinhold
255934a8d01SIngo Weinholdclass Model::IOScheduler {
256934a8d01SIngo Weinholdpublic:
257934a8d01SIngo Weinhold								IOScheduler(
258934a8d01SIngo Weinhold									system_profiler_io_scheduler_added* event,
259934a8d01SIngo Weinhold									int32 index);
260934a8d01SIngo Weinhold
261934a8d01SIngo Weinhold	inline	int32				ID() const;
262934a8d01SIngo Weinhold	inline	const char*			Name() const;
263934a8d01SIngo Weinhold	inline	int32				Index() const;
264934a8d01SIngo Weinhold
265934a8d01SIngo Weinholdprivate:
266934a8d01SIngo Weinhold			system_profiler_io_scheduler_added* fAddedEvent;
267934a8d01SIngo Weinhold			int32				fIndex;
268934a8d01SIngo Weinhold};
269934a8d01SIngo Weinhold
270934a8d01SIngo Weinhold
2714e890d34SAxel Dörflerclass Model::WaitObject {
2721e336ebaSIngo Weinholdpublic:
2731e336ebaSIngo Weinhold								WaitObject(
2741e336ebaSIngo Weinhold									const system_profiler_wait_object_info*
2751e336ebaSIngo Weinhold										event);
2761e336ebaSIngo Weinhold								~WaitObject();
2771e336ebaSIngo Weinhold
2781e336ebaSIngo Weinhold	inline	uint32				Type() const;
2791e336ebaSIngo Weinhold	inline	addr_t				Object() const;
2801e336ebaSIngo Weinhold	inline	const char*			Name() const;
2811e336ebaSIngo Weinhold	inline	addr_t				ReferencedObject();
2821e336ebaSIngo Weinhold
2834e890d34SAxel Dörfler	inline	int64				Waits() const;
284d8d4b902SIngo Weinhold	inline	nanotime_t			TotalWaitTime() const;
2854e890d34SAxel Dörfler
286d8d4b902SIngo Weinhold			void				AddWait(nanotime_t waitTime);
2874e890d34SAxel Dörfler
2881e336ebaSIngo Weinhold	static inline int			CompareByTypeObject(const WaitObject* a,
2891e336ebaSIngo Weinhold									const WaitObject* b);
2901e336ebaSIngo Weinhold	static inline int			CompareWithTypeObject(
2911e336ebaSIngo Weinhold									const type_and_object* key,
2921e336ebaSIngo Weinhold									const WaitObject* object);
2931e336ebaSIngo Weinhold
2941e336ebaSIngo Weinholdprivate:
2951e336ebaSIngo Weinhold			const system_profiler_wait_object_info* fEvent;
2964e890d34SAxel Dörfler
2974e890d34SAxel Dörflerprivate:
2984e890d34SAxel Dörfler			int64				fWaits;
299d8d4b902SIngo Weinhold			nanotime_t			fTotalWaitTime;
3001e336ebaSIngo Weinhold};
3011e336ebaSIngo Weinhold
3021e336ebaSIngo Weinhold
3031e336ebaSIngo Weinholdclass Model::WaitObjectGroup {
3041e336ebaSIngo Weinholdpublic:
3051e336ebaSIngo Weinhold								WaitObjectGroup(WaitObject* waitObject);
3061e336ebaSIngo Weinhold								~WaitObjectGroup();
3071e336ebaSIngo Weinhold
3081e336ebaSIngo Weinhold	inline	uint32				Type() const;
3091e336ebaSIngo Weinhold	inline	addr_t				Object() const;
3101e336ebaSIngo Weinhold	inline	const char*			Name() const;
3111e336ebaSIngo Weinhold
3124e890d34SAxel Dörfler			int64				Waits();
313d8d4b902SIngo Weinhold			nanotime_t			TotalWaitTime();
3144e890d34SAxel Dörfler
3151e336ebaSIngo Weinhold	inline	WaitObject*			MostRecentWaitObject() const;
3161e336ebaSIngo Weinhold
3174e890d34SAxel Dörfler	inline	int32				CountWaitObjects() const;
3184e890d34SAxel Dörfler	inline	Model::WaitObject*	WaitObjectAt(int32 index) const;
3194e890d34SAxel Dörfler
3201e336ebaSIngo Weinhold	inline	void				AddWaitObject(WaitObject* waitObject);
3211e336ebaSIngo Weinhold
3221e336ebaSIngo Weinhold	static inline int			CompareByTypeObject(const WaitObjectGroup* a,
3231e336ebaSIngo Weinhold									const WaitObjectGroup* b);
3241e336ebaSIngo Weinhold	static inline int			CompareWithTypeObject(
3251e336ebaSIngo Weinhold									const type_and_object* key,
3261e336ebaSIngo Weinhold									const WaitObjectGroup* group);
3271e336ebaSIngo Weinhold
3281e336ebaSIngo Weinholdprivate:
3294e890d34SAxel Dörfler			typedef BObjectList<WaitObject> WaitObjectList;
3304e890d34SAxel Dörfler
3314e890d34SAxel Dörfler			void				_ComputeWaits();
3321e336ebaSIngo Weinhold
3331e336ebaSIngo Weinholdprivate:
3341e336ebaSIngo Weinhold			WaitObjectList		fWaitObjects;
3354e890d34SAxel Dörfler			int64				fWaits;
336d8d4b902SIngo Weinhold			nanotime_t			fTotalWaitTime;
3371e336ebaSIngo Weinhold};
3381e336ebaSIngo Weinhold
3391e336ebaSIngo Weinhold
3401e336ebaSIngo Weinholdclass Model::ThreadWaitObject
3411e336ebaSIngo Weinhold	: public SinglyLinkedListLinkImpl<ThreadWaitObject> {
3421e336ebaSIngo Weinholdpublic:
3431e336ebaSIngo Weinhold								ThreadWaitObject(WaitObject* waitObject);
3441e336ebaSIngo Weinhold								~ThreadWaitObject();
3451e336ebaSIngo Weinhold
3461e336ebaSIngo Weinhold	inline	WaitObject*			GetWaitObject() const;
3471e336ebaSIngo Weinhold
348b592dac0SIngo Weinhold	inline	uint32				Type() const;
349b592dac0SIngo Weinhold	inline	addr_t				Object() const;
350b592dac0SIngo Weinhold	inline	const char*			Name() const;
351b592dac0SIngo Weinhold	inline	addr_t				ReferencedObject();
352b592dac0SIngo Weinhold
353e9b47e48SIngo Weinhold	inline	int64				Waits() const;
354d8d4b902SIngo Weinhold	inline	nanotime_t			TotalWaitTime() const;
355e9b47e48SIngo Weinhold
356d8d4b902SIngo Weinhold			void				AddWait(nanotime_t waitTime);
3571e336ebaSIngo Weinhold
3581e336ebaSIngo Weinholdprivate:
3591e336ebaSIngo Weinhold			WaitObject*			fWaitObject;
3601e336ebaSIngo Weinhold			int64				fWaits;
361d8d4b902SIngo Weinhold			nanotime_t			fTotalWaitTime;
3621e336ebaSIngo Weinhold};
3631e336ebaSIngo Weinhold
3641e336ebaSIngo Weinhold
3651e336ebaSIngo Weinholdclass Model::ThreadWaitObjectGroup {
3661e336ebaSIngo Weinholdpublic:
3671e336ebaSIngo Weinhold								ThreadWaitObjectGroup(
3681e336ebaSIngo Weinhold									ThreadWaitObject* threadWaitObject);
3691e336ebaSIngo Weinhold								~ThreadWaitObjectGroup();
3701e336ebaSIngo Weinhold
3716d5e661dSIngo Weinhold	inline	uint32				Type() const;
3726d5e661dSIngo Weinhold	inline	addr_t				Object() const;
3736d5e661dSIngo Weinhold	inline	const char*			Name() const;
3746d5e661dSIngo Weinhold
3751e336ebaSIngo Weinhold	inline	ThreadWaitObject*	MostRecentThreadWaitObject() const;
3761e336ebaSIngo Weinhold	inline	WaitObject*			MostRecentWaitObject() const;
3771e336ebaSIngo Weinhold
3781e336ebaSIngo Weinhold	inline	void				AddWaitObject(
3791e336ebaSIngo Weinhold									ThreadWaitObject* threadWaitObject);
3801e336ebaSIngo Weinhold
381055d771cSIngo Weinhold			bool				GetThreadWaitObjects(
382055d771cSIngo Weinhold									BObjectList<ThreadWaitObject>& objects);
383055d771cSIngo Weinhold
3841e336ebaSIngo Weinhold	static inline int			CompareByTypeObject(
3851e336ebaSIngo Weinhold									const ThreadWaitObjectGroup* a,
3861e336ebaSIngo Weinhold									const ThreadWaitObjectGroup* b);
3871e336ebaSIngo Weinhold	static inline int			CompareWithTypeObject(
3881e336ebaSIngo Weinhold									const type_and_object* key,
3891e336ebaSIngo Weinhold									const ThreadWaitObjectGroup* group);
3901e336ebaSIngo Weinhold
3911e336ebaSIngo Weinholdprivate:
3921e336ebaSIngo Weinhold			typedef SinglyLinkedList<ThreadWaitObject> ThreadWaitObjectList;
3931e336ebaSIngo Weinhold
3941e336ebaSIngo Weinholdprivate:
3951e336ebaSIngo Weinhold			ThreadWaitObjectList fWaitObjects;
3961e336ebaSIngo Weinhold};
3971e336ebaSIngo Weinhold
3981e336ebaSIngo Weinhold
39908e34e27SIngo Weinholdclass Model::Team {
40008e34e27SIngo Weinholdpublic:
40108e34e27SIngo Weinhold								Team(const system_profiler_team_added* event,
402d8d4b902SIngo Weinhold									nanotime_t time);
40308e34e27SIngo Weinhold								~Team();
40408e34e27SIngo Weinhold
40508e34e27SIngo Weinhold	inline	team_id				ID() const;
406df540b50SIngo Weinhold	inline	const char*			Name() const;
40708e34e27SIngo Weinhold
408d8d4b902SIngo Weinhold	inline	nanotime_t			CreationTime() const;
409d8d4b902SIngo Weinhold	inline	nanotime_t			DeletionTime() const;
410f57c87acSIngo Weinhold
41108e34e27SIngo Weinhold			bool				AddThread(Thread* thread);
41208e34e27SIngo Weinhold
413d8d4b902SIngo Weinhold	inline	void				SetDeletionTime(nanotime_t time);
41408e34e27SIngo Weinhold
41508e34e27SIngo Weinhold	static inline int			CompareByID(const Team* a, const Team* b);
41608e34e27SIngo Weinhold	static inline int			CompareWithID(const team_id* id,
41708e34e27SIngo Weinhold									const Team* team);
41808e34e27SIngo Weinhold
41908e34e27SIngo Weinholdprivate:
42008e34e27SIngo Weinhold			typedef BObjectList<Thread> ThreadList;
42108e34e27SIngo Weinhold
42208e34e27SIngo Weinholdprivate:
42308e34e27SIngo Weinhold			const system_profiler_team_added* fCreationEvent;
424d8d4b902SIngo Weinhold			nanotime_t			fCreationTime;
425d8d4b902SIngo Weinhold			nanotime_t			fDeletionTime;
42608e34e27SIngo Weinhold			ThreadList			fThreads;	// sorted by creation time, ID
42708e34e27SIngo Weinhold};
42808e34e27SIngo Weinhold
42908e34e27SIngo Weinhold
43008e34e27SIngo Weinholdclass Model::Thread {
43108e34e27SIngo Weinholdpublic:
43208e34e27SIngo Weinhold								Thread(Team* team,
43308e34e27SIngo Weinhold									const system_profiler_thread_added* event,
434d8d4b902SIngo Weinhold									nanotime_t time);
43508e34e27SIngo Weinhold								~Thread();
43608e34e27SIngo Weinhold
43708e34e27SIngo Weinhold	inline	thread_id			ID() const;
43882d9e197SIngo Weinhold	inline	const char*			Name() const;
439df540b50SIngo Weinhold	inline	Team*				GetTeam() const;
44008e34e27SIngo Weinhold
441d4d63490SIngo Weinhold	inline	int32				Index() const;
442d4d63490SIngo Weinhold	inline	void				SetIndex(int32 index);
443d4d63490SIngo Weinhold
444a63809d3SIngo Weinhold	inline	system_profiler_event_header** Events() const;
445a63809d3SIngo Weinhold	inline	size_t				CountEvents() const;
446a63809d3SIngo Weinhold			void				SetEvents(system_profiler_event_header** events,
447a63809d3SIngo Weinhold									size_t eventCount);
448a63809d3SIngo Weinhold
449c2354448SIngo Weinhold	inline	IORequest**			IORequests() const;
450c2354448SIngo Weinhold	inline	size_t				CountIORequests() const;
451c2354448SIngo Weinhold			void				SetIORequests(IORequest** requests,
452c2354448SIngo Weinhold									size_t requestCount);
453f0a592fdSIngo Weinhold			size_t				ClosestRequestStartIndex(
454f0a592fdSIngo Weinhold									nanotime_t minRequestStartTime) const;
455f0a592fdSIngo Weinhold									// Returns the index of the first request
456f0a592fdSIngo Weinhold									// with a start time >= minRequestStartTime.
457f0a592fdSIngo Weinhold									// minRequestStartTime is absolute, not
458f0a592fdSIngo Weinhold									// base time relative.
459c2354448SIngo Weinhold
460d8d4b902SIngo Weinhold	inline	nanotime_t			CreationTime() const;
461d8d4b902SIngo Weinhold	inline	nanotime_t			DeletionTime() const;
462f57c87acSIngo Weinhold
4631e336ebaSIngo Weinhold	inline	int64				Runs() const;
464d8d4b902SIngo Weinhold	inline	nanotime_t			TotalRunTime() const;
4651e336ebaSIngo Weinhold	inline	int64				Reruns() const;
466d8d4b902SIngo Weinhold	inline	nanotime_t			TotalRerunTime() const;
4671e336ebaSIngo Weinhold	inline	int64				Latencies() const;
468d8d4b902SIngo Weinhold	inline	nanotime_t			TotalLatency() const;
4691e336ebaSIngo Weinhold	inline	int64				Preemptions() const;
470d1331844SIngo Weinhold	inline	int64				Waits() const;
471d8d4b902SIngo Weinhold	inline	nanotime_t			TotalWaitTime() const;
472d8d4b902SIngo Weinhold	inline	nanotime_t			UnspecifiedWaitTime() const;
4731e336ebaSIngo Weinhold
474c2354448SIngo Weinhold	inline	int64				IOCount() const;
475c2354448SIngo Weinhold	inline	nanotime_t			IOTime() const;
476c2354448SIngo Weinhold
4771e336ebaSIngo Weinhold			ThreadWaitObjectGroup* ThreadWaitObjectGroupFor(uint32 type,
4781e336ebaSIngo Weinhold									addr_t object) const;
479055d771cSIngo Weinhold	inline	int32				CountThreadWaitObjectGroups() const;
480055d771cSIngo Weinhold	inline	ThreadWaitObjectGroup* ThreadWaitObjectGroupAt(int32 index) const;
4811e336ebaSIngo Weinhold
482d8d4b902SIngo Weinhold	inline	void				SetDeletionTime(nanotime_t time);
48308e34e27SIngo Weinhold
484d8d4b902SIngo Weinhold			void				AddRun(nanotime_t runTime);
485d8d4b902SIngo Weinhold			void				AddRerun(nanotime_t runTime);
486d8d4b902SIngo Weinhold			void				AddLatency(nanotime_t latency);
487d8d4b902SIngo Weinhold			void				AddPreemption(nanotime_t runTime);
488d8d4b902SIngo Weinhold			void				AddWait(nanotime_t waitTime);
489d8d4b902SIngo Weinhold			void				AddUnspecifiedWait(nanotime_t waitTime);
4901e336ebaSIngo Weinhold
4911e336ebaSIngo Weinhold			ThreadWaitObject*	AddThreadWaitObject(WaitObject* waitObject,
4921e336ebaSIngo Weinhold									ThreadWaitObjectGroup**
4931e336ebaSIngo Weinhold										_threadWaitObjectGroup);
4941e336ebaSIngo Weinhold
495c2354448SIngo Weinhold			void				SetIOs(int64 count, nanotime_t time);
496c2354448SIngo Weinhold
49708e34e27SIngo Weinhold	static inline int			CompareByID(const Thread* a, const Thread* b);
49808e34e27SIngo Weinhold	static inline int			CompareWithID(const thread_id* id,
49908e34e27SIngo Weinhold									const Thread* thread);
50008e34e27SIngo Weinhold
50108e34e27SIngo Weinhold	static inline int			CompareByCreationTimeID(const Thread* a,
50208e34e27SIngo Weinhold									const Thread* b);
50308e34e27SIngo Weinhold	static inline int			CompareWithCreationTimeID(
50408e34e27SIngo Weinhold									const creation_time_id* key,
50508e34e27SIngo Weinhold									const Thread* thread);
50608e34e27SIngo Weinhold
5071e336ebaSIngo Weinholdprivate:
5081e336ebaSIngo Weinhold			typedef BObjectList<ThreadWaitObjectGroup>
5091e336ebaSIngo Weinhold				ThreadWaitObjectGroupList;
5101e336ebaSIngo Weinhold
5113dc9bfd1SIngo Weinholdprivate:
512a63809d3SIngo Weinhold			system_profiler_event_header** fEvents;
513a63809d3SIngo Weinhold			size_t				fEventCount;
514a63809d3SIngo Weinhold
515c2354448SIngo Weinhold			IORequest**			fIORequests;
516c2354448SIngo Weinhold			size_t				fIORequestCount;
517c2354448SIngo Weinhold
51808e34e27SIngo Weinhold			Team*				fTeam;
51908e34e27SIngo Weinhold			const system_profiler_thread_added* fCreationEvent;
520d8d4b902SIngo Weinhold			nanotime_t			fCreationTime;
521d8d4b902SIngo Weinhold			nanotime_t			fDeletionTime;
5221e336ebaSIngo Weinhold
5231e336ebaSIngo Weinhold			int64				fRuns;
524d8d4b902SIngo Weinhold			nanotime_t			fTotalRunTime;
525d8d4b902SIngo Weinhold			nanotime_t			fMinRunTime;
526d8d4b902SIngo Weinhold			nanotime_t			fMaxRunTime;
5271e336ebaSIngo Weinhold
5281e336ebaSIngo Weinhold			int64				fLatencies;
529d8d4b902SIngo Weinhold			nanotime_t			fTotalLatency;
530d8d4b902SIngo Weinhold			nanotime_t			fMinLatency;
531d8d4b902SIngo Weinhold			nanotime_t			fMaxLatency;
5321e336ebaSIngo Weinhold
5331e336ebaSIngo Weinhold			int64				fReruns;
534d8d4b902SIngo Weinhold			nanotime_t			fTotalRerunTime;
535d8d4b902SIngo Weinhold			nanotime_t			fMinRerunTime;
536d8d4b902SIngo Weinhold			nanotime_t			fMaxRerunTime;
5371e336ebaSIngo Weinhold
538d1331844SIngo Weinhold			int64				fWaits;
539d8d4b902SIngo Weinhold			nanotime_t			fTotalWaitTime;
540d8d4b902SIngo Weinhold			nanotime_t			fUnspecifiedWaitTime;
5411e336ebaSIngo Weinhold
542c2354448SIngo Weinhold			int64				fIOCount;
543c2354448SIngo Weinhold			nanotime_t			fIOTime;
544c2354448SIngo Weinhold
5451e336ebaSIngo Weinhold			int64				fPreemptions;
5461e336ebaSIngo Weinhold
547d4d63490SIngo Weinhold			int32				fIndex;
548d4d63490SIngo Weinhold
5491e336ebaSIngo Weinhold			ThreadWaitObjectGroupList fWaitObjectGroups;
5503dc9bfd1SIngo Weinhold};
5513dc9bfd1SIngo Weinhold
5523dc9bfd1SIngo Weinhold
553d4d63490SIngo Weinholdstruct Model::CompactThreadSchedulingState {
554d8d4b902SIngo Weinhold			nanotime_t			lastTime;
555d4d63490SIngo Weinhold			Model::Thread*		thread;
556d4d63490SIngo Weinhold			ThreadWaitObject*	waitObject;
557d4d63490SIngo Weinhold			ThreadState			state;
558bea40bcdSIngo Weinhold			uint8				priority;
559d4d63490SIngo Weinhold
560d4d63490SIngo Weinholdpublic:
561d4d63490SIngo Weinhold			thread_id			ID() const	{ return thread->ID(); }
562d4d63490SIngo Weinhold
563d4d63490SIngo Weinhold	inline	CompactThreadSchedulingState& operator=(
564d4d63490SIngo Weinhold									const CompactThreadSchedulingState& other);
565d4d63490SIngo Weinhold};
566d4d63490SIngo Weinhold
567d4d63490SIngo Weinhold
568d4d63490SIngo Weinholdstruct Model::ThreadSchedulingState : CompactThreadSchedulingState {
569d4d63490SIngo Weinhold			ThreadSchedulingState* next;
570d4d63490SIngo Weinhold
571d4d63490SIngo Weinholdpublic:
572d4d63490SIngo Weinhold	inline						ThreadSchedulingState(
573d4d63490SIngo Weinhold									const CompactThreadSchedulingState& other);
574d4d63490SIngo Weinhold	inline						ThreadSchedulingState(Thread* thread);
575d4d63490SIngo Weinhold};
576d4d63490SIngo Weinhold
577d4d63490SIngo Weinhold
578d4d63490SIngo Weinholdstruct Model::ThreadSchedulingStateDefinition {
579d4d63490SIngo Weinhold	typedef thread_id				KeyType;
580d4d63490SIngo Weinhold	typedef	ThreadSchedulingState	ValueType;
581d4d63490SIngo Weinhold
582d4d63490SIngo Weinhold	size_t HashKey(thread_id key) const
583d4d63490SIngo Weinhold		{ return (size_t)key; }
584d4d63490SIngo Weinhold
585d4d63490SIngo Weinhold	size_t Hash(const ThreadSchedulingState* value) const
586d4d63490SIngo Weinhold		{ return (size_t)value->ID(); }
587d4d63490SIngo Weinhold
588d4d63490SIngo Weinhold	bool Compare(thread_id key, const ThreadSchedulingState* value) const
589d4d63490SIngo Weinhold		{ return key == value->ID(); }
590d4d63490SIngo Weinhold
591d4d63490SIngo Weinhold	ThreadSchedulingState*& GetLink(ThreadSchedulingState* value) const
592d4d63490SIngo Weinhold		{ return value->next; }
593d4d63490SIngo Weinhold};
594d4d63490SIngo Weinhold
595d4d63490SIngo Weinhold
596d4d63490SIngo Weinholdclass Model::SchedulingState {
597d4d63490SIngo Weinholdpublic:
598d4d63490SIngo Weinhold	inline						SchedulingState();
599a63809d3SIngo Weinhold	virtual						~SchedulingState();
600d4d63490SIngo Weinhold
601d4d63490SIngo Weinhold			status_t			Init();
602d4d63490SIngo Weinhold			status_t			Init(const CompactSchedulingState* state);
603d4d63490SIngo Weinhold			void				Clear();
604d4d63490SIngo Weinhold
605d8d4b902SIngo Weinhold	inline	nanotime_t			LastEventTime() const { return fLastEventTime; }
606d8d4b902SIngo Weinhold	inline	void				SetLastEventTime(nanotime_t time);
607d4d63490SIngo Weinhold
608d4d63490SIngo Weinhold	inline	ThreadSchedulingState* LookupThread(thread_id threadID) const;
609d4d63490SIngo Weinhold	inline	void				InsertThread(ThreadSchedulingState* thread);
610d4d63490SIngo Weinhold	inline	void				RemoveThread(ThreadSchedulingState* thread);
611d4d63490SIngo Weinhold	inline	const ThreadSchedulingStateTable& ThreadStates() const;
612d4d63490SIngo Weinhold
613a63809d3SIngo Weinholdprotected:
614a63809d3SIngo Weinhold	virtual	void				DeleteThread(ThreadSchedulingState* thread);
615a63809d3SIngo Weinhold
616d4d63490SIngo Weinholdprivate:
617d8d4b902SIngo Weinhold			nanotime_t			fLastEventTime;
618d4d63490SIngo Weinhold			ThreadSchedulingStateTable fThreadStates;
619d4d63490SIngo Weinhold};
620d4d63490SIngo Weinhold
621d4d63490SIngo Weinhold
622d4d63490SIngo Weinholdclass Model::CompactSchedulingState {
623d4d63490SIngo Weinholdpublic:
624d4d63490SIngo Weinhold	static	CompactSchedulingState* Create(const SchedulingState& state,
625d4d63490SIngo Weinhold									off_t eventOffset);
626d4d63490SIngo Weinhold			void				Delete();
627d4d63490SIngo Weinhold
628d4d63490SIngo Weinhold	inline	off_t				EventOffset() const;
629d8d4b902SIngo Weinhold	inline	nanotime_t			LastEventTime() const;
630d4d63490SIngo Weinhold
631d4d63490SIngo Weinhold	inline	int32				CountThreadsStates() const;
632d4d63490SIngo Weinhold	inline	const CompactThreadSchedulingState* ThreadStateAt(int32 index)
633d4d63490SIngo Weinhold									const;
634d4d63490SIngo Weinhold
635d4d63490SIngo Weinholdprivate:
636d4d63490SIngo Weinhold	friend class BObjectList<CompactSchedulingState>;
637d4d63490SIngo Weinhold		// work-around for our private destructor
638d4d63490SIngo Weinhold
639d4d63490SIngo Weinholdprivate:
640d4d63490SIngo Weinhold								CompactSchedulingState();
641d4d63490SIngo Weinhold	inline						~CompactSchedulingState() {}
642d4d63490SIngo Weinhold
643d4d63490SIngo Weinholdprivate:
644d8d4b902SIngo Weinhold			nanotime_t			fLastEventTime;
645d4d63490SIngo Weinhold			off_t				fEventOffset;
646d4d63490SIngo Weinhold			int32				fThreadCount;
647d4d63490SIngo Weinhold			CompactThreadSchedulingState fThreadStates[0];
648d4d63490SIngo Weinhold};
649d4d63490SIngo Weinhold
650d4d63490SIngo Weinhold
65131391fedSIngo Weinhold// #pragma mark - Model
65231391fedSIngo Weinhold
65331391fedSIngo Weinhold
65431391fedSIngo Weinholdconst char*
65531391fedSIngo WeinholdModel::DataSourceName() const
65631391fedSIngo Weinhold{
65731391fedSIngo Weinhold	return fDataSourceName.String();
65831391fedSIngo Weinhold}
65931391fedSIngo Weinhold
66031391fedSIngo Weinhold
661e8e86a50SIngo Weinholdvoid*
662e8e86a50SIngo WeinholdModel::EventData() const
663e8e86a50SIngo Weinhold{
664e8e86a50SIngo Weinhold	return fEventData;
665e8e86a50SIngo Weinhold}
666e8e86a50SIngo Weinhold
667e8e86a50SIngo Weinhold
668e8e86a50SIngo Weinholdsize_t
669e8e86a50SIngo WeinholdModel::EventDataSize() const
670e8e86a50SIngo Weinhold{
671e8e86a50SIngo Weinhold	return fEventDataSize;
672e8e86a50SIngo Weinhold}
673e8e86a50SIngo Weinhold
674e8e86a50SIngo Weinhold
6756d5e661dSIngo Weinholdsystem_profiler_event_header**
6766d5e661dSIngo WeinholdModel::Events() const
6776d5e661dSIngo Weinhold{
6786d5e661dSIngo Weinhold	return fEvents;
6796d5e661dSIngo Weinhold}
6806d5e661dSIngo Weinhold
6816d5e661dSIngo Weinhold
6826d5e661dSIngo Weinholdsize_t
6836d5e661dSIngo WeinholdModel::CountEvents() const
6846d5e661dSIngo Weinhold{
6856d5e661dSIngo Weinhold	return fEventCount;
6866d5e661dSIngo Weinhold}
6876d5e661dSIngo Weinhold
6886d5e661dSIngo Weinhold
689d8d4b902SIngo Weinholdnanotime_t
69031391fedSIngo WeinholdModel::BaseTime() const
69131391fedSIngo Weinhold{
69231391fedSIngo Weinhold	return fBaseTime;
69331391fedSIngo Weinhold}
69431391fedSIngo Weinhold
69531391fedSIngo Weinhold
696d8d4b902SIngo Weinholdnanotime_t
69731391fedSIngo WeinholdModel::LastEventTime() const
69831391fedSIngo Weinhold{
69931391fedSIngo Weinhold	return fLastEventTime;
70031391fedSIngo Weinhold}
70131391fedSIngo Weinhold
70231391fedSIngo Weinhold
703bea40bcdSIngo Weinholdnanotime_t
704bea40bcdSIngo WeinholdModel::IdleTime() const
705bea40bcdSIngo Weinhold{
706bea40bcdSIngo Weinhold	return fIdleTime;
707bea40bcdSIngo Weinhold}
708bea40bcdSIngo Weinhold
709bea40bcdSIngo Weinhold
710bea40bcdSIngo Weinholdint32
711bea40bcdSIngo WeinholdModel::CountCPUs() const
712bea40bcdSIngo Weinhold{
713bea40bcdSIngo Weinhold	return fCPUCount;
714bea40bcdSIngo Weinhold}
715bea40bcdSIngo Weinhold
716bea40bcdSIngo Weinhold
717bea40bcdSIngo WeinholdModel::CPU*
718bea40bcdSIngo WeinholdModel::CPUAt(int32 index) const
719bea40bcdSIngo Weinhold{
720bea40bcdSIngo Weinhold	return fCPUs.ItemAt(index);
721bea40bcdSIngo Weinhold}
722bea40bcdSIngo Weinhold
723bea40bcdSIngo Weinhold
724bea40bcdSIngo Weinhold// #pragma mark - CPU
725bea40bcdSIngo Weinhold
726bea40bcdSIngo Weinhold
727bea40bcdSIngo Weinholdnanotime_t
728bea40bcdSIngo WeinholdModel::CPU::IdleTime() const
729bea40bcdSIngo Weinhold{
730bea40bcdSIngo Weinhold	return fIdleTime;
731bea40bcdSIngo Weinhold}
732bea40bcdSIngo Weinhold
733bea40bcdSIngo Weinhold
734934a8d01SIngo Weinhold// #pragma mark - IOOperation
735934a8d01SIngo Weinhold
736934a8d01SIngo Weinhold
737f0a592fdSIngo Weinholdnanotime_t
738f0a592fdSIngo WeinholdModel::IOOperation::StartedTime() const
739f0a592fdSIngo Weinhold{
740f0a592fdSIngo Weinhold	return startedEvent->time;
741f0a592fdSIngo Weinhold}
742f0a592fdSIngo Weinhold
743f0a592fdSIngo Weinhold
744f0a592fdSIngo Weinholdnanotime_t
745f0a592fdSIngo WeinholdModel::IOOperation::FinishedTime() const
746f0a592fdSIngo Weinhold{
747f0a592fdSIngo Weinhold	return finishedEvent != NULL ? finishedEvent->time : 0;
748f0a592fdSIngo Weinhold}
749f0a592fdSIngo Weinhold
750f0a592fdSIngo Weinhold
751f0a592fdSIngo Weinholdbool
752f0a592fdSIngo WeinholdModel::IOOperation::IsFinished() const
753f0a592fdSIngo Weinhold{
754f0a592fdSIngo Weinhold	return finishedEvent != NULL;
755f0a592fdSIngo Weinhold}
756f0a592fdSIngo Weinhold
757f0a592fdSIngo Weinhold
758f0a592fdSIngo Weinholdoff_t
759f0a592fdSIngo WeinholdModel::IOOperation::Offset() const
760f0a592fdSIngo Weinhold{
761f0a592fdSIngo Weinhold	return startedEvent->offset;
762f0a592fdSIngo Weinhold}
763f0a592fdSIngo Weinhold
764f0a592fdSIngo Weinhold
765f0a592fdSIngo Weinholdsize_t
766f0a592fdSIngo WeinholdModel::IOOperation::Length() const
767f0a592fdSIngo Weinhold{
768f0a592fdSIngo Weinhold	return startedEvent->length;
769f0a592fdSIngo Weinhold}
770f0a592fdSIngo Weinhold
771f0a592fdSIngo Weinhold
772f0a592fdSIngo Weinholdbool
773f0a592fdSIngo WeinholdModel::IOOperation::IsWrite() const
774f0a592fdSIngo Weinhold{
775f0a592fdSIngo Weinhold	return startedEvent->write;
776f0a592fdSIngo Weinhold}
777f0a592fdSIngo Weinhold
778f0a592fdSIngo Weinhold
779f0a592fdSIngo Weinholdstatus_t
780f0a592fdSIngo WeinholdModel::IOOperation::Status() const
781f0a592fdSIngo Weinhold{
782f0a592fdSIngo Weinhold	return finishedEvent != NULL ? finishedEvent->status : B_OK;
783f0a592fdSIngo Weinhold}
784f0a592fdSIngo Weinhold
785f0a592fdSIngo Weinhold
786f0a592fdSIngo Weinholdsize_t
787f0a592fdSIngo WeinholdModel::IOOperation::BytesTransferred() const
788f0a592fdSIngo Weinhold{
789f0a592fdSIngo Weinhold	return finishedEvent != NULL ? finishedEvent->transferred : 0;
790f0a592fdSIngo Weinhold}
791f0a592fdSIngo Weinhold
792f0a592fdSIngo Weinhold
793934a8d01SIngo Weinhold/*static*/ int
794934a8d01SIngo WeinholdModel::IOOperation::CompareByTime(const IOOperation* a, const IOOperation* b)
795934a8d01SIngo Weinhold{
796934a8d01SIngo Weinhold	nanotime_t timeA = a->startedEvent->time;
797934a8d01SIngo Weinhold	nanotime_t timeB = b->startedEvent->time;
798934a8d01SIngo Weinhold
799934a8d01SIngo Weinhold	if (timeA < timeB)
800934a8d01SIngo Weinhold		return -1;
801934a8d01SIngo Weinhold	return timeA == timeB ? 0 : 1;
802934a8d01SIngo Weinhold}
803934a8d01SIngo Weinhold
804934a8d01SIngo Weinhold
805934a8d01SIngo Weinhold// #pragma mark - IORequest
806934a8d01SIngo Weinhold
807934a8d01SIngo Weinhold
808f0a592fdSIngo Weinholdnanotime_t
809f0a592fdSIngo WeinholdModel::IORequest::ScheduledTime() const
810f0a592fdSIngo Weinhold{
811f0a592fdSIngo Weinhold	return scheduledEvent->time;
812f0a592fdSIngo Weinhold}
813f0a592fdSIngo Weinhold
814f0a592fdSIngo Weinhold
815f0a592fdSIngo Weinholdnanotime_t
816f0a592fdSIngo WeinholdModel::IORequest::FinishedTime() const
817f0a592fdSIngo Weinhold{
818f0a592fdSIngo Weinhold	return finishedEvent != NULL ? finishedEvent->time : 0;
819f0a592fdSIngo Weinhold}
820f0a592fdSIngo Weinhold
821f0a592fdSIngo Weinhold
822f0a592fdSIngo Weinholdbool
823f0a592fdSIngo WeinholdModel::IORequest::IsFinished() const
824f0a592fdSIngo Weinhold{
825f0a592fdSIngo Weinhold	return finishedEvent != NULL;
826f0a592fdSIngo Weinhold}
827f0a592fdSIngo Weinhold
828f0a592fdSIngo Weinhold
829f0a592fdSIngo Weinholdint32
830f0a592fdSIngo WeinholdModel::IORequest::Scheduler() const
831f0a592fdSIngo Weinhold{
832f0a592fdSIngo Weinhold	return scheduledEvent->scheduler;
833f0a592fdSIngo Weinhold}
834f0a592fdSIngo Weinhold
835f0a592fdSIngo Weinhold
836f0a592fdSIngo Weinholdoff_t
837f0a592fdSIngo WeinholdModel::IORequest::Offset() const
838f0a592fdSIngo Weinhold{
839f0a592fdSIngo Weinhold	return scheduledEvent->offset;
840f0a592fdSIngo Weinhold}
841f0a592fdSIngo Weinhold
842f0a592fdSIngo Weinhold
843f0a592fdSIngo Weinholdsize_t
844f0a592fdSIngo WeinholdModel::IORequest::Length() const
845f0a592fdSIngo Weinhold{
846f0a592fdSIngo Weinhold	return scheduledEvent->length;
847f0a592fdSIngo Weinhold}
848f0a592fdSIngo Weinhold
849f0a592fdSIngo Weinhold
850f0a592fdSIngo Weinholdbool
851f0a592fdSIngo WeinholdModel::IORequest::IsWrite() const
852f0a592fdSIngo Weinhold{
853f0a592fdSIngo Weinhold	return scheduledEvent->write;
854f0a592fdSIngo Weinhold}
855f0a592fdSIngo Weinhold
856f0a592fdSIngo Weinhold
857f0a592fdSIngo Weinholduint8
858f0a592fdSIngo WeinholdModel::IORequest::Priority() const
859f0a592fdSIngo Weinhold{
860f0a592fdSIngo Weinhold	return scheduledEvent->priority;
861f0a592fdSIngo Weinhold}
862f0a592fdSIngo Weinhold
863f0a592fdSIngo Weinhold
864f0a592fdSIngo Weinholdstatus_t
865f0a592fdSIngo WeinholdModel::IORequest::Status() const
866f0a592fdSIngo Weinhold{
867f0a592fdSIngo Weinhold	return finishedEvent != NULL ? finishedEvent->status : B_OK;
868f0a592fdSIngo Weinhold}
869f0a592fdSIngo Weinhold
870f0a592fdSIngo Weinhold
871f0a592fdSIngo Weinholdsize_t
872f0a592fdSIngo WeinholdModel::IORequest::BytesTransferred() const
873f0a592fdSIngo Weinhold{
874f0a592fdSIngo Weinhold	return finishedEvent != NULL ? finishedEvent->transferred : 0;
875f0a592fdSIngo Weinhold}
876f0a592fdSIngo Weinhold
877f0a592fdSIngo Weinhold
878934a8d01SIngo Weinhold/*static*/ bool
879934a8d01SIngo WeinholdModel::IORequest::TimeLess(const IORequest* a, const IORequest* b)
880934a8d01SIngo Weinhold{
881934a8d01SIngo Weinhold	return a->scheduledEvent->time < b->scheduledEvent->time;
882934a8d01SIngo Weinhold}
8831e336ebaSIngo Weinhold
8841e336ebaSIngo Weinhold
885c2354448SIngo Weinhold/*static*/ bool
886c2354448SIngo WeinholdModel::IORequest::SchedulerTimeLess(const IORequest* a, const IORequest* b)
887c2354448SIngo Weinhold{
888c2354448SIngo Weinhold	int32 cmp = a->scheduledEvent->scheduler - b->scheduledEvent->scheduler;
889c2354448SIngo Weinhold	if (cmp != 0)
890c2354448SIngo Weinhold		return cmp < 0;
891c2354448SIngo Weinhold
892c2354448SIngo Weinhold	return a->scheduledEvent->time < b->scheduledEvent->time;
893c2354448SIngo Weinhold}
894c2354448SIngo Weinhold
895c2354448SIngo Weinhold
896f0a592fdSIngo Weinhold/*static*/ int
897f0a592fdSIngo WeinholdModel::IORequest::CompareSchedulerTime(const IORequest* a, const IORequest* b)
898f0a592fdSIngo Weinhold{
899f0a592fdSIngo Weinhold	int32 cmp = a->scheduledEvent->scheduler - b->scheduledEvent->scheduler;
900f0a592fdSIngo Weinhold	if (cmp != 0)
901f0a592fdSIngo Weinhold		return cmp < 0;
902f0a592fdSIngo Weinhold
903f0a592fdSIngo Weinhold	nanotime_t timeCmp = a->scheduledEvent->time - b->scheduledEvent->time;
904f0a592fdSIngo Weinhold	if (timeCmp == 0)
905f0a592fdSIngo Weinhold		return 0;
906f0a592fdSIngo Weinhold	return timeCmp < 0 ? -1 : 1;
907f0a592fdSIngo Weinhold}
908f0a592fdSIngo Weinhold
909f0a592fdSIngo Weinhold
910934a8d01SIngo Weinhold// #pragma mark - IOScheduler
911934a8d01SIngo Weinhold
912934a8d01SIngo Weinhold
913934a8d01SIngo Weinholdint32
914