From e4f846aae7f089703d4f73e7092e377a577c4ec9 Mon Sep 17 00:00:00 2001 From: Brian Osman Date: Thu, 10 Aug 2017 15:45:30 -0400 Subject: Bypass libandroid dynamic linking for ATrace in framework builds These symbols were resolving, but weren't really connected to systrace on Android. Using the macros/functions allows this to work correctly. This change doesn't actually cause anything to happen in framework builds - that still requires installing an instance of SkATrace, but now doing so will route all of Skia's TRACE_EVENT macros to systrace. Bug: skia: Change-Id: I6d2eafac7ef2531ba92094b92f68e59e0490ef62 Reviewed-on: https://skia-review.googlesource.com/33400 Reviewed-by: Derek Sollenberger Commit-Queue: Brian Osman --- src/core/SkATrace.cpp | 7 ++++++- src/core/SkATrace.h | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/core/SkATrace.cpp b/src/core/SkATrace.cpp index ed158e2e52..f465286c4f 100644 --- a/src/core/SkATrace.cpp +++ b/src/core/SkATrace.cpp @@ -14,13 +14,18 @@ #endif SkATrace::SkATrace() : fBeginSection(nullptr), fEndSection(nullptr), fIsEnabled(nullptr) { -#ifdef SK_BUILD_FOR_ANDROID +#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) + fIsEnabled = []{ return static_cast(CC_UNLIKELY(ATRACE_ENABLED())); }; + fBeginSection = [](const char* name){ ATRACE_BEGIN(name); }; + fEndSection = []{ ATRACE_END(); }; +#elif defined(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; }; } diff --git a/src/core/SkATrace.h b/src/core/SkATrace.h index f2282f78c1..ad2c8a52cf 100644 --- a/src/core/SkATrace.h +++ b/src/core/SkATrace.h @@ -12,7 +12,7 @@ /** * This class is used to support ATrace in android apps. It hooks into the SkEventTracer system. It - * currently supports the macros TRACE_EVENT*, TRACE_EVENT_INSTANT*, and TRANCE_EVENT_BEGIN/END*. + * currently supports the macros TRACE_EVENT*, TRACE_EVENT_INSTANT*, and TRACE_EVENT_BEGIN/END*. * For versions of these calls that take additoinal args and value pairs we currently just drop them * and report only the name. Since ATrace is a simple push and pop system (all traces are fully * nested), if using BEGIN and END you should also make sure your calls are properly nested (i.e. if -- cgit v1.2.3