Improve shader compile tracing with Android framework
Log shader compile "cache miss" and "cache hit" tags. Shader
compile tags are logged even if debug.hwui.skia_atrace_enabled is
not enabled. "shader_compile" tag measures the total time to
prepare the shader (regardless of cache miss or hit).
"cache_hit" measures the time to load the binary program from
cache (with glProgramBinary). "cache_miss" measures the time
to compile from SkSL to GLSL, compile GLSL and link the program.
Test: Ran systrace on android
Bug: b/146635333
Change-Id: I984b9681cdcf78fc5f4a2e2ef0ad072ebc851ca1
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/264097
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Derek Sollenberger <djsollen@google.com>
Commit-Queue: Stan Iliev <stani@google.com>
diff --git a/src/core/SkTraceEventCommon.h b/src/core/SkTraceEventCommon.h
index 5dad9b5..03439d7 100644
--- a/src/core/SkTraceEventCommon.h
+++ b/src/core/SkTraceEventCommon.h
@@ -62,6 +62,7 @@
#ifdef SK_DISABLE_TRACING
#define ATRACE_ANDROID_FRAMEWORK(fmt, ...) TRACE_EMPTY
+#define ATRACE_ANDROID_FRAMEWORK_ALWAYS(fmt, ...) TRACE_EMPTY
#define TRACE_EVENT0(cg, n) TRACE_EMPTY
#define TRACE_EVENT1(cg, n, a1n, a1v) TRACE_EMPTY
#define TRACE_EVENT2(cg, n, a1n, a1v, a2n, a2v) TRACE_EMPTY
@@ -114,7 +115,28 @@
static bool gEnableAndroidTracing;
};
+class SkAndroidFrameworkTraceUtilAlways {
+public:
+ SkAndroidFrameworkTraceUtilAlways(const char* fmt, ...) {
+ if (!ATRACE_ENABLED()) return;
+
+ const int BUFFER_SIZE = 256;
+ va_list ap;
+ char buf[BUFFER_SIZE];
+
+ va_start(ap, fmt);
+ vsnprintf(buf, BUFFER_SIZE, fmt, ap);
+ va_end(ap);
+
+ ATRACE_BEGIN(buf);
+ }
+ ~SkAndroidFrameworkTraceUtilAlways() {
+ ATRACE_END();
+ }
+};
+
#define ATRACE_ANDROID_FRAMEWORK(fmt, ...) SkAndroidFrameworkTraceUtil __trace(true, fmt, ##__VA_ARGS__)
+#define ATRACE_ANDROID_FRAMEWORK_ALWAYS(fmt, ...) SkAndroidFrameworkTraceUtilAlways __trace(fmt, ##__VA_ARGS__)
// 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.
@@ -168,6 +190,7 @@
#else // !SK_BUILD_FOR_ANDROID_FRAMEWORK && !SK_DISABLE_TRACING
#define ATRACE_ANDROID_FRAMEWORK(fmt, ...) TRACE_EMPTY
+#define ATRACE_ANDROID_FRAMEWORK_ALWAYS(fmt, ...) TRACE_EMPTY
// Records a pair of begin and end events called "name" for the current scope, with 0, 1 or 2
// associated arguments. If the category is not enabled, then this does nothing.
diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.cpp b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
index dda21cc..6c12794 100644
--- a/src/gpu/gl/builders/GrGLProgramBuilder.cpp
+++ b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
@@ -50,7 +50,7 @@
GrProgramDesc* desc,
GrGLGpu* gpu,
const GrGLPrecompiledProgram* precompiledProgram) {
- ATRACE_ANDROID_FRAMEWORK("Shader Compile");
+ ATRACE_ANDROID_FRAMEWORK_ALWAYS("shader_compile");
GrAutoLocaleSetter als("C");
// create a builder. This will be handed off to effects so they can use it to add
@@ -254,6 +254,7 @@
this->computeCountsAndStrides(programID, primProc, false);
usedProgramBinaries = true;
} else if (cached) {
+ ATRACE_ANDROID_FRAMEWORK_ALWAYS("cache_hit");
SkReader32 reader(fCached->data(), fCached->size());
SkFourByteTag shaderType = reader.readU32();
@@ -303,6 +304,7 @@
}
}
if (!usedProgramBinaries) {
+ ATRACE_ANDROID_FRAMEWORK_ALWAYS("cache_miss");
// Either a cache miss, or we got something other than binaries from the cache
/*