Handle account removal correctly on all platforms.
[chromium-blink-merge.git] / gpu / command_buffer / service / gpu_tracer.h
blob63e5646b09cf780178181746a125ef97b3a91aff
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 enum GpuTracerType {
37 kTracerTypeInvalid = -1,
39 kTracerTypeARBTimer,
40 kTracerTypeDisjointTimer
43 // Marker structure for a Trace.
44 struct TraceMarker {
45 TraceMarker(const std::string& name);
46 ~TraceMarker();
48 std::string name_;
49 scoped_refptr<GPUTrace> trace_;
52 // Traces GPU Commands.
53 class GPUTracer : public base::SupportsWeakPtr<GPUTracer> {
54 public:
55 explicit GPUTracer(gles2::GLES2Decoder* decoder);
56 ~GPUTracer();
58 // Scheduled processing in decoder begins.
59 bool BeginDecoding();
61 // Scheduled processing in decoder ends.
62 bool EndDecoding();
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);
70 bool IsTracing();
72 // Retrieve the name of the current open trace.
73 // Returns empty string if no current open trace.
74 const std::string& CurrentName() const;
76 private:
77 // Trace Processing.
78 scoped_refptr<GPUTrace> CreateTrace(const std::string& name);
79 void Process();
80 void ProcessTraces();
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_;
93 int64 timer_offset_;
94 GpuTracerSource last_tracer_source_;
96 GpuTracerType tracer_type_;
97 bool gpu_timing_synced_;
98 bool gpu_executing_;
99 bool process_posted_;
101 DISALLOW_COPY_AND_ASSIGN(GPUTracer);
104 class Outputter : public base::RefCounted<Outputter> {
105 public:
106 virtual void Trace(const std::string& name,
107 int64 start_time,
108 int64 end_time) = 0;
110 protected:
111 virtual ~Outputter() {}
112 friend class base::RefCounted<Outputter>;
115 class TraceOutputter : public Outputter {
116 public:
117 static scoped_refptr<TraceOutputter> Create(const std::string& name);
118 virtual void Trace(const std::string& name,
119 int64 start_time,
120 int64 end_time) OVERRIDE;
122 protected:
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> {
135 public:
136 GPUTrace(scoped_refptr<Outputter> outputter,
137 const std::string& name,
138 int64 offset,
139 GpuTracerType tracer_type);
141 bool IsEnabled() { return tracer_type_ != kTracerTypeInvalid; }
142 const std::string& name() { return name_; }
144 void Start();
145 void End();
146 bool IsAvailable();
147 void Process();
149 private:
150 ~GPUTrace();
152 void Output();
154 friend class base::RefCounted<GPUTrace>;
156 std::string name_;
157 scoped_refptr<Outputter> outputter_;
159 int64 offset_;
160 int64 start_time_;
161 int64 end_time_;
162 GpuTracerType tracer_type_;
163 bool end_requested_;
165 GLuint queries_[2];
167 DISALLOW_COPY_AND_ASSIGN(GPUTrace);
170 } // namespace gles2
171 } // namespace gpu
173 #endif // GPU_COMMAND_BUFFER_SERVICE_GPU_TRACER_H_