13dc9bfd1SIngo Weinhold/*
23dc9bfd1SIngo Weinhold * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
33dc9bfd1SIngo Weinhold * Distributed under the terms of the MIT License.
43dc9bfd1SIngo Weinhold */
53dc9bfd1SIngo Weinhold#ifndef MAIN_MODEL_LOADER_H
63dc9bfd1SIngo Weinhold#define MAIN_MODEL_LOADER_H
73dc9bfd1SIngo Weinhold
81e336ebaSIngo Weinhold
9c2354448SIngo Weinhold#include <util/DoublyLinkedList.h>
10c2354448SIngo Weinhold
1164d5660eSIngo Weinhold#include "AbstractModelLoader.h"
121e336ebaSIngo Weinhold#include "Model.h"
131e336ebaSIngo Weinhold
143dc9bfd1SIngo Weinhold
153dc9bfd1SIngo Weinholdclass BDataIO;
163dc9bfd1SIngo Weinholdclass BDebugEventInputStream;
17c442235eSIngo Weinholdclass DataSource;
181e336ebaSIngo Weinholdstruct system_profiler_thread_added;
193dc9bfd1SIngo Weinhold
203dc9bfd1SIngo Weinhold
2164d5660eSIngo Weinholdclass ModelLoader : public AbstractModelLoader {
223dc9bfd1SIngo Weinholdpublic:
234f1804a1SIngo Weinhold								ModelLoader(DataSource* dataSource,
24c442235eSIngo Weinhold									const BMessenger& target,
25c442235eSIngo Weinhold									void* targetCookie);
263dc9bfd1SIngo Weinhold
2764d5660eSIngo Weinholdprotected:
2864d5660eSIngo Weinhold								~ModelLoader();
293dc9bfd1SIngo Weinhold
3064d5660eSIngo Weinholdpublic:
314f1804a1SIngo Weinhold			Model*				DetachModel();
323dc9bfd1SIngo Weinhold
3364d5660eSIngo Weinholdprotected:
3464d5660eSIngo Weinhold	virtual	status_t			PrepareForLoading();
3564d5660eSIngo Weinhold	virtual	status_t			Load();
3664d5660eSIngo Weinhold	virtual	void				FinishLoading(bool success);
3764d5660eSIngo Weinhold
381e336ebaSIngo Weinholdprivate:
391e336ebaSIngo Weinhold			// shorthands for the longish structure names
401e336ebaSIngo Weinhold			typedef system_profiler_thread_enqueued_in_run_queue
411e336ebaSIngo Weinhold				thread_enqueued_in_run_queue;
421e336ebaSIngo Weinhold			typedef system_profiler_thread_removed_from_run_queue
431e336ebaSIngo Weinhold				thread_removed_from_run_queue;
44c2354448SIngo Weinhold			typedef system_profiler_io_request_scheduled io_request_scheduled;
45c2354448SIngo Weinhold			typedef system_profiler_io_request_finished io_request_finished;
46c2354448SIngo Weinhold			typedef system_profiler_io_operation_started io_operation_started;
47c2354448SIngo Weinhold			typedef system_profiler_io_operation_finished io_operation_finished;
481e336ebaSIngo Weinhold
49bea40bcdSIngo Weinhold			struct CPUInfo;
50c2354448SIngo Weinhold			struct IOOperation;
51c2354448SIngo Weinhold			struct IORequest;
52c2354448SIngo Weinhold			struct IORequestHashDefinition;
53a63809d3SIngo Weinhold			struct ExtendedThreadSchedulingState;
54a63809d3SIngo Weinhold			struct ExtendedSchedulingState;
55bea40bcdSIngo Weinhold
56c2354448SIngo Weinhold			typedef DoublyLinkedList<ModelLoader::IOOperation> IOOperationList;
57c2354448SIngo Weinhold			typedef DoublyLinkedList<ModelLoader::IORequest> IORequestList;
58c2354448SIngo Weinhold			typedef BOpenHashTable<IORequestHashDefinition> IORequestTable;
59c2354448SIngo Weinhold
603dc9bfd1SIngo Weinholdprivate:
61c442235eSIngo Weinhold			status_t			_Load();
6208e34e27SIngo Weinhold			status_t			_ReadDebugEvents(void** _eventData,
6308e34e27SIngo Weinhold									size_t* _size);
646d5e661dSIngo Weinhold			status_t			_CreateDebugEventArray(void* eventData,
656d5e661dSIngo Weinhold									size_t eventDataSize,
666d5e661dSIngo Weinhold									system_profiler_event_header**& _events,
676d5e661dSIngo Weinhold									size_t& _eventCount);
6836e78710SIngo Weinhold			status_t			_ProcessEvent(uint32 event, uint32 cpu,
6936e78710SIngo Weinhold									const void* buffer, size_t size);
70a63809d3SIngo Weinhold			bool				_SetThreadEvents();
71c2354448SIngo Weinhold			bool				_SetThreadIORequests();
72c2354448SIngo Weinhold			void				_SetThreadIORequests(Model::Thread* thread,
73c2354448SIngo Weinhold									Model::IORequest** requests,
74c2354448SIngo Weinhold									size_t requestCount);
753dc9bfd1SIngo Weinhold
76d8d4b902SIngo Weinhold	inline	void				_UpdateLastEventTime(nanotime_t time);
779d7f0c33SIngo Weinhold
781e336ebaSIngo Weinhold			void				_HandleTeamAdded(
791e336ebaSIngo Weinhold									system_profiler_team_added* event);
801e336ebaSIngo Weinhold			void				_HandleTeamRemoved(
811e336ebaSIngo Weinhold									system_profiler_team_removed* event);
821e336ebaSIngo Weinhold			void				_HandleTeamExec(
831e336ebaSIngo Weinhold									system_profiler_team_exec* event);
841e336ebaSIngo Weinhold			void				_HandleThreadAdded(
851e336ebaSIngo Weinhold									system_profiler_thread_added* event);
861e336ebaSIngo Weinhold			void				_HandleThreadRemoved(
871e336ebaSIngo Weinhold									system_profiler_thread_removed* event);
88bea40bcdSIngo Weinhold			void				_HandleThreadScheduled(uint32 cpu,
891e336ebaSIngo Weinhold									system_profiler_thread_scheduled* event);
901e336ebaSIngo Weinhold			void				_HandleThreadEnqueuedInRunQueue(
911e336ebaSIngo Weinhold									thread_enqueued_in_run_queue* event);
92bea40bcdSIngo Weinhold			void				_HandleThreadRemovedFromRunQueue(uint32 cpu,
931e336ebaSIngo Weinhold									thread_removed_from_run_queue* event);
941e336ebaSIngo Weinhold			void				_HandleWaitObjectInfo(
951e336ebaSIngo Weinhold									system_profiler_wait_object_info* event);
96934a8d01SIngo Weinhold			void				_HandleIOSchedulerAdded(
97934a8d01SIngo Weinhold									system_profiler_io_scheduler_added* event);
98c2354448SIngo Weinhold			void				_HandleIORequestScheduled(
99c2354448SIngo Weinhold									io_request_scheduled* event);
100c2354448SIngo Weinhold			void				_HandleIORequestFinished(
101c2354448SIngo Weinhold									io_request_finished* event);
102c2354448SIngo Weinhold			void				_HandleIOOperationStarted(
103c2354448SIngo Weinhold									io_operation_started* event);
104c2354448SIngo Weinhold			void				_HandleIOOperationFinished(
105c2354448SIngo Weinhold									io_operation_finished* event);
1061e336ebaSIngo Weinhold
107a63809d3SIngo Weinhold			ExtendedThreadSchedulingState* _AddThread(
108d4d63490SIngo Weinhold									system_profiler_thread_added* event);
1095b78a987SIngo Weinhold			ExtendedThreadSchedulingState* _AddUnknownThread(
1105b78a987SIngo Weinhold									thread_id threadID);
1115b78a987SIngo Weinhold			Model::Team*		_AddUnknownTeam();
1125b78a987SIngo Weinhold
113a63809d3SIngo Weinhold			void				_AddThreadWaitObject(
114a63809d3SIngo Weinhold									ExtendedThreadSchedulingState* thread,
1151e336ebaSIngo Weinhold									uint32 type, addr_t object);
1161e336ebaSIngo Weinhold
117bea40bcdSIngo Weinhold			void				_AddIdleTime(uint32 cpu, nanotime_t time);
118bea40bcdSIngo Weinhold
1193dc9bfd1SIngo Weinholdprivate:
1204f1804a1SIngo Weinhold			Model*				fModel;
121c442235eSIngo Weinhold			DataSource*			fDataSource;
122bea40bcdSIngo Weinhold			CPUInfo*			fCPUInfos;
123d8d4b902SIngo Weinhold			nanotime_t			fBaseTime;
124a63809d3SIngo Weinhold			ExtendedSchedulingState* fState;
125c2354448SIngo Weinhold			IORequestTable*		fIORequests;
126bea40bcdSIngo Weinhold			uint32				fMaxCPUIndex;
1273dc9bfd1SIngo Weinhold};
1283dc9bfd1SIngo Weinhold
1293dc9bfd1SIngo Weinhold
1303dc9bfd1SIngo Weinhold#endif	// MAIN_MODEL_LOADER_H
131