Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(716)

Side by Side Diff: base/debug/trace_event.h

Issue 7495031: trace_event support for thread names (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove process names. With thread names, they are redundant. Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | base/debug/trace_event.cc » ('j') | base/debug/trace_event.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 const char* name, 495 const char* name,
494 const void* id, 496 const void* id,
495 const char* extra); 497 const char* extra);
496 static void AddTraceEventEtw(TraceEventPhase phase, 498 static void AddTraceEventEtw(TraceEventPhase phase,
497 const char* name, 499 const char* name,
498 const void* id, 500 const void* id,
499 const std::string& extra) { 501 const std::string& extra) {
500 AddTraceEventEtw(phase, name, id, extra.c_str()); 502 AddTraceEventEtw(phase, name, id, extra.c_str());
501 } 503 }
502 504
505 // Metadata
506 void SetCurrentThreadName(const char* name);
507
503 // Exposed for unittesting only, allows resurrecting our 508 // Exposed for unittesting only, allows resurrecting our
504 // singleton instance post-AtExit processing. 509 // singleton instance post-AtExit processing.
505 static void Resurrect(); 510 static void Resurrect();
506 511
507 private: 512 private:
508 // This allows constructor and destructor to be private and usable only 513 // This allows constructor and destructor to be private and usable only
509 // by the Singleton class. 514 // by the Singleton class.
510 friend struct StaticMemorySingletonTraits<TraceLog>; 515 friend struct StaticMemorySingletonTraits<TraceLog>;
511 516
512 TraceLog(); 517 TraceLog();
513 ~TraceLog(); 518 ~TraceLog();
514 const TraceCategory* GetCategoryInternal(const char* name); 519 const TraceCategory* GetCategoryInternal(const char* name);
520 void AddCurrentMetadataEvents();
515 521
516 // TODO(nduca): switch to per-thread trace buffers to reduce thread 522 // TODO(nduca): switch to per-thread trace buffers to reduce thread
517 // synchronization. 523 // synchronization.
518 Lock lock_; 524 Lock lock_;
519 bool enabled_; 525 bool enabled_;
520 OutputCallback output_callback_; 526 OutputCallback output_callback_;
521 BufferFullCallback buffer_full_callback_; 527 BufferFullCallback buffer_full_callback_;
522 std::vector<TraceEvent> logged_events_; 528 std::vector<TraceEvent> logged_events_;
523 529
530 base::hash_map<PlatformThreadId, std::string> thread_names_;
Sigurður Ásgeirsson 2011/08/02 19:36:41 It looks like this map will grow without bounds as
531
524 DISALLOW_COPY_AND_ASSIGN(TraceLog); 532 DISALLOW_COPY_AND_ASSIGN(TraceLog);
525 }; 533 };
526 534
527 namespace internal { 535 namespace internal {
528 536
529 // Used by TRACE_EVENTx macro. Do not use directly. 537 // Used by TRACE_EVENTx macro. Do not use directly.
530 class BASE_API TraceEndOnScopeClose { 538 class BASE_API TraceEndOnScopeClose {
531 public: 539 public:
532 TraceEndOnScopeClose() : p_data_(NULL) {} 540 TraceEndOnScopeClose() : p_data_(NULL) {}
533 ~TraceEndOnScopeClose() { 541 ~TraceEndOnScopeClose() {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 Data* p_data_; 597 Data* p_data_;
590 Data data_; 598 Data data_;
591 }; 599 };
592 600
593 } // namespace internal 601 } // namespace internal
594 602
595 } // namespace debug 603 } // namespace debug
596 } // namespace base 604 } // namespace base
597 605
598 #endif // BASE_DEBUG_TRACE_EVENT_H_ 606 #endif // BASE_DEBUG_TRACE_EVENT_H_
OLDNEW
« no previous file with comments | « no previous file | base/debug/trace_event.cc » ('j') | base/debug/trace_event.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698