From 8cd416d9e638d1b89f0608d22c92e2e6f530e708 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Thu, 30 Apr 2009 12:25:56 +0000 Subject: [PATCH] The thread model does now also store the scheduling events for the thread. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30506 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/debuganalyzer/model/ThreadModel.cpp | 43 ++++++++++++++++++++ src/apps/debuganalyzer/model/ThreadModel.h | 24 +++++++++++ 2 files changed, 67 insertions(+) diff --git a/src/apps/debuganalyzer/model/ThreadModel.cpp b/src/apps/debuganalyzer/model/ThreadModel.cpp index 00772b112e..f8517b2a3e 100644 --- a/src/apps/debuganalyzer/model/ThreadModel.cpp +++ b/src/apps/debuganalyzer/model/ThreadModel.cpp @@ -83,3 +83,46 @@ ThreadModel::AddWaitObjectGroup( return group; } + + +bool +ThreadModel::AddSchedulingEvent(const system_profiler_event_header* eventHeader) +{ + return fSchedulingEvents.AddItem(eventHeader); +} + + +int32 +ThreadModel::FindSchedulingEvent(bigtime_t time) +{ + if (time < 0) + return 0; + + time += fModel->BaseTime(); + + int32 lower = 0; + int32 upper = CountSchedulingEvents(); + + while (lower < upper) { + int32 mid = (lower + upper) / 2; + const system_profiler_event_header* header = SchedulingEventAt(mid); + system_profiler_thread_scheduling_event* event + = (system_profiler_thread_scheduling_event*)(header + 1); + if (event->time < time) + lower = mid + 1; + else + upper = mid; + } + + // We've found the first event that has a time >= the given time. If its + // time is >, we rather return the previous event. + if (lower > 0) { + const system_profiler_event_header* header = SchedulingEventAt(lower); + system_profiler_thread_scheduling_event* event + = (system_profiler_thread_scheduling_event*)(header + 1); + if (event->time > time) + lower--; + } + + return lower; +} diff --git a/src/apps/debuganalyzer/model/ThreadModel.h b/src/apps/debuganalyzer/model/ThreadModel.h index 8e21644123..9d56ff8a29 100644 --- a/src/apps/debuganalyzer/model/ThreadModel.h +++ b/src/apps/debuganalyzer/model/ThreadModel.h @@ -30,13 +30,23 @@ public: inline int32 CountWaitObjectGroups() const; inline WaitObjectGroup* WaitObjectGroupAt(int32 index) const; + bool AddSchedulingEvent( + const system_profiler_event_header* + eventHeader); + inline int32 CountSchedulingEvents() const; + inline const system_profiler_event_header* SchedulingEventAt( + int32 index) const; + int32 FindSchedulingEvent(bigtime_t time); + private: typedef BObjectList WaitObjectGroupList; + typedef BObjectList EventList; private: Model* fModel; Model::Thread* fThread; WaitObjectGroupList fWaitObjectGroups; + EventList fSchedulingEvents; }; @@ -93,6 +103,20 @@ ThreadModel::WaitObjectGroupAt(int32 index) const } +int32 +ThreadModel::CountSchedulingEvents() const +{ + return fSchedulingEvents.CountItems(); +} + + +const system_profiler_event_header* +ThreadModel::SchedulingEventAt(int32 index) const +{ + return fSchedulingEvents.ItemAt(index); +} + + // #pragma mark - WaitObjectGroup