aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/trace/SkEventTracingPriv.cpp
diff options
context:
space:
mode:
authorGravatar Brian Osman <brianosman@google.com>2017-07-21 11:06:24 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-07-21 16:38:23 +0000
commit65e4c614f0edbcf8d05bfc2a25a6e60d277fb7df (patch)
tree4fac7baec4b6f5ace655263b65262a23cefc8f4d /tools/trace/SkEventTracingPriv.cpp
parent57aa367aa3c5911cd4a21230799b147e44190282 (diff)
Add category support to JSON and SkDebugf tracing
Bug: skia: Change-Id: I4d0bdb9d954e49b79ace0552d7b74b36a512c00d Reviewed-on: https://skia-review.googlesource.com/25642 Reviewed-by: Mike Klein <mtklein@chromium.org> Commit-Queue: Brian Osman <brianosman@google.com>
Diffstat (limited to 'tools/trace/SkEventTracingPriv.cpp')
-rw-r--r--tools/trace/SkEventTracingPriv.cpp41
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;
+}