| 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 #define BASE_DEBUG_TRACE_EVENT_H_ | 95 #define BASE_DEBUG_TRACE_EVENT_H_ |
| 96 #pragma once | 96 #pragma once |
| 97 | 97 |
| 98 #include "build/build_config.h" | 98 #include "build/build_config.h" |
| 99 | 99 |
| 100 #include <string> | 100 #include <string> |
| 101 #include <vector> | 101 #include <vector> |
| 102 | 102 |
| 103 #include "base/callback.h" | 103 #include "base/callback.h" |
| 104 #include "base/hash_tables.h" | 104 #include "base/hash_tables.h" |
| 105 #include "base/memory/ref_counted_memory.h" |
| 105 #include "base/memory/singleton.h" | 106 #include "base/memory/singleton.h" |
| 106 #include "base/string_util.h" | 107 #include "base/string_util.h" |
| 107 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 108 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
| 108 #include "base/timer.h" | 109 #include "base/timer.h" |
| 109 | 110 |
| 110 // By default, const char* argument values are assumed to have long-lived scope | 111 // By default, const char* argument values are assumed to have long-lived scope |
| 111 // and will not be copied. Use this macro to force a const char* to be copied. | 112 // and will not be copied. Use this macro to force a const char* to be copied. |
| 112 #define TRACE_STR_COPY(str) base::debug::TraceValue::StringWithCopy(str) | 113 #define TRACE_STR_COPY(str) base::debug::TraceValue::StringWithCopy(str) |
| 113 | 114 |
| 114 // Older style trace macros with explicit id and extra data | 115 // Older style trace macros with explicit id and extra data |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 return value; | 413 return value; |
| 413 } | 414 } |
| 414 | 415 |
| 415 static TraceValue ForceCopy(const TraceValue& rhs) { | 416 static TraceValue ForceCopy(const TraceValue& rhs) { |
| 416 TraceValue value(rhs); | 417 TraceValue value(rhs); |
| 417 if (value.type_ == TRACE_TYPE_STATIC_STRING && value.as_string()) | 418 if (value.type_ == TRACE_TYPE_STATIC_STRING && value.as_string()) |
| 418 value.type_ = TRACE_TYPE_STRING; | 419 value.type_ = TRACE_TYPE_STRING; |
| 419 return value; | 420 return value; |
| 420 } | 421 } |
| 421 | 422 |
| 423 bool is_string() const { |
| 424 return type_ == TRACE_TYPE_STRING || type_ == TRACE_TYPE_STATIC_STRING; |
| 425 } |
| 426 |
| 422 void AppendAsJSON(std::string* out) const; | 427 void AppendAsJSON(std::string* out) const; |
| 423 | 428 |
| 424 Type type() const { | 429 Type type() const { |
| 425 return type_; | 430 return type_; |
| 426 } | 431 } |
| 427 uint64 as_uint() const { | 432 uint64 as_uint() const { |
| 428 DCHECK_EQ(TRACE_TYPE_UINT, type_); | 433 DCHECK_EQ(TRACE_TYPE_UINT, type_); |
| 429 return value_.as_uint; | 434 return value_.as_uint; |
| 430 } | 435 } |
| 431 bool as_bool() const { | 436 bool as_bool() const { |
| 432 DCHECK_EQ(TRACE_TYPE_BOOL, type_); | 437 DCHECK_EQ(TRACE_TYPE_BOOL, type_); |
| 433 return value_.as_bool; | 438 return value_.as_bool; |
| 434 } | 439 } |
| 435 int64 as_int() const { | 440 int64 as_int() const { |
| 436 DCHECK_EQ(TRACE_TYPE_INT, type_); | 441 DCHECK_EQ(TRACE_TYPE_INT, type_); |
| 437 return value_.as_int; | 442 return value_.as_int; |
| 438 } | 443 } |
| 439 double as_double() const { | 444 double as_double() const { |
| 440 DCHECK_EQ(TRACE_TYPE_DOUBLE, type_); | 445 DCHECK_EQ(TRACE_TYPE_DOUBLE, type_); |
| 441 return value_.as_double; | 446 return value_.as_double; |
| 442 } | 447 } |
| 443 const void* as_pointer() const { | 448 const void* as_pointer() const { |
| 444 DCHECK_EQ(TRACE_TYPE_POINTER, type_); | 449 DCHECK_EQ(TRACE_TYPE_POINTER, type_); |
| 445 return value_.as_pointer; | 450 return value_.as_pointer; |
| 446 } | 451 } |
| 447 const char* as_string() const { | 452 const char* as_string() const { |
| 448 DCHECK(type_ == TRACE_TYPE_STRING || type_ == TRACE_TYPE_STATIC_STRING); | 453 DCHECK(is_string()); |
| 449 return value_.as_string; | 454 return value_.as_string; |
| 450 } | 455 } |
| 451 const char** as_assignable_string() { | 456 const char** as_assignable_string() { |
| 452 DCHECK_EQ(TRACE_TYPE_STRING, type_); | 457 DCHECK_EQ(TRACE_TYPE_STRING, type_); |
| 453 return &value_.as_string; | 458 return &value_.as_string; |
| 454 } | 459 } |
| 455 | 460 |
| 456 private: | 461 private: |
| 457 union Value { | 462 union Value { |
| 458 bool as_bool; | 463 bool as_bool; |
| 459 uint64 as_uint; | 464 uint64 as_uint; |
| 460 int64 as_int; | 465 int64 as_int; |
| 461 double as_double; | 466 double as_double; |
| 462 const void* as_pointer; | 467 const void* as_pointer; |
| 463 const char* as_string; | 468 const char* as_string; |
| 464 }; | 469 }; |
| 465 | 470 |
| 466 Type type_; | 471 Type type_; |
| 467 Value value_; | 472 Value value_; |
| 468 }; | 473 }; |
| 469 | 474 |
| 470 // Output records are "Events" and can be obtained via the | 475 // Output records are "Events" and can be obtained via the |
| 471 // OutputCallback whenever the tracing system decides to flush. This | 476 // OutputCallback whenever the tracing system decides to flush. This |
| 472 // can happen at any time, on any thread, or you can programatically | 477 // can happen at any time, on any thread, or you can programatically |
| 473 // force it to happen. | 478 // force it to happen. |
| 474 class TraceEvent { | 479 class BASE_EXPORT TraceEvent { |
| 475 public: | 480 public: |
| 476 TraceEvent(); | 481 TraceEvent(); |
| 477 TraceEvent(unsigned long process_id, | 482 TraceEvent(unsigned long process_id, |
| 478 unsigned long thread_id, | 483 unsigned long thread_id, |
| 479 TimeTicks timestamp, | 484 TimeTicks timestamp, |
| 480 TraceEventPhase phase, | 485 TraceEventPhase phase, |
| 481 const TraceCategory* category, | 486 const TraceCategory* category, |
| 482 const char* name, | 487 const char* name, |
| 483 const char* arg1_name, const TraceValue& arg1_val, | 488 const char* arg1_name, const TraceValue& arg1_val, |
| 484 const char* arg2_name, const TraceValue& arg2_val, | 489 const char* arg2_name, const TraceValue& arg2_val, |
| 485 bool copy); | 490 bool copy); |
| 486 ~TraceEvent(); | 491 ~TraceEvent(); |
| 487 | 492 |
| 493 static const char* GetPhaseString(TraceEventPhase phase); |
| 494 static TraceEventPhase GetPhase(const char* phase); |
| 495 |
| 488 // Serialize event data to JSON | 496 // Serialize event data to JSON |
| 489 static void AppendEventsAsJSON(const std::vector<TraceEvent>& events, | 497 static void AppendEventsAsJSON(const std::vector<TraceEvent>& events, |
| 490 size_t start, | 498 size_t start, |
| 491 size_t count, | 499 size_t count, |
| 492 std::string* out); | 500 std::string* out); |
| 493 void AppendAsJSON(std::string* out) const; | 501 void AppendAsJSON(std::string* out) const; |
| 494 | 502 |
| 495 TimeTicks timestamp() const { return timestamp_; } | 503 TimeTicks timestamp() const { return timestamp_; } |
| 496 | 504 |
| 497 // Exposed for unittesting: | 505 // Exposed for unittesting: |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 Data* p_data_; | 752 Data* p_data_; |
| 745 Data data_; | 753 Data data_; |
| 746 }; | 754 }; |
| 747 | 755 |
| 748 } // namespace internal | 756 } // namespace internal |
| 749 | 757 |
| 750 } // namespace debug | 758 } // namespace debug |
| 751 } // namespace base | 759 } // namespace base |
| 752 | 760 |
| 753 #endif // BASE_DEBUG_TRACE_EVENT_H_ | 761 #endif // BASE_DEBUG_TRACE_EVENT_H_ |
| OLD | NEW |