Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(203)

Side by Side Diff: gpu/command_buffer/service/gpu_tracer.cc

Issue 940633004: Added disjoint context class which manages disjoints within gpu timing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Simplified DisjointContext to simply be an ID instead of an object Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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() {
145 } 148 }
146 149
147 bool GPUTracer::BeginDecoding() { 150 bool GPUTracer::BeginDecoding() {
148 if (gpu_executing_) 151 if (gpu_executing_)
149 return false; 152 return false;
150 153
151 if (outputter_ == NULL) { 154 if (outputter_ == NULL) {
152 outputter_ = CreateOutputter(gpu_timing_.GetTimerTypeName()); 155 outputter_ = CreateOutputter(gpu_timing_->GetTimerTypeName());
153 gpu_timing_.Initialize(decoder_->GetGLContext());
154 } 156 }
155 157
156 if (*gpu_trace_dev_category == '\0') { 158 if (*gpu_trace_dev_category == '\0') {
157 // If GPU device category is off, invalidate timing sync. 159 // If GPU device category is off, invalidate timing sync.
158 gpu_timing_.InvalidateTimerOffset(); 160 gpu_timing_->InvalidateTimerOffset();
159 } 161 }
160 162
161 gpu_executing_ = true; 163 gpu_executing_ = true;
162 if (IsTracing()) { 164 if (IsTracing()) {
163 gpu_timing_.CheckAndResetTimerErrors(); 165 gpu_timing_->CheckAndResetTimerErrors(disjoint_context_id_);
164 // Begin a Trace for all active markers 166 // Begin a Trace for all active markers
165 for (int n = 0; n < NUM_TRACER_SOURCES; n++) { 167 for (int n = 0; n < NUM_TRACER_SOURCES; n++) {
166 for (size_t i = 0; i < markers_[n].size(); i++) { 168 for (size_t i = 0; i < markers_[n].size(); i++) {
167 TraceMarker& trace_marker = markers_[n][i]; 169 TraceMarker& trace_marker = markers_[n][i];
168 trace_marker.trace_ = 170 trace_marker.trace_ =
169 new GPUTrace(outputter_, &gpu_timing_, trace_marker.category_, 171 new GPUTrace(outputter_, gpu_timing_, trace_marker.category_,
170 trace_marker.name_, *gpu_trace_dev_category != 0); 172 trace_marker.name_, *gpu_trace_dev_category != 0);
171 trace_marker.trace_->Start(*gpu_trace_srv_category != 0); 173 trace_marker.trace_->Start(*gpu_trace_srv_category != 0);
172 } 174 }
173 } 175 }
174 } 176 }
175 return true; 177 return true;
176 } 178 }
177 179
178 bool GPUTracer::EndDecoding() { 180 bool GPUTracer::EndDecoding() {
179 if (!gpu_executing_) 181 if (!gpu_executing_)
(...skipping 29 matching lines...) Expand all
209 return false; 211 return false;
210 212
211 DCHECK(source >= 0 && source < NUM_TRACER_SOURCES); 213 DCHECK(source >= 0 && source < NUM_TRACER_SOURCES);
212 214
213 // Push new marker from given 'source' 215 // Push new marker from given 'source'
214 markers_[source].push_back(TraceMarker(category, name)); 216 markers_[source].push_back(TraceMarker(category, name));
215 217
216 // Create trace 218 // Create trace
217 if (IsTracing()) { 219 if (IsTracing()) {
218 scoped_refptr<GPUTrace> trace = new GPUTrace( 220 scoped_refptr<GPUTrace> trace = new GPUTrace(
219 outputter_, &gpu_timing_, category, name, *gpu_trace_dev_category != 0); 221 outputter_, gpu_timing_, category, name, *gpu_trace_dev_category != 0);
220 trace->Start(*gpu_trace_srv_category != 0); 222 trace->Start(*gpu_trace_srv_category != 0);
221 markers_[source].back().trace_ = trace; 223 markers_[source].back().trace_ = trace;
222 } 224 }
223 225
224 return true; 226 return true;
225 } 227 }
226 228
227 bool GPUTracer::End(GpuTracerSource source) { 229 bool GPUTracer::End(GpuTracerSource source) {
228 if (!gpu_executing_) 230 if (!gpu_executing_)
229 return false; 231 return false;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 base::TimeDelta::FromMilliseconds(kProcessInterval)); 283 base::TimeDelta::FromMilliseconds(kProcessInterval));
282 } 284 }
283 285
284 void GPUTracer::Process() { 286 void GPUTracer::Process() {
285 process_posted_ = false; 287 process_posted_ = false;
286 ProcessTraces(); 288 ProcessTraces();
287 IssueProcessTask(); 289 IssueProcessTask();
288 } 290 }
289 291
290 void GPUTracer::ProcessTraces() { 292 void GPUTracer::ProcessTraces() {
291 if (!gpu_timing_.IsAvailable()) { 293 if (!gpu_timing_->IsAvailable()) {
292 traces_.clear(); 294 traces_.clear();
293 return; 295 return;
294 } 296 }
295 297
296 TRACE_EVENT0("gpu", "GPUTracer::ProcessTraces"); 298 TRACE_EVENT0("gpu", "GPUTracer::ProcessTraces");
297 299
298 // Make owning decoder's GL context current 300 // Make owning decoder's GL context current
299 if (!decoder_->MakeCurrent()) { 301 if (!decoder_->MakeCurrent()) {
300 // Skip subsequent GL calls if MakeCurrent fails 302 // Skip subsequent GL calls if MakeCurrent fails
301 traces_.clear(); 303 traces_.clear();
302 return; 304 return;
303 } 305 }
304 306
305 // Check if timers are still valid (e.g: a disjoint operation 307 // Check if timers are still valid (e.g: a disjoint operation
306 // might have occurred.) 308 // might have occurred.)
307 if (gpu_timing_.CheckAndResetTimerErrors()) 309 if (gpu_timing_->CheckAndResetTimerErrors(disjoint_context_id_))
308 traces_.clear(); 310 traces_.clear();
309 311
310 while (!traces_.empty() && traces_.front()->IsAvailable()) { 312 while (!traces_.empty() && traces_.front()->IsAvailable()) {
311 traces_.front()->Process(); 313 traces_.front()->Process();
312 traces_.pop_front(); 314 traces_.pop_front();
313 } 315 }
314 316
315 // Clear pending traces if there were are any errors 317 // Clear pending traces if there were are any errors
316 GLenum err = glGetError(); 318 GLenum err = glGetError();
317 if (err != GL_NO_ERROR) 319 if (err != GL_NO_ERROR)
318 traces_.clear(); 320 traces_.clear();
319 } 321 }
320 322
321 void GPUTracer::IssueProcessTask() { 323 void GPUTracer::IssueProcessTask() {
322 if (traces_.empty() || process_posted_) 324 if (traces_.empty() || process_posted_)
323 return; 325 return;
324 326
325 process_posted_ = true; 327 process_posted_ = true;
326 PostTask(); 328 PostTask();
327 } 329 }
328 330
329 } // namespace gles2 331 } // namespace gles2
330 } // namespace gpu 332 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698