OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // Trace events are for tracking application performance. | 5 // Trace events are for tracking application performance. |
6 // | 6 // |
7 // Events are issued against categories. Whereas LOG's | 7 // Events are issued against categories. Whereas LOG's |
8 // categories are statically defined, TRACE categories are created | 8 // categories are statically defined, TRACE categories are created |
9 // implicitly with a string. For example: | 9 // implicitly with a string. For example: |
10 // GPU_TRACE_EVENT_INSTANT0("MY_SUBSYSTEM", "SomeImportantEvent") | 10 // GPU_TRACE_EVENT_INSTANT0("MY_SUBSYSTEM", "SomeImportantEvent") |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 }; | 173 }; |
174 | 174 |
175 #define TRACE_MAX_NUM_ARGS 2 | 175 #define TRACE_MAX_NUM_ARGS 2 |
176 | 176 |
177 enum TraceEventPhase { | 177 enum TraceEventPhase { |
178 GPU_TRACE_EVENT_PHASE_BEGIN, | 178 GPU_TRACE_EVENT_PHASE_BEGIN, |
179 GPU_TRACE_EVENT_PHASE_END, | 179 GPU_TRACE_EVENT_PHASE_END, |
180 GPU_TRACE_EVENT_PHASE_INSTANT | 180 GPU_TRACE_EVENT_PHASE_INSTANT |
181 }; | 181 }; |
182 | 182 |
| 183 class TraceAnyType { |
| 184 public: |
| 185 enum Type { |
| 186 NONE, |
| 187 BOOLEAN, |
| 188 UINT, |
| 189 INT, |
| 190 DOUBLE, |
| 191 POINTER, |
| 192 STRING |
| 193 }; |
| 194 |
| 195 TraceAnyType() : type_(NONE) { |
| 196 value_.as_uint = 0ull; |
| 197 } |
| 198 TraceAnyType(bool rhs) : type_(BOOLEAN) { |
| 199 value_.as_uint = 0ull; // zero all bits |
| 200 value_.as_bool = rhs; |
| 201 } |
| 202 TraceAnyType(uint64 rhs) : type_(UINT) { |
| 203 value_.as_uint = rhs; |
| 204 } |
| 205 TraceAnyType(uint32 rhs) : type_(UINT) { |
| 206 value_.as_uint = rhs; |
| 207 } |
| 208 TraceAnyType(uint16 rhs) : type_(UINT) { |
| 209 value_.as_uint = rhs; |
| 210 } |
| 211 TraceAnyType(uint8 rhs) : type_(UINT) { |
| 212 value_.as_uint = rhs; |
| 213 } |
| 214 TraceAnyType(int64 rhs) : type_(INT) { |
| 215 value_.as_int = rhs; |
| 216 } |
| 217 TraceAnyType(int32 rhs) : type_(INT) { |
| 218 value_.as_int = rhs; |
| 219 } |
| 220 TraceAnyType(int16 rhs) : type_(INT) { |
| 221 value_.as_int = rhs; |
| 222 } |
| 223 TraceAnyType(int8 rhs) : type_(INT) { |
| 224 value_.as_int = rhs; |
| 225 } |
| 226 TraceAnyType(double rhs) : type_(DOUBLE) { |
| 227 value_.as_double = rhs; |
| 228 } |
| 229 TraceAnyType(void* rhs) : type_(POINTER) { |
| 230 value_.as_uint = 0ull; // zero all bits |
| 231 value_.as_pointer = rhs; |
| 232 } |
| 233 TraceAnyType(const char* rhs) : type_(STRING) { |
| 234 value_.as_uint = 0ull; // zero all bits |
| 235 value_.as_string = strdup(rhs); |
| 236 } |
| 237 TraceAnyType(const TraceAnyType& rhs) : type_(NONE) { |
| 238 operator=(rhs); |
| 239 } |
| 240 ~TraceAnyType() { |
| 241 Destroy(); |
| 242 } |
| 243 |
| 244 TraceAnyType& operator=(const TraceAnyType& rhs); |
| 245 bool operator==(const TraceAnyType& rhs) const; |
| 246 bool operator!=(const TraceAnyType& rhs) const { |
| 247 return !operator==(rhs); |
| 248 } |
| 249 |
| 250 void Destroy(); |
| 251 |
| 252 void AppendAsJSON(std::string* out) const; |
| 253 |
| 254 Type type() const { |
| 255 return type_; |
| 256 } |
| 257 uint64 as_uint() const { |
| 258 return value_.as_uint; |
| 259 } |
| 260 bool as_bool() const { |
| 261 return value_.as_bool; |
| 262 } |
| 263 int64 as_int() const { |
| 264 return value_.as_int; |
| 265 } |
| 266 double as_double() const { |
| 267 return value_.as_double; |
| 268 } |
| 269 void* as_pointer() const { |
| 270 return value_.as_pointer; |
| 271 } |
| 272 const char* as_string() const { |
| 273 return value_.as_string; |
| 274 } |
| 275 |
| 276 private: |
| 277 union Value { |
| 278 bool as_bool; |
| 279 uint64 as_uint; |
| 280 int64 as_int; |
| 281 double as_double; |
| 282 void* as_pointer; |
| 283 char* as_string; |
| 284 }; |
| 285 |
| 286 Type type_; |
| 287 Value value_; |
| 288 }; |
| 289 |
183 // Output records are "Events" and can be obtained via the | 290 // Output records are "Events" and can be obtained via the |
184 // OutputCallback whenever the logging system decides to flush. This | 291 // OutputCallback whenever the logging system decides to flush. This |
185 // can happen at any time, on any thread, or you can programatically | 292 // can happen at any time, on any thread, or you can programatically |
186 // force it to happen. | 293 // force it to happen. |
187 struct TraceEvent { | 294 struct TraceEvent { |
188 static void AppendAsJSON(std::string* out, | 295 static void AppendAsJSON(std::string* out, |
189 const std::vector<TraceEvent>& events, | 296 const std::vector<TraceEvent>& events, |
190 size_t start, | 297 size_t start, |
191 size_t count); | 298 size_t count); |
192 TraceEvent(); | 299 TraceEvent(); |
193 ~TraceEvent(); | 300 ~TraceEvent(); |
194 void AppendAsJSON(std::string* out) const; | 301 void AppendAsJSON(std::string* out) const; |
195 | 302 |
196 | 303 |
197 unsigned long processId; | 304 unsigned long processId; |
198 unsigned long threadId; | 305 unsigned long threadId; |
199 base::TimeTicks timestamp; | 306 base::TimeTicks timestamp; |
200 TraceEventPhase phase; | 307 TraceEventPhase phase; |
201 TraceCategory* category; | 308 TraceCategory* category; |
202 const char* name; | 309 const char* name; |
203 const char* argNames[TRACE_MAX_NUM_ARGS]; | 310 const char* argNames[TRACE_MAX_NUM_ARGS]; |
204 std::string argValues[TRACE_MAX_NUM_ARGS]; | 311 TraceAnyType argValues[TRACE_MAX_NUM_ARGS]; |
205 }; | 312 }; |
206 | 313 |
207 | 314 |
208 class TraceLog { | 315 class TraceLog { |
209 public: | 316 public: |
210 static TraceLog* GetInstance(); | 317 static TraceLog* GetInstance(); |
211 | 318 |
212 // Global enable of tracing. Currently enables all categories or not. | 319 // Global enable of tracing. Currently enables all categories or not. |
213 // TODO(nduca) Replaced with an Enable/DisableCategory() that | 320 // TODO(nduca) Replaced with an Enable/DisableCategory() that |
214 // implicitly controls the global logging state. | 321 // implicitly controls the global logging state. |
(...skipping 21 matching lines...) Expand all Loading... |
236 void Flush(); | 343 void Flush(); |
237 | 344 |
238 // Called by GPU_TRACE_EVENT* macros, don't call this directly. | 345 // Called by GPU_TRACE_EVENT* macros, don't call this directly. |
239 TraceCategory* GetCategory(const char* name); | 346 TraceCategory* GetCategory(const char* name); |
240 | 347 |
241 // Called by GPU_TRACE_EVENT* macros, don't call this directly. | 348 // Called by GPU_TRACE_EVENT* macros, don't call this directly. |
242 void AddTraceEvent(TraceEventPhase phase, | 349 void AddTraceEvent(TraceEventPhase phase, |
243 const char* file, int line, | 350 const char* file, int line, |
244 TraceCategory* category, | 351 TraceCategory* category, |
245 const char* name, | 352 const char* name, |
246 const char* arg1name, const char* arg1val, | 353 const char* arg1name, TraceAnyType arg1val, |
247 const char* arg2name, const char* arg2val); | 354 const char* arg2name, TraceAnyType arg2val); |
248 | 355 |
249 private: | 356 private: |
250 // This allows constructor and destructor to be private and usable only | 357 // This allows constructor and destructor to be private and usable only |
251 // by the Singleton class. | 358 // by the Singleton class. |
252 friend struct StaticMemorySingletonTraits<TraceLog>; | 359 friend struct StaticMemorySingletonTraits<TraceLog>; |
253 | 360 |
254 TraceLog(); | 361 TraceLog(); |
255 ~TraceLog(); | 362 ~TraceLog(); |
256 void FlushWithLockAlreadyHeld(); | 363 void FlushWithLockAlreadyHeld(); |
257 | 364 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 int line_; | 402 int line_; |
296 TraceCategory* category_; | 403 TraceCategory* category_; |
297 const char* name_; | 404 const char* name_; |
298 }; | 405 }; |
299 | 406 |
300 } // namespace internal | 407 } // namespace internal |
301 | 408 |
302 } // namespace gpu | 409 } // namespace gpu |
303 | 410 |
304 #endif // GPU_TRACE_EVENT_H_ | 411 #endif // GPU_TRACE_EVENT_H_ |
OLD | NEW |