From f0a592fd2215b5a349ae791d3bad99aa4970891a Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Wed, 23 Dec 2009 17:03:26 +0000 Subject: [PATCH] Added IOOperation and IORequest accessors and support methods. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34758 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/debuganalyzer/model/Model.cpp | 51 ++++--- src/apps/debuganalyzer/model/Model.h | 186 +++++++++++++++++++++++-- 2 files changed, 212 insertions(+), 25 deletions(-) diff --git a/src/apps/debuganalyzer/model/Model.cpp b/src/apps/debuganalyzer/model/Model.cpp index 3acce678d0..0c24b3f8f4 100644 --- a/src/apps/debuganalyzer/model/Model.cpp +++ b/src/apps/debuganalyzer/model/Model.cpp @@ -78,6 +78,22 @@ Model::CPU::SetIdleTime(nanotime_t time) // #pragma mark - IORequest +Model::IORequest::IORequest( + system_profiler_io_request_scheduled* scheduledEvent, + system_profiler_io_request_finished* finishedEvent, size_t operationCount) + : + scheduledEvent(scheduledEvent), + finishedEvent(finishedEvent), + operationCount(operationCount) +{ +} + + +Model::IORequest::~IORequest() +{ +} + + /*static*/ Model::IORequest* Model::IORequest::Create(system_profiler_io_request_scheduled* scheduledEvent, system_profiler_io_request_finished* finishedEvent, size_t operationCount) @@ -98,22 +114,6 @@ Model::IORequest::Delete() } -Model::IORequest::IORequest( - system_profiler_io_request_scheduled* scheduledEvent, - system_profiler_io_request_finished* finishedEvent, size_t operationCount) - : - scheduledEvent(scheduledEvent), - finishedEvent(finishedEvent), - operationCount(operationCount) -{ -} - - -Model::IORequest::~IORequest() -{ -} - - // #pragma mark - IOScheduler @@ -352,6 +352,25 @@ Model::Thread::SetIORequests(IORequest** requests, size_t requestCount) } +size_t +Model::Thread::ClosestRequestStartIndex(nanotime_t minRequestStartTime) const +{ + size_t lower = 0; + size_t upper = fIORequestCount; + while (lower < upper) { + size_t mid = (lower + upper) / 2; + IORequest* request = fIORequests[mid]; + + if (request->ScheduledTime() < minRequestStartTime) + lower = mid + 1; + else + upper = mid; + } + + return lower; +} + + Model::ThreadWaitObjectGroup* Model::Thread::ThreadWaitObjectGroupFor(uint32 type, addr_t object) const { diff --git a/src/apps/debuganalyzer/model/Model.h b/src/apps/debuganalyzer/model/Model.h index 7a1e7d95be..bf7ec9b704 100644 --- a/src/apps/debuganalyzer/model/Model.h +++ b/src/apps/debuganalyzer/model/Model.h @@ -193,6 +193,15 @@ struct Model::IOOperation { static inline int CompareByTime(const IOOperation* a, const IOOperation* b); + + inline nanotime_t StartedTime() const; + inline nanotime_t FinishedTime() const; + inline bool IsFinished() const; + inline off_t Offset() const; + inline size_t Length() const; + inline bool IsWrite() const; + inline status_t Status() const; + inline size_t BytesTransferred() const; }; @@ -202,6 +211,14 @@ struct Model::IORequest { size_t operationCount; IOOperation operations[0]; + IORequest( + system_profiler_io_request_scheduled* + scheduledEvent, + system_profiler_io_request_finished* + finishedEvent, + size_t operationCount); + ~IORequest(); + static IORequest* Create( system_profiler_io_request_scheduled* scheduledEvent, @@ -210,19 +227,24 @@ struct Model::IORequest { size_t operationCount); void Delete(); + inline nanotime_t ScheduledTime() const; + inline nanotime_t FinishedTime() const; + inline bool IsFinished() const; + inline int32 Scheduler() const; + inline off_t Offset() const; + inline size_t Length() const; + inline bool IsWrite() const; + inline uint8 Priority() const; + inline status_t Status() const; + inline size_t BytesTransferred() const; + + static inline bool TimeLess(const IORequest* a, const IORequest* b); static inline bool SchedulerTimeLess(const IORequest* a, const IORequest* b); - -private: - IORequest( - system_profiler_io_request_scheduled* - scheduledEvent, - system_profiler_io_request_finished* - finishedEvent, - size_t operationCount); - ~IORequest(); + static inline int CompareSchedulerTime(const IORequest* a, + const IORequest* b); }; @@ -424,6 +446,12 @@ public: inline size_t CountIORequests() const; void SetIORequests(IORequest** requests, size_t requestCount); + size_t ClosestRequestStartIndex( + nanotime_t minRequestStartTime) const; + // Returns the index of the first request + // with a start time >= minRequestStartTime. + // minRequestStartTime is absolute, not + // base time relative. inline nanotime_t CreationTime() const; inline nanotime_t DeletionTime() const; @@ -702,6 +730,62 @@ Model::CPU::IdleTime() const // #pragma mark - IOOperation +nanotime_t +Model::IOOperation::StartedTime() const +{ + return startedEvent->time; +} + + +nanotime_t +Model::IOOperation::FinishedTime() const +{ + return finishedEvent != NULL ? finishedEvent->time : 0; +} + + +bool +Model::IOOperation::IsFinished() const +{ + return finishedEvent != NULL; +} + + +off_t +Model::IOOperation::Offset() const +{ + return startedEvent->offset; +} + + +size_t +Model::IOOperation::Length() const +{ + return startedEvent->length; +} + + +bool +Model::IOOperation::IsWrite() const +{ + return startedEvent->write; +} + + +status_t +Model::IOOperation::Status() const +{ + return finishedEvent != NULL ? finishedEvent->status : B_OK; +} + + +size_t +Model::IOOperation::BytesTransferred() const +{ + return finishedEvent != NULL ? finishedEvent->transferred : 0; +} + + /*static*/ int Model::IOOperation::CompareByTime(const IOOperation* a, const IOOperation* b) { @@ -717,6 +801,76 @@ Model::IOOperation::CompareByTime(const IOOperation* a, const IOOperation* b) // #pragma mark - IORequest +nanotime_t +Model::IORequest::ScheduledTime() const +{ + return scheduledEvent->time; +} + + +nanotime_t +Model::IORequest::FinishedTime() const +{ + return finishedEvent != NULL ? finishedEvent->time : 0; +} + + +bool +Model::IORequest::IsFinished() const +{ + return finishedEvent != NULL; +} + + +int32 +Model::IORequest::Scheduler() const +{ + return scheduledEvent->scheduler; +} + + +off_t +Model::IORequest::Offset() const +{ + return scheduledEvent->offset; +} + + +size_t +Model::IORequest::Length() const +{ + return scheduledEvent->length; +} + + +bool +Model::IORequest::IsWrite() const +{ + return scheduledEvent->write; +} + + +uint8 +Model::IORequest::Priority() const +{ + return scheduledEvent->priority; +} + + +status_t +Model::IORequest::Status() const +{ + return finishedEvent != NULL ? finishedEvent->status : B_OK; +} + + +size_t +Model::IORequest::BytesTransferred() const +{ + return finishedEvent != NULL ? finishedEvent->transferred : 0; +} + + /*static*/ bool Model::IORequest::TimeLess(const IORequest* a, const IORequest* b) { @@ -735,6 +889,20 @@ Model::IORequest::SchedulerTimeLess(const IORequest* a, const IORequest* b) } +/*static*/ int +Model::IORequest::CompareSchedulerTime(const IORequest* a, const IORequest* b) +{ + int32 cmp = a->scheduledEvent->scheduler - b->scheduledEvent->scheduler; + if (cmp != 0) + return cmp < 0; + + nanotime_t timeCmp = a->scheduledEvent->time - b->scheduledEvent->time; + if (timeCmp == 0) + return 0; + return timeCmp < 0 ? -1 : 1; +} + + // #pragma mark - IOScheduler