diff --git a/src/util/trace.cpp b/src/util/trace.cpp index 8c379ca6b..5d195fa76 100644 --- a/src/util/trace.cpp +++ b/src/util/trace.cpp @@ -57,7 +57,7 @@ void finalize_trace() { g_enabled_trace_tags = nullptr; } -const TraceTag* get_tag_classes() { +static const TraceTag* get_tag_classes() { static bool tag_class_init = false; // ignore thread safety assuming TRACE is already under a lock. if (!tag_class_init) { // Arrays to track first and last tag in each class @@ -91,19 +91,20 @@ const TraceTag* get_tag_classes() { void enable_trace(const char * tag) { get_enabled_trace_tags().insert(tag); - // TODO(#7663): Implement tag_class activation of all associated tags - // int count = 0; - // TraceTag tag_str = find_trace_tag_by_string(tag); - // if(tag_str == TraceTag::Count) { - // return; - // } - // const TraceTag* tags = get_tags_by_class(tag_str, count); - // for (int i = 0; i < count; ++i) { - // const char* tag_str = tracetag_to_string(tags[i]); - // if (!get_enabled_trace_tags().contains(tag_str)) { - // get_enabled_trace_tags().insert(tag_str); - // } - // } + TraceTag tag_str = find_trace_tag_by_string(tag); + if (tag_str == TraceTag::Count) + return; + + auto tag_class = get_trace_tag_class(tag_str); + if (tag_class != tag_str) + return; // Only enable the tag if it is a class tag. + auto const& next_tag = get_tag_classes(); + + auto t = next_tag[static_cast(tag_str)]; + while (t != tag_str) { + get_enabled_trace_tags().insert(tracetag_to_string(t)); + t = next_tag[static_cast(t)]; + } } void enable_all_trace(bool flag) { diff --git a/src/util/trace_tags.h b/src/util/trace_tags.h index cef20d3cd..34c32eed4 100644 --- a/src/util/trace_tags.h +++ b/src/util/trace_tags.h @@ -83,9 +83,9 @@ static TraceTag tag_classes[] = { // } // Find TraceTag by string -// inline TraceTag find_trace_tag_by_string(const char* tag_str) { -// #define X(tag, tag_class, desc) if (strncmp(#tag, tag_str, strlen(#tag)) == 0) return TraceTag::tag; -// include "util/trace_tags.def" -// #undef X -// return TraceTag::Count; -// } \ No newline at end of file +inline TraceTag find_trace_tag_by_string(const char* tag_str) { +#define X(tag, tag_class, desc) if (strncmp(#tag, tag_str, strlen(#tag)) == 0) return TraceTag::tag; +#include "util/trace_tags.def" +#undef X + return TraceTag::Count; +} \ No newline at end of file