* 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
This commit is contained in:
Ingo Weinhold
2008-08-12 21:16:15 +00:00
parent b31df46fd2
commit ef7102fa29
2 changed files with 121 additions and 98 deletions
+45
View File
@@ -63,6 +63,7 @@ class TraceOutput {
bigtime_t fLastEntryTime; bigtime_t fLastEntryTime;
}; };
class TraceEntry { class TraceEntry {
public: public:
TraceEntry(); TraceEntry();
@@ -89,6 +90,7 @@ class TraceEntry {
} }
}; };
class AbstractTraceEntry : public TraceEntry { class AbstractTraceEntry : public TraceEntry {
public: public:
AbstractTraceEntry(); AbstractTraceEntry();
@@ -108,6 +110,7 @@ class AbstractTraceEntry : public TraceEntry {
bigtime_t fTime; bigtime_t fTime;
}; };
class LazyTraceOutput : public TraceOutput { class LazyTraceOutput : public TraceOutput {
public: public:
LazyTraceOutput(char* buffer, size_t bufferSize, uint32 flags) LazyTraceOutput(char* buffer, size_t bufferSize, uint32 flags)
@@ -126,6 +129,7 @@ public:
} }
}; };
class TraceFilter { class TraceFilter {
public: public:
virtual ~TraceFilter(); virtual ~TraceFilter();
@@ -145,11 +149,52 @@ public:
}; };
}; };
class WrapperTraceFilter : public TraceFilter { class WrapperTraceFilter : public TraceFilter {
public: public:
virtual void Init(TraceFilter* filter, int direction, bool continued) = 0; 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 #endif // __cplusplus
#ifdef __cplusplus #ifdef __cplusplus
+76 -98
View File
@@ -697,119 +697,97 @@ TraceFilterParser TraceFilterParser::sParser;
#if ENABLE_TRACING #if ENABLE_TRACING
class TraceEntryIterator { TraceEntry*
public: TraceEntryIterator::Next()
TraceEntryIterator() {
: if (fIndex == 0) {
fEntry(NULL), fEntry = _NextNonBufferEntry(sFirstEntry);
fIndex(0) 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; fEntry = NULL;
fIndex = 0; fIndex = 0;
} }
if ((int32)sEntries + 1 - fIndex < distance) {
int32 Index() const distance = sEntries + 1 - fIndex;
{ direction = -1;
return fIndex; fEntry = NULL;
fIndex = sEntries + 1;
} }
TraceEntry* Current() const // iterate to the index
{ if (direction < 0) {
return TraceEntry::FromTraceEntry(fEntry); while (fIndex != index)
Previous();
} else {
while (fIndex != index)
Next();
} }
TraceEntry* Next() return Current();
{ }
if (fIndex == 0) {
fEntry = _NextNonBufferEntry(sFirstEntry);
fIndex = 1;
} else if (fEntry != NULL) {
fEntry = _NextNonBufferEntry(next_entry(fEntry));
fIndex++;
}
return Current();
}
TraceEntry* Previous() trace_entry*
{ TraceEntryIterator::_NextNonBufferEntry(trace_entry* entry)
if (fIndex == (int32)sEntries + 1) {
fEntry = sAfterLastEntry; while (entry != NULL && (entry->flags & BUFFER_ENTRY) != 0)
entry = next_entry(entry);
if (fEntry != NULL) { return entry;
fEntry = _PreviousNonBufferEntry(previous_entry(fEntry)); }
fIndex--;
}
return Current();
}
TraceEntry* MoveTo(int32 index) trace_entry*
{ TraceEntryIterator::_PreviousNonBufferEntry(trace_entry* entry)
if (index == fIndex) {
return Current(); while (entry != NULL && (entry->flags & BUFFER_ENTRY) != 0)
entry = previous_entry(entry);
if (index <= 0 || index > (int32)sEntries) { return entry;
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;
};
int int