Index: gpu/command_buffer/service/gpu_tracer.cc |
diff --git a/gpu/command_buffer/service/gpu_tracer.cc b/gpu/command_buffer/service/gpu_tracer.cc |
index d7cd1b8b747957e2599c60b95eb418f39fb8f6d6..1f91696cd7a317b238f2a9ef931fe5a64f9b301e 100644 |
--- a/gpu/command_buffer/service/gpu_tracer.cc |
+++ b/gpu/command_buffer/service/gpu_tracer.cc |
@@ -18,6 +18,16 @@ namespace gles2 { |
static const unsigned int kProcessInterval = 16; |
static TraceOutputter* g_outputter_thread = NULL; |
+CPUTime::CPUTime() { |
+} |
+ |
+int64 CPUTime::GetCurrentTime() { |
+ return base::TimeTicks::NowFromSystemTraceTime().ToInternalValue(); |
+} |
+ |
+CPUTime::~CPUTime() { |
+} |
+ |
TraceMarker::TraceMarker(const std::string& category, const std::string& name) |
: category_(category), |
name_(name), |
@@ -42,10 +52,10 @@ TraceOutputter::TraceOutputter(const std::string& name) |
TraceOutputter::~TraceOutputter() { g_outputter_thread = NULL; } |
-void TraceOutputter::Trace(const std::string& category, |
- const std::string& name, |
- int64 start_time, |
- int64 end_time) { |
+void TraceOutputter::TraceDevice(const std::string& category, |
+ const std::string& name, |
+ int64 start_time, |
+ int64 end_time) { |
TRACE_EVENT_COPY_BEGIN_WITH_ID_TID_AND_TIMESTAMP0(category.c_str(), |
name.c_str(), |
local_trace_id_, |
@@ -59,7 +69,20 @@ void TraceOutputter::Trace(const std::string& category, |
++local_trace_id_; |
} |
+void TraceOutputter::TraceServiceBegin(const std::string& category, |
+ const std::string& name, |
+ void* id) { |
+ TRACE_EVENT_COPY_ASYNC_BEGIN0(category.c_str(), name.c_str(), id); |
+} |
+ |
+void TraceOutputter::TraceServiceEnd(const std::string& category, |
+ const std::string& name, |
+ void* id) { |
+ TRACE_EVENT_COPY_ASYNC_END0(category.c_str(), name.c_str(), id); |
+} |
+ |
GPUTrace::GPUTrace(scoped_refptr<Outputter> outputter, |
+ scoped_refptr<CPUTime> cpu_time, |
const std::string& category, |
const std::string& name, |
int64 offset, |
@@ -67,6 +90,7 @@ GPUTrace::GPUTrace(scoped_refptr<Outputter> outputter, |
: category_(category), |
name_(name), |
outputter_(outputter), |
+ cpu_time_(cpu_time), |
offset_(offset), |
start_time_(0), |
end_time_(0), |
@@ -98,7 +122,7 @@ GPUTrace::~GPUTrace() { |
void GPUTrace::Start(bool trace_service) { |
if (trace_service) { |
- TRACE_EVENT_COPY_ASYNC_BEGIN0(category().c_str(), name().c_str(), this); |
+ outputter_->TraceServiceBegin(category_, name_, this); |
} |
switch (tracer_type_) { |
@@ -115,7 +139,7 @@ void GPUTrace::Start(bool trace_service) { |
if (offset_ == 0) { |
GLint64 gl_now = 0; |
glGetInteger64v(GL_TIMESTAMP, &gl_now); |
- offset_ = base::TimeTicks::NowFromSystemTraceTime().ToInternalValue() - |
+ offset_ = cpu_time_->GetCurrentTime() - |
gl_now / base::Time::kNanosecondsPerMicrosecond; |
} |
// Intentionally fall through to kTracerTypeARBTimer case.xs |
@@ -140,7 +164,7 @@ void GPUTrace::End(bool tracing_service) { |
} |
if (tracing_service) { |
- TRACE_EVENT_COPY_ASYNC_END0(category().c_str(), name().c_str(), this); |
+ outputter_->TraceServiceEnd(category_, name_, this); |
} |
} |
@@ -175,7 +199,7 @@ void GPUTrace::Process() { |
start_time_ = (begin_stamp / base::Time::kNanosecondsPerMicrosecond) + |
offset_; |
end_time_ = (end_stamp / base::Time::kNanosecondsPerMicrosecond) + offset_; |
- outputter_->Trace(category(), name(), start_time_, end_time_); |
+ outputter_->TraceDevice(category(), name(), start_time_, end_time_); |
} |
GPUTracer::GPUTracer(gles2::GLES2Decoder* decoder) |
@@ -190,13 +214,6 @@ GPUTracer::GPUTracer(gles2::GLES2Decoder* decoder) |
gpu_timing_synced_(false), |
gpu_executing_(false), |
process_posted_(false) { |
- if (gfx::g_driver_gl.ext.b_GL_EXT_disjoint_timer_query) { |
- tracer_type_ = kTracerTypeDisjointTimer; |
- outputter_ = TraceOutputter::Create("GL_EXT_disjoint_timer_query"); |
- } else if (gfx::g_driver_gl.ext.b_GL_ARB_timer_query) { |
- tracer_type_ = kTracerTypeARBTimer; |
- outputter_ = TraceOutputter::Create("GL_ARB_timer_query"); |
- } |
} |
GPUTracer::~GPUTracer() { |
@@ -206,6 +223,28 @@ bool GPUTracer::BeginDecoding() { |
if (gpu_executing_) |
return false; |
+ if (outputter_ == NULL) { |
+ tracer_type_ = DetermineTracerType(); |
+ const char* tracer_type_name = "Unknown"; |
+ switch (tracer_type_) { |
+ case kTracerTypeDisjointTimer: |
+ tracer_type_name = "GL_EXT_disjoint_timer_query"; |
+ break; |
+ case kTracerTypeARBTimer: |
+ tracer_type_name = "GL_ARB_timer_query"; |
+ break; |
+ |
+ default: |
+ break; |
+ } |
+ |
+ outputter_ = CreateOutputter(tracer_type_name); |
+ } |
+ |
+ if (cpu_time_ == NULL) { |
+ cpu_time_ = CreateCPUTime(); |
+ } |
+ |
CalculateTimerOffset(); |
gpu_executing_ = true; |
@@ -327,7 +366,33 @@ scoped_refptr<GPUTrace> GPUTracer::CreateTrace(const std::string& category, |
GpuTracerType tracer_type = *gpu_trace_dev_category ? tracer_type_ : |
kTracerTypeInvalid; |
- return new GPUTrace(outputter_, category, name, timer_offset_, tracer_type); |
+ return new GPUTrace(outputter_, cpu_time_, category, name, |
+ timer_offset_, tracer_type); |
+} |
+ |
+scoped_refptr<Outputter> GPUTracer::CreateOutputter(const std::string& name) { |
+ return TraceOutputter::Create(name); |
+} |
+ |
+scoped_refptr<CPUTime> GPUTracer::CreateCPUTime() { |
+ return new CPUTime(); |
+} |
+ |
+GpuTracerType GPUTracer::DetermineTracerType() { |
+ if (gfx::g_driver_gl.ext.b_GL_EXT_disjoint_timer_query) { |
+ return kTracerTypeDisjointTimer; |
+ } else if (gfx::g_driver_gl.ext.b_GL_ARB_timer_query) { |
+ return kTracerTypeARBTimer; |
+ } |
+ |
+ return kTracerTypeInvalid; |
+} |
+ |
+void GPUTracer::PostTask() { |
+ base::MessageLoop::current()->PostDelayedTask( |
+ FROM_HERE, |
+ base::Bind(&GPUTracer::Process, base::AsWeakPtr(this)), |
+ base::TimeDelta::FromMilliseconds(kProcessInterval)); |
} |
void GPUTracer::Process() { |
@@ -401,10 +466,8 @@ void GPUTracer::CalculateTimerOffset() { |
glGetQueryObjectui64v(query, GL_QUERY_RESULT, &gl_now); |
glDeleteQueriesARB(1, &query); |
- base::TimeTicks system_now = base::TimeTicks::NowFromSystemTraceTime(); |
- |
gl_now /= base::Time::kNanosecondsPerMicrosecond; |
- timer_offset_ = system_now.ToInternalValue() - gl_now; |
+ timer_offset_ = cpu_time_->GetCurrentTime() - gl_now; |
gpu_timing_synced_ = true; |
} |
} |
@@ -414,10 +477,7 @@ void GPUTracer::IssueProcessTask() { |
return; |
process_posted_ = true; |
- base::MessageLoop::current()->PostDelayedTask( |
- FROM_HERE, |
- base::Bind(&GPUTracer::Process, base::AsWeakPtr(this)), |
- base::TimeDelta::FromMilliseconds(kProcessInterval)); |
+ PostTask(); |
} |
} // namespace gles2 |