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

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

Issue 1340013002: Add thread-local allocation context for tracing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix typo Created 5 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef BASE_TRACE_EVENT_TRACE_EVENT_H_ 5 #ifndef BASE_TRACE_EVENT_TRACE_EVENT_H_
6 #define BASE_TRACE_EVENT_TRACE_EVENT_H_ 6 #define BASE_TRACE_EVENT_TRACE_EVENT_H_
7 7
8 // This header file defines implementation details of how the trace macros in 8 // This header file defines implementation details of how the trace macros in
9 // trace_event_common.h collect and store trace events. Anything not 9 // trace_event_common.h collect and store trace events. Anything not
10 // implementation-specific should go in trace_macros_common.h instead of here. 10 // implementation-specific should go in trace_macros_common.h instead of here.
11 11
12 #include <string> 12 #include <string>
13 13
14 #include "base/atomicops.h" 14 #include "base/atomicops.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "base/trace_event/pseudo_stack.h"
16 #include "base/trace_event/trace_event_common.h" 17 #include "base/trace_event/trace_event_common.h"
17 #include "base/trace_event/trace_event_memory.h" 18 #include "base/trace_event/trace_event_memory.h"
18 #include "base/trace_event/trace_event_system_stats_monitor.h" 19 #include "base/trace_event/trace_event_system_stats_monitor.h"
19 #include "base/trace_event/trace_log.h" 20 #include "base/trace_event/trace_log.h"
20 #include "build/build_config.h" 21 #include "build/build_config.h"
21 22
22 // By default, const char* argument values are assumed to have long-lived scope 23 // By default, const char* argument values are assumed to have long-lived scope
23 // and will not be copied. Use this macro to force a const char* to be copied. 24 // and will not be copied. Use this macro to force a const char* to be copied.
24 #define TRACE_STR_COPY(str) \ 25 #define TRACE_STR_COPY(str) \
25 trace_event_internal::TraceStringWithCopy(str) 26 trace_event_internal::TraceStringWithCopy(str)
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 // Used by TRACE_EVENTx macros. Do not use directly. 744 // Used by TRACE_EVENTx macros. Do not use directly.
744 class TRACE_EVENT_API_CLASS_EXPORT ScopedTracer { 745 class TRACE_EVENT_API_CLASS_EXPORT ScopedTracer {
745 public: 746 public:
746 // Note: members of data_ intentionally left uninitialized. See Initialize. 747 // Note: members of data_ intentionally left uninitialized. See Initialize.
747 ScopedTracer() : p_data_(NULL) {} 748 ScopedTracer() : p_data_(NULL) {}
748 749
749 ~ScopedTracer() { 750 ~ScopedTracer() {
750 if (p_data_ && *data_.category_group_enabled) 751 if (p_data_ && *data_.category_group_enabled)
751 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION( 752 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(
752 data_.category_group_enabled, data_.name, data_.event_handle); 753 data_.category_group_enabled, data_.name, data_.event_handle);
754
755 if (base::trace_event::PseudoStackController::capture_enabled())
756 base::trace_event::PseudoStack::GetInstance()->Pop();
753 } 757 }
754 758
755 void Initialize(const unsigned char* category_group_enabled, 759 void Initialize(const unsigned char* category_group_enabled,
756 const char* name, 760 const char* name,
757 base::trace_event::TraceEventHandle event_handle) { 761 base::trace_event::TraceEventHandle event_handle) {
758 data_.category_group_enabled = category_group_enabled; 762 data_.category_group_enabled = category_group_enabled;
759 data_.name = name; 763 data_.name = name;
760 data_.event_handle = event_handle; 764 data_.event_handle = event_handle;
761 p_data_ = &data_; 765 p_data_ = &data_;
766
767 if (base::trace_event::PseudoStackController::capture_enabled()) {
768 base::trace_event::PseudoStackFrame frame = {name};
769 base::trace_event::PseudoStack::GetInstance()->Push(frame);
770 }
762 } 771 }
763 772
764 private: 773 private:
765 // This Data struct workaround is to avoid initializing all the members 774 // This Data struct workaround is to avoid initializing all the members
766 // in Data during construction of this object, since this object is always 775 // in Data during construction of this object, since this object is always
767 // constructed, even when tracing is disabled. If the members of Data were 776 // constructed, even when tracing is disabled. If the members of Data were
768 // members of this class instead, compiler warnings occur about potential 777 // members of this class instead, compiler warnings occur about potential
769 // uninitialized accesses. 778 // uninitialized accesses.
770 struct Data { 779 struct Data {
771 const unsigned char* category_group_enabled; 780 const unsigned char* category_group_enabled;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 const char* name_; 865 const char* name_;
857 IDType id_; 866 IDType id_;
858 867
859 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject); 868 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject);
860 }; 869 };
861 870
862 } // namespace trace_event 871 } // namespace trace_event
863 } // namespace base 872 } // namespace base
864 873
865 #endif // BASE_TRACE_EVENT_TRACE_EVENT_H_ 874 #endif // BASE_TRACE_EVENT_TRACE_EVENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698