From f7a5d9c5831397de59dc37ad27f5b4cd17a35db1 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sat, 19 Jan 2008 22:23:32 +0000 Subject: [PATCH] Changed TraceEntry::Dump() to take a TraceOutput& and removed AbstractTraceEntry::AddDump(char*, size_t). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23655 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/kernel/tracing.h | 6 ++-- .../file_systems/bfs/BlockAllocator.cpp | 15 ++++---- src/add-ons/kernel/file_systems/bfs/Inode.cpp | 17 +++++---- src/system/kernel/cache/block_cache.cpp | 18 +++++----- src/system/kernel/debug/tracing.cpp | 35 ++++++++++--------- src/system/kernel/team.cpp | 34 +++++++----------- 6 files changed, 57 insertions(+), 68 deletions(-) diff --git a/headers/private/kernel/tracing.h b/headers/private/kernel/tracing.h index 25fa9a6b76..fa6a589fb4 100644 --- a/headers/private/kernel/tracing.h +++ b/headers/private/kernel/tracing.h @@ -23,6 +23,7 @@ class TraceOutput { public: TraceOutput(char* buffer, size_t bufferSize); + void Clear(); void Print(const char* format,...); bool IsFull() const { return fSize >= fCapacity; } @@ -37,7 +38,7 @@ class TraceEntry : trace_entry { TraceEntry(); virtual ~TraceEntry(); - virtual void Dump(char* buffer, size_t bufferSize); + virtual void Dump(TraceOutput& out); size_t Size() const { return size; } uint16 Flags() const { return flags; } @@ -58,9 +59,8 @@ class AbstractTraceEntry : public TraceEntry { virtual ~AbstractTraceEntry(); - virtual void Dump(char* buffer, size_t bufferSize); + virtual void Dump(TraceOutput& out); - virtual void AddDump(char* buffer, size_t bufferSize); virtual void AddDump(TraceOutput& out); thread_id Thread() const { return fThread; } diff --git a/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp b/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp index 9895d3df8e..8139cac401 100644 --- a/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp +++ b/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp @@ -48,9 +48,9 @@ class Allocate : public AbstractTraceEntry { Initialized(); } - virtual void AddDump(char *buffer, size_t size) + virtual void AddDump(TraceOutput& out) { - snprintf(buffer, size, "alloc %lu.%u.%u", fRun.AllocationGroup(), + out.Print("alloc %lu.%u.%u", fRun.AllocationGroup(), fRun.Start(), fRun.Length()); } @@ -67,9 +67,9 @@ class Free : public AbstractTraceEntry { Initialized(); } - virtual void AddDump(char *buffer, size_t size) + virtual void AddDump(TraceOutput& out) { - snprintf(buffer, size, "free %lu.%u.%u", fRun.AllocationGroup(), + out.Print("free %lu.%u.%u", fRun.AllocationGroup(), fRun.Start(), fRun.Length()); } @@ -107,11 +107,10 @@ class Block : public AbstractTraceEntry { Initialized(); } - virtual void AddDump(char *buffer, size_t size) + virtual void AddDump(TraceOutput& out) { - uint32 length = snprintf(buffer, size, "%s: block %Ld (%p), sum %lu," - " s/l %lu/%lu", fLabel, fBlock, fData, fSum, fStart, - fLength); + out.Print("%s: block %Ld (%p), sum %lu, s/l %lu/%lu", fLabel, + fBlock, fData, fSum, fStart, fLength); } private: diff --git a/src/add-ons/kernel/file_systems/bfs/Inode.cpp b/src/add-ons/kernel/file_systems/bfs/Inode.cpp index b93a99d1b0..9dd9353565 100644 --- a/src/add-ons/kernel/file_systems/bfs/Inode.cpp +++ b/src/add-ons/kernel/file_systems/bfs/Inode.cpp @@ -36,9 +36,9 @@ class Create : public AbstractTraceEntry { Initialized(); } - virtual void AddDump(char *buffer, size_t size) + virtual void AddDump(TraceOutput& out) { - snprintf(buffer, size, "CREATE %Ld (%p), parent %Ld (%p), \"%s\", " + out.Print("CREATE %Ld (%p), parent %Ld (%p), \"%s\", " "mode %lx, omode %x, type %lx", fID, fInode, fParentID, fParent, fName, fMode, fOpenMode, fType); } @@ -66,10 +66,9 @@ class Remove : public AbstractTraceEntry { Initialized(); } - virtual void AddDump(char *buffer, size_t size) + virtual void AddDump(TraceOutput& out) { - snprintf(buffer, size, "REMOVE %Ld (%p), \"%s\"", fID, fInode, - fName); + out.Print("REMOVE %Ld (%p), \"%s\"", fID, fInode, fName); } private: @@ -89,9 +88,9 @@ class Action : public AbstractTraceEntry { Initialized(); } - virtual void AddDump(char *buffer, size_t size) + virtual void AddDump(TraceOutput& out) { - snprintf(buffer, size, "%s %Ld (%p)\n", fAction, fID, fInode); + out.Print("%s %Ld (%p)\n", fAction, fID, fInode); } private: @@ -112,9 +111,9 @@ class Resize : public AbstractTraceEntry { Initialized(); } - virtual void AddDump(char *buffer, size_t size) + virtual void AddDump(TraceOutput& out) { - snprintf(buffer, size, "RESIZE %Ld (%p), %Ld -> %Ld", fID, fInode, + out.Print("RESIZE %Ld (%p), %Ld -> %Ld", fID, fInode, fOldSize, fNewSize); } diff --git a/src/system/kernel/cache/block_cache.cpp b/src/system/kernel/cache/block_cache.cpp index 64fc93ed5c..2e9b21bc5b 100644 --- a/src/system/kernel/cache/block_cache.cpp +++ b/src/system/kernel/cache/block_cache.cpp @@ -91,9 +91,9 @@ class Action : public AbstractTraceEntry { Initialized(); } - virtual void AddDump(char *buffer, size_t size) + virtual void AddDump(TraceOutput& out) { - snprintf(buffer, size, "cache %p, %s transaction %p (id %ld)%s" + out.Print("cache %p, %s transaction %p (id %ld)%s" ", %ld/%ld blocks", fCache, fLabel, fTransaction, fID, fSub ? " sub" : "", fNumBlocks, fSubNumBlocks); } @@ -123,9 +123,9 @@ class Detach : public AbstractTraceEntry { Initialized(); } - virtual void AddDump(char *buffer, size_t size) + virtual void AddDump(TraceOutput& out) { - snprintf(buffer, size, "cache %p, detach transaction %p (id %ld)" + out.Print("cache %p, detach transaction %p (id %ld)" "from transaction %p (id %ld)%s", fCache, fNewTransaction, fNewID, fTransaction, fID, fSub ? " sub" : ""); @@ -164,14 +164,12 @@ class Abort : public AbstractTraceEntry { Initialized(); } - virtual void AddDump(char *buffer, size_t size) + virtual void AddDump(TraceOutput& out) { - int length = snprintf(buffer, size, "cache %p, abort transaction " + out.Print("cache %p, abort transaction " "%p (id %ld), blocks", fCache, fTransaction, fID); - for (int32 i = 0; i < fNumBlocks && (size_t)length < size; i++) { - length += snprintf(buffer + length, size - length, " %Ld", - fBlocks[i]); - } + for (int32 i = 0; i < fNumBlocks && !out.IsFull(); i++) + out.Print(" %Ld", fBlocks[i]); } private: diff --git a/src/system/kernel/debug/tracing.cpp b/src/system/kernel/debug/tracing.cpp index b1a6f878b4..42ef4d9767 100644 --- a/src/system/kernel/debug/tracing.cpp +++ b/src/system/kernel/debug/tracing.cpp @@ -146,9 +146,18 @@ allocate_entry(size_t size, uint16 flags) TraceOutput::TraceOutput(char* buffer, size_t bufferSize) : fBuffer(buffer), - fCapacity(bufferSize), - fSize(0) + fCapacity(bufferSize) { + Clear(); +} + + +void +TraceOutput::Clear() +{ + if (fCapacity > 0) + fBuffer[0] = '\0'; + fSize = 0; } @@ -179,11 +188,11 @@ TraceEntry::~TraceEntry() void -TraceEntry::Dump(char* buffer, size_t bufferSize) +TraceEntry::Dump(TraceOutput& out) { #if ENABLE_TRACING // to be overridden by subclasses - kprintf(buffer, bufferSize, "ENTRY %p", this); + out.Print("ENTRY %p", this); #endif } @@ -218,18 +227,9 @@ AbstractTraceEntry::~AbstractTraceEntry() void -AbstractTraceEntry::Dump(char* buffer, size_t bufferSize) +AbstractTraceEntry::Dump(TraceOutput& out) { - 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); + out.Print("[%6ld] %Ld: ", fThread, fTime); AddDump(out); } @@ -305,8 +305,9 @@ dump_tracing(int argc, char** argv) if ((current->flags & ENTRY_INITIALIZED) != 0) { char buffer[256]; - buffer[0] = '\0'; - ((TraceEntry*)current)->Dump(buffer, sizeof(buffer)); + TraceOutput out(buffer, sizeof(buffer)); + + ((TraceEntry*)current)->Dump(out); if (pattern != NULL && strstr(buffer, pattern) == NULL) continue; diff --git a/src/system/kernel/team.cpp b/src/system/kernel/team.cpp index f77579140e..9c6a103938 100644 --- a/src/system/kernel/team.cpp +++ b/src/system/kernel/team.cpp @@ -97,10 +97,9 @@ class TeamForked : public AbstractTraceEntry { Initialized(); } - virtual void AddDump(char *buffer, size_t size) + virtual void AddDump(TraceOutput& out) { - snprintf(buffer, size, "team forked, new thread %ld", - fForkedThread); + out.Print("team forked, new thread %ld", fForkedThread); } private: @@ -142,20 +141,13 @@ class ExecTeam : public AbstractTraceEntry { Initialized(); } - virtual void AddDump(char *buffer, size_t size) + virtual void AddDump(TraceOutput& out) { - snprintf(buffer, size, "team exec, \"%p\", args:", fPath); - size_t printedChars = strlen(buffer); - buffer += printedChars; - size -= printedChars; + out.Print("team exec, \"%p\", args:", fPath); char* args = fArgs; - for (int32 i = 0; size > 0 && i < fArgCount; i++) { - snprintf(buffer, size, " \"%s\"", args); - - printedChars = strlen(buffer); - buffer += printedChars; - size -= printedChars; + for (int32 i = 0; !out.IsFull() && i < fArgCount; i++) { + out.Print(" \"%s\"", args); args += strlen(args) + 1; } } @@ -196,9 +188,9 @@ class SetJobControlState : public AbstractTraceEntry { Initialized(); } - virtual void AddDump(char *buffer, size_t size) + virtual void AddDump(TraceOutput& out) { - snprintf(buffer, size, "team set job control state, team %ld, " + out.Print("team set job control state, team %ld, " "new state: %s, signal: %d", fTeam, job_control_state_name(fNewState), fSignal); } @@ -220,9 +212,9 @@ class WaitForChild : public AbstractTraceEntry { Initialized(); } - virtual void AddDump(char *buffer, size_t size) + virtual void AddDump(TraceOutput& out) { - snprintf(buffer, size, "team wait for child, child: %ld, " + out.Print("team wait for child, child: %ld, " "flags: 0x%lx", fChild, fFlags); } @@ -252,15 +244,15 @@ class WaitForChildDone : public AbstractTraceEntry { Initialized(); } - virtual void AddDump(char *buffer, size_t size) + virtual void AddDump(TraceOutput& out) { if (fTeam >= 0) { - snprintf(buffer, size, "team wait for child done, team: %ld, " + out.Print("team wait for child done, team: %ld, " "state: %s, status: 0x%lx, reason: 0x%x, signal: %d\n", fTeam, job_control_state_name(fState), fStatus, fReason, fSignal); } else { - snprintf(buffer, size, "team wait for child failed, error: " + out.Print("team wait for child failed, error: " "0x%lx, ", fTeam); } }