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 // This file contains the GPUTrace class. | 5 // This file contains the GPUTrace class. |
6 #ifndef GPU_COMMAND_BUFFER_SERVICE_GPU_TRACER_H_ | 6 #ifndef GPU_COMMAND_BUFFER_SERVICE_GPU_TRACER_H_ |
7 #define GPU_COMMAND_BUFFER_SERVICE_GPU_TRACER_H_ | 7 #define GPU_COMMAND_BUFFER_SERVICE_GPU_TRACER_H_ |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 NUM_TRACER_SOURCES | 33 NUM_TRACER_SOURCES |
34 }; | 34 }; |
35 | 35 |
36 enum GpuTracerType { | 36 enum GpuTracerType { |
37 kTracerTypeInvalid = -1, | 37 kTracerTypeInvalid = -1, |
38 | 38 |
39 kTracerTypeARBTimer, | 39 kTracerTypeARBTimer, |
40 kTracerTypeDisjointTimer | 40 kTracerTypeDisjointTimer |
41 }; | 41 }; |
42 | 42 |
| 43 // Central accesser to CPU Time |
| 44 class GPU_EXPORT CPUTime |
| 45 : public base::RefCounted<CPUTime> { |
| 46 public: |
| 47 CPUTime(); |
| 48 |
| 49 virtual int64 GetCurrentTime(); |
| 50 |
| 51 protected: |
| 52 virtual ~CPUTime(); |
| 53 friend class base::RefCounted<CPUTime>; |
| 54 |
| 55 DISALLOW_COPY_AND_ASSIGN(CPUTime); |
| 56 }; |
| 57 |
43 // Marker structure for a Trace. | 58 // Marker structure for a Trace. |
44 struct TraceMarker { | 59 struct TraceMarker { |
45 TraceMarker(const std::string& category, const std::string& name); | 60 TraceMarker(const std::string& category, const std::string& name); |
46 ~TraceMarker(); | 61 ~TraceMarker(); |
47 | 62 |
48 std::string category_; | 63 std::string category_; |
49 std::string name_; | 64 std::string name_; |
50 scoped_refptr<GPUTrace> trace_; | 65 scoped_refptr<GPUTrace> trace_; |
51 }; | 66 }; |
52 | 67 |
53 // Traces GPU Commands. | 68 // Traces GPU Commands. |
54 class GPUTracer : public base::SupportsWeakPtr<GPUTracer> { | 69 class GPU_EXPORT GPUTracer |
| 70 : public base::SupportsWeakPtr<GPUTracer> { |
55 public: | 71 public: |
56 explicit GPUTracer(gles2::GLES2Decoder* decoder); | 72 explicit GPUTracer(gles2::GLES2Decoder* decoder); |
57 ~GPUTracer(); | 73 virtual ~GPUTracer(); |
58 | 74 |
59 // Scheduled processing in decoder begins. | 75 // Scheduled processing in decoder begins. |
60 bool BeginDecoding(); | 76 bool BeginDecoding(); |
61 | 77 |
62 // Scheduled processing in decoder ends. | 78 // Scheduled processing in decoder ends. |
63 bool EndDecoding(); | 79 bool EndDecoding(); |
64 | 80 |
65 // Begin a trace marker. | 81 // Begin a trace marker. |
66 bool Begin(const std::string& category, const std::string& name, | 82 bool Begin(const std::string& category, const std::string& name, |
67 GpuTracerSource source); | 83 GpuTracerSource source); |
68 | 84 |
69 // End the last started trace marker. | 85 // End the last started trace marker. |
70 bool End(GpuTracerSource source); | 86 bool End(GpuTracerSource source); |
71 | 87 |
72 bool IsTracing(); | 88 virtual bool IsTracing(); |
73 | 89 |
74 // Retrieve the name of the current open trace. | 90 // Retrieve the name of the current open trace. |
75 // Returns empty string if no current open trace. | 91 // Returns empty string if no current open trace. |
76 const std::string& CurrentCategory() const; | 92 const std::string& CurrentCategory() const; |
77 const std::string& CurrentName() const; | 93 const std::string& CurrentName() const; |
78 | 94 |
79 private: | 95 protected: |
80 // Trace Processing. | 96 // Trace Processing. |
81 scoped_refptr<GPUTrace> CreateTrace(const std::string& category, | 97 scoped_refptr<GPUTrace> CreateTrace(const std::string& category, |
82 const std::string& name); | 98 const std::string& name); |
| 99 virtual scoped_refptr<Outputter> CreateOutputter(const std::string& name); |
| 100 virtual scoped_refptr<CPUTime> CreateCPUTime(); |
| 101 virtual GpuTracerType DetermineTracerType(); |
| 102 virtual void PostTask(); |
| 103 |
83 void Process(); | 104 void Process(); |
84 void ProcessTraces(); | 105 void ProcessTraces(); |
85 | 106 |
86 void CalculateTimerOffset(); | 107 void CalculateTimerOffset(); |
87 void IssueProcessTask(); | 108 void IssueProcessTask(); |
88 | 109 |
89 scoped_refptr<Outputter> outputter_; | 110 scoped_refptr<Outputter> outputter_; |
| 111 scoped_refptr<CPUTime> cpu_time_; |
90 std::vector<TraceMarker> markers_[NUM_TRACER_SOURCES]; | 112 std::vector<TraceMarker> markers_[NUM_TRACER_SOURCES]; |
91 std::deque<scoped_refptr<GPUTrace> > traces_; | 113 std::deque<scoped_refptr<GPUTrace> > traces_; |
92 | 114 |
93 const unsigned char* gpu_trace_srv_category; | 115 const unsigned char* gpu_trace_srv_category; |
94 const unsigned char* gpu_trace_dev_category; | 116 const unsigned char* gpu_trace_dev_category; |
95 gles2::GLES2Decoder* decoder_; | 117 gles2::GLES2Decoder* decoder_; |
96 | 118 |
97 int64 timer_offset_; | 119 int64 timer_offset_; |
98 GpuTracerSource last_tracer_source_; | 120 GpuTracerSource last_tracer_source_; |
99 | 121 |
100 GpuTracerType tracer_type_; | 122 GpuTracerType tracer_type_; |
101 bool gpu_timing_synced_; | 123 bool gpu_timing_synced_; |
102 bool gpu_executing_; | 124 bool gpu_executing_; |
103 bool process_posted_; | 125 bool process_posted_; |
104 | 126 |
105 DISALLOW_COPY_AND_ASSIGN(GPUTracer); | 127 DISALLOW_COPY_AND_ASSIGN(GPUTracer); |
106 }; | 128 }; |
107 | 129 |
108 class Outputter : public base::RefCounted<Outputter> { | 130 class Outputter : public base::RefCounted<Outputter> { |
109 public: | 131 public: |
110 virtual void Trace(const std::string& category, | 132 virtual void TraceDevice(const std::string& category, |
111 const std::string& name, | 133 const std::string& name, |
112 int64 start_time, | 134 int64 start_time, |
113 int64 end_time) = 0; | 135 int64 end_time) = 0; |
| 136 |
| 137 virtual void TraceServiceBegin(const std::string& category, |
| 138 const std::string& name, |
| 139 void* id) = 0; |
| 140 |
| 141 virtual void TraceServiceEnd(const std::string& category, |
| 142 const std::string& name, |
| 143 void* id) = 0; |
114 | 144 |
115 protected: | 145 protected: |
116 virtual ~Outputter() {} | 146 virtual ~Outputter() {} |
117 friend class base::RefCounted<Outputter>; | 147 friend class base::RefCounted<Outputter>; |
118 }; | 148 }; |
119 | 149 |
120 class TraceOutputter : public Outputter { | 150 class TraceOutputter : public Outputter { |
121 public: | 151 public: |
122 static scoped_refptr<TraceOutputter> Create(const std::string& name); | 152 static scoped_refptr<TraceOutputter> Create(const std::string& name); |
123 void Trace(const std::string& category, | 153 void TraceDevice(const std::string& category, |
124 const std::string& name, | 154 const std::string& name, |
125 int64 start_time, | 155 int64 start_time, |
126 int64 end_time) override; | 156 int64 end_time) override; |
| 157 |
| 158 void TraceServiceBegin(const std::string& category, |
| 159 const std::string& name, |
| 160 void* id) override; |
| 161 |
| 162 void TraceServiceEnd(const std::string& category, |
| 163 const std::string& name, |
| 164 void* id) override; |
127 | 165 |
128 protected: | 166 protected: |
129 friend class base::RefCounted<Outputter>; | 167 friend class base::RefCounted<Outputter>; |
130 explicit TraceOutputter(const std::string& name); | 168 explicit TraceOutputter(const std::string& name); |
131 ~TraceOutputter() override; | 169 ~TraceOutputter() override; |
132 | 170 |
133 base::Thread named_thread_; | 171 base::Thread named_thread_; |
134 uint64 local_trace_id_; | 172 uint64 local_trace_id_; |
135 | 173 |
136 DISALLOW_COPY_AND_ASSIGN(TraceOutputter); | 174 DISALLOW_COPY_AND_ASSIGN(TraceOutputter); |
137 }; | 175 }; |
138 | 176 |
139 class GPU_EXPORT GPUTrace | 177 class GPU_EXPORT GPUTrace |
140 : public base::RefCounted<GPUTrace> { | 178 : public base::RefCounted<GPUTrace> { |
141 public: | 179 public: |
142 GPUTrace(scoped_refptr<Outputter> outputter, | 180 GPUTrace(scoped_refptr<Outputter> outputter, |
| 181 scoped_refptr<CPUTime> cpu_time, |
143 const std::string& category, | 182 const std::string& category, |
144 const std::string& name, | 183 const std::string& name, |
145 int64 offset, | 184 int64 offset, |
146 GpuTracerType tracer_type); | 185 GpuTracerType tracer_type); |
147 | 186 |
148 bool IsEnabled() { return tracer_type_ != kTracerTypeInvalid; } | 187 bool IsEnabled() { return tracer_type_ != kTracerTypeInvalid; } |
149 | 188 |
150 const std::string& category() { return category_; } | 189 const std::string& category() { return category_; } |
151 const std::string& name() { return name_; } | 190 const std::string& name() { return name_; } |
152 | 191 |
153 void Start(bool trace_service); | 192 void Start(bool trace_service); |
154 void End(bool tracing_service); | 193 void End(bool tracing_service); |
155 bool IsAvailable(); | 194 bool IsAvailable(); |
156 void Process(); | 195 void Process(); |
157 | 196 |
158 private: | 197 private: |
159 ~GPUTrace(); | 198 ~GPUTrace(); |
160 | 199 |
161 void Output(); | 200 void Output(); |
162 | 201 |
163 friend class base::RefCounted<GPUTrace>; | 202 friend class base::RefCounted<GPUTrace>; |
164 | 203 |
165 std::string category_; | 204 std::string category_; |
166 std::string name_; | 205 std::string name_; |
167 scoped_refptr<Outputter> outputter_; | 206 scoped_refptr<Outputter> outputter_; |
| 207 scoped_refptr<CPUTime> cpu_time_; |
168 | 208 |
169 int64 offset_; | 209 int64 offset_; |
170 int64 start_time_; | 210 int64 start_time_; |
171 int64 end_time_; | 211 int64 end_time_; |
172 GpuTracerType tracer_type_; | 212 GpuTracerType tracer_type_; |
173 bool end_requested_; | 213 bool end_requested_; |
174 | 214 |
175 GLuint queries_[2]; | 215 GLuint queries_[2]; |
176 | 216 |
177 DISALLOW_COPY_AND_ASSIGN(GPUTrace); | 217 DISALLOW_COPY_AND_ASSIGN(GPUTrace); |
178 }; | 218 }; |
179 | 219 |
180 } // namespace gles2 | 220 } // namespace gles2 |
181 } // namespace gpu | 221 } // namespace gpu |
182 | 222 |
183 #endif // GPU_COMMAND_BUFFER_SERVICE_GPU_TRACER_H_ | 223 #endif // GPU_COMMAND_BUFFER_SERVICE_GPU_TRACER_H_ |
OLD | NEW |