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
3 // found in the LICENSE file.
5 // This file contains the GPUTrace class.
6 #ifndef GPU_COMMAND_BUFFER_SERVICE_GPU_TRACER_H_
7 #define GPU_COMMAND_BUFFER_SERVICE_GPU_TRACER_H_
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/threading/thread.h"
15 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
16 #include "gpu/gpu_export.h"
17 #include "ui/gl/gl_bindings.h"
25 // Id used to keep trace namespaces separate
26 enum GpuTracerSource {
27 kTraceGroupInvalid = -1,
29 kTraceGroupMarker = 0,
37 kTracerTypeInvalid = -1,
40 kTracerTypeDisjointTimer
43 // Marker structure for a Trace.
45 TraceMarker(const std::string& name);
49 scoped_refptr<GPUTrace> trace_;
52 // Traces GPU Commands.
53 class GPUTracer : public base::SupportsWeakPtr<GPUTracer> {
55 explicit GPUTracer(gles2::GLES2Decoder* decoder);
58 // Scheduled processing in decoder begins.
61 // Scheduled processing in decoder ends.
64 // Begin a trace marker.
65 bool Begin(const std::string& name, GpuTracerSource source);
67 // End the last started trace marker.
68 bool End(GpuTracerSource source);
72 // Retrieve the name of the current open trace.
73 // Returns empty string if no current open trace.
74 const std::string& CurrentName() const;
78 scoped_refptr<GPUTrace> CreateTrace(const std::string& name);
82 void CalculateTimerOffset();
83 void IssueProcessTask();
85 scoped_refptr<Outputter> outputter_;
86 std::vector<TraceMarker> markers_[NUM_TRACER_SOURCES];
87 std::deque<scoped_refptr<GPUTrace> > traces_;
89 const unsigned char* gpu_trace_srv_category;
90 const unsigned char* gpu_trace_dev_category;
91 gles2::GLES2Decoder* decoder_;
94 GpuTracerSource last_tracer_source_;
96 GpuTracerType tracer_type_;
97 bool gpu_timing_synced_;
101 DISALLOW_COPY_AND_ASSIGN(GPUTracer);
104 class Outputter : public base::RefCounted<Outputter> {
106 virtual void Trace(const std::string& name,
111 virtual ~Outputter() {}
112 friend class base::RefCounted<Outputter>;
115 class TraceOutputter : public Outputter {
117 static scoped_refptr<TraceOutputter> Create(const std::string& name);
118 virtual void Trace(const std::string& name,
120 int64 end_time) OVERRIDE;
123 friend class base::RefCounted<Outputter>;
124 explicit TraceOutputter(const std::string& name);
125 virtual ~TraceOutputter();
127 base::Thread named_thread_;
128 uint64 local_trace_id_;
130 DISALLOW_COPY_AND_ASSIGN(TraceOutputter);
133 class GPU_EXPORT GPUTrace
134 : public base::RefCounted<GPUTrace> {
136 GPUTrace(scoped_refptr<Outputter> outputter,
137 const std::string& name,
139 GpuTracerType tracer_type);
141 bool IsEnabled() { return tracer_type_ != kTracerTypeInvalid; }
142 const std::string& name() { return name_; }
154 friend class base::RefCounted<GPUTrace>;
157 scoped_refptr<Outputter> outputter_;
162 GpuTracerType tracer_type_;
167 DISALLOW_COPY_AND_ASSIGN(GPUTrace);
173 #endif // GPU_COMMAND_BUFFER_SERVICE_GPU_TRACER_H_