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