Chromium Code Reviews| Index: base/debug/trace_event.h |
| diff --git a/base/debug/trace_event.h b/base/debug/trace_event.h |
| index aa4cc759b79eeabca051ff795c07455cf56eb3c2..367044040282a62777e031d858e4d8d0df9de74d 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) |
|
scottmg
2013/07/03 02:40:45
sorry, i missed the other formatting, should be tw
haraken
2013/07/03 02:46:04
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 |
| //////////////////////////////////////////////////////////////////////////////// |