Chromium Code Reviews| 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 // Simple union of values. This is much lighter weight than base::Value, which | |
| 184 // requires dynamic allocation and a vtable. To keep the trace runtime overhead | |
| 185 // low, we want constant size storage here. | |
| 186 class TraceAnyType { | |
|
nduca
2011/04/21 22:15:44
TraceVar or TraceVariadic?
Very similar to PP_Var
jbates
2011/04/21 23:57:53
Done.
| |
| 187 public: | |
| 188 enum Type { | |
| 189 NONE, | |
| 190 BOOLEAN, | |
|
nduca
2011/04/21 22:15:44
/me wonders if we usually prefix with TYPE_? pp_va
jbates
2011/04/21 23:57:53
Done.
| |
| 191 UINT, | |
| 192 INT, | |
| 193 DOUBLE, | |
| 194 POINTER, | |
| 195 STRING | |
| 196 }; | |
| 197 | |
| 198 TraceAnyType() : type_(NONE) { | |
| 199 value_.as_uint = 0ull; | |
| 200 } | |
| 201 TraceAnyType(bool rhs) : type_(BOOLEAN) { | |
| 202 value_.as_uint = 0ull; // zero all bits | |
| 203 value_.as_bool = rhs; | |
| 204 } | |
| 205 TraceAnyType(uint64 rhs) : type_(UINT) { | |
| 206 value_.as_uint = rhs; | |
| 207 } | |
| 208 TraceAnyType(uint32 rhs) : type_(UINT) { | |
| 209 value_.as_uint = rhs; | |
| 210 } | |
| 211 TraceAnyType(uint16 rhs) : type_(UINT) { | |
| 212 value_.as_uint = rhs; | |
| 213 } | |
| 214 TraceAnyType(uint8 rhs) : type_(UINT) { | |
| 215 value_.as_uint = rhs; | |
| 216 } | |
| 217 TraceAnyType(int64 rhs) : type_(INT) { | |
| 218 value_.as_int = rhs; | |
| 219 } | |
| 220 TraceAnyType(int32 rhs) : type_(INT) { | |
| 221 value_.as_int = rhs; | |
| 222 } | |
| 223 TraceAnyType(int16 rhs) : type_(INT) { | |
| 224 value_.as_int = rhs; | |
| 225 } | |
| 226 TraceAnyType(int8 rhs) : type_(INT) { | |
| 227 value_.as_int = rhs; | |
| 228 } | |
| 229 TraceAnyType(double rhs) : type_(DOUBLE) { | |
| 230 value_.as_double = rhs; | |
| 231 } | |
| 232 TraceAnyType(void* rhs) : type_(POINTER) { | |
| 233 value_.as_uint = 0ull; // zero all bits | |
| 234 value_.as_pointer = rhs; | |
| 235 } | |
| 236 TraceAnyType(const char* rhs) : type_(STRING) { | |
| 237 value_.as_uint = 0ull; // zero all bits | |
| 238 value_.as_string = strdup(rhs); | |
| 239 } | |
| 240 TraceAnyType(const TraceAnyType& rhs) : type_(NONE) { | |
| 241 operator=(rhs); | |
| 242 } | |
| 243 ~TraceAnyType() { | |
| 244 Destroy(); | |
| 245 } | |
| 246 | |
| 247 TraceAnyType& operator=(const TraceAnyType& rhs); | |
| 248 bool operator==(const TraceAnyType& rhs) const; | |
| 249 bool operator!=(const TraceAnyType& rhs) const { | |
| 250 return !operator==(rhs); | |
| 251 } | |
| 252 | |
| 253 void Destroy(); | |
| 254 | |
| 255 void AppendAsJSON(std::string* out) const; | |
| 256 | |
| 257 Type type() const { | |
| 258 return type_; | |
| 259 } | |
| 260 uint64 as_uint() const { | |
| 261 return value_.as_uint; | |
| 262 } | |
| 263 bool as_bool() const { | |
| 264 return value_.as_bool; | |
| 265 } | |
| 266 int64 as_int() const { | |
| 267 return value_.as_int; | |
| 268 } | |
| 269 double as_double() const { | |
| 270 return value_.as_double; | |
| 271 } | |
| 272 void* as_pointer() const { | |
| 273 return value_.as_pointer; | |
| 274 } | |
| 275 const char* as_string() const { | |
| 276 return value_.as_string; | |
| 277 } | |
| 278 | |
| 279 private: | |
| 280 union Value { | |
| 281 bool as_bool; | |
| 282 uint64 as_uint; | |
| 283 int64 as_int; | |
| 284 double as_double; | |
| 285 void* as_pointer; | |
| 286 char* as_string; | |
| 287 }; | |
| 288 | |
| 289 Type type_; | |
| 290 Value value_; | |
| 291 }; | |
| 292 | |
| 183 // Output records are "Events" and can be obtained via the | 293 // Output records are "Events" and can be obtained via the |
| 184 // OutputCallback whenever the logging system decides to flush. This | 294 // OutputCallback whenever the logging system decides to flush. This |
| 185 // can happen at any time, on any thread, or you can programatically | 295 // can happen at any time, on any thread, or you can programatically |
| 186 // force it to happen. | 296 // force it to happen. |
| 187 struct TraceEvent { | 297 struct TraceEvent { |
| 188 static void AppendAsJSON(std::string* out, | 298 static void AppendAsJSON(std::string* out, |
| 189 const std::vector<TraceEvent>& events, | 299 const std::vector<TraceEvent>& events, |
| 190 size_t start, | 300 size_t start, |
| 191 size_t count); | 301 size_t count); |
| 192 TraceEvent(); | 302 TraceEvent(); |
| 193 ~TraceEvent(); | 303 ~TraceEvent(); |
| 194 void AppendAsJSON(std::string* out) const; | 304 void AppendAsJSON(std::string* out) const; |
| 195 | 305 |
| 196 | 306 |
| 197 unsigned long processId; | 307 unsigned long processId; |
| 198 unsigned long threadId; | 308 unsigned long threadId; |
| 199 base::TimeTicks timestamp; | 309 base::TimeTicks timestamp; |
| 200 TraceEventPhase phase; | 310 TraceEventPhase phase; |
| 201 TraceCategory* category; | 311 TraceCategory* category; |
| 202 const char* name; | 312 const char* name; |
| 203 const char* argNames[TRACE_MAX_NUM_ARGS]; | 313 const char* argNames[TRACE_MAX_NUM_ARGS]; |
| 204 std::string argValues[TRACE_MAX_NUM_ARGS]; | 314 TraceAnyType argValues[TRACE_MAX_NUM_ARGS]; |
| 205 }; | 315 }; |
| 206 | 316 |
| 207 | 317 |
| 208 class TraceLog { | 318 class TraceLog { |
| 209 public: | 319 public: |
| 210 static TraceLog* GetInstance(); | 320 static TraceLog* GetInstance(); |
| 211 | 321 |
| 212 // Global enable of tracing. Currently enables all categories or not. | 322 // Global enable of tracing. Currently enables all categories or not. |
| 213 // TODO(nduca) Replaced with an Enable/DisableCategory() that | 323 // TODO(nduca) Replaced with an Enable/DisableCategory() that |
| 214 // implicitly controls the global logging state. | 324 // implicitly controls the global logging state. |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 236 void Flush(); | 346 void Flush(); |
| 237 | 347 |
| 238 // Called by GPU_TRACE_EVENT* macros, don't call this directly. | 348 // Called by GPU_TRACE_EVENT* macros, don't call this directly. |
| 239 TraceCategory* GetCategory(const char* name); | 349 TraceCategory* GetCategory(const char* name); |
| 240 | 350 |
| 241 // Called by GPU_TRACE_EVENT* macros, don't call this directly. | 351 // Called by GPU_TRACE_EVENT* macros, don't call this directly. |
| 242 void AddTraceEvent(TraceEventPhase phase, | 352 void AddTraceEvent(TraceEventPhase phase, |
| 243 const char* file, int line, | 353 const char* file, int line, |
| 244 TraceCategory* category, | 354 TraceCategory* category, |
| 245 const char* name, | 355 const char* name, |
| 246 const char* arg1name, const char* arg1val, | 356 const char* arg1name, TraceAnyType arg1val, |
| 247 const char* arg2name, const char* arg2val); | 357 const char* arg2name, TraceAnyType arg2val); |
| 248 | 358 |
| 249 private: | 359 private: |
| 250 // This allows constructor and destructor to be private and usable only | 360 // This allows constructor and destructor to be private and usable only |
| 251 // by the Singleton class. | 361 // by the Singleton class. |
| 252 friend struct StaticMemorySingletonTraits<TraceLog>; | 362 friend struct StaticMemorySingletonTraits<TraceLog>; |
| 253 | 363 |
| 254 TraceLog(); | 364 TraceLog(); |
| 255 ~TraceLog(); | 365 ~TraceLog(); |
| 256 void FlushWithLockAlreadyHeld(); | 366 void FlushWithLockAlreadyHeld(); |
| 257 | 367 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 int line_; | 405 int line_; |
| 296 TraceCategory* category_; | 406 TraceCategory* category_; |
| 297 const char* name_; | 407 const char* name_; |
| 298 }; | 408 }; |
| 299 | 409 |
| 300 } // namespace internal | 410 } // namespace internal |
| 301 | 411 |
| 302 } // namespace gpu | 412 } // namespace gpu |
| 303 | 413 |
| 304 #endif // GPU_TRACE_EVENT_H_ | 414 #endif // GPU_TRACE_EVENT_H_ |
| OLD | NEW |