Add a runtime flag to enable ATRACE

Implement a runtime flag for android framework to enable systrace
logging. To enable logging call SkATrace::setEnableTracing(true),
instead of changing compile time flag
SK_TRACE_EVENTS_IN_FRAMEWORK.

Bug: skia:
Change-Id: Ib4f607e001577a84e944042d799a98af8eb51626
Reviewed-on: https://skia-review.googlesource.com/138594
Commit-Queue: Stan Iliev <stani@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
Stan Iliev 2018-06-29 18:19:12 -04:00 committed by Skia Commit-Bot
parent d2f8eafbb8
commit b7b9d02ac0
2 changed files with 42 additions and 31 deletions

View File

@ -9,6 +9,8 @@
#include "SkTraceEvent.h"
#include "SkTraceEventCommon.h"
#ifdef SK_BUILD_FOR_ANDROID
#include <dlfcn.h>
#endif
@ -70,3 +72,12 @@ const uint8_t* SkATrace::getCategoryGroupEnabled(const char* name) {
return &yes;
}
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
bool SkAndroidFrameworkTraceUtil::gEnableAndroidTracing = false;
#endif //SK_BUILD_FOR_ANDROID_FRAMEWORK

View File

@ -5,6 +5,7 @@
#define SkTraceEventCommon_DEFINED
#include "SkTraceEventPhase.h"
#include "SkTypes.h"
// Trace events are for tracking application performance and resource usage.
// Macros are provided to track:
@ -61,13 +62,15 @@
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
#include <cutils/trace.h>
struct SkAndroidFrameworkTraceUtil {
class SkAndroidFrameworkTraceUtil {
public:
SkAndroidFrameworkTraceUtil(const char* name) {
if (CC_UNLIKELY(gEnableAndroidTracing)) {
ATRACE_BEGIN(name);
}
}
SkAndroidFrameworkTraceUtil(bool, const char* fmt, ...) {
if (CC_LIKELY(!ATRACE_ENABLED())) return;
if (CC_LIKELY((!gEnableAndroidTracing) || (!ATRACE_ENABLED()))) return;
const int BUFFER_SIZE = 256;
va_list ap;
@ -79,19 +82,26 @@ struct SkAndroidFrameworkTraceUtil {
ATRACE_BEGIN(buf);
}
~SkAndroidFrameworkTraceUtil() { ATRACE_END(); }
~SkAndroidFrameworkTraceUtil() {
if (CC_UNLIKELY(gEnableAndroidTracing)) {
ATRACE_END();
}
}
static void setEnableTracing(bool enableAndroidTracing) {
gEnableAndroidTracing = enableAndroidTracing;
}
static bool getEnableTracing() {
return gEnableAndroidTracing;
}
private:
static bool gEnableAndroidTracing;
};
#define ATRACE_ANDROID_FRAMEWORK(fmt, ...) SkAndroidFrameworkTraceUtil __trace(true, fmt, ##__VA_ARGS__)
// If profiling Skia within the Android framework, setting this to 1 will route all Skia
// tracing events to ATrace.
#ifndef SK_TRACE_EVENTS_IN_FRAMEWORK
#define SK_TRACE_EVENTS_IN_FRAMEWORK 0
#endif
#if SK_TRACE_EVENTS_IN_FRAMEWORK
// Records a pair of begin and end events called "name" for the current scope, with 0, 1 or 2
// associated arguments. In the framework, the arguments are ignored.
#define TRACE_EVENT0(category_group, name) \
@ -115,32 +125,22 @@ struct SkAndroidFrameworkTraceUtil {
// Records the value of a counter called "name" immediately. Value
// must be representable as a 32 bit integer.
#define TRACE_COUNTER1(category_group, name, value) ATRACE_INT(name, value)
#define TRACE_COUNTER1(category_group, name, value) \
if (CC_UNLIKELY(SkAndroidFrameworkTraceUtil::getEnableTracing())) { \
ATRACE_INT(name, value); \
}
// Records the values of a multi-parted counter called "name" immediately.
// In Chrome, this macro produces a stacked bar chart. ATrace doesn't support
// that, so this just produces two separate counters.
#define TRACE_COUNTER2(category_group, name, value1_name, value1_val, value2_name, value2_val) \
do { \
if (CC_UNLIKELY(SkAndroidFrameworkTraceUtil::getEnableTracing())) { \
ATRACE_INT(name "-" value1_name, value1_val); \
ATRACE_INT(name "-" value2_name, value2_val); \
} \
} while (0)
#else
#define TRACE_EVENT0(category_group, name) TRACE_EMPTY
#define TRACE_EVENT1(category_group, name, arg1_name, arg1_val) TRACE_EMPTY
#define TRACE_EVENT2(category_group, name, arg1_name, arg1_val, arg2_name, arg2_val) TRACE_EMPTY
#define TRACE_EVENT_INSTANT0(category_group, name, scope) TRACE_EMPTY
#define TRACE_EVENT_INSTANT1(category_group, name, scope, arg1_name, arg1_val) TRACE_EMPTY
#define TRACE_EVENT_INSTANT2(category_group, name, scope, arg1_name, arg1_val, arg2_name, arg2_val) TRACE_EMPTY
#define TRACE_COUNTER1(category_group, name, value) TRACE_EMPTY
#define TRACE_COUNTER2(category_group, name, value1_name, value1_val, value2_name, value2_val) TRACE_EMPTY
#endif
// ATrace has no object tracking
#define TRACE_EVENT_OBJECT_CREATED_WITH_ID(category_group, name, id) TRACE_EMPTY
#define TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(category_group, name, id, snapshot) TRACE_EMPTY