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 <djsollen@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
Brian Osman 2017-08-10 15:45:30 -04:00 committed by Skia Commit-Bot
parent 6da8f79618
commit e4f846aae7
2 changed files with 7 additions and 2 deletions

View File

@ -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<bool>(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; };
}

View File

@ -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