Index: base/debug/trace_event.h |
diff --git a/base/debug/trace_event.h b/base/debug/trace_event.h |
index aa4cc759b79eeabca051ff795c07455cf56eb3c2..e0d72bd65a0e26549815ac12b81a940f0cdf523f 100644 |
--- a/base/debug/trace_event.h |
+++ b/base/debug/trace_event.h |
@@ -299,9 +299,16 @@ |
// want the inconsistency/expense of storing two pointers. |
// |thread_bucket| is [0..2] and is used to statically isolate samples in one |
// thread from others. |
-#define TRACE_EVENT_SAMPLE_STATE(thread_bucket, category, name) \ |
- TRACE_EVENT_API_ATOMIC_STORE( \ |
- TRACE_EVENT_API_THREAD_BUCKET(thread_bucket), \ |
+#define TRACE_EVENT_SAMPLING_STATE0(category, name) \ |
nduca
2013/07/03 05:34:24
can you provide some explanation on why the rename
haraken
2013/07/03 07:33:15
Makes sense. I renamed it to TARCE_EVENT_SET_SAMPL
|
+ INTERNAL_TRACE_EVENT_SAMPLING_STATE(0, category, name) |
+#define TRACE_EVENT_SAMPLING_STATE1(category, name) \ |
+ INTERNAL_TRACE_EVENT_SAMPLING_STATE(1, category, name) |
+#define TRACE_EVENT_SAMPLING_STATE2(category, name) \ |
+ INTERNAL_TRACE_EVENT_SAMPLING_STATE(2, category, name) |
+ |
+#define INTERNAL_TRACE_EVENT_SAMPLING_STATE(thread_bucket, category, name) \ |
+ TRACE_EVENT_API_ATOMIC_STORE( \ |
+ TRACE_EVENT_API_THREAD_BUCKET(thread_bucket), \ |
reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>(category "\0" name)); |
// Records a single BEGIN event called "name" immediately, with 0, 1 or 2 |
@@ -763,6 +770,36 @@ TRACE_EVENT_API_CLASS_EXPORT extern TRACE_EVENT_API_ATOMIC_WORD g_trace_state1; |
TRACE_EVENT_API_CLASS_EXPORT extern TRACE_EVENT_API_ATOMIC_WORD g_trace_state2; |
#define TRACE_EVENT_API_THREAD_BUCKET(thread_bucket) \ |
g_trace_state##thread_bucket |
+ |
+// TraceEventSamplingState0Scope records the current sampling state |
+// and sets a new sampling state. When the scope exists, it restores |
+// the sampling state having recorded. |
+class TraceEventSamplingState0Scope { |
nduca
2013/07/03 05:34:24
Can we templatize this so that this works for 1,2
haraken
2013/07/03 07:33:15
Done.
|
+ public: |
+ TraceEventSamplingState0Scope(const char* category_and_name) { |
nduca
2013/07/03 05:34:24
we prefer people not use the scope objects directl
haraken
2013/07/03 07:33:15
Done.
|
+ previous_state0_ = TraceEventSamplingState0Scope::Current(); |
+ TraceEventSamplingState0Scope::Set(category_and_name); |
+ } |
+ |
+ ~TraceEventSamplingState0Scope() { |
+ TraceEventSamplingState0Scope::Set(previous_state0_); |
+ } |
+ |
+ static inline const char* Current() { |
+ return reinterpret_cast<const char*>(TRACE_EVENT_API_ATOMIC_LOAD( |
+ TRACE_EVENT_API_THREAD_BUCKET(0))); |
+ } |
+ |
+ static inline void Set(const char* category_and_name) { |
+ TRACE_EVENT_API_ATOMIC_STORE( |
+ TRACE_EVENT_API_THREAD_BUCKET(0), |
+ reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>( |
+ const_cast<char*>(category_and_name))); |
+ } |
+ |
+ private: |
+ const char* previous_state0_; |
+}; |
#endif |
//////////////////////////////////////////////////////////////////////////////// |