Index: base/debug/trace_event.h |
diff --git a/base/debug/trace_event.h b/base/debug/trace_event.h |
index aa4cc759b79eeabca051ff795c07455cf56eb3c2..2bb04061ea63fd993d328f279fd89e57eb9e6afc 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) \ |
+ 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,40 @@ 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 { |
+public: |
+ TraceEventSamplingState0Scope(const char* category_and_name) |
+ { |
+ previousState0_ = TraceEventSamplingState0Scope::current(); |
+ TraceEventSamplingState0Scope::forceCurrent(category_and_name); |
+ } |
+ |
+ ~TraceEventSamplingState0Scope() |
+ { |
+ TraceEventSamplingState0Scope::forceCurrent(previousState0_); |
+ } |
+ |
+ static inline const char* current() |
scottmg
2013/07/03 02:16:10
In chromium code, these should be Current()
haraken
2013/07/03 02:38:50
Done.
|
+ { |
+ return reinterpret_cast<const char*>(TRACE_EVENT_API_ATOMIC_LOAD( |
+ TRACE_EVENT_API_THREAD_BUCKET(0))); |
+ } |
+ |
+ static inline void forceCurrent(const char* category_and_name) |
scottmg
2013/07/03 02:16:10
and ForceCurrent. Maybe just "Set" would be fine t
haraken
2013/07/03 02:38:50
Done.
|
+ { |
+ 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* previousState0_; |
scottmg
2013/07/03 02:16:10
and previous_state0_
haraken
2013/07/03 02:38:50
Done.
|
+}; |
#endif |
//////////////////////////////////////////////////////////////////////////////// |