diff --git a/src/apps/debuganalyzer/Jamfile b/src/apps/debuganalyzer/Jamfile index 98e83d4e87..7b871af454 100644 --- a/src/apps/debuganalyzer/Jamfile +++ b/src/apps/debuganalyzer/Jamfile @@ -11,6 +11,7 @@ Application DebugAnalyzer Model.cpp ModelLoader.cpp Table.cpp + TableColumns.cpp ThreadsPage.cpp Variant.cpp diff --git a/src/apps/debuganalyzer/ModelLoader.cpp b/src/apps/debuganalyzer/ModelLoader.cpp index c407b214ea..e96daeb79b 100644 --- a/src/apps/debuganalyzer/ModelLoader.cpp +++ b/src/apps/debuganalyzer/ModelLoader.cpp @@ -21,6 +21,16 @@ #include "Model.h" +inline void +ModelLoader::_UpdateLastEventTime(bigtime_t time) +{ + if (fBaseTime < 0) + fBaseTime = time; + + fLastEventTime = time - fBaseTime; +} + + ModelLoader::ModelLoader(DataSource* dataSource, const BMessenger& target, void* targetCookie) : @@ -172,6 +182,7 @@ ModelLoader::_Load() return error; // process the events + fBaseTime = -1; fLastEventTime = -1; uint32 count = 0; @@ -284,7 +295,6 @@ ModelLoader::_ProcessEvent(uint32 event, uint32 cpu, const void* buffer, switch (event) { case B_SYSTEM_PROFILER_TEAM_ADDED: { -//printf("B_SYSTEM_PROFILER_TEAM_ADDED: %lu\n", size); system_profiler_team_added* event = (system_profiler_team_added*)buffer; @@ -295,7 +305,6 @@ ModelLoader::_ProcessEvent(uint32 event, uint32 cpu, const void* buffer, case B_SYSTEM_PROFILER_TEAM_REMOVED: { -//printf("B_SYSTEM_PROFILER_TEAM_REMOVED: %lu\n", size); system_profiler_team_removed* event = (system_profiler_team_removed*)buffer; @@ -308,12 +317,10 @@ ModelLoader::_ProcessEvent(uint32 event, uint32 cpu, const void* buffer, } case B_SYSTEM_PROFILER_TEAM_EXEC: -printf("B_SYSTEM_PROFILER_TEAM_EXEC: %lu\n", size); break; case B_SYSTEM_PROFILER_THREAD_ADDED: { -//printf("B_SYSTEM_PROFILER_THREAD_ADDED: %lu\n", size); system_profiler_thread_added* event = (system_profiler_thread_added*)buffer; @@ -325,7 +332,6 @@ printf("B_SYSTEM_PROFILER_TEAM_EXEC: %lu\n", size); } case B_SYSTEM_PROFILER_THREAD_REMOVED: -//printf("B_SYSTEM_PROFILER_THREAD_REMOVED: %lu\n", size); { system_profiler_thread_removed* event = (system_profiler_thread_removed*)buffer; @@ -339,16 +345,39 @@ printf("B_SYSTEM_PROFILER_TEAM_EXEC: %lu\n", size); } case B_SYSTEM_PROFILER_THREAD_SCHEDULED: -printf("B_SYSTEM_PROFILER_THREAD_SCHEDULED: %lu\n", size); + { + system_profiler_thread_scheduled* event + = (system_profiler_thread_scheduled*)buffer; + + _UpdateLastEventTime(event->time); + + // TODO:... break; + } + case B_SYSTEM_PROFILER_THREAD_ENQUEUED_IN_RUN_QUEUE: -printf("B_SYSTEM_PROFILER_THREAD_ENQUEUED_IN_RUN_QUEUE: %lu\n", size); + { + system_profiler_thread_enqueued_in_run_queue* event + = (system_profiler_thread_enqueued_in_run_queue*)buffer; + + _UpdateLastEventTime(event->time); + + // TODO:... break; + } + case B_SYSTEM_PROFILER_THREAD_REMOVED_FROM_RUN_QUEUE: -printf("B_SYSTEM_PROFILER_THREAD_REMOVED_FROM_RUN_QUEUE: %lu\n", size); + { + system_profiler_thread_removed_from_run_queue* event + = (system_profiler_thread_removed_from_run_queue*)buffer; + + _UpdateLastEventTime(event->time); + + // TODO:... break; + } + case B_SYSTEM_PROFILER_WAIT_OBJECT_INFO: -printf("B_SYSTEM_PROFILER_WAIT_OBJECT_INFO: %lu\n", size); break; default: printf("unsupported event type %lu, size: %lu\n", event, size); diff --git a/src/apps/debuganalyzer/ModelLoader.h b/src/apps/debuganalyzer/ModelLoader.h index d4bbc4ac6d..2e56402d8f 100644 --- a/src/apps/debuganalyzer/ModelLoader.h +++ b/src/apps/debuganalyzer/ModelLoader.h @@ -37,6 +37,8 @@ private: status_t _ProcessEvent(uint32 event, uint32 cpu, const void* buffer, size_t size); + inline void _UpdateLastEventTime(bigtime_t time); + private: BLocker fLock; Model* fModel; @@ -46,6 +48,7 @@ private: thread_id fLoaderThread; bool fLoading; bool fAborted; + bigtime_t fBaseTime; bigtime_t fLastEventTime; }; diff --git a/src/apps/debuganalyzer/Table.cpp b/src/apps/debuganalyzer/Table.cpp index ea52944024..7a41f0f8cb 100644 --- a/src/apps/debuganalyzer/Table.cpp +++ b/src/apps/debuganalyzer/Table.cpp @@ -137,90 +137,6 @@ TableColumn::GetPreferredWidth(BField* _field, BView* parent) const } -// #pragma mark - DelagateBasedTableColumn - - -DelagateBasedTableColumn::DelagateBasedTableColumn(BColumn* columnDelegate, - int32 modelIndex, float width, float minWidth, float maxWidth, - alignment align) - : - TableColumn(modelIndex, width, minWidth, maxWidth, align), - fColumnDelegate(columnDelegate) -{ -} - - -DelagateBasedTableColumn::~DelagateBasedTableColumn() -{ -} - - -void -DelagateBasedTableColumn::DrawTitle(BRect rect, BView* targetView) -{ - fColumnDelegate->DrawTitle(rect, targetView); -} - - -void -DelagateBasedTableColumn::GetColumnName(BString* into) const -{ - fColumnDelegate->GetColumnName(into); -} - - -void -DelagateBasedTableColumn::DrawValue(const Variant& value, BRect rect, - BView* targetView) -{ - fColumnDelegate->DrawField(PrepareField(value), rect, targetView); -} - - -float -DelagateBasedTableColumn::GetPreferredValueWidth(const Variant& value, - BView* parent) const -{ - return fColumnDelegate->GetPreferredWidth(PrepareField(value), parent); -} - - -// #pragma mark - StringTableColumn - - -StringTableColumn::StringTableColumn(int32 modelIndex, const char* title, - float width, float minWidth, float maxWidth, uint32 truncate, - alignment align) - : - DelagateBasedTableColumn(&fColumn, modelIndex, width, minWidth, maxWidth, - align), - fColumn(title, width, minWidth, maxWidth, truncate, align), - fField("") -{ -} - - -StringTableColumn::~StringTableColumn() -{ -} - - -BField* -StringTableColumn::PrepareField(const Variant& value) const -{ - fField.SetString(value.ToString()); - fField.SetWidth(Width()); - return &fField; -} - - -int -StringTableColumn::CompareValues(const Variant& a, const Variant& b) -{ - return strcmp(a.ToString(), b.ToString()); -} - - // #pragma mark - Table diff --git a/src/apps/debuganalyzer/Table.h b/src/apps/debuganalyzer/Table.h index f53a431554..a11090699b 100644 --- a/src/apps/debuganalyzer/Table.h +++ b/src/apps/debuganalyzer/Table.h @@ -66,52 +66,6 @@ private: }; -class DelagateBasedTableColumn : public TableColumn { -public: - DelagateBasedTableColumn( - BColumn* columnDelegate, - int32 modelIndex, float width, - float minWidth, float maxWidth, - alignment align); - virtual ~DelagateBasedTableColumn(); - -protected: - virtual void DrawTitle(BRect rect, BView* targetView); - virtual void GetColumnName(BString* into) const; - - virtual void DrawValue(const Variant& value, BRect rect, - BView* targetView); - virtual float GetPreferredValueWidth(const Variant& value, - BView* parent) const; - - virtual BField* PrepareField(const Variant& value) const = 0; - -protected: - BColumn* fColumnDelegate; -}; - - -class StringTableColumn : public DelagateBasedTableColumn { -public: - StringTableColumn(int32 modelIndex, - const char* title, float width, - float minWidth, float maxWidth, - uint32 truncate, - alignment align = B_ALIGN_LEFT); - virtual ~StringTableColumn(); - -protected: - virtual BField* PrepareField(const Variant& value) const; - - virtual int CompareValues(const Variant& a, - const Variant& b); - -private: - BStringColumn fColumn; - mutable BStringField fField; -}; - - class Table : private BColumnListView { public: Table(const char* name, uint32 flags, @@ -139,5 +93,4 @@ private: }; - #endif // TABLE_H diff --git a/src/apps/debuganalyzer/TableColumns.cpp b/src/apps/debuganalyzer/TableColumns.cpp new file mode 100644 index 0000000000..0f0d9dbc91 --- /dev/null +++ b/src/apps/debuganalyzer/TableColumns.cpp @@ -0,0 +1,178 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ + +#include "TableColumns.h" + +#include + + +// #pragma mark - DelagateBasedTableColumn + + +DelagateBasedTableColumn::DelagateBasedTableColumn(BColumn* columnDelegate, + int32 modelIndex, float width, float minWidth, float maxWidth, + alignment align) + : + TableColumn(modelIndex, width, minWidth, maxWidth, align), + fColumnDelegate(columnDelegate) +{ +} + + +DelagateBasedTableColumn::~DelagateBasedTableColumn() +{ +} + + +void +DelagateBasedTableColumn::DrawTitle(BRect rect, BView* targetView) +{ + fColumnDelegate->DrawTitle(rect, targetView); +} + + +void +DelagateBasedTableColumn::GetColumnName(BString* into) const +{ + fColumnDelegate->GetColumnName(into); +} + + +void +DelagateBasedTableColumn::DrawValue(const Variant& value, BRect rect, + BView* targetView) +{ + fColumnDelegate->DrawField(PrepareField(value), rect, targetView); +} + + +float +DelagateBasedTableColumn::GetPreferredValueWidth(const Variant& value, + BView* parent) const +{ + return fColumnDelegate->GetPreferredWidth(PrepareField(value), parent); +} + + +// #pragma mark - StringTableColumn + + +StringTableColumn::StringTableColumn(int32 modelIndex, const char* title, + float width, float minWidth, float maxWidth, uint32 truncate, + alignment align) + : + DelagateBasedTableColumn(&fColumn, modelIndex, width, minWidth, maxWidth, + align), + fColumn(title, width, minWidth, maxWidth, truncate, align), + fField("") +{ +} + + +StringTableColumn::~StringTableColumn() +{ +} + + +BField* +StringTableColumn::PrepareField(const Variant& value) const +{ + fField.SetString(value.ToString()); + fField.SetWidth(Width()); + return &fField; +} + + +int +StringTableColumn::CompareValues(const Variant& a, const Variant& b) +{ + return strcasecmp(a.ToString(), b.ToString()); +} + + +// #pragma mark - Int32TableColumn + + +Int32TableColumn::Int32TableColumn(int32 modelIndex, const char* title, + float width, float minWidth, float maxWidth, uint32 truncate, + alignment align) + : + StringTableColumn(modelIndex, title, width, minWidth, maxWidth, truncate, + align) +{ +} + + +BField* +Int32TableColumn::PrepareField(const Variant& value) const +{ + char buffer[16]; + snprintf(buffer, sizeof(buffer), "%ld", value.ToInt32()); + return StringTableColumn::PrepareField( + Variant(buffer, VARIANT_DONT_COPY_DATA)); +} + + +int +Int32TableColumn::CompareValues(const Variant& a, const Variant& b) +{ + return a.ToInt32() - b.ToInt32(); +} + + +// #pragma mark - BigtimeTableColumn + + +BigtimeTableColumn::BigtimeTableColumn(int32 modelIndex, const char* title, + float width, float minWidth, float maxWidth, bool invalidFirst, + uint32 truncate, alignment align) + : + StringTableColumn(modelIndex, title, width, minWidth, maxWidth, truncate, + align), + fInvalidFirst(invalidFirst) +{ +} + + +BField* +BigtimeTableColumn::PrepareField(const Variant& value) const +{ + bigtime_t time = value.ToInt64(); + if (time < 0) { + return StringTableColumn::PrepareField( + Variant("-", VARIANT_DONT_COPY_DATA)); + } + + int micros = int(time % 1000000); + time /= 1000000; + int seconds = int(time % 60); + time /= 60; + int minutes = int(time % 60); + time /= 60; + + char buffer[64]; + snprintf(buffer, sizeof(buffer), "%02lld:%02d:%02d:%06d", time, minutes, + seconds, micros); + return StringTableColumn::PrepareField( + Variant(buffer, VARIANT_DONT_COPY_DATA)); +} + + +int +BigtimeTableColumn::CompareValues(const Variant& _a, const Variant& _b) +{ + bigtime_t a = _a.ToInt64(); + bigtime_t b = _b.ToInt64(); + + if (a == b) + return 0; + + if (a < 0) + return fInvalidFirst ? -1 : 1; + if (b < 0) + return fInvalidFirst ? 1 : -1; + + return a - b < 0 ? -1 : 1; +} diff --git a/src/apps/debuganalyzer/TableColumns.h b/src/apps/debuganalyzer/TableColumns.h new file mode 100644 index 0000000000..d41ca15f46 --- /dev/null +++ b/src/apps/debuganalyzer/TableColumns.h @@ -0,0 +1,95 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ +#ifndef TABLE_COLUMNS_H +#define TABLE_COLUMNS_H + +#include + +#include "Table.h" + + +class DelagateBasedTableColumn : public TableColumn { +public: + DelagateBasedTableColumn( + BColumn* columnDelegate, + int32 modelIndex, float width, + float minWidth, float maxWidth, + alignment align); + virtual ~DelagateBasedTableColumn(); + +protected: + virtual void DrawTitle(BRect rect, BView* targetView); + virtual void GetColumnName(BString* into) const; + + virtual void DrawValue(const Variant& value, BRect rect, + BView* targetView); + virtual float GetPreferredValueWidth(const Variant& value, + BView* parent) const; + + virtual BField* PrepareField(const Variant& value) const = 0; + +protected: + BColumn* fColumnDelegate; +}; + + +class StringTableColumn : public DelagateBasedTableColumn { +public: + StringTableColumn(int32 modelIndex, + const char* title, float width, + float minWidth, float maxWidth, + uint32 truncate, + alignment align = B_ALIGN_LEFT); + virtual ~StringTableColumn(); + +protected: + virtual BField* PrepareField(const Variant& value) const; + + virtual int CompareValues(const Variant& a, + const Variant& b); + +private: + BStringColumn fColumn; + mutable BStringField fField; +}; + + +class Int32TableColumn : public StringTableColumn { +public: + Int32TableColumn(int32 modelIndex, + const char* title, float width, + float minWidth, float maxWidth, + uint32 truncate = B_TRUNCATE_MIDDLE, + alignment align = B_ALIGN_RIGHT); + +protected: + virtual BField* PrepareField(const Variant& value) const; + + virtual int CompareValues(const Variant& a, + const Variant& b); +}; + + +class BigtimeTableColumn : public StringTableColumn { +public: + BigtimeTableColumn(int32 modelIndex, + const char* title, float width, + float minWidth, float maxWidth, + bool invalidFirst, + uint32 truncate = B_TRUNCATE_MIDDLE, + alignment align = B_ALIGN_RIGHT); + +protected: + virtual BField* PrepareField(const Variant& value) const; + + virtual int CompareValues(const Variant& a, + const Variant& b); + +private: + bool fInvalidFirst; +}; + + +#endif // TABLE_COLUMNS_H diff --git a/src/apps/debuganalyzer/ThreadsPage.cpp b/src/apps/debuganalyzer/ThreadsPage.cpp index c201807202..e8e95c7ae3 100644 --- a/src/apps/debuganalyzer/ThreadsPage.cpp +++ b/src/apps/debuganalyzer/ThreadsPage.cpp @@ -10,7 +10,7 @@ #include #include "Model.h" -#include "Table.h" +#include "TableColumns.h" // #pragma mark - ThreadsTableModel @@ -41,9 +41,18 @@ public: return false; switch (columnIndex) { + case 0: + value.SetTo(thread->ID()); + return true; case 1: value.SetTo(thread->Name(), VARIANT_DONT_COPY_DATA); return true; + case 2: + value.SetTo(thread->CreationTime()); + return true; + case 3: + value.SetTo(thread->DeletionTime()); + return true; default: return false; } @@ -70,10 +79,14 @@ ThreadsPage::ThreadsPage() fThreadsTable = new Table("threads list", 0); AddChild(fThreadsTable->ToView()); -// fThreadsTable->AddColumn(new StringTableColumn(0, "Thread", 40, 20, 1000, -// B_TRUNCATE_END, B_ALIGN_RIGHT)); + fThreadsTable->AddColumn(new Int32TableColumn(0, "Thread", 40, 20, 1000, + B_TRUNCATE_MIDDLE, B_ALIGN_RIGHT)); fThreadsTable->AddColumn(new StringTableColumn(1, "Name", 80, 40, 1000, B_TRUNCATE_END, B_ALIGN_LEFT)); + fThreadsTable->AddColumn(new BigtimeTableColumn(2, "Creation", 80, 40, 1000, + true, B_TRUNCATE_MIDDLE, B_ALIGN_RIGHT)); + fThreadsTable->AddColumn(new BigtimeTableColumn(3, "Deletion", 80, 40, 1000, + false, B_TRUNCATE_MIDDLE, B_ALIGN_RIGHT)); // fThreadsTable->AddColumn(new StringTableColumn(2, "Run Time", 80, 20, 1000, // B_TRUNCATE_END, B_ALIGN_RIGHT)); // fThreadsTable->AddColumn(new StringTableColumn(3, "Wait Time", 80, 20, 1000,