Adds gpu stats for program cache

With the addition of the DDL program pre-compilation we need to know how it is working.

This CL also fixes some threading bugs.

Bug: skia:9455
Change-Id: I20da58a7f1b19685687fae1d159d4e0db8a4964d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/273001
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/gl/GrGLGpuProgramCache.cpp b/src/gpu/gl/GrGLGpuProgramCache.cpp
index 02c75a1..bf54a88 100644
--- a/src/gpu/gl/GrGLGpuProgramCache.cpp
+++ b/src/gpu/gl/GrGLGpuProgramCache.cpp
@@ -55,12 +55,22 @@
         return nullptr;
     }
 
-    return this->findOrCreateProgram(renderTarget, desc, programInfo);
+    Stats::ProgramCacheResult stat;
+    sk_sp<GrGLProgram> tmp = this->findOrCreateProgram(renderTarget, desc, programInfo, &stat);
+    if (!tmp) {
+        fGpu->fStats.incNumInlineCompilationFailures();
+    } else {
+        fGpu->fStats.incNumInlineProgramCacheResult(stat);
+    }
+
+    return tmp;
 }
 
 sk_sp<GrGLProgram> GrGLGpu::ProgramCache::findOrCreateProgram(GrRenderTarget* renderTarget,
                                                               const GrProgramDesc& desc,
-                                                              const GrProgramInfo& programInfo) {
+                                                              const GrProgramInfo& programInfo,
+                                                              Stats::ProgramCacheResult* stat) {
+    *stat = Stats::ProgramCacheResult::kHit;
     std::unique_ptr<Entry>* entry = fMap.find(desc);
     if (entry && !(*entry)->fProgram) {
         // We've pre-compiled the GL program, but don't have the GrGLProgram scaffolding
@@ -71,16 +81,22 @@
         if (!(*entry)->fProgram) {
             // Should we purge the program ID from the cache at this point?
             SkDEBUGFAIL("Couldn't create program from precompiled program");
+            fGpu->fStats.incNumCompilationFailures();
             return nullptr;
         }
+        fGpu->fStats.incNumPartialCompilationSuccesses();
+        *stat = Stats::ProgramCacheResult::kPartial;
     } else if (!entry) {
         // We have a cache miss
         sk_sp<GrGLProgram> program = GrGLProgramBuilder::CreateProgram(fGpu, renderTarget,
                                                                        desc, programInfo);
         if (!program) {
+            fGpu->fStats.incNumCompilationFailures();
             return nullptr;
         }
+        fGpu->fStats.incNumCompilationSuccesses();
         entry = fMap.insert(desc, std::unique_ptr<Entry>(new Entry(std::move(program))));
+        *stat = Stats::ProgramCacheResult::kMiss;
     }
 
     return (*entry)->fProgram;