Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / gpu / command_buffer / service / gpu_tracer.h
blob5aa2cd8a4e07e49ab5379a8fa344c9891ed0a498
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_
9 #include <string>
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"
19 namespace gpu {
20 namespace gles2 {
22 class Outputter;
23 class GPUTrace;
25 // Id used to keep trace namespaces separate
26 enum GpuTracerSource {
27 kTraceGroupInvalid = -1,
29 kTraceGroupMarker = 0,
30 kTraceCHROMIUM = 1,
31 kTraceDecoder = 2,
33 NUM_TRACER_SOURCES
36 // Marker structure for a Trace.
37 struct TraceMarker {
38 TraceMarker(const std::string& name);
39 ~TraceMarker();
41 std::string name_;
42 scoped_refptr<GPUTrace> trace_;
45 // Traces GPU Commands.
46 class GPUTracer : public base::SupportsWeakPtr<GPUTracer> {
47 public:
48 explicit GPUTracer(gles2::GLES2Decoder* decoder);
49 ~GPUTracer();
51 // Scheduled processing in decoder begins.
52 bool BeginDecoding();
54 // Scheduled processing in decoder ends.
55 bool EndDecoding();
57 // Begin a trace marker.
58 bool Begin(const std::string& name, GpuTracerSource source);
60 // End the last started trace marker.
61 bool End(GpuTracerSource source);
63 bool IsTracing();
65 // Retrieve the name of the current open trace.
66 // Returns empty string if no current open trace.
67 const std::string& CurrentName() const;
69 private:
70 // Trace Processing.
71 scoped_refptr<GPUTrace> CreateTrace(const std::string& name);
72 void Process();
73 void ProcessTraces();
75 void CalculateTimerOffset();
76 void IssueProcessTask();
78 scoped_refptr<Outputter> outputter_;
79 std::vector<TraceMarker> markers_[NUM_TRACER_SOURCES];
80 std::deque<scoped_refptr<GPUTrace> > traces_;
82 const unsigned char* gpu_trace_srv_category;
83 const unsigned char* gpu_trace_dev_category;
84 gles2::GLES2Decoder* decoder_;
86 int64 timer_offset_;
87 GpuTracerSource last_tracer_source_;
89 bool enabled_;
90 bool gpu_timing_synced_;
91 bool gpu_executing_;
92 bool process_posted_;
94 DISALLOW_COPY_AND_ASSIGN(GPUTracer);
97 class Outputter : public base::RefCounted<Outputter> {
98 public:
99 virtual void Trace(const std::string& name,
100 int64 start_time,
101 int64 end_time) = 0;
103 protected:
104 virtual ~Outputter() {}
105 friend class base::RefCounted<Outputter>;
108 class TraceOutputter : public Outputter {
109 public:
110 static scoped_refptr<TraceOutputter> Create(const std::string& name);
111 virtual void Trace(const std::string& name,
112 int64 start_time,
113 int64 end_time) OVERRIDE;
115 protected:
116 friend class base::RefCounted<Outputter>;
117 explicit TraceOutputter(const std::string& name);
118 virtual ~TraceOutputter();
120 base::Thread named_thread_;
121 uint64 local_trace_id_;
123 DISALLOW_COPY_AND_ASSIGN(TraceOutputter);
126 class GPU_EXPORT GPUTrace
127 : public base::RefCounted<GPUTrace> {
128 public:
129 explicit GPUTrace(const std::string& name);
130 GPUTrace(scoped_refptr<Outputter> outputter,
131 const std::string& name,
132 int64 offset);
134 bool IsEnabled() { return enabled_; }
135 const std::string& name() { return name_; }
137 void Start();
138 void End();
139 bool IsAvailable();
140 void Process();
142 private:
143 ~GPUTrace();
145 void Output();
147 friend class base::RefCounted<GPUTrace>;
149 std::string name_;
150 scoped_refptr<Outputter> outputter_;
152 int64 offset_;
153 int64 start_time_;
154 int64 end_time_;
155 bool end_requested_;
156 bool enabled_;
158 GLuint queries_[2];
160 DISALLOW_COPY_AND_ASSIGN(GPUTrace);
163 } // namespace gles2
164 } // namespace gpu
166 #endif // GPU_COMMAND_BUFFER_SERVICE_GPU_TRACER_H_