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

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

Issue 2406703002: tracing: remove sampling state profiler (Closed)
Patch Set: . Created 4 years, 2 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
« no previous file with comments | « base/trace_event/trace_config_unittest.cc ('k') | base/trace_event/trace_event_unittest.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) 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_event_common.h instead of here. 10 // implementation-specific should go in trace_event_common.h instead of here.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 trace_event_internal::TraceID::DontMangle(id) 42 trace_event_internal::TraceID::DontMangle(id)
43 43
44 // By default, trace IDs are eventually converted to a single 64-bit number. Use 44 // By default, trace IDs are eventually converted to a single 64-bit number. Use
45 // this macro to add a scope string. 45 // this macro to add a scope string.
46 #define TRACE_ID_WITH_SCOPE(scope, id) \ 46 #define TRACE_ID_WITH_SCOPE(scope, id) \
47 trace_event_internal::TraceID::WithScope(scope, id) 47 trace_event_internal::TraceID::WithScope(scope, id)
48 48
49 #define TRACE_ID_GLOBAL(id) trace_event_internal::TraceID::GlobalId(id) 49 #define TRACE_ID_GLOBAL(id) trace_event_internal::TraceID::GlobalId(id)
50 #define TRACE_ID_LOCAL(id) trace_event_internal::TraceID::LocalId(id) 50 #define TRACE_ID_LOCAL(id) trace_event_internal::TraceID::LocalId(id)
51 51
52 // Sets the current sample state to the given category and name (both must be
53 // constant strings). These states are intended for a sampling profiler.
54 // Implementation note: we store category and name together because we don't
55 // want the inconsistency/expense of storing two pointers.
56 // |thread_bucket| is [0..2] and is used to statically isolate samples in one
57 // thread from others.
58 #define TRACE_EVENT_SET_SAMPLING_STATE_FOR_BUCKET( \
59 bucket_number, category, name) \
60 trace_event_internal:: \
61 TraceEventSamplingStateScope<bucket_number>::Set(category "\0" name)
62
63 // Returns a current sampling state of the given bucket.
64 #define TRACE_EVENT_GET_SAMPLING_STATE_FOR_BUCKET(bucket_number) \
65 trace_event_internal::TraceEventSamplingStateScope<bucket_number>::Current()
66
67 // Sets a current sampling state of the given bucket.
68 // |category_and_name| doesn't need to be a constant string.
69 // The format of the string is "category\0name".
70 #define TRACE_EVENT_SET_NONCONST_SAMPLING_STATE_FOR_BUCKET( \
71 bucket_number, category_and_name) \
72 trace_event_internal:: \
73 TraceEventSamplingStateScope<bucket_number>::Set(category_and_name)
74
75 // Creates a scope of a sampling state of the given bucket.
76 //
77 // { // The sampling state is set within this scope.
78 // TRACE_EVENT_SAMPLING_STATE_SCOPE_FOR_BUCKET(0, "category", "name");
79 // ...;
80 // }
81 #define TRACE_EVENT_SCOPED_SAMPLING_STATE_FOR_BUCKET( \
82 bucket_number, category, name) \
83 trace_event_internal::TraceEventSamplingStateScope<bucket_number> \
84 traceEventSamplingScope(category "\0" name);
85
86 #define TRACE_EVENT_API_CURRENT_THREAD_ID \ 52 #define TRACE_EVENT_API_CURRENT_THREAD_ID \
87 static_cast<int>(base::PlatformThread::CurrentId()) 53 static_cast<int>(base::PlatformThread::CurrentId())
88 54
89 #define INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE() \ 55 #define INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE() \
90 UNLIKELY(*INTERNAL_TRACE_EVENT_UID(category_group_enabled) & \ 56 UNLIKELY(*INTERNAL_TRACE_EVENT_UID(category_group_enabled) & \
91 (base::trace_event::TraceLog::ENABLED_FOR_RECORDING | \ 57 (base::trace_event::TraceLog::ENABLED_FOR_RECORDING | \
92 base::trace_event::TraceLog::ENABLED_FOR_EVENT_CALLBACK | \ 58 base::trace_event::TraceLog::ENABLED_FOR_EVENT_CALLBACK | \
93 base::trace_event::TraceLog::ENABLED_FOR_ETW_EXPORT | \ 59 base::trace_event::TraceLog::ENABLED_FOR_ETW_EXPORT | \
94 base::trace_event::TraceLog::ENABLED_FOR_FILTERING)) 60 base::trace_event::TraceLog::ENABLED_FOR_FILTERING))
95 61
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 191
226 // Defines atomic operations used internally by the tracing system. 192 // Defines atomic operations used internally by the tracing system.
227 #define TRACE_EVENT_API_ATOMIC_WORD base::subtle::AtomicWord 193 #define TRACE_EVENT_API_ATOMIC_WORD base::subtle::AtomicWord
228 #define TRACE_EVENT_API_ATOMIC_LOAD(var) base::subtle::NoBarrier_Load(&(var)) 194 #define TRACE_EVENT_API_ATOMIC_LOAD(var) base::subtle::NoBarrier_Load(&(var))
229 #define TRACE_EVENT_API_ATOMIC_STORE(var, value) \ 195 #define TRACE_EVENT_API_ATOMIC_STORE(var, value) \
230 base::subtle::NoBarrier_Store(&(var), (value)) 196 base::subtle::NoBarrier_Store(&(var), (value))
231 197
232 // Defines visibility for classes in trace_event.h 198 // Defines visibility for classes in trace_event.h
233 #define TRACE_EVENT_API_CLASS_EXPORT BASE_EXPORT 199 #define TRACE_EVENT_API_CLASS_EXPORT BASE_EXPORT
234 200
235 // The thread buckets for the sampling profiler.
236 TRACE_EVENT_API_CLASS_EXPORT extern \
237 TRACE_EVENT_API_ATOMIC_WORD g_trace_state[3];
238
239 #define TRACE_EVENT_API_THREAD_BUCKET(thread_bucket) \
240 g_trace_state[thread_bucket]
241
242 //////////////////////////////////////////////////////////////////////////////// 201 ////////////////////////////////////////////////////////////////////////////////
243 202
244 // Implementation detail: trace event macros create temporary variables 203 // Implementation detail: trace event macros create temporary variables
245 // to keep instrumentation overhead low. These macros give each temporary 204 // to keep instrumentation overhead low. These macros give each temporary
246 // variable a unique name based on the line number to prevent name collisions. 205 // variable a unique name based on the line number to prevent name collisions.
247 #define INTERNAL_TRACE_EVENT_UID3(a,b) \ 206 #define INTERNAL_TRACE_EVENT_UID3(a,b) \
248 trace_event_unique_##a##b 207 trace_event_unique_##a##b
249 #define INTERNAL_TRACE_EVENT_UID2(a,b) \ 208 #define INTERNAL_TRACE_EVENT_UID2(a,b) \
250 INTERNAL_TRACE_EVENT_UID3(a,b) 209 INTERNAL_TRACE_EVENT_UID3(a,b)
251 #define INTERNAL_TRACE_EVENT_UID(name_prefix) \ 210 #define INTERNAL_TRACE_EVENT_UID(name_prefix) \
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 1052
1094 // This macro generates less code then TRACE_EVENT0 but is also 1053 // This macro generates less code then TRACE_EVENT0 but is also
1095 // slower to execute when tracing is off. It should generally only be 1054 // slower to execute when tracing is off. It should generally only be
1096 // used with code that is seldom executed or conditionally executed 1055 // used with code that is seldom executed or conditionally executed
1097 // when debugging. 1056 // when debugging.
1098 // For now the category_group must be "gpu". 1057 // For now the category_group must be "gpu".
1099 #define TRACE_EVENT_BINARY_EFFICIENT0(category_group, name) \ 1058 #define TRACE_EVENT_BINARY_EFFICIENT0(category_group, name) \
1100 trace_event_internal::ScopedTraceBinaryEfficient \ 1059 trace_event_internal::ScopedTraceBinaryEfficient \
1101 INTERNAL_TRACE_EVENT_UID(scoped_trace)(category_group, name); 1060 INTERNAL_TRACE_EVENT_UID(scoped_trace)(category_group, name);
1102 1061
1103 // TraceEventSamplingStateScope records the current sampling state
1104 // and sets a new sampling state. When the scope exists, it restores
1105 // the sampling state having recorded.
1106 template<size_t BucketNumber>
1107 class TraceEventSamplingStateScope {
1108 public:
1109 TraceEventSamplingStateScope(const char* category_and_name) {
1110 previous_state_ = TraceEventSamplingStateScope<BucketNumber>::Current();
1111 TraceEventSamplingStateScope<BucketNumber>::Set(category_and_name);
1112 }
1113
1114 ~TraceEventSamplingStateScope() {
1115 TraceEventSamplingStateScope<BucketNumber>::Set(previous_state_);
1116 }
1117
1118 static inline const char* Current() {
1119 return reinterpret_cast<const char*>(TRACE_EVENT_API_ATOMIC_LOAD(
1120 g_trace_state[BucketNumber]));
1121 }
1122
1123 static inline void Set(const char* category_and_name) {
1124 TRACE_EVENT_API_ATOMIC_STORE(
1125 g_trace_state[BucketNumber],
1126 reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>(
1127 const_cast<char*>(category_and_name)));
1128 }
1129
1130 private:
1131 const char* previous_state_;
1132 };
1133
1134 } // namespace trace_event_internal 1062 } // namespace trace_event_internal
1135 1063
1136 namespace base { 1064 namespace base {
1137 namespace trace_event { 1065 namespace trace_event {
1138 1066
1139 template<typename IDType> class TraceScopedTrackableObject { 1067 template<typename IDType> class TraceScopedTrackableObject {
1140 public: 1068 public:
1141 TraceScopedTrackableObject(const char* category_group, const char* name, 1069 TraceScopedTrackableObject(const char* category_group, const char* name,
1142 IDType id) 1070 IDType id)
1143 : category_group_(category_group), 1071 : category_group_(category_group),
(...skipping 15 matching lines...) Expand all
1159 const char* name_; 1087 const char* name_;
1160 IDType id_; 1088 IDType id_;
1161 1089
1162 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject); 1090 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject);
1163 }; 1091 };
1164 1092
1165 } // namespace trace_event 1093 } // namespace trace_event
1166 } // namespace base 1094 } // namespace base
1167 1095
1168 #endif // BASE_TRACE_EVENT_TRACE_EVENT_H_ 1096 #endif // BASE_TRACE_EVENT_TRACE_EVENT_H_
OLDNEW
« no previous file with comments | « base/trace_event/trace_config_unittest.cc ('k') | base/trace_event/trace_event_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698