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 // TRACE_EVENT_INSTANT0("MY_SUBSYSTEM", "SomeImportantEvent") | 10 // TRACE_EVENT_INSTANT0("MY_SUBSYSTEM", "SomeImportantEvent") |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 return value; | 412 return value; |
413 } | 413 } |
414 | 414 |
415 static TraceValue ForceCopy(const TraceValue& rhs) { | 415 static TraceValue ForceCopy(const TraceValue& rhs) { |
416 TraceValue value(rhs); | 416 TraceValue value(rhs); |
417 if (value.type_ == TRACE_TYPE_STATIC_STRING && value.as_string()) | 417 if (value.type_ == TRACE_TYPE_STATIC_STRING && value.as_string()) |
418 value.type_ = TRACE_TYPE_STRING; | 418 value.type_ = TRACE_TYPE_STRING; |
419 return value; | 419 return value; |
420 } | 420 } |
421 | 421 |
| 422 bool is_string() const { |
| 423 return type_ == TRACE_TYPE_STRING || type_ == TRACE_TYPE_STATIC_STRING; |
| 424 } |
| 425 |
422 void AppendAsJSON(std::string* out) const; | 426 void AppendAsJSON(std::string* out) const; |
423 | 427 |
424 Type type() const { | 428 Type type() const { |
425 return type_; | 429 return type_; |
426 } | 430 } |
427 uint64 as_uint() const { | 431 uint64 as_uint() const { |
428 DCHECK_EQ(TRACE_TYPE_UINT, type_); | 432 DCHECK_EQ(TRACE_TYPE_UINT, type_); |
429 return value_.as_uint; | 433 return value_.as_uint; |
430 } | 434 } |
431 bool as_bool() const { | 435 bool as_bool() const { |
432 DCHECK_EQ(TRACE_TYPE_BOOL, type_); | 436 DCHECK_EQ(TRACE_TYPE_BOOL, type_); |
433 return value_.as_bool; | 437 return value_.as_bool; |
434 } | 438 } |
435 int64 as_int() const { | 439 int64 as_int() const { |
436 DCHECK_EQ(TRACE_TYPE_INT, type_); | 440 DCHECK_EQ(TRACE_TYPE_INT, type_); |
437 return value_.as_int; | 441 return value_.as_int; |
438 } | 442 } |
439 double as_double() const { | 443 double as_double() const { |
440 DCHECK_EQ(TRACE_TYPE_DOUBLE, type_); | 444 DCHECK_EQ(TRACE_TYPE_DOUBLE, type_); |
441 return value_.as_double; | 445 return value_.as_double; |
442 } | 446 } |
443 const void* as_pointer() const { | 447 const void* as_pointer() const { |
444 DCHECK_EQ(TRACE_TYPE_POINTER, type_); | 448 DCHECK_EQ(TRACE_TYPE_POINTER, type_); |
445 return value_.as_pointer; | 449 return value_.as_pointer; |
446 } | 450 } |
447 const char* as_string() const { | 451 const char* as_string() const { |
448 DCHECK(type_ == TRACE_TYPE_STRING || type_ == TRACE_TYPE_STATIC_STRING); | 452 DCHECK(is_string()); |
449 return value_.as_string; | 453 return value_.as_string; |
450 } | 454 } |
451 const char** as_assignable_string() { | 455 const char** as_assignable_string() { |
452 DCHECK_EQ(TRACE_TYPE_STRING, type_); | 456 DCHECK_EQ(TRACE_TYPE_STRING, type_); |
453 return &value_.as_string; | 457 return &value_.as_string; |
454 } | 458 } |
455 | 459 |
456 private: | 460 private: |
457 union Value { | 461 union Value { |
458 bool as_bool; | 462 bool as_bool; |
(...skipping 19 matching lines...) Expand all Loading... |
478 unsigned long thread_id, | 482 unsigned long thread_id, |
479 TimeTicks timestamp, | 483 TimeTicks timestamp, |
480 TraceEventPhase phase, | 484 TraceEventPhase phase, |
481 const TraceCategory* category, | 485 const TraceCategory* category, |
482 const char* name, | 486 const char* name, |
483 const char* arg1_name, const TraceValue& arg1_val, | 487 const char* arg1_name, const TraceValue& arg1_val, |
484 const char* arg2_name, const TraceValue& arg2_val, | 488 const char* arg2_name, const TraceValue& arg2_val, |
485 bool copy); | 489 bool copy); |
486 ~TraceEvent(); | 490 ~TraceEvent(); |
487 | 491 |
| 492 static const char* GetPhaseStr(TraceEventPhase phase); |
| 493 static TraceEventPhase GetPhase(const char* phase); |
| 494 |
488 // Serialize event data to JSON | 495 // Serialize event data to JSON |
489 static void AppendEventsAsJSON(const std::vector<TraceEvent>& events, | 496 static void AppendEventsAsJSON(const std::vector<TraceEvent>& events, |
490 size_t start, | 497 size_t start, |
491 size_t count, | 498 size_t count, |
492 std::string* out); | 499 std::string* out); |
493 void AppendAsJSON(std::string* out) const; | 500 void AppendAsJSON(std::string* out) const; |
494 | 501 |
495 TimeTicks timestamp() const { return timestamp_; } | 502 TimeTicks timestamp() const { return timestamp_; } |
496 | 503 |
497 // Exposed for unittesting: | 504 // Exposed for unittesting: |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
698 Data* p_data_; | 705 Data* p_data_; |
699 Data data_; | 706 Data data_; |
700 }; | 707 }; |
701 | 708 |
702 } // namespace internal | 709 } // namespace internal |
703 | 710 |
704 } // namespace debug | 711 } // namespace debug |
705 } // namespace base | 712 } // namespace base |
706 | 713 |
707 #endif // BASE_DEBUG_TRACE_EVENT_H_ | 714 #endif // BASE_DEBUG_TRACE_EVENT_H_ |
OLD | NEW |