Chromium Code Reviews| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 private: | 62 private: |
| 63 virtual ~NoopTrace() {} | 63 virtual ~NoopTrace() {} |
| 64 | 64 |
| 65 DISALLOW_COPY_AND_ASSIGN(NoopTrace); | 65 DISALLOW_COPY_AND_ASSIGN(NoopTrace); |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 class GPUTracerImpl | 68 class GPUTracerImpl |
| 69 : public GPUTracer, | 69 : public GPUTracer, |
| 70 public base::SupportsWeakPtr<GPUTracerImpl> { | 70 public base::SupportsWeakPtr<GPUTracerImpl> { |
| 71 public: | 71 public: |
| 72 GPUTracerImpl() | 72 explicit GPUTracerImpl(base::WeakPtr<gles2::GLES2Decoder> decoder) |
| 73 : gpu_category_enabled_( | 73 : GPUTracer(decoder), |
| 74 TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED("gpu")), | 74 gpu_category_enabled_( |
| 75 process_posted_(false) { | 75 TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED("gpu")), |
| 76 } | 76 process_posted_(false) {} |
| 77 virtual ~GPUTracerImpl() {} | 77 virtual ~GPUTracerImpl() {} |
| 78 | 78 |
| 79 // Implementation of gpu::gles2::GPUTracer | 79 // Implementation of gpu::gles2::GPUTracer |
| 80 virtual bool Begin(const std::string& name) OVERRIDE; | 80 virtual bool Begin(const std::string& name) OVERRIDE; |
| 81 virtual bool End() OVERRIDE; | 81 virtual bool End() OVERRIDE; |
| 82 virtual const std::string& CurrentName() const OVERRIDE; | 82 virtual const std::string& CurrentName() const OVERRIDE; |
| 83 | 83 |
| 84 // Process any completed traces. | 84 // Process any completed traces. |
| 85 virtual void Process(); | 85 virtual void Process(); |
| 86 | 86 |
| 87 protected: | 87 protected: |
| 88 // Create a new trace. | 88 // Create a new trace. |
| 89 virtual scoped_refptr<Trace> CreateTrace(const std::string& name); | 89 virtual scoped_refptr<Trace> CreateTrace(const std::string& name); |
| 90 | 90 |
| 91 const unsigned char* gpu_category_enabled_; | 91 const unsigned char* gpu_category_enabled_; |
| 92 | 92 |
| 93 private: | 93 private: |
| 94 void IssueProcessTask(); | 94 void IssueProcessTask(); |
| 95 | 95 |
| 96 scoped_refptr<Trace> current_trace_; | 96 scoped_refptr<Trace> current_trace_; |
| 97 std::deque<scoped_refptr<Trace> > traces_; | 97 std::deque<scoped_refptr<Trace> > traces_; |
| 98 | 98 |
| 99 bool process_posted_; | 99 bool process_posted_; |
| 100 | 100 |
| 101 DISALLOW_COPY_AND_ASSIGN(GPUTracerImpl); | 101 DISALLOW_COPY_AND_ASSIGN(GPUTracerImpl); |
| 102 }; | 102 }; |
| 103 | 103 |
| 104 class GPUTracerARBTimerQuery : public GPUTracerImpl { | 104 class GPUTracerARBTimerQuery : public GPUTracerImpl { |
| 105 public: | 105 public: |
| 106 GPUTracerARBTimerQuery(); | 106 explicit GPUTracerARBTimerQuery(base::WeakPtr<gles2::GLES2Decoder> decoder); |
| 107 virtual ~GPUTracerARBTimerQuery(); | 107 virtual ~GPUTracerARBTimerQuery(); |
| 108 | 108 |
| 109 // Implementation of GPUTracerImpl | 109 // Implementation of GPUTracerImpl |
| 110 virtual void Process() OVERRIDE; | 110 virtual void Process() OVERRIDE; |
| 111 | 111 |
| 112 private: | 112 private: |
| 113 // Implementation of GPUTracerImpl. | 113 // Implementation of GPUTracerImpl. |
| 114 virtual scoped_refptr<Trace> CreateTrace(const std::string& name) OVERRIDE; | 114 virtual scoped_refptr<Trace> CreateTrace(const std::string& name) OVERRIDE; |
| 115 | 115 |
| 116 void CalculateTimerOffset(); | 116 void CalculateTimerOffset(); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 197 traces_.push_back(current_trace_); | 197 traces_.push_back(current_trace_); |
| 198 current_trace_ = NULL; | 198 current_trace_ = NULL; |
| 199 | 199 |
| 200 IssueProcessTask(); | 200 IssueProcessTask(); |
| 201 return true; | 201 return true; |
| 202 } | 202 } |
| 203 | 203 |
| 204 void GPUTracerImpl::Process() { | 204 void GPUTracerImpl::Process() { |
| 205 process_posted_ = false; | 205 process_posted_ = false; |
| 206 | 206 |
| 207 // Make owning decoder's GL context current | |
| 208 decoder_->MakeCurrent(); | |
|
piman
2014/01/09 02:10:33
note: MakeCurrent can fail (e.g. lost context). In
vmiura
2014/01/09 02:57:02
Done.
In this case I will skip all GL calls, incl
| |
| 209 | |
| 207 while (!traces_.empty() && traces_.front()->IsAvailable()) { | 210 while (!traces_.empty() && traces_.front()->IsAvailable()) { |
| 208 traces_.front()->Process(); | 211 traces_.front()->Process(); |
| 209 traces_.pop_front(); | 212 traces_.pop_front(); |
| 210 } | 213 } |
| 211 | 214 |
| 212 IssueProcessTask(); | 215 IssueProcessTask(); |
| 213 } | 216 } |
| 214 | 217 |
| 215 const std::string& GPUTracerImpl::CurrentName() const { | 218 const std::string& GPUTracerImpl::CurrentName() const { |
| 216 if (!current_trace_.get()) | 219 if (!current_trace_.get()) |
| 217 return base::EmptyString(); | 220 return base::EmptyString(); |
| 218 return current_trace_->name(); | 221 return current_trace_->name(); |
| 219 } | 222 } |
| 220 | 223 |
| 221 scoped_refptr<Trace> GPUTracerImpl::CreateTrace(const std::string& name) { | 224 scoped_refptr<Trace> GPUTracerImpl::CreateTrace(const std::string& name) { |
| 222 return new NoopTrace(name); | 225 return new NoopTrace(name); |
| 223 } | 226 } |
| 224 | 227 |
| 225 void GPUTracerImpl::IssueProcessTask() { | 228 void GPUTracerImpl::IssueProcessTask() { |
| 226 if (traces_.empty() || process_posted_) | 229 if (traces_.empty() || process_posted_) |
| 227 return; | 230 return; |
| 228 | 231 |
| 229 process_posted_ = true; | 232 process_posted_ = true; |
| 230 base::MessageLoop::current()->PostDelayedTask( | 233 base::MessageLoop::current()->PostDelayedTask( |
| 231 FROM_HERE, | 234 FROM_HERE, |
| 232 base::Bind(&GPUTracerImpl::Process, base::AsWeakPtr(this)), | 235 base::Bind(&GPUTracerImpl::Process, base::AsWeakPtr(this)), |
| 233 base::TimeDelta::FromMilliseconds(kProcessInterval)); | 236 base::TimeDelta::FromMilliseconds(kProcessInterval)); |
| 234 } | 237 } |
| 235 | 238 |
| 236 GPUTracerARBTimerQuery::GPUTracerARBTimerQuery() | 239 GPUTracerARBTimerQuery::GPUTracerARBTimerQuery( |
| 237 : GPUTracerImpl(), | 240 base::WeakPtr<gles2::GLES2Decoder> decoder) |
| 238 timer_offset_(0), | 241 : GPUTracerImpl(decoder), timer_offset_(0), last_offset_check_(0) { |
| 239 last_offset_check_(0) { | |
| 240 CalculateTimerOffset(); | 242 CalculateTimerOffset(); |
| 241 outputter_ = TraceOutputter::Create("GL_ARB_timer_query"); | 243 outputter_ = TraceOutputter::Create("GL_ARB_timer_query"); |
| 242 } | 244 } |
| 243 | 245 |
| 244 GPUTracerARBTimerQuery::~GPUTracerARBTimerQuery() { | 246 GPUTracerARBTimerQuery::~GPUTracerARBTimerQuery() { |
| 245 } | 247 } |
| 246 | 248 |
| 247 scoped_refptr<Trace> GPUTracerARBTimerQuery::CreateTrace( | 249 scoped_refptr<Trace> GPUTracerARBTimerQuery::CreateTrace( |
| 248 const std::string& name) { | 250 const std::string& name) { |
| 249 if (*gpu_category_enabled_) | 251 if (*gpu_category_enabled_) |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 271 glGetQueryObjectui64v(query, GL_QUERY_RESULT, &gl_now); | 273 glGetQueryObjectui64v(query, GL_QUERY_RESULT, &gl_now); |
| 272 base::TimeTicks system_now = base::TimeTicks::NowFromSystemTraceTime(); | 274 base::TimeTicks system_now = base::TimeTicks::NowFromSystemTraceTime(); |
| 273 | 275 |
| 274 gl_now /= base::Time::kNanosecondsPerMicrosecond; | 276 gl_now /= base::Time::kNanosecondsPerMicrosecond; |
| 275 timer_offset_ = system_now.ToInternalValue() - gl_now; | 277 timer_offset_ = system_now.ToInternalValue() - gl_now; |
| 276 glDeleteQueries(1, &query); | 278 glDeleteQueries(1, &query); |
| 277 | 279 |
| 278 last_offset_check_ = system_now.ToInternalValue(); | 280 last_offset_check_ = system_now.ToInternalValue(); |
| 279 } | 281 } |
| 280 | 282 |
| 281 scoped_ptr<GPUTracer> GPUTracer::Create() { | 283 GPUTracer::GPUTracer(base::WeakPtr<gles2::GLES2Decoder> decoder) |
| 284 : decoder_(decoder) {} | |
| 285 | |
| 286 GPUTracer::~GPUTracer() {} | |
| 287 | |
| 288 scoped_ptr<GPUTracer> GPUTracer::Create( | |
| 289 base::WeakPtr<gles2::GLES2Decoder> decoder) { | |
| 282 if (gfx::g_driver_gl.ext.b_GL_ARB_timer_query) { | 290 if (gfx::g_driver_gl.ext.b_GL_ARB_timer_query) { |
| 283 return scoped_ptr<GPUTracer>(new GPUTracerARBTimerQuery()); | 291 return scoped_ptr<GPUTracer>(new GPUTracerARBTimerQuery(decoder)); |
| 284 } | 292 } |
| 285 return scoped_ptr<GPUTracer>(new GPUTracerImpl()); | 293 return scoped_ptr<GPUTracer>(new GPUTracerImpl(decoder)); |
| 286 } | 294 } |
| 287 | 295 |
| 288 } // namespace gles2 | 296 } // namespace gles2 |
| 289 } // namespace gpu | 297 } // namespace gpu |
| OLD | NEW |