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

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

Issue 937263006: Refactored GLContext to own GPUTiming which spawn GPUTimingClients. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "base/trace_event/trace_event.h" 12 #include "base/trace_event/trace_event.h"
13 #include "gpu/command_buffer/common/gles2_cmd_utils.h" 13 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
14 #include "gpu/command_buffer/service/context_group.h" 14 #include "gpu/command_buffer/service/context_group.h"
15 #include "ui/gl/gl_bindings.h" 15 #include "ui/gl/gl_bindings.h"
16 #include "ui/gl/gl_version_info.h" 16 #include "ui/gl/gl_version_info.h"
17 #include "ui/gl/gpu_timing.h"
17 18
18 namespace gpu { 19 namespace gpu {
19 namespace gles2 { 20 namespace gles2 {
20 21
21 static const unsigned int kProcessInterval = 16; 22 static const unsigned int kProcessInterval = 16;
22 static TraceOutputter* g_outputter_thread = NULL; 23 static TraceOutputter* g_outputter_thread = NULL;
23 24
24 TraceMarker::TraceMarker(const std::string& category, const std::string& name) 25 TraceMarker::TraceMarker(const std::string& category, const std::string& name)
25 : category_(category), 26 : category_(category),
26 name_(name), 27 name_(name),
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 name.c_str(), "gl_category", category.c_str()); 75 name.c_str(), "gl_category", category.c_str());
75 } 76 }
76 77
77 void TraceOutputter::TraceServiceEnd(const std::string& category, 78 void TraceOutputter::TraceServiceEnd(const std::string& category,
78 const std::string& name) { 79 const std::string& name) {
79 TRACE_EVENT_COPY_END1(TRACE_DISABLED_BY_DEFAULT("gpu.service"), 80 TRACE_EVENT_COPY_END1(TRACE_DISABLED_BY_DEFAULT("gpu.service"),
80 name.c_str(), "gl_category", category.c_str()); 81 name.c_str(), "gl_category", category.c_str());
81 } 82 }
82 83
83 GPUTrace::GPUTrace(scoped_refptr<Outputter> outputter, 84 GPUTrace::GPUTrace(scoped_refptr<Outputter> outputter,
84 gpu::GPUTiming* gpu_timing, 85 GPUTimingClient* gpu_timing_client,
85 const std::string& category, 86 const std::string& category,
86 const std::string& name, 87 const std::string& name,
87 const bool enabled) 88 const bool enabled)
88 : category_(category), 89 : category_(category),
89 name_(name), 90 name_(name),
90 outputter_(outputter), 91 outputter_(outputter),
91 enabled_(enabled) { 92 enabled_(enabled) {
92 if (gpu_timing->IsAvailable()) { 93 if (gpu_timing_client->IsAvailable()) {
93 gpu_timer_.reset(new GPUTimer(gpu_timing)); 94 gpu_timer_.reset(new GPUTimer(gpu_timing_client));
vmiura 2015/02/24 20:51:07 It would be nicer to make GpuTimingClient the fact
David Yen 2015/02/24 22:13:01 Done.
94 } 95 }
95 } 96 }
96 97
97 GPUTrace::~GPUTrace() { 98 GPUTrace::~GPUTrace() {
98 } 99 }
99 100
100 void GPUTrace::Start(bool trace_service) { 101 void GPUTrace::Start(bool trace_service) {
101 if (trace_service) { 102 if (trace_service) {
102 outputter_->TraceServiceBegin(category_, name_); 103 outputter_->TraceServiceBegin(category_, name_);
103 } 104 }
(...skipping 25 matching lines...) Expand all
129 outputter_->TraceDevice(category_, name_, start, end); 130 outputter_->TraceDevice(category_, name_, start, end);
130 } 131 }
131 } 132 }
132 133
133 GPUTracer::GPUTracer(gles2::GLES2Decoder* decoder) 134 GPUTracer::GPUTracer(gles2::GLES2Decoder* decoder)
134 : gpu_trace_srv_category(TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( 135 : gpu_trace_srv_category(TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(
135 TRACE_DISABLED_BY_DEFAULT("gpu.service"))), 136 TRACE_DISABLED_BY_DEFAULT("gpu.service"))),
136 gpu_trace_dev_category(TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( 137 gpu_trace_dev_category(TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(
137 TRACE_DISABLED_BY_DEFAULT("gpu.device"))), 138 TRACE_DISABLED_BY_DEFAULT("gpu.device"))),
138 decoder_(decoder), 139 decoder_(decoder),
139 gpu_timing_(),
140 gpu_executing_(false), 140 gpu_executing_(false),
141 process_posted_(false) { 141 process_posted_(false) {
142 DCHECK(decoder_);
143 gfx::GLContext* context = decoder_->GetGLContext();
144 if (context) {
145 gpu_timing_client_ = context->GetGPUTiming()->CreateGPUTimingClient();
146 } else {
147 gpu_timing_client_ = new GPUTimingClient();
148 }
142 } 149 }
143 150
144 GPUTracer::~GPUTracer() { 151 GPUTracer::~GPUTracer() {
145 } 152 }
146 153
147 bool GPUTracer::BeginDecoding() { 154 bool GPUTracer::BeginDecoding() {
148 if (gpu_executing_) 155 if (gpu_executing_)
149 return false; 156 return false;
150 157
151 if (outputter_ == NULL) { 158 if (!outputter_) {
152 outputter_ = CreateOutputter(gpu_timing_.GetTimerTypeName()); 159 outputter_ = CreateOutputter(gpu_timing_client_->GetTimerTypeName());
153 gpu_timing_.Initialize(decoder_->GetGLContext());
154 } 160 }
155 161
156 if (*gpu_trace_dev_category == '\0') { 162 if (*gpu_trace_dev_category == '\0') {
157 // If GPU device category is off, invalidate timing sync. 163 // If GPU device category is off, invalidate timing sync.
158 gpu_timing_.InvalidateTimerOffset(); 164 gpu_timing_client_->InvalidateTimerOffset();
159 } 165 }
160 166
161 gpu_executing_ = true; 167 gpu_executing_ = true;
162 if (IsTracing()) { 168 if (IsTracing()) {
163 gpu_timing_.CheckAndResetTimerErrors(); 169 gpu_timing_client_->CheckAndResetTimerErrors();
164 // Begin a Trace for all active markers 170 // Begin a Trace for all active markers
165 for (int n = 0; n < NUM_TRACER_SOURCES; n++) { 171 for (int n = 0; n < NUM_TRACER_SOURCES; n++) {
166 for (size_t i = 0; i < markers_[n].size(); i++) { 172 for (size_t i = 0; i < markers_[n].size(); i++) {
167 TraceMarker& trace_marker = markers_[n][i]; 173 TraceMarker& trace_marker = markers_[n][i];
168 trace_marker.trace_ = 174 trace_marker.trace_ =
169 new GPUTrace(outputter_, &gpu_timing_, trace_marker.category_, 175 new GPUTrace(outputter_, gpu_timing_client_.get(),
170 trace_marker.name_, *gpu_trace_dev_category != 0); 176 trace_marker.category_, trace_marker.name_,
177 *gpu_trace_dev_category != 0);
171 trace_marker.trace_->Start(*gpu_trace_srv_category != 0); 178 trace_marker.trace_->Start(*gpu_trace_srv_category != 0);
172 } 179 }
173 } 180 }
174 } 181 }
175 return true; 182 return true;
176 } 183 }
177 184
178 bool GPUTracer::EndDecoding() { 185 bool GPUTracer::EndDecoding() {
179 if (!gpu_executing_) 186 if (!gpu_executing_)
180 return false; 187 return false;
(...skipping 28 matching lines...) Expand all
209 return false; 216 return false;
210 217
211 DCHECK(source >= 0 && source < NUM_TRACER_SOURCES); 218 DCHECK(source >= 0 && source < NUM_TRACER_SOURCES);
212 219
213 // Push new marker from given 'source' 220 // Push new marker from given 'source'
214 markers_[source].push_back(TraceMarker(category, name)); 221 markers_[source].push_back(TraceMarker(category, name));
215 222
216 // Create trace 223 // Create trace
217 if (IsTracing()) { 224 if (IsTracing()) {
218 scoped_refptr<GPUTrace> trace = new GPUTrace( 225 scoped_refptr<GPUTrace> trace = new GPUTrace(
219 outputter_, &gpu_timing_, category, name, *gpu_trace_dev_category != 0); 226 outputter_, gpu_timing_client_.get(), category, name,
227 *gpu_trace_dev_category != 0);
220 trace->Start(*gpu_trace_srv_category != 0); 228 trace->Start(*gpu_trace_srv_category != 0);
221 markers_[source].back().trace_ = trace; 229 markers_[source].back().trace_ = trace;
222 } 230 }
223 231
224 return true; 232 return true;
225 } 233 }
226 234
227 bool GPUTracer::End(GpuTracerSource source) { 235 bool GPUTracer::End(GpuTracerSource source) {
228 if (!gpu_executing_) 236 if (!gpu_executing_)
229 return false; 237 return false;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 base::TimeDelta::FromMilliseconds(kProcessInterval)); 289 base::TimeDelta::FromMilliseconds(kProcessInterval));
282 } 290 }
283 291
284 void GPUTracer::Process() { 292 void GPUTracer::Process() {
285 process_posted_ = false; 293 process_posted_ = false;
286 ProcessTraces(); 294 ProcessTraces();
287 IssueProcessTask(); 295 IssueProcessTask();
288 } 296 }
289 297
290 void GPUTracer::ProcessTraces() { 298 void GPUTracer::ProcessTraces() {
291 if (!gpu_timing_.IsAvailable()) { 299 if (!gpu_timing_client_->IsAvailable()) {
292 traces_.clear(); 300 traces_.clear();
293 return; 301 return;
294 } 302 }
295 303
296 TRACE_EVENT0("gpu", "GPUTracer::ProcessTraces"); 304 TRACE_EVENT0("gpu", "GPUTracer::ProcessTraces");
297 305
298 // Make owning decoder's GL context current 306 // Make owning decoder's GL context current
299 if (!decoder_->MakeCurrent()) { 307 if (!decoder_->MakeCurrent()) {
300 // Skip subsequent GL calls if MakeCurrent fails 308 // Skip subsequent GL calls if MakeCurrent fails
301 traces_.clear(); 309 traces_.clear();
302 return; 310 return;
303 } 311 }
304 312
305 // Check if timers are still valid (e.g: a disjoint operation 313 // Check if timers are still valid (e.g: a disjoint operation
306 // might have occurred.) 314 // might have occurred.)
307 if (gpu_timing_.CheckAndResetTimerErrors()) 315 if (gpu_timing_client_->CheckAndResetTimerErrors())
308 traces_.clear(); 316 traces_.clear();
309 317
310 while (!traces_.empty() && traces_.front()->IsAvailable()) { 318 while (!traces_.empty() && traces_.front()->IsAvailable()) {
311 traces_.front()->Process(); 319 traces_.front()->Process();
312 traces_.pop_front(); 320 traces_.pop_front();
313 } 321 }
314 322
315 // Clear pending traces if there were are any errors 323 // Clear pending traces if there were are any errors
316 GLenum err = glGetError(); 324 GLenum err = glGetError();
317 if (err != GL_NO_ERROR) 325 if (err != GL_NO_ERROR)
318 traces_.clear(); 326 traces_.clear();
319 } 327 }
320 328
321 void GPUTracer::IssueProcessTask() { 329 void GPUTracer::IssueProcessTask() {
322 if (traces_.empty() || process_posted_) 330 if (traces_.empty() || process_posted_)
323 return; 331 return;
324 332
325 process_posted_ = true; 333 process_posted_ = true;
326 PostTask(); 334 PostTask();
327 } 335 }
328 336
329 } // namespace gles2 337 } // namespace gles2
330 } // namespace gpu 338 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/gpu_tracer.h ('k') | gpu/command_buffer/service/gpu_tracer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698