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/location.h" | 10 #include "base/location.h" |
11 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
14 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "base/trace_event/trace_event.h" | 16 #include "base/trace_event/trace_event.h" |
17 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 17 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
18 #include "gpu/command_buffer/service/context_group.h" | 18 #include "gpu/command_buffer/service/context_group.h" |
19 #include "ui/gl/gl_bindings.h" | 19 #include "ui/gl/gl_bindings.h" |
20 #include "ui/gl/gl_context.h" | 20 #include "ui/gl/gl_context.h" |
21 #include "ui/gl/gl_version_info.h" | 21 #include "ui/gl/gl_version_info.h" |
22 #include "ui/gl/gpu_timing.h" | 22 #include "ui/gl/gpu_timing.h" |
23 | 23 |
24 namespace gpu { | 24 namespace gpu { |
25 namespace gles2 { | 25 namespace gles2 { |
26 | 26 |
27 static const unsigned int kProcessInterval = 16; | |
28 static const char* kGpuTraceSourceNames[] = { | 27 static const char* kGpuTraceSourceNames[] = { |
29 "TraceCHROMIUM", // kTraceCHROMIUM, | 28 "TraceCHROMIUM", // kTraceCHROMIUM, |
30 "TraceCmd", // kTraceDecoder, | 29 "TraceCmd", // kTraceDecoder, |
31 "Disjoint", // kTraceDisjoint, // Used internally. | 30 "Disjoint", // kTraceDisjoint, // Used internally. |
32 }; | 31 }; |
33 static_assert(NUM_TRACER_SOURCES == arraysize(kGpuTraceSourceNames), | 32 static_assert(NUM_TRACER_SOURCES == arraysize(kGpuTraceSourceNames), |
34 "Trace source names must match enumeration."); | 33 "Trace source names must match enumeration."); |
35 | 34 |
36 static TraceOutputter* g_outputter_thread = NULL; | 35 static TraceOutputter* g_outputter_thread = NULL; |
37 | 36 |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 TraceMarker& marker = markers_[n][i]; | 243 TraceMarker& marker = markers_[n][i]; |
245 if (marker.trace_.get()) { | 244 if (marker.trace_.get()) { |
246 marker.trace_->End(); | 245 marker.trace_->End(); |
247 | 246 |
248 finished_traces_.push_back(marker.trace_); | 247 finished_traces_.push_back(marker.trace_); |
249 marker.trace_ = 0; | 248 marker.trace_ = 0; |
250 } | 249 } |
251 } | 250 } |
252 } | 251 } |
253 } | 252 } |
254 IssueProcessTask(); | |
255 } | 253 } |
256 | 254 |
257 gpu_executing_ = false; | 255 gpu_executing_ = false; |
258 return true; | 256 return true; |
259 } | 257 } |
260 | 258 |
261 bool GPUTracer::Begin(const std::string& category, const std::string& name, | 259 bool GPUTracer::Begin(const std::string& category, const std::string& name, |
262 GpuTracerSource source) { | 260 GpuTracerSource source) { |
263 if (!gpu_executing_) | 261 if (!gpu_executing_) |
264 return false; | 262 return false; |
(...skipping 25 matching lines...) Expand all Loading... |
290 | 288 |
291 // Pop last marker with matching 'source' | 289 // Pop last marker with matching 'source' |
292 if (!markers_[source].empty()) { | 290 if (!markers_[source].empty()) { |
293 scoped_refptr<GPUTrace> trace = markers_[source].back().trace_; | 291 scoped_refptr<GPUTrace> trace = markers_[source].back().trace_; |
294 if (trace.get()) { | 292 if (trace.get()) { |
295 if (IsTracing()) { | 293 if (IsTracing()) { |
296 trace->End(); | 294 trace->End(); |
297 } | 295 } |
298 | 296 |
299 finished_traces_.push_back(trace); | 297 finished_traces_.push_back(trace); |
300 IssueProcessTask(); | |
301 } | 298 } |
302 | 299 |
303 markers_[source].pop_back(); | 300 markers_[source].pop_back(); |
304 return true; | 301 return true; |
305 } | 302 } |
306 return false; | 303 return false; |
307 } | 304 } |
308 | 305 |
309 bool GPUTracer::IsTracing() { | 306 bool GPUTracer::HasTracesToProcess() { |
310 return (*gpu_trace_srv_category != 0) || (*gpu_trace_dev_category != 0); | 307 return !finished_traces_.empty(); |
311 } | |
312 | |
313 const std::string& GPUTracer::CurrentCategory(GpuTracerSource source) const { | |
314 if (source >= 0 && | |
315 source < NUM_TRACER_SOURCES && | |
316 !markers_[source].empty()) { | |
317 return markers_[source].back().category_; | |
318 } | |
319 return base::EmptyString(); | |
320 } | |
321 | |
322 const std::string& GPUTracer::CurrentName(GpuTracerSource source) const { | |
323 if (source >= 0 && | |
324 source < NUM_TRACER_SOURCES && | |
325 !markers_[source].empty()) { | |
326 return markers_[source].back().name_; | |
327 } | |
328 return base::EmptyString(); | |
329 } | |
330 | |
331 scoped_refptr<Outputter> GPUTracer::CreateOutputter(const std::string& name) { | |
332 return TraceOutputter::Create(name); | |
333 } | |
334 | |
335 void GPUTracer::PostTask() { | |
336 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
337 FROM_HERE, base::Bind(&GPUTracer::Process, base::AsWeakPtr(this)), | |
338 base::TimeDelta::FromMilliseconds(kProcessInterval)); | |
339 } | |
340 | |
341 void GPUTracer::Process() { | |
342 process_posted_ = false; | |
343 ProcessTraces(); | |
344 IssueProcessTask(); | |
345 } | 308 } |
346 | 309 |
347 void GPUTracer::ProcessTraces() { | 310 void GPUTracer::ProcessTraces() { |
348 if (!gpu_timing_client_->IsAvailable()) { | 311 if (!gpu_timing_client_->IsAvailable()) { |
349 while (!finished_traces_.empty()) { | 312 while (!finished_traces_.empty()) { |
350 finished_traces_.front()->Destroy(false); | 313 finished_traces_.front()->Destroy(false); |
351 finished_traces_.pop_front(); | 314 finished_traces_.pop_front(); |
352 } | 315 } |
353 return; | 316 return; |
354 } | 317 } |
(...skipping 24 matching lines...) Expand all Loading... |
379 scoped_refptr<GPUTrace>& trace = finished_traces_.front(); | 342 scoped_refptr<GPUTrace>& trace = finished_traces_.front(); |
380 trace->Process(); | 343 trace->Process(); |
381 trace->Destroy(true); | 344 trace->Destroy(true); |
382 finished_traces_.pop_front(); | 345 finished_traces_.pop_front(); |
383 } | 346 } |
384 } | 347 } |
385 | 348 |
386 DCHECK(GL_NO_ERROR == glGetError()); | 349 DCHECK(GL_NO_ERROR == glGetError()); |
387 } | 350 } |
388 | 351 |
| 352 bool GPUTracer::IsTracing() { |
| 353 return (*gpu_trace_srv_category != 0) || (*gpu_trace_dev_category != 0); |
| 354 } |
| 355 |
| 356 const std::string& GPUTracer::CurrentCategory(GpuTracerSource source) const { |
| 357 if (source >= 0 && |
| 358 source < NUM_TRACER_SOURCES && |
| 359 !markers_[source].empty()) { |
| 360 return markers_[source].back().category_; |
| 361 } |
| 362 return base::EmptyString(); |
| 363 } |
| 364 |
| 365 const std::string& GPUTracer::CurrentName(GpuTracerSource source) const { |
| 366 if (source >= 0 && |
| 367 source < NUM_TRACER_SOURCES && |
| 368 !markers_[source].empty()) { |
| 369 return markers_[source].back().name_; |
| 370 } |
| 371 return base::EmptyString(); |
| 372 } |
| 373 |
| 374 scoped_refptr<Outputter> GPUTracer::CreateOutputter(const std::string& name) { |
| 375 return TraceOutputter::Create(name); |
| 376 } |
| 377 |
389 bool GPUTracer::CheckDisjointStatus() { | 378 bool GPUTracer::CheckDisjointStatus() { |
390 const int64 current_time = gpu_timing_client_->GetCurrentCPUTime(); | 379 const int64 current_time = gpu_timing_client_->GetCurrentCPUTime(); |
391 if (*gpu_trace_dev_category == 0) | 380 if (*gpu_trace_dev_category == 0) |
392 return false; | 381 return false; |
393 | 382 |
394 bool status = gpu_timing_client_->CheckAndResetTimerErrors(); | 383 bool status = gpu_timing_client_->CheckAndResetTimerErrors(); |
395 if (status && began_device_traces_) { | 384 if (status && began_device_traces_) { |
396 // Log disjoint event if we have active traces. | 385 // Log disjoint event if we have active traces. |
397 const std::string unique_disjoint_name = | 386 const std::string unique_disjoint_name = |
398 base::StringPrintf("DisjointEvent-%p", this); | 387 base::StringPrintf("DisjointEvent-%p", this); |
(...skipping 17 matching lines...) Expand all Loading... |
416 } | 405 } |
417 } | 406 } |
418 } | 407 } |
419 | 408 |
420 while (!finished_traces_.empty()) { | 409 while (!finished_traces_.empty()) { |
421 finished_traces_.front()->Destroy(have_context); | 410 finished_traces_.front()->Destroy(have_context); |
422 finished_traces_.pop_front(); | 411 finished_traces_.pop_front(); |
423 } | 412 } |
424 } | 413 } |
425 | 414 |
426 void GPUTracer::IssueProcessTask() { | |
427 if (finished_traces_.empty() || process_posted_) | |
428 return; | |
429 | |
430 process_posted_ = true; | |
431 PostTask(); | |
432 } | |
433 | |
434 } // namespace gles2 | 415 } // namespace gles2 |
435 } // namespace gpu | 416 } // namespace gpu |
OLD | NEW |