1 /*
2 * Copyright 2021 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "src/gpu/GrThreadSafePipelineBuilder.h"
9
10 #if GR_GPU_STATS
11 #if GR_TEST_UTILS
12 #include "include/core/SkString.h"
13
14 using Stats = GrThreadSafePipelineBuilder::Stats;
15
cache_result_to_str(int i)16 static const char* cache_result_to_str(int i) {
17 const char* kCacheResultStrings[Stats::kNumProgramCacheResults] = {
18 "hits",
19 "misses",
20 "partials"
21 };
22 static_assert(0 == (int) Stats::ProgramCacheResult::kHit);
23 static_assert(1 == (int) Stats::ProgramCacheResult::kMiss);
24 static_assert(2 == (int) Stats::ProgramCacheResult::kPartial);
25 static_assert(Stats::kNumProgramCacheResults == 3);
26 return kCacheResultStrings[i];
27 }
28
dump(SkString * out)29 void GrThreadSafePipelineBuilder::Stats::dump(SkString* out) {
30 out->appendf("Shader Compilations: %d\n", fShaderCompilations.load());
31
32 SkASSERT(fNumInlineCompilationFailures == 0);
33 out->appendf("Number of Inline compile failures %d\n", fNumInlineCompilationFailures.load());
34 for (int i = 0; i < Stats::kNumProgramCacheResults-1; ++i) {
35 out->appendf("Inline Program Cache %s %d\n", cache_result_to_str(i),
36 fInlineProgramCacheStats[i].load());
37 }
38
39 SkASSERT(fNumPreCompilationFailures == 0);
40 out->appendf("Number of precompile failures %d\n", fNumPreCompilationFailures.load());
41 for (int i = 0; i < Stats::kNumProgramCacheResults-1; ++i) {
42 out->appendf("Precompile Program Cache %s %d\n", cache_result_to_str(i),
43 fPreProgramCacheStats[i].load());
44 }
45
46 SkASSERT(fNumCompilationFailures == 0);
47 out->appendf("Total number of compilation failures %d\n", fNumCompilationFailures.load());
48 out->appendf("Total number of partial compilation successes %d\n",
49 fNumPartialCompilationSuccesses.load());
50 out->appendf("Total number of compilation successes %d\n", fNumCompilationSuccesses.load());
51 }
52
dumpKeyValuePairs(SkTArray<SkString> * keys,SkTArray<double> * values)53 void GrThreadSafePipelineBuilder::Stats::dumpKeyValuePairs(SkTArray<SkString>* keys,
54 SkTArray<double>* values) {
55 keys->push_back(SkString("shader_compilations")); values->push_back(fShaderCompilations);
56 }
57
58 #endif // GR_TEST_UTILS
59 #endif // GR_GPU_STATS
60