Rewrite AndroidSyncSettings to be significantly simpler.
[chromium-blink-merge.git] / gpu / command_buffer / service / gpu_tracer.h
blob1b2c31578a4110c7975bd279fe414c3dddc76b4a
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 <deque>
10 #include <string>
11 #include <vector>
13 #include "base/basictypes.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "base/threading/thread.h"
17 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
18 #include "gpu/gpu_export.h"
20 namespace gfx {
21 class GPUTimingClient;
22 class GPUTimer;
25 namespace gpu {
26 namespace gles2 {
28 class Outputter;
29 class GPUTrace;
31 // Id used to keep trace namespaces separate
32 enum GpuTracerSource {
33 kTraceGroupInvalid = -1,
35 kTraceGroupMarker = 0,
36 kTraceCHROMIUM = 1,
37 kTraceDecoder = 2,
39 NUM_TRACER_SOURCES
42 // Marker structure for a Trace.
43 struct TraceMarker {
44 TraceMarker(const std::string& category, const std::string& name);
45 ~TraceMarker();
47 std::string category_;
48 std::string name_;
49 scoped_refptr<GPUTrace> trace_;
52 // Traces GPU Commands.
53 class GPU_EXPORT GPUTracer
54 : public base::SupportsWeakPtr<GPUTracer> {
55 public:
56 explicit GPUTracer(gles2::GLES2Decoder* decoder);
57 virtual ~GPUTracer();
59 // Scheduled processing in decoder begins.
60 bool BeginDecoding();
62 // Scheduled processing in decoder ends.
63 bool EndDecoding();
65 // Begin a trace marker.
66 bool Begin(const std::string& category, const std::string& name,
67 GpuTracerSource source);
69 // End the last started trace marker.
70 bool End(GpuTracerSource source);
72 virtual bool IsTracing();
74 // Retrieve the name of the current open trace.
75 // Returns empty string if no current open trace.
76 const std::string& CurrentCategory(GpuTracerSource source) const;
77 const std::string& CurrentName(GpuTracerSource source) const;
79 protected:
80 // Trace Processing.
81 virtual scoped_refptr<Outputter> CreateOutputter(const std::string& name);
82 virtual void PostTask();
84 void Process();
85 void ProcessTraces();
87 void IssueProcessTask();
89 scoped_refptr<gfx::GPUTimingClient> gpu_timing_client_;
90 scoped_refptr<Outputter> outputter_;
91 std::vector<TraceMarker> markers_[NUM_TRACER_SOURCES];
92 std::deque<scoped_refptr<GPUTrace> > traces_;
94 const unsigned char* gpu_trace_srv_category;
95 const unsigned char* gpu_trace_dev_category;
96 gles2::GLES2Decoder* decoder_;
98 bool gpu_executing_;
99 bool process_posted_;
101 private:
102 DISALLOW_COPY_AND_ASSIGN(GPUTracer);
105 class Outputter : public base::RefCounted<Outputter> {
106 public:
107 virtual void TraceDevice(const std::string& category,
108 const std::string& name,
109 int64 start_time,
110 int64 end_time) = 0;
112 virtual void TraceServiceBegin(const std::string& category,
113 const std::string& name) = 0;
115 virtual void TraceServiceEnd(const std::string& category,
116 const std::string& name) = 0;
118 protected:
119 virtual ~Outputter() {}
120 friend class base::RefCounted<Outputter>;
123 class TraceOutputter : public Outputter {
124 public:
125 static scoped_refptr<TraceOutputter> Create(const std::string& name);
126 void TraceDevice(const std::string& category,
127 const std::string& name,
128 int64 start_time,
129 int64 end_time) override;
131 void TraceServiceBegin(const std::string& category,
132 const std::string& name) override;
134 void TraceServiceEnd(const std::string& category,
135 const std::string& name) override;
137 protected:
138 friend class base::RefCounted<Outputter>;
139 explicit TraceOutputter(const std::string& name);
140 ~TraceOutputter() override;
142 base::Thread named_thread_;
143 uint64 local_trace_id_;
145 private:
146 DISALLOW_COPY_AND_ASSIGN(TraceOutputter);
149 class GPU_EXPORT GPUTrace
150 : public base::RefCounted<GPUTrace> {
151 public:
152 GPUTrace(scoped_refptr<Outputter> outputter,
153 gfx::GPUTimingClient* gpu_timing_client,
154 const std::string& category,
155 const std::string& name,
156 const bool enabled);
158 void Start(bool trace_service);
159 void End(bool tracing_service);
160 bool IsAvailable();
161 bool IsEnabled() { return enabled_; }
162 void Process();
164 private:
165 ~GPUTrace();
167 void Output();
169 friend class base::RefCounted<GPUTrace>;
171 std::string category_;
172 std::string name_;
173 scoped_refptr<Outputter> outputter_;
174 scoped_ptr<gfx::GPUTimer> gpu_timer_;
175 const bool enabled_ = false;
177 DISALLOW_COPY_AND_ASSIGN(GPUTrace);
180 class ScopedGPUTrace {
181 public:
182 ScopedGPUTrace(GPUTracer* gpu_tracer,
183 GpuTracerSource source,
184 const std::string& category,
185 const std::string& name)
186 : gpu_tracer_(gpu_tracer), source_(source) {
187 gpu_tracer_->Begin(category, name, source_);
190 ~ScopedGPUTrace() { gpu_tracer_->End(source_); }
192 private:
193 GPUTracer* gpu_tracer_;
194 GpuTracerSource source_;
197 } // namespace gles2
198 } // namespace gpu
200 #endif // GPU_COMMAND_BUFFER_SERVICE_GPU_TRACER_H_