Introduced helper class TraceOutput that represents an output buffer

and added AbstractTraceEntry::AddDump(TraceOutput&) method.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23622 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2008-01-18 22:15:30 +00:00
parent 2f1836da5c
commit f1047a1c3e
2 changed files with 76 additions and 11 deletions
+58 -2
View File
@@ -7,6 +7,7 @@
#include <tracing.h>
#include <stdarg.h>
#include <stdlib.h>
#include <debug.h>
@@ -140,6 +141,30 @@ allocate_entry(size_t size, uint16 flags)
#endif // ENABLE_TRACING
// #pragma mark -
TraceOutput::TraceOutput(char* buffer, size_t bufferSize)
: fBuffer(buffer),
fCapacity(bufferSize),
fSize(0)
{
}
void
TraceOutput::Print(const char* format,...)
{
if (IsFull())
return;
va_list args;
va_start(args, format);
fSize += vsnprintf(fBuffer + fSize, fCapacity - fSize, format, args);
va_end(args);
}
// #pragma mark -
@@ -157,8 +182,8 @@ void
TraceEntry::Dump(char* buffer, size_t bufferSize)
{
#if ENABLE_TRACING
// to be overloaded by subclasses
snprintf(buffer, bufferSize, "ENTRY %p", this);
// to be overridden by subclasses
kprintf(buffer, bufferSize, "ENTRY %p", this);
#endif
}
@@ -187,6 +212,37 @@ TraceEntry::operator new(size_t size, const std::nothrow_t&) throw()
// #pragma mark -
AbstractTraceEntry::~AbstractTraceEntry()
{
}
void
AbstractTraceEntry::Dump(char* buffer, size_t bufferSize)
{
int length = snprintf(buffer, bufferSize, "[%6ld] %Ld: ",
fThread, fTime);
AddDump(buffer + length, bufferSize - length);
}
void
AbstractTraceEntry::AddDump(char* buffer, size_t bufferSize)
{
TraceOutput out(buffer, bufferSize);
AddDump(out);
}
void
AbstractTraceEntry::AddDump(TraceOutput& out)
{
}
// #pragma mark -
#if ENABLE_TRACING