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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 | 65 |
66 #include <string> | 66 #include <string> |
67 | 67 |
68 #include "base/memory/scoped_ptr.h" | 68 #include "base/memory/scoped_ptr.h" |
69 #include "base/atomicops.h" | 69 #include "base/atomicops.h" |
70 #include "base/memory/scoped_vector.h" | 70 #include "base/memory/scoped_vector.h" |
71 #include "base/memory/singleton.h" | 71 #include "base/memory/singleton.h" |
72 #include "base/time.h" | 72 #include "base/time.h" |
73 #include "base/timer.h" | 73 #include "base/timer.h" |
74 #include "base/callback.h" | 74 #include "base/callback.h" |
| 75 #include "base/string_util.h" |
75 #include <vector> | 76 #include <vector> |
76 | 77 |
77 | 78 |
78 // Implementation detail: trace event macros create temporary variables | 79 // Implementation detail: trace event macros create temporary variables |
79 // to keep instrumentation overhead low. These macros give each temporary | 80 // to keep instrumentation overhead low. These macros give each temporary |
80 // variable a unique name based on the line number to prevent name collissions. | 81 // variable a unique name based on the line number to prevent name collissions. |
81 #define GPU_TRACE_EVENT_UNIQUE_IDENTIFIER3(a,b) a##b | 82 #define GPU_TRACE_EVENT_UNIQUE_IDENTIFIER3(a,b) a##b |
82 #define GPU_TRACE_EVENT_UNIQUE_IDENTIFIER2(a,b) \ | 83 #define GPU_TRACE_EVENT_UNIQUE_IDENTIFIER2(a,b) \ |
83 GPU_TRACE_EVENT_UNIQUE_IDENTIFIER3(a,b) | 84 GPU_TRACE_EVENT_UNIQUE_IDENTIFIER3(a,b) |
84 #define GPU_TRACE_EVENT_UNIQUE_IDENTIFIER(name_prefix) \ | 85 #define GPU_TRACE_EVENT_UNIQUE_IDENTIFIER(name_prefix) \ |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 }; | 193 }; |
193 | 194 |
194 #define TRACE_MAX_NUM_ARGS 2 | 195 #define TRACE_MAX_NUM_ARGS 2 |
195 | 196 |
196 enum TraceEventPhase { | 197 enum TraceEventPhase { |
197 GPU_TRACE_EVENT_PHASE_BEGIN, | 198 GPU_TRACE_EVENT_PHASE_BEGIN, |
198 GPU_TRACE_EVENT_PHASE_END, | 199 GPU_TRACE_EVENT_PHASE_END, |
199 GPU_TRACE_EVENT_PHASE_INSTANT | 200 GPU_TRACE_EVENT_PHASE_INSTANT |
200 }; | 201 }; |
201 | 202 |
| 203 // Simple union of values. This is much lighter weight than base::Value, which |
| 204 // requires dynamic allocation and a vtable. To keep the trace runtime overhead |
| 205 // low, we want constant size storage here. |
| 206 class TraceValue { |
| 207 public: |
| 208 enum Type { |
| 209 TRACE_TYPE_UNDEFINED, |
| 210 TRACE_TYPE_BOOL, |
| 211 TRACE_TYPE_UINT, |
| 212 TRACE_TYPE_INT, |
| 213 TRACE_TYPE_DOUBLE, |
| 214 TRACE_TYPE_POINTER, |
| 215 TRACE_TYPE_STRING |
| 216 }; |
| 217 |
| 218 TraceValue() : type_(TRACE_TYPE_UNDEFINED) { |
| 219 value_.as_uint = 0ull; |
| 220 } |
| 221 TraceValue(bool rhs) : type_(TRACE_TYPE_BOOL) { |
| 222 value_.as_uint = 0ull; // zero all bits |
| 223 value_.as_bool = rhs; |
| 224 } |
| 225 TraceValue(uint64 rhs) : type_(TRACE_TYPE_UINT) { |
| 226 value_.as_uint = rhs; |
| 227 } |
| 228 TraceValue(uint32 rhs) : type_(TRACE_TYPE_UINT) { |
| 229 value_.as_uint = rhs; |
| 230 } |
| 231 TraceValue(uint16 rhs) : type_(TRACE_TYPE_UINT) { |
| 232 value_.as_uint = rhs; |
| 233 } |
| 234 TraceValue(uint8 rhs) : type_(TRACE_TYPE_UINT) { |
| 235 value_.as_uint = rhs; |
| 236 } |
| 237 TraceValue(int64 rhs) : type_(TRACE_TYPE_INT) { |
| 238 value_.as_int = rhs; |
| 239 } |
| 240 TraceValue(int32 rhs) : type_(TRACE_TYPE_INT) { |
| 241 value_.as_int = rhs; |
| 242 } |
| 243 TraceValue(int16 rhs) : type_(TRACE_TYPE_INT) { |
| 244 value_.as_int = rhs; |
| 245 } |
| 246 TraceValue(int8 rhs) : type_(TRACE_TYPE_INT) { |
| 247 value_.as_int = rhs; |
| 248 } |
| 249 TraceValue(double rhs) : type_(TRACE_TYPE_DOUBLE) { |
| 250 value_.as_double = rhs; |
| 251 } |
| 252 TraceValue(const void* rhs) : type_(TRACE_TYPE_POINTER) { |
| 253 value_.as_uint = 0ull; // zero all bits |
| 254 value_.as_pointer = rhs; |
| 255 } |
| 256 explicit TraceValue(const char* rhs) : type_(TRACE_TYPE_STRING) { |
| 257 value_.as_uint = 0ull; // zero all bits |
| 258 value_.as_string = base::strdup(rhs); |
| 259 } |
| 260 TraceValue(const TraceValue& rhs) : type_(TRACE_TYPE_UNDEFINED) { |
| 261 operator=(rhs); |
| 262 } |
| 263 ~TraceValue() { |
| 264 Destroy(); |
| 265 } |
| 266 |
| 267 TraceValue& operator=(const TraceValue& rhs); |
| 268 bool operator==(const TraceValue& rhs) const; |
| 269 bool operator!=(const TraceValue& rhs) const { |
| 270 return !operator==(rhs); |
| 271 } |
| 272 |
| 273 void Destroy(); |
| 274 |
| 275 void AppendAsJSON(std::string* out) const; |
| 276 |
| 277 Type type() const { |
| 278 return type_; |
| 279 } |
| 280 uint64 as_uint() const { |
| 281 return value_.as_uint; |
| 282 } |
| 283 bool as_bool() const { |
| 284 return value_.as_bool; |
| 285 } |
| 286 int64 as_int() const { |
| 287 return value_.as_int; |
| 288 } |
| 289 double as_double() const { |
| 290 return value_.as_double; |
| 291 } |
| 292 const void* as_pointer() const { |
| 293 return value_.as_pointer; |
| 294 } |
| 295 const char* as_string() const { |
| 296 return value_.as_string; |
| 297 } |
| 298 |
| 299 private: |
| 300 union Value { |
| 301 bool as_bool; |
| 302 uint64 as_uint; |
| 303 int64 as_int; |
| 304 double as_double; |
| 305 const void* as_pointer; |
| 306 char* as_string; |
| 307 }; |
| 308 |
| 309 Type type_; |
| 310 Value value_; |
| 311 }; |
| 312 |
202 // Output records are "Events" and can be obtained via the | 313 // Output records are "Events" and can be obtained via the |
203 // OutputCallback whenever the logging system decides to flush. This | 314 // OutputCallback whenever the logging system decides to flush. This |
204 // can happen at any time, on any thread, or you can programatically | 315 // can happen at any time, on any thread, or you can programatically |
205 // force it to happen. | 316 // force it to happen. |
206 struct TraceEvent { | 317 struct TraceEvent { |
207 static void AppendAsJSON(std::string* out, | 318 static void AppendAsJSON(std::string* out, |
208 const std::vector<TraceEvent>& events, | 319 const std::vector<TraceEvent>& events, |
209 size_t start, | 320 size_t start, |
210 size_t count); | 321 size_t count); |
211 TraceEvent(); | 322 TraceEvent(); |
212 ~TraceEvent(); | 323 ~TraceEvent(); |
213 void AppendAsJSON(std::string* out) const; | 324 void AppendAsJSON(std::string* out) const; |
214 | 325 |
215 | 326 |
216 unsigned long processId; | 327 unsigned long processId; |
217 unsigned long threadId; | 328 unsigned long threadId; |
218 base::TimeTicks timestamp; | 329 base::TimeTicks timestamp; |
219 TraceEventPhase phase; | 330 TraceEventPhase phase; |
220 TraceCategory* category; | 331 TraceCategory* category; |
221 const char* name; | 332 const char* name; |
222 const char* argNames[TRACE_MAX_NUM_ARGS]; | 333 const char* argNames[TRACE_MAX_NUM_ARGS]; |
223 std::string argValues[TRACE_MAX_NUM_ARGS]; | 334 TraceValue argValues[TRACE_MAX_NUM_ARGS]; |
224 }; | 335 }; |
225 | 336 |
226 | 337 |
227 class TraceLog { | 338 class TraceLog { |
228 public: | 339 public: |
229 static TraceLog* GetInstance(); | 340 static TraceLog* GetInstance(); |
230 | 341 |
231 // Global enable of tracing. Currently enables all categories or not. | 342 // Global enable of tracing. Currently enables all categories or not. |
232 // TODO(nduca) Replaced with an Enable/DisableCategory() that | 343 // TODO(nduca) Replaced with an Enable/DisableCategory() that |
233 // implicitly controls the global logging state. | 344 // implicitly controls the global logging state. |
(...skipping 21 matching lines...) Expand all Loading... |
255 void Flush(); | 366 void Flush(); |
256 | 367 |
257 // Called by GPU_TRACE_EVENT* macros, don't call this directly. | 368 // Called by GPU_TRACE_EVENT* macros, don't call this directly. |
258 TraceCategory* GetCategory(const char* name); | 369 TraceCategory* GetCategory(const char* name); |
259 | 370 |
260 // Called by GPU_TRACE_EVENT* macros, don't call this directly. | 371 // Called by GPU_TRACE_EVENT* macros, don't call this directly. |
261 void AddTraceEvent(TraceEventPhase phase, | 372 void AddTraceEvent(TraceEventPhase phase, |
262 const char* file, int line, | 373 const char* file, int line, |
263 TraceCategory* category, | 374 TraceCategory* category, |
264 const char* name, | 375 const char* name, |
265 const char* arg1name, const char* arg1val, | 376 const char* arg1name, TraceValue arg1val, |
266 const char* arg2name, const char* arg2val); | 377 const char* arg2name, TraceValue arg2val); |
267 | 378 |
268 private: | 379 private: |
269 // This allows constructor and destructor to be private and usable only | 380 // This allows constructor and destructor to be private and usable only |
270 // by the Singleton class. | 381 // by the Singleton class. |
271 friend struct StaticMemorySingletonTraits<TraceLog>; | 382 friend struct StaticMemorySingletonTraits<TraceLog>; |
272 | 383 |
273 TraceLog(); | 384 TraceLog(); |
274 ~TraceLog(); | 385 ~TraceLog(); |
275 void FlushWithLockAlreadyHeld(); | 386 void FlushWithLockAlreadyHeld(); |
276 | 387 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 int line_; | 425 int line_; |
315 TraceCategory* category_; | 426 TraceCategory* category_; |
316 const char* name_; | 427 const char* name_; |
317 }; | 428 }; |
318 | 429 |
319 } // namespace internal | 430 } // namespace internal |
320 | 431 |
321 } // namespace gpu | 432 } // namespace gpu |
322 #endif // __native_client__ | 433 #endif // __native_client__ |
323 #endif // GPU_TRACE_EVENT_H_ | 434 #endif // GPU_TRACE_EVENT_H_ |
OLD | NEW |