diff --git a/headers/private/kernel/tracing.h b/headers/private/kernel/tracing.h index 8b530dbaaf..c31b15c1d3 100644 --- a/headers/private/kernel/tracing.h +++ b/headers/private/kernel/tracing.h @@ -20,9 +20,18 @@ struct trace_entry { #include + +// trace output flags +#define TRACE_OUTPUT_TEAM_ID 0x01 + // print the team ID +#define TRACE_OUTPUT_DIFF_TIME 0x02 + // print the difference time to the previously printed entry instead of the + // absolute time + + class TraceOutput { public: - TraceOutput(char* buffer, size_t bufferSize); + TraceOutput(char* buffer, size_t bufferSize, uint32 flags); void Clear(); void Print(const char* format,...); @@ -32,10 +41,17 @@ class TraceOutput { size_t Capacity() const { return fCapacity; } size_t Size() const { return fSize; } + uint32 Flags() const { return fFlags; } + + void SetLastEntryTime(bigtime_t time); + bigtime_t LastEntryTime() const; + private: - char* fBuffer; - size_t fCapacity; - size_t fSize; + char* fBuffer; + size_t fCapacity; + size_t fSize; + uint32 fFlags; + bigtime_t fLastEntryTime; }; class TraceEntry : public trace_entry { @@ -66,9 +82,6 @@ class AbstractTraceEntry : public TraceEntry { thread_id Team() const { return fTeam; } bigtime_t Time() const { return fTime; } - public: - static bool sPrintTeamID; - protected: thread_id fThread; team_id fTeam; diff --git a/src/system/kernel/debug/tracing.cpp b/src/system/kernel/debug/tracing.cpp index fd960dff9c..b1469a1c9b 100644 --- a/src/system/kernel/debug/tracing.cpp +++ b/src/system/kernel/debug/tracing.cpp @@ -207,9 +207,10 @@ allocate_entry(size_t size, uint16 flags) // #pragma mark - -TraceOutput::TraceOutput(char* buffer, size_t bufferSize) +TraceOutput::TraceOutput(char* buffer, size_t bufferSize, uint32 flags) : fBuffer(buffer), - fCapacity(bufferSize) + fCapacity(bufferSize), + fFlags(flags) { Clear(); } @@ -237,6 +238,20 @@ TraceOutput::Print(const char* format,...) } +void +TraceOutput::SetLastEntryTime(bigtime_t time) +{ + fLastEntryTime = time; +} + + +bigtime_t +TraceOutput::LastEntryTime() const +{ + return fLastEntryTime; +} + + // #pragma mark - @@ -300,11 +315,18 @@ AbstractTraceEntry::~AbstractTraceEntry() void AbstractTraceEntry::Dump(TraceOutput& out) { - if (sPrintTeamID) - out.Print("[%6ld:%6ld] %Ld: ", fThread, fTeam, fTime); + bigtime_t time = (out.Flags() & TRACE_OUTPUT_DIFF_TIME) + ? fTime - out.LastEntryTime() + : fTime; + + if (out.Flags() & TRACE_OUTPUT_TEAM_ID) + out.Print("[%6ld:%6ld] %10Ld: ", fThread, fTeam, time); else - out.Print("[%6ld] %Ld: ", fThread, fTime); + out.Print("[%6ld] %10Ld: ", fThread, time); + AddDump(out); + + out.SetLastEntryTime(fTime); } @@ -314,9 +336,6 @@ AbstractTraceEntry::AddDump(TraceOutput& out) } -bool AbstractTraceEntry::sPrintTeamID = false; - - // #pragma mark - @@ -348,8 +367,8 @@ class UserTraceEntry : public AbstractTraceEntry { class LazyTraceOutput : public TraceOutput { public: - LazyTraceOutput(char* buffer, size_t bufferSize) - : TraceOutput(buffer, bufferSize) + LazyTraceOutput(char* buffer, size_t bufferSize, uint32 flags) + : TraceOutput(buffer, bufferSize, flags) { } @@ -703,6 +722,7 @@ dump_tracing(int argc, char** argv) static int32 _previousDirection = 1; static uint32 _previousWritten = 0; static uint32 _previousEntries = 0; + static uint32 _previousOutputFlags = 0; static TraceEntryIterator iterator; @@ -714,12 +734,16 @@ dump_tracing(int argc, char** argv) bool hasFilter = false; - AbstractTraceEntry::sPrintTeamID = false; - if (argi < argc) { + uint32 outputFlags = 0; + while (argi < argc) { if (strcmp(argv[argi], "--printteam") == 0) { - AbstractTraceEntry::sPrintTeamID = true; + outputFlags |= TRACE_OUTPUT_TEAM_ID; argi++; - } + } else if (strcmp(argv[argi], "--difftime") == 0) { + outputFlags |= TRACE_OUTPUT_DIFF_TIME; + argi++; + } else + break; } if (argi < argc) { @@ -783,6 +807,7 @@ dump_tracing(int argc, char** argv) count = _previousCount; maxToCheck = _previousMaxToCheck; hasFilter = _previousHasFilter; + outputFlags = _previousOutputFlags; if (direction < 0) start = _previousFirstChecked - 1; @@ -830,7 +855,7 @@ dump_tracing(int argc, char** argv) } char buffer[256]; - LazyTraceOutput out(buffer, sizeof(buffer)); + LazyTraceOutput out(buffer, sizeof(buffer), outputFlags); bool markedMatching = false; int32 firstToDump = firstToCheck; @@ -875,6 +900,8 @@ dump_tracing(int argc, char** argv) iterator.Previous(); } + out.SetLastEntryTime(0); + // set the iterator to the entry before the first one to dump iterator.MoveTo(firstToDump - 1); @@ -920,6 +947,7 @@ dump_tracing(int argc, char** argv) _previousDirection = direction; _previousWritten = sWritten; _previousEntries = sEntries; + _previousOutputFlags = outputFlags; return cont != 0 ? B_KDEBUG_CONT : 0; } @@ -1012,7 +1040,7 @@ tracing_init(void) add_debugger_command_etc("traced", &dump_tracing, "Dump recorded trace entries", - "[ \"--printteam\" ] (\"forward\" | \"backward\") " + "[ \"--printteam\" ] [ \"--difftime\" ] (\"forward\" | \"backward\") " "| ([ [ [ ] ] ] " "[ # | (\"filter\" ) ])\n" "Prints recorded trace entries. If \"backward\" or \"forward\" is\n" @@ -1022,7 +1050,8 @@ tracing_init(void) "afterwards entering an empty line in the debugger will reinvoke it.\n" "If no arguments are given, the command continues in the direction\n" "of the last invocation.\n" - "\"--printteam\" enables printing the items' team ID.\n" + "\"--printteam\" enables printing the entries' team IDs.\n" + "\"--difftime\" print difference times for all but the first entry.\n" " - The base index of the entries to print. Depending on\n" " whether the iteration direction is forward or\n" " backward this will be the first or last entry printed\n"