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

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

Issue 7767014: Added support to trace_event for passing static string arguments without copy (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 3 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') | no next file with comments »
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")
11 // 11 //
12 // Events can be INSTANT, or can be pairs of BEGIN and END: 12 // Events can be INSTANT, or can be pairs of BEGIN and END:
13 // TRACE_EVENT_BEGIN0("MY_SUBSYSTEM", "SomethingCostly") 13 // TRACE_EVENT_BEGIN0("MY_SUBSYSTEM", "SomethingCostly")
14 // doSomethingCostly() 14 // doSomethingCostly()
15 // TRACE_EVENT_END0("MY_SUBSYSTEM", "SomethingCostly") 15 // TRACE_EVENT_END0("MY_SUBSYSTEM", "SomethingCostly")
16 // 16 //
17 // A common use case is to trace entire function scopes. This 17 // A common use case is to trace entire function scopes. This
18 // issues a trace BEGIN and END automatically: 18 // issues a trace BEGIN and END automatically:
19 // void doSomethingCostly() { 19 // void doSomethingCostly() {
20 // TRACE_EVENT0("MY_SUBSYSTEM", "doSomethingCostly"); 20 // TRACE_EVENT0("MY_SUBSYSTEM", "doSomethingCostly");
21 // ... 21 // ...
22 // } 22 // }
23 // 23 //
24 // Additional parameters can be associated with an event: 24 // Additional parameters can be associated with an event:
25 // void doSomethingCostly2(int howMuch) { 25 // void doSomethingCostly2(int howMuch) {
26 // TRACE_EVENT1("MY_SUBSYSTEM", "doSomethingCostly", 26 // TRACE_EVENT1("MY_SUBSYSTEM", "doSomethingCostly",
27 // "howMuch", StringPrintf("%i", howMuch).c_str()); 27 // "howMuch", howMuch);
28 // ... 28 // ...
29 // } 29 // }
30 // 30 //
31 // The trace system will automatically add to this information the 31 // The trace system will automatically add to this information the
32 // current process id, thread id, and a timestamp in microseconds. 32 // current process id, thread id, and a timestamp in microseconds.
33 // 33 //
34 // By default, trace collection is compiled in, but turned off at runtime. 34 // By default, trace collection is compiled in, but turned off at runtime.
35 // Collecting trace data is the responsibility of the embedding 35 // Collecting trace data is the responsibility of the embedding
36 // application. In Chrome's case, navigating to about:gpu will turn on 36 // application. In Chrome's case, navigating to about:gpu will turn on
37 // tracing and display data collected across all active processes. 37 // tracing and display data collected across all active processes.
38 // 38 //
39 // 39 //
40 // Memory scoping note: 40 // Memory scoping note:
41 // Tracing copies the pointers, not the string content, of the strings passed 41 // Tracing copies the pointers, not the string content, of the strings passed
42 // in for category, name, and arg_names. Thus, the following code will 42 // in for category, name, and arg_names. Thus, the following code will
43 // cause problems: 43 // cause problems:
44 // char* str = strdup("impprtantName"); 44 // char* str = strdup("impprtantName");
45 // TRACE_EVENT_INSTANT0("SUBSYSTEM", str); // BAD! 45 // TRACE_EVENT_INSTANT0("SUBSYSTEM", str); // BAD!
46 // free(str); // Trace system now has dangling pointer 46 // free(str); // Trace system now has dangling pointer
47 // 47 //
48 // To avoid this issue with the |name| and |arg_name| parameters, use the 48 // To avoid this issue with the |name| and |arg_name| parameters, use the
49 // TRACE_EVENT_COPY_XXX overloads of the macros at additional runtime overhead. 49 // TRACE_EVENT_COPY_XXX overloads of the macros at additional runtime overhead.
50 // Notes: The category must always be in a long-lived char* (i.e. static const). 50 // Notes: The category must always be in a long-lived char* (i.e. static const).
51 // The |arg_values|, when used, are always deep copied and so never have 51 // The |arg_values|, when used, are always deep copied unless type is
52 // this restriction. 52 // const char*, so never have this restriction.
53 //
54 // const char* arg_values are referenced:
55 // TRACE_EVENT1("category", "event1",
John Grabowski 2011/08/30 18:13:38 Comment should have COPY in the name (2 spots)
56 // "arg1", "literal string is only referenced");
57 // std::string arg_values are copied:
58 // TRACE_EVENT1("category", "event2",
John Grabowski 2011/08/30 18:13:38 This actually does not work for us. We convert so
59 // "arg1", std::string("string will be copied"));
53 // 60 //
54 // 61 //
55 // Thread Safety: 62 // Thread Safety:
56 // A thread safe singleton and mutex are used for thread safety. Category 63 // A thread safe singleton and mutex are used for thread safety. Category
57 // enabled flags are used to limit the performance impact when the system 64 // enabled flags are used to limit the performance impact when the system
58 // is not enabled. 65 // is not enabled.
59 // 66 //
60 // TRACE_EVENT macros first cache a pointer to a category. The categories are 67 // TRACE_EVENT macros first cache a pointer to a category. The categories are
61 // statically allocated and safe at all times, even after exit. Fetching a 68 // statically allocated and safe at all times, even after exit. Fetching a
62 // category is protected by the TraceLog::lock_. Multiple threads initializing 69 // category is protected by the TraceLog::lock_. Multiple threads initializing
(...skipping 29 matching lines...) Expand all
92 #include "base/callback.h" 99 #include "base/callback.h"
93 #include "base/hash_tables.h" 100 #include "base/hash_tables.h"
94 #include "base/memory/singleton.h" 101 #include "base/memory/singleton.h"
95 #include "base/string_util.h" 102 #include "base/string_util.h"
96 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" 103 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
97 #include "base/timer.h" 104 #include "base/timer.h"
98 105
99 // Older style trace macros with explicit id and extra data 106 // Older style trace macros with explicit id and extra data
100 // Only these macros result in publishing data to ETW as currently implemented. 107 // Only these macros result in publishing data to ETW as currently implemented.
101 #define TRACE_EVENT_BEGIN_ETW(name, id, extra) \ 108 #define TRACE_EVENT_BEGIN_ETW(name, id, extra) \
102 base::debug::TraceLog::AddTraceEventEtw( \ 109 do { \
103 base::debug::TRACE_EVENT_PHASE_BEGIN, \ 110 INTERNAL_TRACE_EVENT_ETW(name, \
104 name, reinterpret_cast<const void*>(id), extra); 111 base::debug::TRACE_EVENT_PHASE_BEGIN, id, extra); \
112 TRACE_EVENT_BEGIN2("ETW Trace Event", name, \
113 "id", reinterpret_cast<const void*>(id), "extra", extra) \
114 } while(0)
scheib 2011/08/30 16:16:02 Sorry, I'm confused why the changes were needed he
jbates 2011/08/30 17:01:51 The behavior should be the same as before (unless
105 115
106 #define TRACE_EVENT_END_ETW(name, id, extra) \ 116 #define TRACE_EVENT_END_ETW(name, id, extra) \
107 base::debug::TraceLog::AddTraceEventEtw( \ 117 do { \
108 base::debug::TRACE_EVENT_PHASE_END, \ 118 INTERNAL_TRACE_EVENT_ETW(name, \
109 name, reinterpret_cast<const void*>(id), extra); 119 base::debug::TRACE_EVENT_PHASE_END, id, extra); \
120 TRACE_EVENT_END2("ETW Trace Event", name, \
121 "id", reinterpret_cast<const void*>(id), "extra", extra) \
122 } while(0)
110 123
111 #define TRACE_EVENT_INSTANT_ETW(name, id, extra) \ 124 #define TRACE_EVENT_INSTANT_ETW(name, id, extra) \
112 base::debug::TraceLog::AddTraceEventEtw( \ 125 do { \
113 base::debug::TRACE_EVENT_PHASE_INSTANT, \ 126 INTERNAL_TRACE_EVENT_ETW(name, \
114 name, reinterpret_cast<const void*>(id), extra); 127 base::debug::TRACE_EVENT_PHASE_INSTANT, id, extra); \
128 TRACE_EVENT_INSTANT2("ETW Trace Event", name, \
129 "id", reinterpret_cast<const void*>(id), "extra", extra) \
130 } while(0)
115 131
116 // Records a pair of begin and end events called "name" for the current 132 // Records a pair of begin and end events called "name" for the current
117 // scope, with 0, 1 or 2 associated arguments. If the category is not 133 // scope, with 0, 1 or 2 associated arguments. If the category is not
118 // enabled, then this does nothing. 134 // enabled, then this does nothing.
119 // - category and name strings must have application lifetime (statics or 135 // - category and name strings must have application lifetime (statics or
120 // literals). They may not include " chars. 136 // literals). They may not include " chars.
121 #define TRACE_EVENT0(category, name) \ 137 #define TRACE_EVENT0(category, name) \
122 TRACE_EVENT1(category, name, NULL, 0) 138 TRACE_EVENT1(category, name, NULL, 0)
123 #define TRACE_EVENT1(category, name, arg1_name, arg1_val) \ 139 #define TRACE_EVENT1(category, name, arg1_name, arg1_val) \
124 TRACE_EVENT2(category, name, arg1_name, arg1_val, NULL, 0) 140 TRACE_EVENT2(category, name, arg1_name, arg1_val, NULL, 0)
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 int INTERNAL_TRACE_EVENT_UID(begin_event_id) = \ 288 int INTERNAL_TRACE_EVENT_UID(begin_event_id) = \
273 base::debug::TraceLog::GetInstance()->AddTraceEvent( \ 289 base::debug::TraceLog::GetInstance()->AddTraceEvent( \
274 base::debug::TRACE_EVENT_PHASE_BEGIN, \ 290 base::debug::TRACE_EVENT_PHASE_BEGIN, \
275 INTERNAL_TRACE_EVENT_UID(catstatic), \ 291 INTERNAL_TRACE_EVENT_UID(catstatic), \
276 name, arg1_name, arg1_val, arg2_name, arg2_val, -1, 0, false); \ 292 name, arg1_name, arg1_val, arg2_name, arg2_val, -1, 0, false); \
277 INTERNAL_TRACE_EVENT_UID(profileScope).Initialize( \ 293 INTERNAL_TRACE_EVENT_UID(profileScope).Initialize( \
278 INTERNAL_TRACE_EVENT_UID(catstatic), name, \ 294 INTERNAL_TRACE_EVENT_UID(catstatic), name, \
279 INTERNAL_TRACE_EVENT_UID(begin_event_id), threshold); \ 295 INTERNAL_TRACE_EVENT_UID(begin_event_id), threshold); \
280 } 296 }
281 297
298 // Implementation detail: support macro for windows ETW style tracing.
299 #if defined(OS_WIN)
300 #define INTERNAL_TRACE_EVENT_ETW(name, phase, id, extra) \
301 TraceEventETWProvider::Trace( \
302 name, phase, reinterpret_cast<const void*>(id), extra)
303 #else
304 #define INTERNAL_TRACE_EVENT_ETW(name, phase, id, extra)
305 #endif
306
282 namespace base { 307 namespace base {
283 308
284 class RefCountedString; 309 class RefCountedString;
285 310
286 namespace debug { 311 namespace debug {
287 312
288 // Categories allow enabling/disabling of streams of trace events 313 // Categories allow enabling/disabling of streams of trace events
289 struct TraceCategory { 314 struct TraceCategory {
290 const char* name; 315 const char* name;
291 volatile bool enabled; 316 volatile bool enabled;
(...skipping 14 matching lines...) Expand all
306 // low, we want constant size storage here. 331 // low, we want constant size storage here.
307 class BASE_EXPORT TraceValue { 332 class BASE_EXPORT TraceValue {
308 public: 333 public:
309 enum Type { 334 enum Type {
310 TRACE_TYPE_UNDEFINED, 335 TRACE_TYPE_UNDEFINED,
311 TRACE_TYPE_BOOL, 336 TRACE_TYPE_BOOL,
312 TRACE_TYPE_UINT, 337 TRACE_TYPE_UINT,
313 TRACE_TYPE_INT, 338 TRACE_TYPE_INT,
314 TRACE_TYPE_DOUBLE, 339 TRACE_TYPE_DOUBLE,
315 TRACE_TYPE_POINTER, 340 TRACE_TYPE_POINTER,
316 TRACE_TYPE_STRING 341 TRACE_TYPE_STRING,
342 TRACE_TYPE_STATIC_STRING
317 }; 343 };
318 344
319 TraceValue() : type_(TRACE_TYPE_UNDEFINED) { 345 TraceValue() : type_(TRACE_TYPE_UNDEFINED) {
320 value_.as_uint = 0ull; 346 value_.as_uint = 0ull;
321 } 347 }
322 TraceValue(bool rhs) : type_(TRACE_TYPE_BOOL) { 348 TraceValue(bool rhs) : type_(TRACE_TYPE_BOOL) {
323 value_.as_bool = rhs; 349 value_.as_bool = rhs;
324 } 350 }
325 TraceValue(uint64 rhs) : type_(TRACE_TYPE_UINT) { 351 TraceValue(uint64 rhs) : type_(TRACE_TYPE_UINT) {
326 value_.as_uint = rhs; 352 value_.as_uint = rhs;
(...skipping 18 matching lines...) Expand all
345 } 371 }
346 TraceValue(int8 rhs) : type_(TRACE_TYPE_INT) { 372 TraceValue(int8 rhs) : type_(TRACE_TYPE_INT) {
347 value_.as_int = rhs; 373 value_.as_int = rhs;
348 } 374 }
349 TraceValue(double rhs) : type_(TRACE_TYPE_DOUBLE) { 375 TraceValue(double rhs) : type_(TRACE_TYPE_DOUBLE) {
350 value_.as_double = rhs; 376 value_.as_double = rhs;
351 } 377 }
352 TraceValue(const void* rhs) : type_(TRACE_TYPE_POINTER) { 378 TraceValue(const void* rhs) : type_(TRACE_TYPE_POINTER) {
353 value_.as_pointer = rhs; 379 value_.as_pointer = rhs;
354 } 380 }
355 TraceValue(const char* rhs) : type_(TRACE_TYPE_STRING) { 381 TraceValue(const std::string& rhs) : type_(TRACE_TYPE_STRING) {
382 value_.as_string = rhs.c_str();
383 }
384 TraceValue(const char* rhs) : type_(TRACE_TYPE_STATIC_STRING) {
356 value_.as_string = rhs; 385 value_.as_string = rhs;
357 } 386 }
358 387
359 void AppendAsJSON(std::string* out) const; 388 void AppendAsJSON(std::string* out) const;
360 389
361 Type type() const { 390 Type type() const {
362 return type_; 391 return type_;
363 } 392 }
364 uint64 as_uint() const { 393 uint64 as_uint() const {
365 DCHECK_EQ(TRACE_TYPE_UINT, type_); 394 DCHECK_EQ(TRACE_TYPE_UINT, type_);
366 return value_.as_uint; 395 return value_.as_uint;
367 } 396 }
368 bool as_bool() const { 397 bool as_bool() const {
369 DCHECK_EQ(TRACE_TYPE_BOOL, type_); 398 DCHECK_EQ(TRACE_TYPE_BOOL, type_);
370 return value_.as_bool; 399 return value_.as_bool;
371 } 400 }
372 int64 as_int() const { 401 int64 as_int() const {
373 DCHECK_EQ(TRACE_TYPE_INT, type_); 402 DCHECK_EQ(TRACE_TYPE_INT, type_);
374 return value_.as_int; 403 return value_.as_int;
375 } 404 }
376 double as_double() const { 405 double as_double() const {
377 DCHECK_EQ(TRACE_TYPE_DOUBLE, type_); 406 DCHECK_EQ(TRACE_TYPE_DOUBLE, type_);
378 return value_.as_double; 407 return value_.as_double;
379 } 408 }
380 const void* as_pointer() const { 409 const void* as_pointer() const {
381 DCHECK_EQ(TRACE_TYPE_POINTER, type_); 410 DCHECK_EQ(TRACE_TYPE_POINTER, type_);
382 return value_.as_pointer; 411 return value_.as_pointer;
383 } 412 }
384 const char* as_string() const { 413 const char* as_string() const {
385 DCHECK_EQ(TRACE_TYPE_STRING, type_); 414 DCHECK(type_ == TRACE_TYPE_STRING || type_ == TRACE_TYPE_STATIC_STRING);
386 return value_.as_string; 415 return value_.as_string;
387 } 416 }
388 const char** as_assignable_string() { 417 const char** as_assignable_string() {
389 DCHECK_EQ(TRACE_TYPE_STRING, type_); 418 DCHECK_EQ(TRACE_TYPE_STRING, type_);
390 return &value_.as_string; 419 return &value_.as_string;
391 } 420 }
392 421
393 private: 422 private:
394 union Value { 423 union Value {
395 bool as_bool; 424 bool as_bool;
(...skipping 28 matching lines...) Expand all
424 453
425 // Serialize event data to JSON 454 // Serialize event data to JSON
426 static void AppendEventsAsJSON(const std::vector<TraceEvent>& events, 455 static void AppendEventsAsJSON(const std::vector<TraceEvent>& events,
427 size_t start, 456 size_t start,
428 size_t count, 457 size_t count,
429 std::string* out); 458 std::string* out);
430 void AppendAsJSON(std::string* out) const; 459 void AppendAsJSON(std::string* out) const;
431 460
432 TimeTicks timestamp() const { return timestamp_; } 461 TimeTicks timestamp() const { return timestamp_; }
433 462
463 // Exposed for unittesting:
464
465 const base::RefCountedString* parameter_copy_storage() const {
466 return parameter_copy_storage_.get();
467 }
468
469 const char* name() const { return name_; }
470
434 private: 471 private:
435 unsigned long process_id_; 472 unsigned long process_id_;
436 unsigned long thread_id_; 473 unsigned long thread_id_;
437 TimeTicks timestamp_; 474 TimeTicks timestamp_;
438 TraceEventPhase phase_; 475 TraceEventPhase phase_;
439 const TraceCategory* category_; 476 const TraceCategory* category_;
440 const char* name_; 477 const char* name_;
441 const char* arg_names_[kTraceMaxNumArgs]; 478 const char* arg_names_[kTraceMaxNumArgs];
442 TraceValue arg_values_[kTraceMaxNumArgs]; 479 TraceValue arg_values_[kTraceMaxNumArgs];
443 scoped_refptr<base::RefCountedString> parameter_copy_storage_; 480 scoped_refptr<base::RefCountedString> parameter_copy_storage_;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 // If |copy| is set, |name|, |arg_name1| and |arg_name2| will be deep copied 521 // If |copy| is set, |name|, |arg_name1| and |arg_name2| will be deep copied
485 // into the event; see "Memory scoping note" and TRACE_EVENT_COPY_XXX above. 522 // into the event; see "Memory scoping note" and TRACE_EVENT_COPY_XXX above.
486 int AddTraceEvent(TraceEventPhase phase, 523 int AddTraceEvent(TraceEventPhase phase,
487 const TraceCategory* category, 524 const TraceCategory* category,
488 const char* name, 525 const char* name,
489 const char* arg1_name, TraceValue arg1_val, 526 const char* arg1_name, TraceValue arg1_val,
490 const char* arg2_name, TraceValue arg2_val, 527 const char* arg2_name, TraceValue arg2_val,
491 int threshold_begin_id, 528 int threshold_begin_id,
492 int64 threshold, 529 int64 threshold,
493 bool copy); 530 bool copy);
494 static void AddTraceEventEtw(TraceEventPhase phase, 531
495 const char* name, 532 // Exposed for unittesting:
496 const void* id, 533
497 const char* extra); 534 // Allows resurrecting our singleton instance post-AtExit processing.
498 static void AddTraceEventEtw(TraceEventPhase phase, 535 static void Resurrect();
499 const char* name, 536
500 const void* id, 537 // Allow tests to inspect TraceEvents.
501 const std::string& extra) { 538 size_t GetEventsSize() const { return logged_events_.size(); }
502 AddTraceEventEtw(phase, name, id, extra.c_str()); 539 const TraceEvent& GetEventAt(size_t index) const {
540 DCHECK(index < logged_events_.size());
541 return logged_events_[index];
503 } 542 }
504 543
505 // Exposed for unittesting only, allows resurrecting our
506 // singleton instance post-AtExit processing.
507 static void Resurrect();
508
509 private: 544 private:
510 // This allows constructor and destructor to be private and usable only 545 // This allows constructor and destructor to be private and usable only
511 // by the Singleton class. 546 // by the Singleton class.
512 friend struct StaticMemorySingletonTraits<TraceLog>; 547 friend struct StaticMemorySingletonTraits<TraceLog>;
513 548
514 TraceLog(); 549 TraceLog();
515 ~TraceLog(); 550 ~TraceLog();
516 const TraceCategory* GetCategoryInternal(const char* name); 551 const TraceCategory* GetCategoryInternal(const char* name);
517 void AddCurrentMetadataEvents(); 552 void AddCurrentMetadataEvents();
518 553
519 // TODO(nduca): switch to per-thread trace buffers to reduce thread 554 // TODO(nduca): switch to per-thread trace buffers to reduce thread
520 // synchronization. 555 // synchronization.
521 Lock lock_; 556 Lock lock_;
522 bool enabled_; 557 bool enabled_;
523 OutputCallback output_callback_; 558 OutputCallback output_callback_;
524 BufferFullCallback buffer_full_callback_; 559 BufferFullCallback buffer_full_callback_;
525 std::vector<TraceEvent> logged_events_; 560 std::vector<TraceEvent> logged_events_;
526 561
527 base::hash_map<PlatformThreadId, std::string> thread_names_; 562 base::hash_map<PlatformThreadId, std::string> thread_names_;
528 563
529 DISALLOW_COPY_AND_ASSIGN(TraceLog); 564 DISALLOW_COPY_AND_ASSIGN(TraceLog);
530 }; 565 };
531 566
532 namespace internal { 567 namespace internal {
533 568
534 // Used by TRACE_EVENTx macro. Do not use directly. 569 // Used by TRACE_EVENTx macro. Do not use directly.
535 class BASE_EXPORT TraceEndOnScopeClose { 570 class BASE_EXPORT TraceEndOnScopeClose {
536 public: 571 public:
572 // Note: members of data_ intentionally left uninitialized. See Initialize.
537 TraceEndOnScopeClose() : p_data_(NULL) {} 573 TraceEndOnScopeClose() : p_data_(NULL) {}
538 ~TraceEndOnScopeClose() { 574 ~TraceEndOnScopeClose() {
539 if (p_data_) 575 if (p_data_)
540 AddEventIfEnabled(); 576 AddEventIfEnabled();
541 } 577 }
542 578
543 void Initialize(const TraceCategory* category, 579 void Initialize(const TraceCategory* category,
544 const char* name); 580 const char* name);
545 581
546 private: 582 private:
547 // Add the end event if the category is still enabled. 583 // Add the end event if the category is still enabled.
548 void AddEventIfEnabled(); 584 void AddEventIfEnabled();
549 585
550 // This Data struct workaround is to avoid initializing all the members 586 // This Data struct workaround is to avoid initializing all the members
551 // in Data during construction of this object, since this object is always 587 // in Data during construction of this object, since this object is always
552 // constructed, even when tracing is disabled. If the members of Data were 588 // constructed, even when tracing is disabled. If the members of Data were
553 // members of this class instead, compiler warnings occur about potential 589 // members of this class instead, compiler warnings occur about potential
554 // uninitialized accesses. 590 // uninitialized accesses.
555 struct Data { 591 struct Data {
556 const TraceCategory* category; 592 const TraceCategory* category;
557 const char* name; 593 const char* name;
558 }; 594 };
559 Data* p_data_; 595 Data* p_data_;
560 Data data_; 596 Data data_;
561 }; 597 };
562 598
563 // Used by TRACE_EVENTx macro. Do not use directly. 599 // Used by TRACE_EVENTx macro. Do not use directly.
564 class BASE_EXPORT TraceEndOnScopeCloseThreshold { 600 class BASE_EXPORT TraceEndOnScopeCloseThreshold {
565 public: 601 public:
602 // Note: members of data_ intentionally left uninitialized. See Initialize.
566 TraceEndOnScopeCloseThreshold() : p_data_(NULL) {} 603 TraceEndOnScopeCloseThreshold() : p_data_(NULL) {}
567 ~TraceEndOnScopeCloseThreshold() { 604 ~TraceEndOnScopeCloseThreshold() {
568 if (p_data_) 605 if (p_data_)
569 AddEventIfEnabled(); 606 AddEventIfEnabled();
570 } 607 }
571 608
572 // Called by macros only when tracing is enabled at the point when the begin 609 // Called by macros only when tracing is enabled at the point when the begin
573 // event is added. 610 // event is added.
574 void Initialize(const TraceCategory* category, 611 void Initialize(const TraceCategory* category,
575 const char* name, 612 const char* name,
(...skipping 18 matching lines...) Expand all
594 Data* p_data_; 631 Data* p_data_;
595 Data data_; 632 Data data_;
596 }; 633 };
597 634
598 } // namespace internal 635 } // namespace internal
599 636
600 } // namespace debug 637 } // namespace debug
601 } // namespace base 638 } // namespace base
602 639
603 #endif // BASE_DEBUG_TRACE_EVENT_H_ 640 #endif // BASE_DEBUG_TRACE_EVENT_H_
OLDNEW
« no previous file with comments | « no previous file | base/debug/trace_event.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698