Don't preload rarely seen large images
[chromium-blink-merge.git] / gpu / perftests / measurements.cc
blobb2dac91330501ea43517d86935aaa17976b4e80f
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"
11 namespace gpu {
13 Measurement::Measurement() : name(), wall_time(), cpu_time(), gpu_time() {
15 Measurement::Measurement(const Measurement& m)
16 : name(m.name),
17 wall_time(m.wall_time),
18 cpu_time(m.cpu_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(),
30 "ms", true);
31 if (cpu_time.InMicroseconds() >= 0) {
32 perf_test::PrintResult(graph, "", name + "_cpu", cpu_time.InMillisecondsF(),
33 "ms", true);
35 if (gpu_time.InMicroseconds() >= 0) {
36 perf_test::PrintResult(graph, "", name + "_gpu", gpu_time.InMillisecondsF(),
37 "ms", true);
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;
45 return *this;
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::TraceTicks::Now();
59 if (base::ThreadTicks::IsSupported()) {
60 cpu_time_start_ = base::ThreadTicks::Now();
61 } else {
62 static bool logged_once = false;
63 LOG_IF(WARNING, !logged_once) << "ThreadTicks not supported.";
64 logged_once = true;
67 if (gpu_timing_client->IsAvailable()) {
68 gpu_timer_ = gpu_timing_client->CreateGPUTimer(true);
69 gpu_timer_->Start();
73 void MeasurementTimers::Record() {
74 wall_time_ = base::TraceTicks::Now() - wall_time_start_;
75 if (base::ThreadTicks::IsSupported()) {
76 cpu_time_ = base::ThreadTicks::Now() - cpu_time_start_;
78 if (gpu_timer_.get()) {
79 gpu_timer_->End();
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::ThreadTicks::IsSupported()) {
88 cpu_time_ = base::TimeDelta::FromMicroseconds(-1);
90 int64 gpu_time = -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);
104 } // namespace gpu