File: dawn_platform_unittest.cc

package info (click to toggle)
chromium 145.0.7632.109-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 5,974,804 kB
  • sloc: cpp: 36,197,696; ansic: 7,602,761; javascript: 3,563,590; python: 1,649,324; xml: 838,427; asm: 717,087; pascal: 185,708; sh: 88,786; perl: 88,718; objc: 79,984; sql: 59,811; cs: 42,452; fortran: 24,101; makefile: 21,022; tcl: 15,277; php: 14,022; yacc: 9,066; ruby: 7,553; awk: 3,720; lisp: 3,233; lex: 1,328; ada: 727; jsp: 228; sed: 36
file content (101 lines) | stat: -rw-r--r-- 3,778 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "gpu/command_buffer/service/dawn_platform.h"

#include "base/test/metrics/histogram_tester.h"
#include "base/test/task_environment.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace gpu::webgpu {

class DawnPlatformTest : public testing::Test {
 public:
  DawnPlatformTest()
      : task_environment_(base::test::TaskEnvironment::TimeSource::MOCK_TIME) {}

 protected:
  base::test::TaskEnvironment task_environment_;
  base::HistogramTester histogram_tester_;
};

TEST_F(DawnPlatformTest, RecordsCacheHistogramsAfterDelay) {
  DawnPlatform platform(nullptr, nullptr, "GPU.GraphiteDawn.", true);

  // Simulate some cache hits and misses.
  platform.HistogramCustomCounts("D3D11.CompileShader.CacheHit", 1, 1, 100, 50);
  platform.HistogramCustomCounts("D3D11.CompileShader.CacheHit", 1, 1, 100, 50);
  platform.HistogramCustomCounts("D3D11.CompileShader.CacheMiss", 1, 1, 100,
                                 50);

  // The histograms should not be recorded yet.
  histogram_tester_.ExpectTotalCount(
      "GPU.GraphiteDawn.D3D11.CompileShader.CacheHit.Counts."
      "90SecondsPostStartup",
      0);
  histogram_tester_.ExpectTotalCount(
      "GPU.GraphiteDawn.D3D11.CompileShader.CacheMiss.Counts."
      "90SecondsPostStartup",
      0);
  histogram_tester_.ExpectTotalCount(
      "GPU.GraphiteDawn.D3D11.CompileShader.CacheHit.Percentage."
      "90SecondsPostStartup",
      0);

  // Fast forward time by 90 seconds to trigger the delayed task.
  task_environment_.FastForwardBy(base::Seconds(90));

  // Now, the histograms should be recorded.
  histogram_tester_.ExpectUniqueSample(
      "GPU.GraphiteDawn.D3D11.CompileShader.CacheHit.Counts."
      "90SecondsPostStartup",
      2, 1);
  histogram_tester_.ExpectUniqueSample(
      "GPU.GraphiteDawn.D3D11.CompileShader.CacheMiss.Counts."
      "90SecondsPostStartup",
      1, 1);
  // 2 hits / (2 hits + 1 miss) = 66%
  histogram_tester_.ExpectUniqueSample(
      "GPU.GraphiteDawn.D3D11.CompileShader.CacheHit.Percentage."
      "90SecondsPostStartup",
      66, 1);
}

TEST_F(DawnPlatformTest, RecordsCacheHistogramsOnFramePresented) {
  DawnPlatform platform(nullptr, nullptr, "GPU.GraphiteDawn.", true);

  // Simulate some cache hits and misses.
  platform.HistogramCustomCounts("D3D11.CompileShader.CacheHit", 1, 1, 100, 50);
  platform.HistogramCustomCounts("D3D11.CompileShader.CacheHit", 1, 1, 100, 50);
  platform.HistogramCustomCounts("D3D11.CompileShader.CacheMiss", 1, 1, 100,
                                 50);

  // The histograms should not be recorded yet.
  histogram_tester_.ExpectTotalCount(
      "GPU.GraphiteDawn.D3D11.CompileShader.CacheHit.Counts.1stPresent", 0);
  histogram_tester_.ExpectTotalCount(
      "GPU.GraphiteDawn.D3D11.CompileShader.CacheHit.Percentage.1stPresent", 0);

  // Call OnFramePresented to trigger histogram recording.
  platform.OnFramePresented();

  // Now, the histograms should be recorded.
  histogram_tester_.ExpectUniqueSample(
      "GPU.GraphiteDawn.D3D11.CompileShader.CacheHit.Counts.1stPresent", 2, 1);
  // 2 hits / (2 hits + 1 miss) = 66%
  histogram_tester_.ExpectUniqueSample(
      "GPU.GraphiteDawn.D3D11.CompileShader.CacheHit.Percentage.1stPresent", 66,
      1);

  // Call OnFramePresented again and check that histograms are not recorded a
  // second time.
  platform.OnFramePresented();
  histogram_tester_.ExpectUniqueSample(
      "GPU.GraphiteDawn.D3D11.CompileShader.CacheHit.Counts.1stPresent", 2, 1);
  histogram_tester_.ExpectUniqueSample(
      "GPU.GraphiteDawn.D3D11.CompileShader.CacheHit.Percentage.1stPresent", 66,
      1);
}

}  // namespace gpu::webgpu