Chromium Code Reviews| 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 perf_test::PrintResult(name, "_cpu", "", cpu_time.InMillisecondsF(), "ms", | |
| 30 true); | |
| 31 perf_test::PrintResult(name, "_gpu", "", gpu_time.InMillisecondsF(), "ms", | |
| 32 true); | |
| 33 } | |
| 34 | |
| 35 Measurement& Measurement::Increment(const Measurement& m) { | |
| 36 wall_time += m.wall_time; | |
| 37 cpu_time += m.cpu_time; | |
| 38 gpu_time += m.gpu_time; | |
| 39 return *this; | |
| 40 } | |
| 41 | |
| 42 Measurement Measurement::Divide(int a) const { | |
| 43 return Measurement(name, wall_time / a, cpu_time / a, gpu_time / a); | |
| 44 } | |
| 45 | |
| 46 Measurement::~Measurement() { | |
| 47 } | |
| 48 | |
| 49 MeasurementTimers::MeasurementTimers() | |
| 50 : wall_timer_(), cpu_time_begin_(), cpu_time_() { | |
| 51 if (base::TimeTicks::IsThreadNowSupported()) { | |
| 52 cpu_time_begin_ = base::TimeTicks::ThreadNow(); | |
| 53 } | |
| 54 | |
| 55 glGenQueriesARB(2, gl_queries_); | |
| 56 | |
| 57 glQueryCounter(gl_queries_[0], GL_TIMESTAMP); | |
|
piman
2015/01/30 21:12:04
This only works with GL_ARB_timer_query, which is
Daniele Castagna
2015/02/03 04:12:59
Makes sense. I already reached out to dyen@ and vm
Daniele Castagna
2015/02/06 22:52:00
Still working with dyen@ on this: crrev.com/904743
Daniele Castagna
2015/02/13 21:17:42
Done.
| |
| 58 CHECK(glIsQueryARB(gl_queries_[0])); | |
|
piman
2015/01/30 21:12:04
nit: DCHECK instead of CHECK (here and other place
Daniele Castagna
2015/02/03 04:12:59
Done.
| |
| 59 } | |
| 60 | |
| 61 void MeasurementTimers::Record() { | |
| 62 wall_time_ = wall_timer_.Elapsed(); | |
| 63 if (base::TimeTicks::IsThreadNowSupported()) { | |
| 64 cpu_time_ = base::TimeTicks::ThreadNow() - cpu_time_begin_; | |
| 65 } else { | |
| 66 static bool logged_once = false; | |
| 67 LOG_IF(WARNING, !logged_once) << "ThreadNow not supported. :("; | |
| 68 logged_once = true; | |
| 69 } | |
| 70 | |
| 71 glQueryCounter(gl_queries_[1], GL_TIMESTAMP); | |
| 72 CHECK(glIsQueryARB(gl_queries_[1])); | |
| 73 } | |
| 74 | |
| 75 Measurement MeasurementTimers::GetAsMeasurement(const std::string& name) { | |
| 76 CHECK_NE(base::TimeDelta(), wall_time_); // At least wall_time_ has been set. | |
| 77 GLint done = 0; | |
| 78 glGetQueryObjectivARB(gl_queries_[1], GL_QUERY_RESULT_AVAILABLE, &done); | |
| 79 CHECK_GT(done, 0); | |
| 80 | |
| 81 GLuint64 gl_start = 0; | |
| 82 GLuint64 gl_end = 0; | |
| 83 glGetQueryObjectui64v(gl_queries_[0], GL_QUERY_RESULT, &gl_start); | |
| 84 glGetQueryObjectui64v(gl_queries_[1], GL_QUERY_RESULT, &gl_end); | |
| 85 | |
| 86 int64 gpu_time = (gl_end - gl_start) / base::Time::kNanosecondsPerMicrosecond; | |
| 87 return Measurement(name, wall_time_, cpu_time_, | |
| 88 base::TimeDelta::FromMicroseconds(gpu_time)); | |
| 89 } | |
| 90 | |
| 91 MeasurementTimers::~MeasurementTimers() { | |
| 92 glDeleteQueriesARB(2, gl_queries_); | |
| 93 } | |
| 94 | |
| 95 } // namespace gpu | |
| OLD | NEW |