From ef7102fa292c7e917d70749baca47373749a18d5 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Tue, 12 Aug 2008 21:16:15 +0000 Subject: [PATCH] * Made TraceEntryIterator available in the kernel. * Fixed TraceEntryIterator::Current(): If fEntry was NULL, it would return 0x4. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26955 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/kernel/tracing.h | 45 +++++++ src/system/kernel/debug/tracing.cpp | 174 ++++++++++++---------------- 2 files changed, 121 insertions(+), 98 deletions(-) diff --git a/headers/private/kernel/tracing.h b/headers/private/kernel/tracing.h index a5e0aacd43..d8e3fe2d90 100644 --- a/headers/private/kernel/tracing.h +++ b/headers/private/kernel/tracing.h @@ -63,6 +63,7 @@ class TraceOutput { bigtime_t fLastEntryTime; }; + class TraceEntry { public: TraceEntry(); @@ -89,6 +90,7 @@ class TraceEntry { } }; + class AbstractTraceEntry : public TraceEntry { public: AbstractTraceEntry(); @@ -108,6 +110,7 @@ class AbstractTraceEntry : public TraceEntry { bigtime_t fTime; }; + class LazyTraceOutput : public TraceOutput { public: LazyTraceOutput(char* buffer, size_t bufferSize, uint32 flags) @@ -126,6 +129,7 @@ public: } }; + class TraceFilter { public: virtual ~TraceFilter(); @@ -145,11 +149,52 @@ public: }; }; + class WrapperTraceFilter : public TraceFilter { public: virtual void Init(TraceFilter* filter, int direction, bool continued) = 0; }; + +class TraceEntryIterator { +public: + TraceEntryIterator() + : + fEntry(NULL), + fIndex(0) + { + } + + void Reset() + { + fEntry = NULL; + fIndex = 0; + } + + int32 Index() const + { + return fIndex; + } + + TraceEntry* Current() const + { + return fEntry != NULL ? TraceEntry::FromTraceEntry(fEntry) : NULL; + } + + TraceEntry* Next(); + TraceEntry* Previous(); + TraceEntry* MoveTo(int32 index); + +private: + trace_entry* _NextNonBufferEntry(trace_entry* entry); + trace_entry* _PreviousNonBufferEntry(trace_entry* entry); + +private: + trace_entry* fEntry; + int32 fIndex; +}; + + #endif // __cplusplus #ifdef __cplusplus diff --git a/src/system/kernel/debug/tracing.cpp b/src/system/kernel/debug/tracing.cpp index f1b8136581..b233558de3 100644 --- a/src/system/kernel/debug/tracing.cpp +++ b/src/system/kernel/debug/tracing.cpp @@ -697,119 +697,97 @@ TraceFilterParser TraceFilterParser::sParser; #if ENABLE_TRACING -class TraceEntryIterator { -public: - TraceEntryIterator() - : - fEntry(NULL), - fIndex(0) - { +TraceEntry* +TraceEntryIterator::Next() +{ + if (fIndex == 0) { + fEntry = _NextNonBufferEntry(sFirstEntry); + fIndex = 1; + } else if (fEntry != NULL) { + fEntry = _NextNonBufferEntry(next_entry(fEntry)); + fIndex++; } - void Reset() - { + return Current(); +} + + +TraceEntry* +TraceEntryIterator::Previous() +{ + if (fIndex == (int32)sEntries + 1) + fEntry = sAfterLastEntry; + + if (fEntry != NULL) { + fEntry = _PreviousNonBufferEntry(previous_entry(fEntry)); + fIndex--; + } + + return Current(); +} + + +TraceEntry* +TraceEntryIterator::MoveTo(int32 index) +{ + if (index == fIndex) + return Current(); + + if (index <= 0 || index > (int32)sEntries) { + fIndex = (index <= 0 ? 0 : sEntries + 1); + fEntry = NULL; + return NULL; + } + + // get the shortest iteration path + int32 distance = index - fIndex; + int32 direction = distance < 0 ? -1 : 1; + distance *= direction; + + if (index < distance) { + distance = index; + direction = 1; fEntry = NULL; fIndex = 0; } - - int32 Index() const - { - return fIndex; + if ((int32)sEntries + 1 - fIndex < distance) { + distance = sEntries + 1 - fIndex; + direction = -1; + fEntry = NULL; + fIndex = sEntries + 1; } - TraceEntry* Current() const - { - return TraceEntry::FromTraceEntry(fEntry); + // iterate to the index + if (direction < 0) { + while (fIndex != index) + Previous(); + } else { + while (fIndex != index) + Next(); } - TraceEntry* Next() - { - if (fIndex == 0) { - fEntry = _NextNonBufferEntry(sFirstEntry); - fIndex = 1; - } else if (fEntry != NULL) { - fEntry = _NextNonBufferEntry(next_entry(fEntry)); - fIndex++; - } + return Current(); +} - return Current(); - } - TraceEntry* Previous() - { - if (fIndex == (int32)sEntries + 1) - fEntry = sAfterLastEntry; +trace_entry* +TraceEntryIterator::_NextNonBufferEntry(trace_entry* entry) +{ + while (entry != NULL && (entry->flags & BUFFER_ENTRY) != 0) + entry = next_entry(entry); - if (fEntry != NULL) { - fEntry = _PreviousNonBufferEntry(previous_entry(fEntry)); - fIndex--; - } + return entry; +} - return Current(); - } - TraceEntry* MoveTo(int32 index) - { - if (index == fIndex) - return Current(); +trace_entry* +TraceEntryIterator::_PreviousNonBufferEntry(trace_entry* entry) +{ + while (entry != NULL && (entry->flags & BUFFER_ENTRY) != 0) + entry = previous_entry(entry); - if (index <= 0 || index > (int32)sEntries) { - fIndex = (index <= 0 ? 0 : sEntries + 1); - fEntry = NULL; - return NULL; - } - - // get the shortest iteration path - int32 distance = index - fIndex; - int32 direction = distance < 0 ? -1 : 1; - distance *= direction; - - if (index < distance) { - distance = index; - direction = 1; - fEntry = NULL; - fIndex = 0; - } - if ((int32)sEntries + 1 - fIndex < distance) { - distance = sEntries + 1 - fIndex; - direction = -1; - fEntry = NULL; - fIndex = sEntries + 1; - } - - // iterate to the index - if (direction < 0) { - while (fIndex != index) - Previous(); - } else { - while (fIndex != index) - Next(); - } - - return Current(); - } - -private: - trace_entry* _NextNonBufferEntry(trace_entry* entry) - { - while (entry != NULL && (entry->flags & BUFFER_ENTRY) != 0) - entry = next_entry(entry); - - return entry; - } - - trace_entry* _PreviousNonBufferEntry(trace_entry* entry) - { - while (entry != NULL && (entry->flags & BUFFER_ENTRY) != 0) - entry = previous_entry(entry); - - return entry; - } - -private: - trace_entry* fEntry; - int32 fIndex; -}; + return entry; +} int