Add more tracing for SKSL compilation

Bug: b/179848728
Bug: b/146635333

We're seeing some slow shader_compiles on Android, so add some more
tracing to help determine where that time is being spent.

Use ATRACE_ANDROID_FRAMEWORK_ALWAYS instead of ATRACE_ANDROID_FRAMEWORK
for driver_compile_program and driver_link_program so that tracing for
the work done in the GPU driver will be turned on even if the developer
does not manually turn on skia tracing with

  adb shell setprop debug.hwui.skia_atrace_enabled true

This matches the "shader_compile" tag added in b/146635333 and allows
non-Skia developers to easily capture traces with more info.

Change-Id: Ic698daad878bc0b946e15ec2f2f2e8cf53f30fbc
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/369483
Commit-Queue: Leon Scroggins <scroggo@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Derek Sollenberger <djsollen@google.com>
diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.cpp b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
index a0e919c..ef264f3 100644
--- a/src/gpu/gl/builders/GrGLProgramBuilder.cpp
+++ b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
@@ -442,11 +442,14 @@
         }
         this->bindProgramResourceLocations(programID);
 
-        GL_CALL(LinkProgram(programID));
-        if (checkLinked) {
-            if (!this->checkLinkStatus(programID, errorHandler, sksl, glsl)) {
-                cleanup_program(fGpu, programID, shadersToDelete);
-                return nullptr;
+        {
+            ATRACE_ANDROID_FRAMEWORK_ALWAYS("driver_link_program");
+            GL_CALL(LinkProgram(programID));
+            if (checkLinked) {
+                if (!this->checkLinkStatus(programID, errorHandler, sksl, glsl)) {
+                    cleanup_program(fGpu, programID, shadersToDelete);
+                    return nullptr;
+                }
             }
         }
     }
diff --git a/src/gpu/gl/builders/GrGLShaderStringBuilder.cpp b/src/gpu/gl/builders/GrGLShaderStringBuilder.cpp
index 2b5c3ae..9793e2b 100644
--- a/src/gpu/gl/builders/GrGLShaderStringBuilder.cpp
+++ b/src/gpu/gl/builders/GrGLShaderStringBuilder.cpp
@@ -57,6 +57,7 @@
                                     const SkSL::String& glsl,
                                     GrGpu::Stats* stats,
                                     GrContextOptions::ShaderErrorHandler* errorHandler) {
+    ATRACE_ANDROID_FRAMEWORK_ALWAYS("driver_compile_shader");
     const GrGLInterface* gli = glCtx.glInterface();
 
     // Specify GLSL source to the driver.
@@ -75,6 +76,7 @@
     bool checkCompiled = !glCtx.caps()->skipErrorChecks();
 
     if (checkCompiled) {
+        ATRACE_ANDROID_FRAMEWORK("checkCompiled");
         GrGLint compiled = GR_GL_INIT_ZERO;
         GR_GL_CALL(gli, GetShaderiv(shaderId, GR_GL_COMPILE_STATUS, &compiled));
 
diff --git a/src/sksl/SkSLCompiler.cpp b/src/sksl/SkSLCompiler.cpp
index e331470..fbf47d8 100644
--- a/src/sksl/SkSLCompiler.cpp
+++ b/src/sksl/SkSLCompiler.cpp
@@ -10,6 +10,7 @@
 #include <memory>
 #include <unordered_set>
 
+#include "src/core/SkTraceEvent.h"
 #include "src/sksl/SkSLAnalysis.h"
 #include "src/sksl/SkSLCFGGenerator.h"
 #include "src/sksl/SkSLCPPCodeGenerator.h"
@@ -1569,6 +1570,8 @@
         String text,
         const Program::Settings& settings,
         const std::vector<std::unique_ptr<ExternalFunction>>* externalFunctions) {
+    ATRACE_ANDROID_FRAMEWORK("SkSL::Compiler::convertProgram");
+
     SkASSERT(!externalFunctions || (kind == ProgramKind::kGeneric));
 
     // Loading and optimizing our base module might reset the inliner, so do that first,
@@ -1840,6 +1843,7 @@
 }
 
 bool Compiler::toGLSL(Program& program, OutputStream& out) {
+    ATRACE_ANDROID_FRAMEWORK("SkSL::Compiler::toGLSL");
     AutoSource as(this, program.fSource.get());
     GLSLCodeGenerator cg(fContext.get(), &program, this, &out);
     bool result = cg.generateCode();