OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "gpu/perftests/measurements.h" |
| 6 |
| 7 #include "testing/perf/perf_test.h" |
| 8 |
| 9 namespace gpu { |
| 10 |
| 11 Measurement::Measurement() : name(), wall_time(), cpu_time(), gpu_time() { |
| 12 } |
| 13 Measurement::Measurement(const Measurement& m) |
| 14 : name(m.name), |
| 15 wall_time(m.wall_time), |
| 16 cpu_time(m.cpu_time), |
| 17 gpu_time(m.gpu_time) { |
| 18 } |
| 19 Measurement::Measurement(const std::string& name, |
| 20 const base::TimeDelta wall_time, |
| 21 const base::TimeDelta cpu_time, |
| 22 const base::TimeDelta gpu_time) |
| 23 : name(name), wall_time(wall_time), cpu_time(cpu_time), gpu_time(gpu_time) { |
| 24 } |
| 25 |
| 26 void Measurement::PrintResult() const { |
| 27 perf_test::PrintResult(name, "_wall", "", wall_time.InMillisecondsF(), "ms", |
| 28 true); |
| 29 if (cpu_time.InMicroseconds() >= 0) { |
| 30 perf_test::PrintResult(name, "_cpu", "", cpu_time.InMillisecondsF(), "ms", |
| 31 true); |
| 32 } |
| 33 if (gpu_time.InMicroseconds() >= 0) { |
| 34 perf_test::PrintResult(name, "_gpu", "", gpu_time.InMillisecondsF(), "ms", |
| 35 true); |
| 36 } |
| 37 } |
| 38 |
| 39 Measurement& Measurement::Increment(const Measurement& m) { |
| 40 wall_time += m.wall_time; |
| 41 cpu_time += m.cpu_time; |
| 42 gpu_time += m.gpu_time; |
| 43 return *this; |
| 44 } |
| 45 |
| 46 Measurement Measurement::Divide(int a) const { |
| 47 return Measurement(name, wall_time / a, cpu_time / a, gpu_time / a); |
| 48 } |
| 49 |
| 50 Measurement::~Measurement() { |
| 51 } |
| 52 |
| 53 MeasurementTimers::MeasurementTimers(GPUTiming* gpu_timing) |
| 54 : wall_time_start_(), cpu_time_start_(), gpu_timer_() { |
| 55 DCHECK(gpu_timing); |
| 56 wall_time_start_ = base::TimeTicks::NowFromSystemTraceTime(); |
| 57 if (base::TimeTicks::IsThreadNowSupported()) { |
| 58 cpu_time_start_ = base::TimeTicks::ThreadNow(); |
| 59 } else { |
| 60 static bool logged_once = false; |
| 61 LOG_IF(WARNING, !logged_once) << "ThreadNow not supported."; |
| 62 logged_once = true; |
| 63 } |
| 64 |
| 65 if (gpu_timing->IsAvailable()) { |
| 66 gpu_timer_.reset(new GPUTimer(gpu_timing)); |
| 67 gpu_timer_->Start(); |
| 68 } |
| 69 } |
| 70 |
| 71 void MeasurementTimers::Record() { |
| 72 wall_time_ = base::TimeTicks::NowFromSystemTraceTime() - wall_time_start_; |
| 73 if (base::TimeTicks::IsThreadNowSupported()) { |
| 74 cpu_time_ = base::TimeTicks::ThreadNow() - cpu_time_start_; |
| 75 } |
| 76 if (gpu_timer_.get()) { |
| 77 gpu_timer_->End(); |
| 78 } |
| 79 } |
| 80 |
| 81 Measurement MeasurementTimers::GetAsMeasurement(const std::string& name) { |
| 82 DCHECK_NE(base::TimeDelta(), |
| 83 wall_time_); // At least wall_time_ has been set. |
| 84 |
| 85 if (!base::TimeTicks::IsThreadNowSupported()) { |
| 86 cpu_time_ = base::TimeDelta::FromMicroseconds(-1); |
| 87 } |
| 88 int64 gpu_time = -1; |
| 89 if (gpu_timer_.get() != nullptr && gpu_timer_->IsAvailable()) { |
| 90 gpu_time = gpu_timer_->GetDeltaElapsed(); |
| 91 } |
| 92 return Measurement(name, wall_time_, cpu_time_, |
| 93 base::TimeDelta::FromMicroseconds(gpu_time)); |
| 94 } |
| 95 |
| 96 MeasurementTimers::~MeasurementTimers() { |
| 97 } |
| 98 |
| 99 } // namespace gpu |
OLD | NEW |