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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 #ifndef BASE_DEBUG_TRACE_EVENT_H_ | 83 #ifndef BASE_DEBUG_TRACE_EVENT_H_ |
84 #define BASE_DEBUG_TRACE_EVENT_H_ | 84 #define BASE_DEBUG_TRACE_EVENT_H_ |
85 #pragma once | 85 #pragma once |
86 | 86 |
87 #include "build/build_config.h" | 87 #include "build/build_config.h" |
88 | 88 |
89 #include <string> | 89 #include <string> |
90 #include <vector> | 90 #include <vector> |
91 | 91 |
92 #include "base/callback.h" | 92 #include "base/callback.h" |
| 93 #include "base/hash_tables.h" |
93 #include "base/memory/singleton.h" | 94 #include "base/memory/singleton.h" |
94 #include "base/string_util.h" | 95 #include "base/string_util.h" |
95 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 96 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
96 #include "base/timer.h" | 97 #include "base/timer.h" |
97 | 98 |
98 // Older style trace macros with explicit id and extra data | 99 // Older style trace macros with explicit id and extra data |
99 // Only these macros result in publishing data to ETW as currently implemented. | 100 // Only these macros result in publishing data to ETW as currently implemented. |
100 #define TRACE_EVENT_BEGIN_ETW(name, id, extra) \ | 101 #define TRACE_EVENT_BEGIN_ETW(name, id, extra) \ |
101 base::debug::TraceLog::AddTraceEventEtw( \ | 102 base::debug::TraceLog::AddTraceEventEtw( \ |
102 base::debug::TRACE_EVENT_PHASE_BEGIN, \ | 103 base::debug::TRACE_EVENT_PHASE_BEGIN, \ |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 const char* name; | 290 const char* name; |
290 volatile bool enabled; | 291 volatile bool enabled; |
291 }; | 292 }; |
292 | 293 |
293 const size_t kTraceMaxNumArgs = 2; | 294 const size_t kTraceMaxNumArgs = 2; |
294 | 295 |
295 // Phase indicates the nature of an event entry. E.g. part of a begin/end pair. | 296 // Phase indicates the nature of an event entry. E.g. part of a begin/end pair. |
296 enum TraceEventPhase { | 297 enum TraceEventPhase { |
297 TRACE_EVENT_PHASE_BEGIN, | 298 TRACE_EVENT_PHASE_BEGIN, |
298 TRACE_EVENT_PHASE_END, | 299 TRACE_EVENT_PHASE_END, |
299 TRACE_EVENT_PHASE_INSTANT | 300 TRACE_EVENT_PHASE_INSTANT, |
| 301 TRACE_EVENT_PHASE_METADATA |
300 }; | 302 }; |
301 | 303 |
302 // Simple union of values. This is much lighter weight than base::Value, which | 304 // Simple union of values. This is much lighter weight than base::Value, which |
303 // requires dynamic allocation and a vtable. To keep the trace runtime overhead | 305 // requires dynamic allocation and a vtable. To keep the trace runtime overhead |
304 // low, we want constant size storage here. | 306 // low, we want constant size storage here. |
305 class BASE_API TraceValue { | 307 class BASE_API TraceValue { |
306 public: | 308 public: |
307 enum Type { | 309 enum Type { |
308 TRACE_TYPE_UNDEFINED, | 310 TRACE_TYPE_UNDEFINED, |
309 TRACE_TYPE_BOOL, | 311 TRACE_TYPE_BOOL, |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 static void Resurrect(); | 507 static void Resurrect(); |
506 | 508 |
507 private: | 509 private: |
508 // This allows constructor and destructor to be private and usable only | 510 // This allows constructor and destructor to be private and usable only |
509 // by the Singleton class. | 511 // by the Singleton class. |
510 friend struct StaticMemorySingletonTraits<TraceLog>; | 512 friend struct StaticMemorySingletonTraits<TraceLog>; |
511 | 513 |
512 TraceLog(); | 514 TraceLog(); |
513 ~TraceLog(); | 515 ~TraceLog(); |
514 const TraceCategory* GetCategoryInternal(const char* name); | 516 const TraceCategory* GetCategoryInternal(const char* name); |
| 517 void AddCurrentMetadataEvents(); |
515 | 518 |
516 // TODO(nduca): switch to per-thread trace buffers to reduce thread | 519 // TODO(nduca): switch to per-thread trace buffers to reduce thread |
517 // synchronization. | 520 // synchronization. |
518 Lock lock_; | 521 Lock lock_; |
519 bool enabled_; | 522 bool enabled_; |
520 OutputCallback output_callback_; | 523 OutputCallback output_callback_; |
521 BufferFullCallback buffer_full_callback_; | 524 BufferFullCallback buffer_full_callback_; |
522 std::vector<TraceEvent> logged_events_; | 525 std::vector<TraceEvent> logged_events_; |
523 | 526 |
| 527 base::hash_map<PlatformThreadId, std::string> thread_names_; |
| 528 |
524 DISALLOW_COPY_AND_ASSIGN(TraceLog); | 529 DISALLOW_COPY_AND_ASSIGN(TraceLog); |
525 }; | 530 }; |
526 | 531 |
527 namespace internal { | 532 namespace internal { |
528 | 533 |
529 // Used by TRACE_EVENTx macro. Do not use directly. | 534 // Used by TRACE_EVENTx macro. Do not use directly. |
530 class BASE_API TraceEndOnScopeClose { | 535 class BASE_API TraceEndOnScopeClose { |
531 public: | 536 public: |
532 TraceEndOnScopeClose() : p_data_(NULL) {} | 537 TraceEndOnScopeClose() : p_data_(NULL) {} |
533 ~TraceEndOnScopeClose() { | 538 ~TraceEndOnScopeClose() { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 Data* p_data_; | 594 Data* p_data_; |
590 Data data_; | 595 Data data_; |
591 }; | 596 }; |
592 | 597 |
593 } // namespace internal | 598 } // namespace internal |
594 | 599 |
595 } // namespace debug | 600 } // namespace debug |
596 } // namespace base | 601 } // namespace base |
597 | 602 |
598 #endif // BASE_DEBUG_TRACE_EVENT_H_ | 603 #endif // BASE_DEBUG_TRACE_EVENT_H_ |
OLD | NEW |