diff options
Diffstat (limited to 'tools/trace/SkEventTracingPriv.cpp')
-rw-r--r-- | tools/trace/SkEventTracingPriv.cpp | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/tools/trace/SkEventTracingPriv.cpp b/tools/trace/SkEventTracingPriv.cpp index 217511ffa7..c4c793b06e 100644 --- a/tools/trace/SkEventTracingPriv.cpp +++ b/tools/trace/SkEventTracingPriv.cpp @@ -8,10 +8,11 @@ #include "SkEventTracingPriv.h" #include "SkATrace.h" -#include "SkCommandLineFlags.h" -#include "SkEventTracer.h" #include "SkChromeTracingTracer.h" +#include "SkCommandLineFlags.h" #include "SkDebugfTracer.h" +#include "SkEventTracer.h" +#include "SkTraceEventCommon.h" DEFINE_string(trace, "", "Log trace events in one of several modes:\n" @@ -42,3 +43,39 @@ void initializeEventTracingForTools(int32_t* threadsFlag) { SkAssertResult(SkEventTracer::SetInstance(eventTracer)); } + +uint8_t* SkEventTracingCategories::getCategoryGroupEnabled(const char* name) {
+ static_assert(0 == offsetof(CategoryState, fEnabled), "CategoryState");
+
+ // We ignore the "disabled-by-default-" prefix in our internal tools (though we could honor it)
+ if (SkStrStartsWith(name, TRACE_DISABLED_BY_DEFAULT_PREFIX)) {
+ name += strlen(TRACE_DISABLED_BY_DEFAULT_PREFIX);
+ }
+
+ // Chrome's implementation of this API does a two-phase lookup (once without a lock, then again
+ // with a lock. But the tracing macros avoid calling these functions more than once per site,
+ // so just do something simple (and easier to reason about):
+ SkAutoMutexAcquire lock(&fMutex); + for (int i = 0; i < fNumCategories; ++i) { + if (0 == strcmp(name, fCategories[i].fName)) { + return reinterpret_cast<uint8_t*>(&fCategories[i]); + } + } + + if (fNumCategories >= kMaxCategories) { + SkDEBUGFAIL("Exhausted event tracing categories. Increase kMaxCategories."); + return reinterpret_cast<uint8_t*>(&fCategories[0]); + } + + fCategories[fNumCategories].fEnabled = + SkEventTracer::kEnabledForRecording_CategoryGroupEnabledFlags; + fCategories[fNumCategories].fName = name; + return reinterpret_cast<uint8_t*>(&fCategories[fNumCategories++]); +} + +const char* SkEventTracingCategories::getCategoryGroupName(const uint8_t* categoryEnabledFlag) {
+ if (categoryEnabledFlag) { + return reinterpret_cast<const CategoryState*>(categoryEnabledFlag)->fName; + } + return nullptr; +} |