Chromium Code Reviews| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 name.c_str(), "gl_category", category.c_str()); | 74 name.c_str(), "gl_category", category.c_str()); |
| 75 } | 75 } |
| 76 | 76 |
| 77 void TraceOutputter::TraceServiceEnd(const std::string& category, | 77 void TraceOutputter::TraceServiceEnd(const std::string& category, |
| 78 const std::string& name) { | 78 const std::string& name) { |
| 79 TRACE_EVENT_COPY_END1(TRACE_DISABLED_BY_DEFAULT("gpu.service"), | 79 TRACE_EVENT_COPY_END1(TRACE_DISABLED_BY_DEFAULT("gpu.service"), |
| 80 name.c_str(), "gl_category", category.c_str()); | 80 name.c_str(), "gl_category", category.c_str()); |
| 81 } | 81 } |
| 82 | 82 |
| 83 GPUTrace::GPUTrace(scoped_refptr<Outputter> outputter, | 83 GPUTrace::GPUTrace(scoped_refptr<Outputter> outputter, |
| 84 gpu::GPUTiming* gpu_timing, | 84 GPUTiming* gpu_timing, |
| 85 const std::string& category, | 85 const std::string& category, |
| 86 const std::string& name, | 86 const std::string& name, |
| 87 const bool enabled) | 87 const bool enabled) |
| 88 : category_(category), | 88 : category_(category), |
| 89 name_(name), | 89 name_(name), |
| 90 outputter_(outputter), | 90 outputter_(outputter), |
| 91 enabled_(enabled) { | 91 enabled_(enabled) { |
| 92 if (gpu_timing->IsAvailable()) { | 92 if (gpu_timing->IsAvailable()) { |
| 93 gpu_timer_.reset(new GPUTimer(gpu_timing)); | 93 gpu_timer_.reset(new GPUTimer(gpu_timing)); |
| 94 } | 94 } |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 123 if (gpu_timer_.get()) { | 123 if (gpu_timer_.get()) { |
| 124 DCHECK(IsAvailable()); | 124 DCHECK(IsAvailable()); |
| 125 | 125 |
| 126 int64 start = 0; | 126 int64 start = 0; |
| 127 int64 end = 0; | 127 int64 end = 0; |
| 128 gpu_timer_->GetStartEndTimestamps(&start, &end); | 128 gpu_timer_->GetStartEndTimestamps(&start, &end); |
| 129 outputter_->TraceDevice(category_, name_, start, end); | 129 outputter_->TraceDevice(category_, name_, start, end); |
| 130 } | 130 } |
| 131 } | 131 } |
| 132 | 132 |
| 133 GPUTracer::GPUTracer(gles2::GLES2Decoder* decoder) | 133 GPUTracer::GPUTracer(gles2::GLES2Decoder* decoder, GPUTiming* gpu_timing) |
| 134 : gpu_trace_srv_category(TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( | 134 : gpu_trace_srv_category(TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( |
| 135 TRACE_DISABLED_BY_DEFAULT("gpu.service"))), | 135 TRACE_DISABLED_BY_DEFAULT("gpu.service"))), |
| 136 gpu_trace_dev_category(TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( | 136 gpu_trace_dev_category(TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( |
| 137 TRACE_DISABLED_BY_DEFAULT("gpu.device"))), | 137 TRACE_DISABLED_BY_DEFAULT("gpu.device"))), |
| 138 decoder_(decoder), | 138 decoder_(decoder), |
| 139 gpu_timing_(), | 139 gpu_timing_(gpu_timing), |
| 140 disjoint_context_id_(gpu_timing->CreateDisjointContextID()), | |
| 140 gpu_executing_(false), | 141 gpu_executing_(false), |
| 141 process_posted_(false) { | 142 process_posted_(false) { |
| 143 DCHECK(decoder); | |
| 144 DCHECK(gpu_timing); | |
| 142 } | 145 } |
| 143 | 146 |
| 144 GPUTracer::~GPUTracer() { | 147 GPUTracer::~GPUTracer() { |
| 148 gpu_timing_->ReleaseDisjointContextID(disjoint_context_id_); | |
|
Daniele Castagna
2015/02/23 22:21:19
DCHECK the return value of this? disjoint_context_
| |
| 145 } | 149 } |
| 146 | 150 |
| 147 bool GPUTracer::BeginDecoding() { | 151 bool GPUTracer::BeginDecoding() { |
| 148 if (gpu_executing_) | 152 if (gpu_executing_) |
| 149 return false; | 153 return false; |
| 150 | 154 |
| 151 if (outputter_ == NULL) { | 155 if (outputter_ == NULL) { |
| 152 outputter_ = CreateOutputter(gpu_timing_.GetTimerTypeName()); | 156 outputter_ = CreateOutputter(gpu_timing_->GetTimerTypeName()); |
| 153 gpu_timing_.Initialize(decoder_->GetGLContext()); | |
| 154 } | 157 } |
| 155 | 158 |
| 156 if (*gpu_trace_dev_category == '\0') { | 159 if (*gpu_trace_dev_category == '\0') { |
| 157 // If GPU device category is off, invalidate timing sync. | 160 // If GPU device category is off, invalidate timing sync. |
| 158 gpu_timing_.InvalidateTimerOffset(); | 161 gpu_timing_->InvalidateTimerOffset(); |
| 159 } | 162 } |
| 160 | 163 |
| 161 gpu_executing_ = true; | 164 gpu_executing_ = true; |
| 162 if (IsTracing()) { | 165 if (IsTracing()) { |
| 163 gpu_timing_.CheckAndResetTimerErrors(); | 166 gpu_timing_->CheckAndResetTimerErrors(disjoint_context_id_); |
| 164 // Begin a Trace for all active markers | 167 // Begin a Trace for all active markers |
| 165 for (int n = 0; n < NUM_TRACER_SOURCES; n++) { | 168 for (int n = 0; n < NUM_TRACER_SOURCES; n++) { |
| 166 for (size_t i = 0; i < markers_[n].size(); i++) { | 169 for (size_t i = 0; i < markers_[n].size(); i++) { |
| 167 TraceMarker& trace_marker = markers_[n][i]; | 170 TraceMarker& trace_marker = markers_[n][i]; |
| 168 trace_marker.trace_ = | 171 trace_marker.trace_ = |
| 169 new GPUTrace(outputter_, &gpu_timing_, trace_marker.category_, | 172 new GPUTrace(outputter_, gpu_timing_, trace_marker.category_, |
| 170 trace_marker.name_, *gpu_trace_dev_category != 0); | 173 trace_marker.name_, *gpu_trace_dev_category != 0); |
| 171 trace_marker.trace_->Start(*gpu_trace_srv_category != 0); | 174 trace_marker.trace_->Start(*gpu_trace_srv_category != 0); |
| 172 } | 175 } |
| 173 } | 176 } |
| 174 } | 177 } |
| 175 return true; | 178 return true; |
| 176 } | 179 } |
| 177 | 180 |
| 178 bool GPUTracer::EndDecoding() { | 181 bool GPUTracer::EndDecoding() { |
| 179 if (!gpu_executing_) | 182 if (!gpu_executing_) |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 209 return false; | 212 return false; |
| 210 | 213 |
| 211 DCHECK(source >= 0 && source < NUM_TRACER_SOURCES); | 214 DCHECK(source >= 0 && source < NUM_TRACER_SOURCES); |
| 212 | 215 |
| 213 // Push new marker from given 'source' | 216 // Push new marker from given 'source' |
| 214 markers_[source].push_back(TraceMarker(category, name)); | 217 markers_[source].push_back(TraceMarker(category, name)); |
| 215 | 218 |
| 216 // Create trace | 219 // Create trace |
| 217 if (IsTracing()) { | 220 if (IsTracing()) { |
| 218 scoped_refptr<GPUTrace> trace = new GPUTrace( | 221 scoped_refptr<GPUTrace> trace = new GPUTrace( |
| 219 outputter_, &gpu_timing_, category, name, *gpu_trace_dev_category != 0); | 222 outputter_, gpu_timing_, category, name, *gpu_trace_dev_category != 0); |
| 220 trace->Start(*gpu_trace_srv_category != 0); | 223 trace->Start(*gpu_trace_srv_category != 0); |
| 221 markers_[source].back().trace_ = trace; | 224 markers_[source].back().trace_ = trace; |
| 222 } | 225 } |
| 223 | 226 |
| 224 return true; | 227 return true; |
| 225 } | 228 } |
| 226 | 229 |
| 227 bool GPUTracer::End(GpuTracerSource source) { | 230 bool GPUTracer::End(GpuTracerSource source) { |
| 228 if (!gpu_executing_) | 231 if (!gpu_executing_) |
| 229 return false; | 232 return false; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 base::TimeDelta::FromMilliseconds(kProcessInterval)); | 284 base::TimeDelta::FromMilliseconds(kProcessInterval)); |
| 282 } | 285 } |
| 283 | 286 |
| 284 void GPUTracer::Process() { | 287 void GPUTracer::Process() { |
| 285 process_posted_ = false; | 288 process_posted_ = false; |
| 286 ProcessTraces(); | 289 ProcessTraces(); |
| 287 IssueProcessTask(); | 290 IssueProcessTask(); |
| 288 } | 291 } |
| 289 | 292 |
| 290 void GPUTracer::ProcessTraces() { | 293 void GPUTracer::ProcessTraces() { |
| 291 if (!gpu_timing_.IsAvailable()) { | 294 if (!gpu_timing_->IsAvailable()) { |
| 292 traces_.clear(); | 295 traces_.clear(); |
| 293 return; | 296 return; |
| 294 } | 297 } |
| 295 | 298 |
| 296 TRACE_EVENT0("gpu", "GPUTracer::ProcessTraces"); | 299 TRACE_EVENT0("gpu", "GPUTracer::ProcessTraces"); |
| 297 | 300 |
| 298 // Make owning decoder's GL context current | 301 // Make owning decoder's GL context current |
| 299 if (!decoder_->MakeCurrent()) { | 302 if (!decoder_->MakeCurrent()) { |
| 300 // Skip subsequent GL calls if MakeCurrent fails | 303 // Skip subsequent GL calls if MakeCurrent fails |
| 301 traces_.clear(); | 304 traces_.clear(); |
| 302 return; | 305 return; |
| 303 } | 306 } |
| 304 | 307 |
| 305 // Check if timers are still valid (e.g: a disjoint operation | 308 // Check if timers are still valid (e.g: a disjoint operation |
| 306 // might have occurred.) | 309 // might have occurred.) |
| 307 if (gpu_timing_.CheckAndResetTimerErrors()) | 310 if (gpu_timing_->CheckAndResetTimerErrors(disjoint_context_id_)) |
| 308 traces_.clear(); | 311 traces_.clear(); |
| 309 | 312 |
| 310 while (!traces_.empty() && traces_.front()->IsAvailable()) { | 313 while (!traces_.empty() && traces_.front()->IsAvailable()) { |
| 311 traces_.front()->Process(); | 314 traces_.front()->Process(); |
| 312 traces_.pop_front(); | 315 traces_.pop_front(); |
| 313 } | 316 } |
| 314 | 317 |
| 315 // Clear pending traces if there were are any errors | 318 // Clear pending traces if there were are any errors |
| 316 GLenum err = glGetError(); | 319 GLenum err = glGetError(); |
| 317 if (err != GL_NO_ERROR) | 320 if (err != GL_NO_ERROR) |
| 318 traces_.clear(); | 321 traces_.clear(); |
| 319 } | 322 } |
| 320 | 323 |
| 321 void GPUTracer::IssueProcessTask() { | 324 void GPUTracer::IssueProcessTask() { |
| 322 if (traces_.empty() || process_posted_) | 325 if (traces_.empty() || process_posted_) |
| 323 return; | 326 return; |
| 324 | 327 |
| 325 process_posted_ = true; | 328 process_posted_ = true; |
| 326 PostTask(); | 329 PostTask(); |
| 327 } | 330 } |
| 328 | 331 |
| 329 } // namespace gles2 | 332 } // namespace gles2 |
| 330 } // namespace gpu | 333 } // namespace gpu |
| OLD | NEW |