| 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/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 named_thread_.Start(); | 49 named_thread_.Start(); |
| 50 named_thread_.Stop(); | 50 named_thread_.Stop(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 TraceOutputter::~TraceOutputter() { g_outputter_thread = NULL; } | 53 TraceOutputter::~TraceOutputter() { g_outputter_thread = NULL; } |
| 54 | 54 |
| 55 void TraceOutputter::TraceDevice(const std::string& category, | 55 void TraceOutputter::TraceDevice(const std::string& category, |
| 56 const std::string& name, | 56 const std::string& name, |
| 57 int64 start_time, | 57 int64 start_time, |
| 58 int64 end_time) { | 58 int64 end_time) { |
| 59 TRACE_EVENT_COPY_BEGIN_WITH_ID_TID_AND_TIMESTAMP0(category.c_str(), | 59 TRACE_EVENT_COPY_BEGIN_WITH_ID_TID_AND_TIMESTAMP1( |
| 60 name.c_str(), | 60 TRACE_DISABLED_BY_DEFAULT("gpu.device"), |
| 61 local_trace_id_, | 61 name.c_str(), |
| 62 named_thread_.thread_id(), | 62 local_trace_id_, |
| 63 start_time); | 63 named_thread_.thread_id(), |
| 64 TRACE_EVENT_COPY_END_WITH_ID_TID_AND_TIMESTAMP0(category.c_str(), | 64 start_time, |
| 65 name.c_str(), | 65 "gl_category", |
| 66 local_trace_id_, | 66 category.c_str()); |
| 67 named_thread_.thread_id(), | 67 TRACE_EVENT_COPY_END_WITH_ID_TID_AND_TIMESTAMP1( |
| 68 end_time); | 68 TRACE_DISABLED_BY_DEFAULT("gpu.device"), |
| 69 name.c_str(), |
| 70 local_trace_id_, |
| 71 named_thread_.thread_id(), |
| 72 end_time, |
| 73 "gl_category", |
| 74 category.c_str()); |
| 69 ++local_trace_id_; | 75 ++local_trace_id_; |
| 70 } | 76 } |
| 71 | 77 |
| 72 void TraceOutputter::TraceServiceBegin(const std::string& category, | 78 void TraceOutputter::TraceServiceBegin(const std::string& category, |
| 73 const std::string& name, | 79 const std::string& name, |
| 74 void* id) { | 80 void* id) { |
| 75 TRACE_EVENT_COPY_ASYNC_BEGIN0(category.c_str(), name.c_str(), id); | 81 TRACE_EVENT_COPY_ASYNC_BEGIN1(TRACE_DISABLED_BY_DEFAULT("gpu.service"), |
| 82 name.c_str(), this, |
| 83 "gl_category", category.c_str()); |
| 76 } | 84 } |
| 77 | 85 |
| 78 void TraceOutputter::TraceServiceEnd(const std::string& category, | 86 void TraceOutputter::TraceServiceEnd(const std::string& category, |
| 79 const std::string& name, | 87 const std::string& name, |
| 80 void* id) { | 88 void* id) { |
| 81 TRACE_EVENT_COPY_ASYNC_END0(category.c_str(), name.c_str(), id); | 89 TRACE_EVENT_COPY_ASYNC_END1(TRACE_DISABLED_BY_DEFAULT("gpu.service"), |
| 90 name.c_str(), this, |
| 91 "gl_category", category.c_str()); |
| 82 } | 92 } |
| 83 | 93 |
| 84 GPUTrace::GPUTrace(scoped_refptr<Outputter> outputter, | 94 GPUTrace::GPUTrace(scoped_refptr<Outputter> outputter, |
| 85 scoped_refptr<CPUTime> cpu_time, | 95 scoped_refptr<CPUTime> cpu_time, |
| 86 const std::string& category, | 96 const std::string& category, |
| 87 const std::string& name, | 97 const std::string& name, |
| 88 int64 offset, | 98 int64 offset, |
| 89 GpuTracerType tracer_type) | 99 GpuTracerType tracer_type) |
| 90 : category_(category), | 100 : category_(category), |
| 91 name_(name), | 101 name_(name), |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 | 202 |
| 193 // TODO(dsinclair): It's possible for the timer to wrap during the start/end. | 203 // TODO(dsinclair): It's possible for the timer to wrap during the start/end. |
| 194 // We need to detect if the end is less then the start and correct for the | 204 // We need to detect if the end is less then the start and correct for the |
| 195 // wrapping. | 205 // wrapping. |
| 196 glGetQueryObjectui64v(queries_[0], GL_QUERY_RESULT, &begin_stamp); | 206 glGetQueryObjectui64v(queries_[0], GL_QUERY_RESULT, &begin_stamp); |
| 197 glGetQueryObjectui64v(queries_[1], GL_QUERY_RESULT, &end_stamp); | 207 glGetQueryObjectui64v(queries_[1], GL_QUERY_RESULT, &end_stamp); |
| 198 | 208 |
| 199 start_time_ = (begin_stamp / base::Time::kNanosecondsPerMicrosecond) + | 209 start_time_ = (begin_stamp / base::Time::kNanosecondsPerMicrosecond) + |
| 200 offset_; | 210 offset_; |
| 201 end_time_ = (end_stamp / base::Time::kNanosecondsPerMicrosecond) + offset_; | 211 end_time_ = (end_stamp / base::Time::kNanosecondsPerMicrosecond) + offset_; |
| 202 outputter_->TraceDevice(category(), name(), start_time_, end_time_); | 212 outputter_->TraceDevice(category_, name_, start_time_, end_time_); |
| 203 } | 213 } |
| 204 | 214 |
| 205 GPUTracer::GPUTracer(gles2::GLES2Decoder* decoder) | 215 GPUTracer::GPUTracer(gles2::GLES2Decoder* decoder) |
| 206 : gpu_trace_srv_category(TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( | 216 : gpu_trace_srv_category(TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( |
| 207 TRACE_DISABLED_BY_DEFAULT("gpu.service"))), | 217 TRACE_DISABLED_BY_DEFAULT("gpu.service"))), |
| 208 gpu_trace_dev_category(TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( | 218 gpu_trace_dev_category(TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( |
| 209 TRACE_DISABLED_BY_DEFAULT("gpu.device"))), | 219 TRACE_DISABLED_BY_DEFAULT("gpu.device"))), |
| 210 decoder_(decoder), | 220 decoder_(decoder), |
| 211 timer_offset_(0), | 221 timer_offset_(0), |
| 212 last_tracer_source_(kTraceGroupInvalid), | |
| 213 tracer_type_(kTracerTypeInvalid), | 222 tracer_type_(kTracerTypeInvalid), |
| 214 gpu_timing_synced_(false), | 223 gpu_timing_synced_(false), |
| 215 gpu_executing_(false), | 224 gpu_executing_(false), |
| 216 process_posted_(false) { | 225 process_posted_(false) { |
| 217 } | 226 } |
| 218 | 227 |
| 219 GPUTracer::~GPUTracer() { | 228 GPUTracer::~GPUTracer() { |
| 220 } | 229 } |
| 221 | 230 |
| 222 bool GPUTracer::BeginDecoding() { | 231 bool GPUTracer::BeginDecoding() { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 } | 278 } |
| 270 | 279 |
| 271 bool GPUTracer::EndDecoding() { | 280 bool GPUTracer::EndDecoding() { |
| 272 if (!gpu_executing_) | 281 if (!gpu_executing_) |
| 273 return false; | 282 return false; |
| 274 | 283 |
| 275 // End Trace for all active markers | 284 // End Trace for all active markers |
| 276 if (IsTracing()) { | 285 if (IsTracing()) { |
| 277 for (int n = 0; n < NUM_TRACER_SOURCES; n++) { | 286 for (int n = 0; n < NUM_TRACER_SOURCES; n++) { |
| 278 for (size_t i = 0; i < markers_[n].size(); i++) { | 287 for (size_t i = 0; i < markers_[n].size(); i++) { |
| 279 if (markers_[n][i].trace_.get()) { | 288 TraceMarker& marker = markers_[n][i]; |
| 280 markers_[n][i].trace_->End(*gpu_trace_srv_category != 0); | 289 if (marker.trace_.get()) { |
| 281 if (markers_[n][i].trace_->IsEnabled()) | 290 marker.trace_->End(*gpu_trace_srv_category != 0); |
| 282 traces_.push_back(markers_[n][i].trace_); | 291 if (marker.trace_->IsEnabled()) |
| 292 traces_.push_back(marker.trace_); |
| 293 |
| 283 markers_[n][i].trace_ = 0; | 294 markers_[n][i].trace_ = 0; |
| 284 } | 295 } |
| 285 } | 296 } |
| 286 } | 297 } |
| 287 IssueProcessTask(); | 298 IssueProcessTask(); |
| 288 } | 299 } |
| 289 | 300 |
| 290 gpu_executing_ = false; | 301 gpu_executing_ = false; |
| 291 | 302 |
| 292 // NOTE(vmiura): glFlush() here can help give better trace results, | 303 // NOTE(vmiura): glFlush() here can help give better trace results, |
| 293 // but it distorts the normal device behavior. | 304 // but it distorts the normal device behavior. |
| 294 return true; | 305 return true; |
| 295 } | 306 } |
| 296 | 307 |
| 297 bool GPUTracer::Begin(const std::string& category, const std::string& name, | 308 bool GPUTracer::Begin(const std::string& category, const std::string& name, |
| 298 GpuTracerSource source) { | 309 GpuTracerSource source) { |
| 299 if (!gpu_executing_) | 310 if (!gpu_executing_) |
| 300 return false; | 311 return false; |
| 301 | 312 |
| 302 DCHECK(source >= 0 && source < NUM_TRACER_SOURCES); | 313 DCHECK(source >= 0 && source < NUM_TRACER_SOURCES); |
| 303 | 314 |
| 304 // Push new marker from given 'source' | 315 // Push new marker from given 'source' |
| 305 last_tracer_source_ = source; | |
| 306 markers_[source].push_back(TraceMarker(category, name)); | 316 markers_[source].push_back(TraceMarker(category, name)); |
| 307 | 317 |
| 308 // Create trace | 318 // Create trace |
| 309 if (IsTracing()) { | 319 if (IsTracing()) { |
| 310 scoped_refptr<GPUTrace> trace = CreateTrace(category, name); | 320 scoped_refptr<GPUTrace> trace = CreateTrace(category, name); |
| 311 trace->Start(*gpu_trace_srv_category != 0); | 321 trace->Start(*gpu_trace_srv_category != 0); |
| 312 markers_[source].back().trace_ = trace; | 322 markers_[source].back().trace_ = trace; |
| 313 } | 323 } |
| 314 | 324 |
| 315 return true; | 325 return true; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 336 markers_[source].pop_back(); | 346 markers_[source].pop_back(); |
| 337 return true; | 347 return true; |
| 338 } | 348 } |
| 339 return false; | 349 return false; |
| 340 } | 350 } |
| 341 | 351 |
| 342 bool GPUTracer::IsTracing() { | 352 bool GPUTracer::IsTracing() { |
| 343 return (*gpu_trace_srv_category != 0) || (*gpu_trace_dev_category != 0); | 353 return (*gpu_trace_srv_category != 0) || (*gpu_trace_dev_category != 0); |
| 344 } | 354 } |
| 345 | 355 |
| 346 const std::string& GPUTracer::CurrentCategory() const { | 356 const std::string& GPUTracer::CurrentCategory(GpuTracerSource source) const { |
| 347 if (last_tracer_source_ >= 0 && | 357 if (source >= 0 && |
| 348 last_tracer_source_ < NUM_TRACER_SOURCES && | 358 source < NUM_TRACER_SOURCES && |
| 349 !markers_[last_tracer_source_].empty()) { | 359 !markers_[source].empty()) { |
| 350 return markers_[last_tracer_source_].back().category_; | 360 return markers_[source].back().category_; |
| 351 } | 361 } |
| 352 return base::EmptyString(); | 362 return base::EmptyString(); |
| 353 } | 363 } |
| 354 | 364 |
| 355 const std::string& GPUTracer::CurrentName() const { | 365 const std::string& GPUTracer::CurrentName(GpuTracerSource source) const { |
| 356 if (last_tracer_source_ >= 0 && | 366 if (source >= 0 && |
| 357 last_tracer_source_ < NUM_TRACER_SOURCES && | 367 source < NUM_TRACER_SOURCES && |
| 358 !markers_[last_tracer_source_].empty()) { | 368 !markers_[source].empty()) { |
| 359 return markers_[last_tracer_source_].back().name_; | 369 return markers_[source].back().name_; |
| 360 } | 370 } |
| 361 return base::EmptyString(); | 371 return base::EmptyString(); |
| 362 } | 372 } |
| 363 | 373 |
| 364 scoped_refptr<GPUTrace> GPUTracer::CreateTrace(const std::string& category, | 374 scoped_refptr<GPUTrace> GPUTracer::CreateTrace(const std::string& category, |
| 365 const std::string& name) { | 375 const std::string& name) { |
| 366 GpuTracerType tracer_type = *gpu_trace_dev_category ? tracer_type_ : | 376 GpuTracerType tracer_type = *gpu_trace_dev_category ? tracer_type_ : |
| 367 kTracerTypeInvalid; | 377 kTracerTypeInvalid; |
| 368 | 378 |
| 369 return new GPUTrace(outputter_, cpu_time_, category, name, | 379 return new GPUTrace(outputter_, cpu_time_, category, name, |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 void GPUTracer::IssueProcessTask() { | 485 void GPUTracer::IssueProcessTask() { |
| 476 if (traces_.empty() || process_posted_) | 486 if (traces_.empty() || process_posted_) |
| 477 return; | 487 return; |
| 478 | 488 |
| 479 process_posted_ = true; | 489 process_posted_ = true; |
| 480 PostTask(); | 490 PostTask(); |
| 481 } | 491 } |
| 482 | 492 |
| 483 } // namespace gles2 | 493 } // namespace gles2 |
| 484 } // namespace gpu | 494 } // namespace gpu |
| OLD | NEW |