Index: gpu/perftests/measurements.cc |
diff --git a/gpu/perftests/measurements.cc b/gpu/perftests/measurements.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e1694e4ae0f91be2c882a3ee01d6e782eb2b4ec9 |
--- /dev/null |
+++ b/gpu/perftests/measurements.cc |
@@ -0,0 +1,95 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "gpu/perftests/measurements.h" |
+ |
+#include "testing/perf/perf_test.h" |
+ |
+namespace gpu { |
+ |
+Measurement::Measurement() : name(), wall_time(), cpu_time(), gpu_time() { |
+} |
+Measurement::Measurement(const Measurement& m) |
+ : name(m.name), |
+ wall_time(m.wall_time), |
+ cpu_time(m.cpu_time), |
+ gpu_time(m.gpu_time) { |
+} |
+Measurement::Measurement(const std::string& name, |
+ const base::TimeDelta wall_time, |
+ const base::TimeDelta cpu_time, |
+ const base::TimeDelta gpu_time) |
+ : name(name), wall_time(wall_time), cpu_time(cpu_time), gpu_time(gpu_time) { |
+} |
+ |
+void Measurement::PrintResult() const { |
+ perf_test::PrintResult(name, "_wall", "", wall_time.InMillisecondsF(), "ms", |
+ true); |
+ perf_test::PrintResult(name, "_cpu", "", cpu_time.InMillisecondsF(), "ms", |
+ true); |
+ perf_test::PrintResult(name, "_gpu", "", gpu_time.InMillisecondsF(), "ms", |
+ true); |
+} |
+ |
+Measurement& Measurement::Increment(const Measurement& m) { |
+ wall_time += m.wall_time; |
+ cpu_time += m.cpu_time; |
+ gpu_time += m.gpu_time; |
+ return *this; |
+} |
+ |
+Measurement Measurement::Divide(int a) const { |
+ return Measurement(name, wall_time / a, cpu_time / a, gpu_time / a); |
+} |
+ |
+Measurement::~Measurement() { |
+} |
+ |
+MeasurementTimers::MeasurementTimers() |
+ : wall_timer_(), cpu_time_begin_(), cpu_time_() { |
+ if (base::TimeTicks::IsThreadNowSupported()) { |
+ cpu_time_begin_ = base::TimeTicks::ThreadNow(); |
+ } |
+ |
+ glGenQueriesARB(2, gl_queries_); |
+ |
+ 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.
|
+ 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.
|
+} |
+ |
+void MeasurementTimers::Record() { |
+ wall_time_ = wall_timer_.Elapsed(); |
+ if (base::TimeTicks::IsThreadNowSupported()) { |
+ cpu_time_ = base::TimeTicks::ThreadNow() - cpu_time_begin_; |
+ } else { |
+ static bool logged_once = false; |
+ LOG_IF(WARNING, !logged_once) << "ThreadNow not supported. :("; |
+ logged_once = true; |
+ } |
+ |
+ glQueryCounter(gl_queries_[1], GL_TIMESTAMP); |
+ CHECK(glIsQueryARB(gl_queries_[1])); |
+} |
+ |
+Measurement MeasurementTimers::GetAsMeasurement(const std::string& name) { |
+ CHECK_NE(base::TimeDelta(), wall_time_); // At least wall_time_ has been set. |
+ GLint done = 0; |
+ glGetQueryObjectivARB(gl_queries_[1], GL_QUERY_RESULT_AVAILABLE, &done); |
+ CHECK_GT(done, 0); |
+ |
+ GLuint64 gl_start = 0; |
+ GLuint64 gl_end = 0; |
+ glGetQueryObjectui64v(gl_queries_[0], GL_QUERY_RESULT, &gl_start); |
+ glGetQueryObjectui64v(gl_queries_[1], GL_QUERY_RESULT, &gl_end); |
+ |
+ int64 gpu_time = (gl_end - gl_start) / base::Time::kNanosecondsPerMicrosecond; |
+ return Measurement(name, wall_time_, cpu_time_, |
+ base::TimeDelta::FromMicroseconds(gpu_time)); |
+} |
+ |
+MeasurementTimers::~MeasurementTimers() { |
+ glDeleteQueriesARB(2, gl_queries_); |
+} |
+ |
+} // namespace gpu |