| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "gpu/command_buffer/service/gpu_tracer.h" | 5 #include "gpu/command_buffer/service/gpu_tracer.h" |
| 6 | 6 |
| 7 #include <deque> | 7 #include <deque> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 void TraceOutputter::TraceServiceEnd(const std::string& category, | 78 void TraceOutputter::TraceServiceEnd(const std::string& category, |
| 79 const std::string& name) { | 79 const std::string& name) { |
| 80 TRACE_EVENT_COPY_END1(TRACE_DISABLED_BY_DEFAULT("gpu.service"), | 80 TRACE_EVENT_COPY_END1(TRACE_DISABLED_BY_DEFAULT("gpu.service"), |
| 81 name.c_str(), "gl_category", category.c_str()); | 81 name.c_str(), "gl_category", category.c_str()); |
| 82 } | 82 } |
| 83 | 83 |
| 84 GPUTrace::GPUTrace(scoped_refptr<Outputter> outputter, | 84 GPUTrace::GPUTrace(scoped_refptr<Outputter> outputter, |
| 85 gfx::GPUTimingClient* gpu_timing_client, | 85 gfx::GPUTimingClient* gpu_timing_client, |
| 86 const std::string& category, | 86 const std::string& category, |
| 87 const std::string& name, | 87 const std::string& name, |
| 88 const bool enabled) | 88 const bool tracing_service, |
| 89 const bool tracing_device) |
| 89 : category_(category), | 90 : category_(category), |
| 90 name_(name), | 91 name_(name), |
| 91 outputter_(outputter), | 92 outputter_(outputter), |
| 92 enabled_(enabled) { | 93 service_enabled_(tracing_service), |
| 93 if (gpu_timing_client->IsAvailable() && | 94 device_enabled_(tracing_device) { |
| 95 if (tracing_device && |
| 96 gpu_timing_client->IsAvailable() && |
| 94 gpu_timing_client->IsTimerOffsetAvailable()) { | 97 gpu_timing_client->IsTimerOffsetAvailable()) { |
| 95 gpu_timer_ = gpu_timing_client->CreateGPUTimer(); | 98 gpu_timer_ = gpu_timing_client->CreateGPUTimer(); |
| 96 } | 99 } |
| 97 } | 100 } |
| 98 | 101 |
| 99 GPUTrace::~GPUTrace() { | 102 GPUTrace::~GPUTrace() { |
| 100 } | 103 } |
| 101 | 104 |
| 102 void GPUTrace::Destroy(bool have_context) { | 105 void GPUTrace::Destroy(bool have_context) { |
| 103 if (gpu_timer_.get()) { | 106 if (gpu_timer_.get()) { |
| 104 gpu_timer_->Destroy(have_context); | 107 gpu_timer_->Destroy(have_context); |
| 105 } | 108 } |
| 106 } | 109 } |
| 107 | 110 |
| 108 void GPUTrace::Start(bool trace_service) { | 111 void GPUTrace::Start() { |
| 109 if (trace_service) { | 112 if (service_enabled_) { |
| 110 outputter_->TraceServiceBegin(category_, name_); | 113 outputter_->TraceServiceBegin(category_, name_); |
| 111 } | 114 } |
| 112 if (gpu_timer_.get()) { | 115 if (gpu_timer_.get()) { |
| 113 gpu_timer_->Start(); | 116 gpu_timer_->Start(); |
| 114 } | 117 } |
| 115 } | 118 } |
| 116 | 119 |
| 117 void GPUTrace::End(bool tracing_service) { | 120 void GPUTrace::End() { |
| 118 if (gpu_timer_.get()) { | 121 if (gpu_timer_.get()) { |
| 119 gpu_timer_->End(); | 122 gpu_timer_->End(); |
| 120 } | 123 } |
| 121 if (tracing_service) { | 124 if (service_enabled_) { |
| 122 outputter_->TraceServiceEnd(category_, name_); | 125 outputter_->TraceServiceEnd(category_, name_); |
| 123 } | 126 } |
| 124 } | 127 } |
| 125 | 128 |
| 126 bool GPUTrace::IsAvailable() { | 129 bool GPUTrace::IsAvailable() { |
| 127 return !gpu_timer_.get() || gpu_timer_->IsAvailable(); | 130 return !gpu_timer_.get() || gpu_timer_->IsAvailable(); |
| 128 } | 131 } |
| 129 | 132 |
| 130 void GPUTrace::Process() { | 133 void GPUTrace::Process() { |
| 131 if (gpu_timer_.get()) { | 134 if (gpu_timer_.get()) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 gpu_executing_ = true; | 191 gpu_executing_ = true; |
| 189 if (IsTracing()) { | 192 if (IsTracing()) { |
| 190 gpu_timing_client_->CheckAndResetTimerErrors(); | 193 gpu_timing_client_->CheckAndResetTimerErrors(); |
| 191 // Begin a Trace for all active markers | 194 // Begin a Trace for all active markers |
| 192 for (int n = 0; n < NUM_TRACER_SOURCES; n++) { | 195 for (int n = 0; n < NUM_TRACER_SOURCES; n++) { |
| 193 for (size_t i = 0; i < markers_[n].size(); i++) { | 196 for (size_t i = 0; i < markers_[n].size(); i++) { |
| 194 TraceMarker& trace_marker = markers_[n][i]; | 197 TraceMarker& trace_marker = markers_[n][i]; |
| 195 trace_marker.trace_ = | 198 trace_marker.trace_ = |
| 196 new GPUTrace(outputter_, gpu_timing_client_.get(), | 199 new GPUTrace(outputter_, gpu_timing_client_.get(), |
| 197 trace_marker.category_, trace_marker.name_, | 200 trace_marker.category_, trace_marker.name_, |
| 201 *gpu_trace_srv_category != 0, |
| 198 *gpu_trace_dev_category != 0); | 202 *gpu_trace_dev_category != 0); |
| 199 trace_marker.trace_->Start(*gpu_trace_srv_category != 0); | 203 trace_marker.trace_->Start(); |
| 200 } | 204 } |
| 201 } | 205 } |
| 202 } | 206 } |
| 203 return true; | 207 return true; |
| 204 } | 208 } |
| 205 | 209 |
| 206 bool GPUTracer::EndDecoding() { | 210 bool GPUTracer::EndDecoding() { |
| 207 if (!gpu_executing_) | 211 if (!gpu_executing_) |
| 208 return false; | 212 return false; |
| 209 | 213 |
| 210 // End Trace for all active markers | 214 // End Trace for all active markers |
| 211 if (IsTracing()) { | 215 if (IsTracing()) { |
| 212 for (int n = 0; n < NUM_TRACER_SOURCES; n++) { | 216 for (int n = 0; n < NUM_TRACER_SOURCES; n++) { |
| 213 for (size_t i = 0; i < markers_[n].size(); i++) { | 217 for (size_t i = 0; i < markers_[n].size(); i++) { |
| 214 TraceMarker& marker = markers_[n][i]; | 218 TraceMarker& marker = markers_[n][i]; |
| 215 if (marker.trace_.get()) { | 219 if (marker.trace_.get()) { |
| 216 marker.trace_->End(*gpu_trace_srv_category != 0); | 220 marker.trace_->End(); |
| 217 | 221 |
| 218 finished_traces_.push_back(marker.trace_); | 222 finished_traces_.push_back(marker.trace_); |
| 219 marker.trace_ = 0; | 223 marker.trace_ = 0; |
| 220 } | 224 } |
| 221 } | 225 } |
| 222 } | 226 } |
| 223 IssueProcessTask(); | 227 IssueProcessTask(); |
| 224 } | 228 } |
| 225 | 229 |
| 226 gpu_executing_ = false; | 230 gpu_executing_ = false; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 237 | 241 |
| 238 DCHECK(source >= 0 && source < NUM_TRACER_SOURCES); | 242 DCHECK(source >= 0 && source < NUM_TRACER_SOURCES); |
| 239 | 243 |
| 240 // Push new marker from given 'source' | 244 // Push new marker from given 'source' |
| 241 markers_[source].push_back(TraceMarker(category, name)); | 245 markers_[source].push_back(TraceMarker(category, name)); |
| 242 | 246 |
| 243 // Create trace | 247 // Create trace |
| 244 if (IsTracing()) { | 248 if (IsTracing()) { |
| 245 scoped_refptr<GPUTrace> trace = new GPUTrace( | 249 scoped_refptr<GPUTrace> trace = new GPUTrace( |
| 246 outputter_, gpu_timing_client_.get(), category, name, | 250 outputter_, gpu_timing_client_.get(), category, name, |
| 251 *gpu_trace_srv_category != 0, |
| 247 *gpu_trace_dev_category != 0); | 252 *gpu_trace_dev_category != 0); |
| 248 trace->Start(*gpu_trace_srv_category != 0); | 253 trace->Start(); |
| 249 markers_[source].back().trace_ = trace; | 254 markers_[source].back().trace_ = trace; |
| 250 } | 255 } |
| 251 | 256 |
| 252 return true; | 257 return true; |
| 253 } | 258 } |
| 254 | 259 |
| 255 bool GPUTracer::End(GpuTracerSource source) { | 260 bool GPUTracer::End(GpuTracerSource source) { |
| 256 if (!gpu_executing_) | 261 if (!gpu_executing_) |
| 257 return false; | 262 return false; |
| 258 | 263 |
| 259 DCHECK(source >= 0 && source < NUM_TRACER_SOURCES); | 264 DCHECK(source >= 0 && source < NUM_TRACER_SOURCES); |
| 260 | 265 |
| 261 // Pop last marker with matching 'source' | 266 // Pop last marker with matching 'source' |
| 262 if (!markers_[source].empty()) { | 267 if (!markers_[source].empty()) { |
| 263 scoped_refptr<GPUTrace> trace = markers_[source].back().trace_; | 268 scoped_refptr<GPUTrace> trace = markers_[source].back().trace_; |
| 264 if (trace.get()) { | 269 if (trace.get()) { |
| 265 if (IsTracing()) { | 270 if (IsTracing()) { |
| 266 trace->End(*gpu_trace_srv_category != 0); | 271 trace->End(); |
| 267 } | 272 } |
| 268 | 273 |
| 269 finished_traces_.push_back(trace); | 274 finished_traces_.push_back(trace); |
| 270 IssueProcessTask(); | 275 IssueProcessTask(); |
| 271 } | 276 } |
| 272 | 277 |
| 273 markers_[source].pop_back(); | 278 markers_[source].pop_back(); |
| 274 return true; | 279 return true; |
| 275 } | 280 } |
| 276 return false; | 281 return false; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 } | 336 } |
| 332 | 337 |
| 333 // Check if timers are still valid (e.g: a disjoint operation | 338 // Check if timers are still valid (e.g: a disjoint operation |
| 334 // might have occurred.) | 339 // might have occurred.) |
| 335 if (gpu_timing_client_->CheckAndResetTimerErrors()) { | 340 if (gpu_timing_client_->CheckAndResetTimerErrors()) { |
| 336 ClearFinishedTraces(true); | 341 ClearFinishedTraces(true); |
| 337 } | 342 } |
| 338 | 343 |
| 339 while (!finished_traces_.empty()) { | 344 while (!finished_traces_.empty()) { |
| 340 scoped_refptr<GPUTrace>& trace = finished_traces_.front(); | 345 scoped_refptr<GPUTrace>& trace = finished_traces_.front(); |
| 341 if (trace->IsEnabled()) { | 346 if (trace->IsDeviceTraceEnabled()) { |
| 342 if (!finished_traces_.front()->IsAvailable()) | 347 if (!finished_traces_.front()->IsAvailable()) |
| 343 break; | 348 break; |
| 344 finished_traces_.front()->Process(); | 349 finished_traces_.front()->Process(); |
| 345 } | 350 } |
| 346 finished_traces_.front()->Destroy(true); | 351 finished_traces_.front()->Destroy(true); |
| 347 finished_traces_.pop_front(); | 352 finished_traces_.pop_front(); |
| 348 } | 353 } |
| 349 | 354 |
| 350 // Clear pending traces if there were are any errors | 355 // Clear pending traces if there were are any errors |
| 351 GLenum err = glGetError(); | 356 GLenum err = glGetError(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 363 void GPUTracer::IssueProcessTask() { | 368 void GPUTracer::IssueProcessTask() { |
| 364 if (finished_traces_.empty() || process_posted_) | 369 if (finished_traces_.empty() || process_posted_) |
| 365 return; | 370 return; |
| 366 | 371 |
| 367 process_posted_ = true; | 372 process_posted_ = true; |
| 368 PostTask(); | 373 PostTask(); |
| 369 } | 374 } |
| 370 | 375 |
| 371 } // namespace gles2 | 376 } // namespace gles2 |
| 372 } // namespace gpu | 377 } // namespace gpu |
| OLD | NEW |