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 d00deb0a2ff8d747341b51446365bdbe43dcbfb7..33d318d74b26bfe723f17282051b0e9b6f533652 100644 |
--- a/gpu/command_buffer/service/gpu_tracer.cc |
+++ b/gpu/command_buffer/service/gpu_tracer.cc |
@@ -85,12 +85,15 @@ GPUTrace::GPUTrace(scoped_refptr<Outputter> outputter, |
gfx::GPUTimingClient* gpu_timing_client, |
const std::string& category, |
const std::string& name, |
- const bool enabled) |
+ const bool tracing_service, |
+ const bool tracing_device) |
: category_(category), |
name_(name), |
outputter_(outputter), |
- enabled_(enabled) { |
- if (gpu_timing_client->IsAvailable() && |
+ service_enabled_(tracing_service), |
+ device_enabled_(tracing_device) { |
+ if (tracing_device && |
+ gpu_timing_client->IsAvailable() && |
gpu_timing_client->IsTimerOffsetAvailable()) { |
gpu_timer_ = gpu_timing_client->CreateGPUTimer(); |
} |
@@ -99,8 +102,14 @@ GPUTrace::GPUTrace(scoped_refptr<Outputter> outputter, |
GPUTrace::~GPUTrace() { |
} |
-void GPUTrace::Start(bool trace_service) { |
- if (trace_service) { |
+void GPUTrace::Destroy(bool have_context) { |
+ if (gpu_timer_.get()) { |
+ gpu_timer_->Destroy(have_context); |
+ } |
+} |
+ |
+void GPUTrace::Start() { |
+ if (service_enabled_) { |
outputter_->TraceServiceBegin(category_, name_); |
} |
if (gpu_timer_.get()) { |
@@ -108,11 +117,11 @@ void GPUTrace::Start(bool trace_service) { |
} |
} |
-void GPUTrace::End(bool tracing_service) { |
+void GPUTrace::End() { |
if (gpu_timer_.get()) { |
gpu_timer_->End(); |
} |
- if (tracing_service) { |
+ if (service_enabled_) { |
outputter_->TraceServiceEnd(category_, name_); |
} |
} |
@@ -152,6 +161,20 @@ GPUTracer::GPUTracer(gles2::GLES2Decoder* decoder) |
GPUTracer::~GPUTracer() { |
} |
+void GPUTracer::Destroy(bool have_context) { |
+ for (int n = 0; n < NUM_TRACER_SOURCES; n++) { |
+ for (size_t i = 0; i < markers_[n].size(); i++) { |
+ TraceMarker& marker = markers_[n][i]; |
+ if (marker.trace_.get()) { |
+ marker.trace_->Destroy(have_context); |
+ marker.trace_ = 0; |
+ } |
+ } |
+ } |
+ |
+ ClearFinishedTraces(have_context); |
+} |
+ |
bool GPUTracer::BeginDecoding() { |
if (gpu_executing_) |
return false; |
@@ -175,8 +198,9 @@ bool GPUTracer::BeginDecoding() { |
trace_marker.trace_ = |
new GPUTrace(outputter_, gpu_timing_client_.get(), |
trace_marker.category_, trace_marker.name_, |
+ *gpu_trace_srv_category != 0, |
*gpu_trace_dev_category != 0); |
- trace_marker.trace_->Start(*gpu_trace_srv_category != 0); |
+ trace_marker.trace_->Start(); |
} |
} |
} |
@@ -193,11 +217,10 @@ bool GPUTracer::EndDecoding() { |
for (size_t i = 0; i < markers_[n].size(); i++) { |
TraceMarker& marker = markers_[n][i]; |
if (marker.trace_.get()) { |
- marker.trace_->End(*gpu_trace_srv_category != 0); |
- if (marker.trace_->IsEnabled()) |
- traces_.push_back(marker.trace_); |
+ marker.trace_->End(); |
- markers_[n][i].trace_ = 0; |
+ finished_traces_.push_back(marker.trace_); |
+ marker.trace_ = 0; |
} |
} |
} |
@@ -225,8 +248,9 @@ bool GPUTracer::Begin(const std::string& category, const std::string& name, |
if (IsTracing()) { |
scoped_refptr<GPUTrace> trace = new GPUTrace( |
outputter_, gpu_timing_client_.get(), category, name, |
+ *gpu_trace_srv_category != 0, |
*gpu_trace_dev_category != 0); |
- trace->Start(*gpu_trace_srv_category != 0); |
+ trace->Start(); |
markers_[source].back().trace_ = trace; |
} |
@@ -241,14 +265,14 @@ bool GPUTracer::End(GpuTracerSource source) { |
// Pop last marker with matching 'source' |
if (!markers_[source].empty()) { |
- if (IsTracing()) { |
- scoped_refptr<GPUTrace> trace = markers_[source].back().trace_; |
- if (trace.get()) { |
- trace->End(*gpu_trace_srv_category != 0); |
- if (trace->IsEnabled()) |
- traces_.push_back(trace); |
- IssueProcessTask(); |
+ scoped_refptr<GPUTrace> trace = markers_[source].back().trace_; |
+ if (trace.get()) { |
+ if (IsTracing()) { |
+ trace->End(); |
} |
+ |
+ finished_traces_.push_back(trace); |
+ IssueProcessTask(); |
} |
markers_[source].pop_back(); |
@@ -298,7 +322,7 @@ void GPUTracer::Process() { |
void GPUTracer::ProcessTraces() { |
if (!gpu_timing_client_->IsAvailable()) { |
- traces_.clear(); |
+ ClearFinishedTraces(false); |
return; |
} |
@@ -307,28 +331,42 @@ void GPUTracer::ProcessTraces() { |
// Make owning decoder's GL context current |
if (!decoder_->MakeCurrent()) { |
// Skip subsequent GL calls if MakeCurrent fails |
- traces_.clear(); |
+ ClearFinishedTraces(false); |
return; |
} |
// Check if timers are still valid (e.g: a disjoint operation |
// might have occurred.) |
- if (gpu_timing_client_->CheckAndResetTimerErrors()) |
- traces_.clear(); |
+ if (gpu_timing_client_->CheckAndResetTimerErrors()) { |
+ ClearFinishedTraces(true); |
+ } |
- while (!traces_.empty() && traces_.front()->IsAvailable()) { |
- traces_.front()->Process(); |
- traces_.pop_front(); |
+ while (!finished_traces_.empty()) { |
+ scoped_refptr<GPUTrace>& trace = finished_traces_.front(); |
+ if (trace->IsDeviceTraceEnabled()) { |
+ if (!finished_traces_.front()->IsAvailable()) |
+ break; |
+ finished_traces_.front()->Process(); |
+ } |
+ finished_traces_.front()->Destroy(true); |
+ finished_traces_.pop_front(); |
} |
// Clear pending traces if there were are any errors |
GLenum err = glGetError(); |
if (err != GL_NO_ERROR) |
- traces_.clear(); |
+ ClearFinishedTraces(true); |
+} |
+ |
+void GPUTracer::ClearFinishedTraces(bool have_context) { |
+ while (!finished_traces_.empty()) { |
+ finished_traces_.front()->Destroy(have_context); |
+ finished_traces_.pop_front(); |
+ } |
} |
void GPUTracer::IssueProcessTask() { |
- if (traces_.empty() || process_posted_) |
+ if (finished_traces_.empty() || process_posted_) |
return; |
process_posted_ = true; |