aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkATrace.cpp
diff options
context:
space:
mode:
authorGravatar Greg Daniel <egdaniel@google.com>2016-10-14 09:12:53 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2016-10-14 13:43:00 +0000
commit285db44562da7136686e6d34a8443c6c6e0b942c (patch)
tree2012e5d962dd732250bdc851168c715edefcd03e /src/core/SkATrace.cpp
parentad146f6ef5d2de94bd2d8c678757a6274844d20e (diff)
Add support for Atrace and hook into SkEventTracer framework.
This change is a different version of: https://skia-review.googlesource.com/c/3269/ BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=3345 Change-Id: I49d4f2987740d3ad1307f6aba3add0d63a46b22d Reviewed-on: https://skia-review.googlesource.com/3345 Reviewed-by: Brian Salomon <bsalomon@google.com> Reviewed-by: Mike Klein <mtklein@chromium.org> Commit-Queue: Greg Daniel <egdaniel@google.com>
Diffstat (limited to 'src/core/SkATrace.cpp')
-rw-r--r--src/core/SkATrace.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/core/SkATrace.cpp b/src/core/SkATrace.cpp
new file mode 100644
index 0000000000..b40795e4da
--- /dev/null
+++ b/src/core/SkATrace.cpp
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkATrace.h"
+
+#include "SkTraceEvent.h"
+
+#ifdef SK_BUILD_FOR_ANDROID
+#include <dlfcn.h>
+#endif
+
+SkATrace::SkATrace() : fBeginSection(nullptr), fEndSection(nullptr), fIsEnabled(nullptr) {
+#ifdef SK_BUILD_FOR_ANDROID
+ if (void* lib = dlopen("libandroid.so", RTLD_NOW | RTLD_LOCAL)) {
+ fBeginSection = (decltype(fBeginSection))dlsym(lib, "ATrace_beginSection");
+ fEndSection = (decltype(fEndSection))dlsym(lib, "ATrace_endSection");
+ fIsEnabled = (decltype(fIsEnabled))dlsym(lib, "ATrace_isEnabled");
+ }
+#endif
+ if (!fIsEnabled) {
+ fIsEnabled = []{ return false; };
+ }
+}
+
+SkEventTracer::Handle SkATrace::addTraceEvent(char phase,
+ const uint8_t* categoryEnabledFlag,
+ const char* name,
+ uint64_t id,
+ int numArgs,
+ const char** argNames,
+ const uint8_t* argTypes,
+ const uint64_t* argValues,
+ uint8_t flags) {
+ if (fIsEnabled()) {
+ if (TRACE_EVENT_PHASE_COMPLETE == phase ||
+ TRACE_EVENT_PHASE_BEGIN == phase ||
+ TRACE_EVENT_PHASE_INSTANT == phase) {
+ fBeginSection(name);
+ }
+
+ if (TRACE_EVENT_PHASE_END == phase ||
+ TRACE_EVENT_PHASE_INSTANT == phase) {
+ fEndSection();
+ }
+ }
+ return 0;
+}
+
+void SkATrace::updateTraceEventDuration(const uint8_t* categoryEnabledFlag,
+ const char* name,
+ SkEventTracer::Handle handle) {
+ // This is only ever called from a scoped trace event so we will just end the ATrace section.
+ if (fIsEnabled()) {
+ fEndSection();
+ }
+}
+
+const uint8_t* SkATrace::getCategoryGroupEnabled(const char* name) {
+ // Chrome tracing is setup to not repeatly call this function once it has been initialized. So
+ // we can't use this to do a check for ATrace isEnabled(). Thus we will always return yes here
+ // and then check to see if ATrace is enabled when beginning and ending a section.
+ static uint8_t yes = SkEventTracer::kEnabledForRecording_CategoryGroupEnabledFlags;
+ return &yes;
+}
+