From 64fe37ee897678e76e9b6a9b03b831bfeaeddc71 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Mon, 21 Jan 2008 13:31:27 +0000 Subject: [PATCH] * AbstractTraceEntry records the team ID too, now. * Added "printteam" switch to "traced" command, enabling the printing of the team ID. * Added "team" filter to the "traced" command expression language. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23684 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/kernel/tracing.h | 13 +++--- src/system/kernel/debug/tracing.cpp | 64 +++++++++++++++++++++++++---- 2 files changed, 63 insertions(+), 14 deletions(-) diff --git a/headers/private/kernel/tracing.h b/headers/private/kernel/tracing.h index e7a9d0daac..4b5599160a 100644 --- a/headers/private/kernel/tracing.h +++ b/headers/private/kernel/tracing.h @@ -55,13 +55,7 @@ class TraceEntry : public trace_entry { class AbstractTraceEntry : public TraceEntry { public: - AbstractTraceEntry() - : - fThread(find_thread(NULL)), - fTime(system_time()) - { - } - + AbstractTraceEntry(); virtual ~AbstractTraceEntry(); virtual void Dump(TraceOutput& out); @@ -69,10 +63,15 @@ class AbstractTraceEntry : public TraceEntry { virtual void AddDump(TraceOutput& out); thread_id Thread() const { return fThread; } + thread_id Team() const { return fTeam; } bigtime_t Time() const { return fTime; } + public: + static bool sPrintTeamID; + protected: thread_id fThread; + team_id fTeam; bigtime_t fTime; }; diff --git a/src/system/kernel/debug/tracing.cpp b/src/system/kernel/debug/tracing.cpp index 8b1a1f4e28..06e6719ad8 100644 --- a/src/system/kernel/debug/tracing.cpp +++ b/src/system/kernel/debug/tracing.cpp @@ -12,6 +12,8 @@ #include #include +#include +#include #include @@ -282,6 +284,14 @@ TraceEntry::operator new(size_t size, const std::nothrow_t&) throw() // #pragma mark - +AbstractTraceEntry::AbstractTraceEntry() + : + fThread(thread_get_current_thread_id()), + fTeam(team_get_current_team_id()), + fTime(system_time()) +{ +} + AbstractTraceEntry::~AbstractTraceEntry() { } @@ -290,7 +300,10 @@ AbstractTraceEntry::~AbstractTraceEntry() void AbstractTraceEntry::Dump(TraceOutput& out) { - out.Print("[%6ld] %Ld: ", fThread, fTime); + if (sPrintTeamID) + out.Print("[%6ld:%6ld] %Ld: ", fThread, fTeam, fTime); + else + out.Print("[%6ld] %Ld: ", fThread, fTime); AddDump(out); } @@ -301,6 +314,9 @@ AbstractTraceEntry::AddDump(TraceOutput& out) } +bool AbstractTraceEntry::sPrintTeamID = false; + + // #pragma mark - trace filters @@ -337,6 +353,7 @@ public: public: union { thread_id fThread; + team_id fTeam; const char* fString; struct { TraceFilter* first; @@ -357,6 +374,17 @@ public: }; +class TeamTraceFilter : public TraceFilter { +public: + virtual bool Filter(const TraceEntry* _entry, LazyTraceOutput& out) + { + const AbstractTraceEntry* entry + = dynamic_cast(_entry); + return (entry != NULL && entry->Team() == fTeam); + } +}; + + class PatternTraceFilter : public TraceFilter { public: virtual bool Filter(const TraceEntry* entry, LazyTraceOutput& out) @@ -467,6 +495,17 @@ private: ThreadTraceFilter; filter->fThread = strtol(arg, NULL, 0); return filter; + } else if (strcmp(token, "team") == 0) { + const char* arg = _NextToken(); + if (arg == NULL) { + // unexpected end of expression + return NULL; + } + + TraceFilter* filter = new(&fFilters[fFilterCount++]) + TeamTraceFilter; + filter->fTeam = strtol(arg, NULL, 0); + return filter; } else { // invalid token return NULL; @@ -648,6 +687,14 @@ dump_tracing(int argc, char** argv) bool hasFilter = false; + AbstractTraceEntry::sPrintTeamID = false; + if (argi < argc) { + if (strcmp(argv[argi], "printteam") == 0) { + AbstractTraceEntry::sPrintTeamID = true; + argi++; + } + } + if (argi < argc) { if (strcmp(argv[argi], "forward") == 0) { cont = 1; @@ -936,13 +983,15 @@ tracing_init(void) add_debugger_command_etc("traced", &dump_tracing, "Dump recorded trace entries", - "(\"forward\" | \"backward\") | ([ [ [ ] ] ] " - "[ # | (\"filter\" ) ])\n" + "[ \"printteam\" ] (\"forward\" | \"backward\") " + "| ([ [ [ ] ] ] " + "[ # | (\"filter\" ) ])\n" "Prints recorded trace entries. If \"backward\" or \"forward\" is\n" "specified, the command continues where the previous invocation left\n" "off, i.e. printing the previous respectively next entries (as many\n" "as printed before). In this case the command is continuable, that is\n" "afterwards entering an empty line in the debugger will reinvoke it.\n" + "\"printteam\" enables printing the items' team ID.\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" @@ -967,11 +1016,12 @@ tracing_init(void) " printed.\n" " - If specified only entries matching this filter\n" " expression are printed. The expression can consist of\n" - " prefix operators \"not\", \"and\", \"or\", filters of\n" - " the kind \"'thread' \" (matching entries\n" - " with the given thread ID), or filter of the kind\n" + " prefix operators \"not\", \"and\", \"or\", and\n" + " filters \"'thread' \" (matching entries\n" + " with the given thread ID), \"'team' \"\n" + "(matching entries with the given team ID), and\n" " \"#\" (matching entries containing the given\n" - " string.\n", 0); + " string).\n", 0); #endif // ENABLE_TRACING return B_OK; }