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