1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "gpu/perftests/measurements.h"
7 #include "base/logging.h"
8 #include "testing/perf/perf_test.h"
9 #include "ui/gl/gpu_timing.h"
13 Measurement::Measurement() : name(), wall_time(), cpu_time(), gpu_time() {
15 Measurement::Measurement(const Measurement
& m
)
17 wall_time(m
.wall_time
),
19 gpu_time(m
.gpu_time
) {
21 Measurement::Measurement(const std::string
& name
,
22 const base::TimeDelta wall_time
,
23 const base::TimeDelta cpu_time
,
24 const base::TimeDelta gpu_time
)
25 : name(name
), wall_time(wall_time
), cpu_time(cpu_time
), gpu_time(gpu_time
) {
28 void Measurement::PrintResult(const std::string
& graph
) const {
29 perf_test::PrintResult(graph
, "", name
+ "_wall", wall_time
.InMillisecondsF(),
31 if (cpu_time
.InMicroseconds() >= 0) {
32 perf_test::PrintResult(graph
, "", name
+ "_cpu", cpu_time
.InMillisecondsF(),
35 if (gpu_time
.InMicroseconds() >= 0) {
36 perf_test::PrintResult(graph
, "", name
+ "_gpu", gpu_time
.InMillisecondsF(),
41 Measurement
& Measurement::Increment(const Measurement
& m
) {
42 wall_time
+= m
.wall_time
;
43 cpu_time
+= m
.cpu_time
;
44 gpu_time
+= m
.gpu_time
;
48 Measurement
Measurement::Divide(int a
) const {
49 return Measurement(name
, wall_time
/ a
, cpu_time
/ a
, gpu_time
/ a
);
52 Measurement::~Measurement() {
55 MeasurementTimers::MeasurementTimers(gfx::GPUTimingClient
* gpu_timing_client
)
56 : wall_time_start_(), cpu_time_start_(), gpu_timer_() {
57 DCHECK(gpu_timing_client
);
58 wall_time_start_
= base::TimeTicks::NowFromSystemTraceTime();
59 if (base::TimeTicks::IsThreadNowSupported()) {
60 cpu_time_start_
= base::TimeTicks::ThreadNow();
62 static bool logged_once
= false;
63 LOG_IF(WARNING
, !logged_once
) << "ThreadNow not supported.";
67 if (gpu_timing_client
->IsAvailable()) {
68 gpu_timer_
= gpu_timing_client
->CreateGPUTimer();
73 void MeasurementTimers::Record() {
74 wall_time_
= base::TimeTicks::NowFromSystemTraceTime() - wall_time_start_
;
75 if (base::TimeTicks::IsThreadNowSupported()) {
76 cpu_time_
= base::TimeTicks::ThreadNow() - cpu_time_start_
;
78 if (gpu_timer_
.get()) {
83 Measurement
MeasurementTimers::GetAsMeasurement(const std::string
& name
) {
84 DCHECK_NE(base::TimeDelta(),
85 wall_time_
); // At least wall_time_ has been set.
87 if (!base::TimeTicks::IsThreadNowSupported()) {
88 cpu_time_
= base::TimeDelta::FromMicroseconds(-1);
91 if (gpu_timer_
.get() != nullptr && gpu_timer_
->IsAvailable()) {
92 gpu_time
= gpu_timer_
->GetDeltaElapsed();
94 return Measurement(name
, wall_time_
, cpu_time_
,
95 base::TimeDelta::FromMicroseconds(gpu_time
));
98 MeasurementTimers::~MeasurementTimers() {
99 if (gpu_timer_
.get()) {
100 gpu_timer_
->Destroy(true);