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..2413272b54dd62a019eb857419066fff36f506c5 100644 |
| --- a/base/debug/trace_event.h |
| +++ b/base/debug/trace_event.h |
| @@ -299,10 +299,43 @@ |
| // 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), \ |
| - reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>(category "\0" name)); |
| +#define TRACE_EVENT_SET_SAMPLING_STATE_FOR_BUCKET( \ |
| + bucket_number, category, name) \ |
| + TRACE_EVENT_API_ATOMIC_STORE( \ |
| + TRACE_EVENT_API_THREAD_BUCKET(bucket_number), \ |
| + reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>(category "\0" name)); |
| + |
| +// Creates a scope of a sampling state of the given bucket. |
| +// |
| +// { // The sampling state is set within this scope. |
| +// TRACE_EVENT_SAMPLING_STATE_SCOPE_FOR_BUCKET(0, "category", "name"); |
|
nduca
2013/07/03 09:54:34
bikeshed: how about TRACE_EVENT_SCOPED_SET_SAMPLIN
haraken
2013/07/04 02:03:16
Done.
|
| +// ...; |
| +// } |
| +#define TRACE_EVENT_SAMPLING_STATE_SCOPE_FOR_BUCKET( \ |
| + bucket_number, category, name) \ |
| + trace_event_internal::TraceEventSamplingStateScope<bucket_number> \ |
| + traceEventSamplingScope(category "\0" name); |
| + |
| +// Returns a current sampling state of the current scope of the given bucket. |
| +#define TRACE_EVENT_SAMPLING_STATE_SCOPE_CURRENT_FOR_BUCKET(bucket_number) \ |
| + trace_event_internal::TraceEventSamplingStateScope<bucket_number>::Current() |
| + |
| +// Updates a sampling state of the current scope of the given bucket. |
| +// You should use this macro only when the overhead of |
| +// TRACE_EVENT_SAMPLING_STATE_SCOPE_FOR_BUCKET is not acceptable. |
| +#define TRACE_EVENT_SAMPLING_STATE_SCOPE_SET_CURRENT_FOR_BUCKET( \ |
| + bucket_number, category, name) \ |
| + trace_event_internal:: \ |
| + TraceEventSamplingStateScope<bucket_number>::Set(category "\0" name) |
| + |
| +// Syntactic sugars for the sampling tracing in the main thread. |
| +#define TRACE_EVENT_SAMPLING_STATE_SCOPE(category, name) \ |
| + TRACE_EVENT_SAMPLING_STATE_SCOPE_FOR_BUCKET(0, category, name) |
| +#define TRACE_EVENT_SAMPLING_STATE_SCOPE_CURRENT() \ |
| + TRACE_EVENT_SAMPLING_STATE_SCOPE_CURRENT_FOR_BUCKET(0) |
| +#define TRACE_EVENT_SAMPLING_STATE_SCOPE_SET_CURRENT(category, name) \ |
| + TRACE_EVENT_SAMPLING_STATE_SCOPE_SET_CURRENT_FOR_BUCKET(0, category, name) |
| + |
| // Records a single BEGIN event called "name" immediately, with 0, 1 or 2 |
| // associated arguments. If the category is not enabled, then this |
| @@ -755,14 +788,15 @@ |
| // Defines visibility for classes in trace_event.h |
| #define TRACE_EVENT_API_CLASS_EXPORT BASE_EXPORT |
| -// Not supported in split-dll build. http://crbug.com/237249 |
| +// Not supported in split-dll build. http://crbug.com/256965 |
| #if !defined(CHROME_SPLIT_DLL) |
| // The thread buckets for the sampling profiler. |
| -TRACE_EVENT_API_CLASS_EXPORT extern TRACE_EVENT_API_ATOMIC_WORD g_trace_state0; |
| -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; |
| +TRACE_EVENT_API_CLASS_EXPORT extern \ |
| + TRACE_EVENT_API_ATOMIC_WORD g_trace_state[3]; |
| + |
| #define TRACE_EVENT_API_THREAD_BUCKET(thread_bucket) \ |
| - g_trace_state##thread_bucket |
| + g_trace_state[thread_bucket] |
| + |
| #endif |
| //////////////////////////////////////////////////////////////////////////////// |
| @@ -1439,6 +1473,37 @@ class TRACE_EVENT_API_CLASS_EXPORT ScopedTrace { |
| #define TRACE_EVENT_BINARY_EFFICIENT0(category_group, name) \ |
| INTERNAL_TRACE_EVENT_BINARY_EFFICIENT_ADD_SCOPED(category_group, name) |
| +// TraceEventSamplingStateScope records the current sampling state |
| +// and sets a new sampling state. When the scope exists, it restores |
| +// the sampling state having recorded. |
| +template<size_t BucketNumber> |
| +class TraceEventSamplingStateScope { |
| + public: |
| + TraceEventSamplingStateScope(const char* category_and_name) { |
| + previous_state_ = TraceEventSamplingStateScope<BucketNumber>::Current(); |
| + TraceEventSamplingStateScope<BucketNumber>::Set(category_and_name); |
| + } |
| + |
| + ~TraceEventSamplingStateScope() { |
| + TraceEventSamplingStateScope<BucketNumber>::Set(previous_state_); |
| + } |
| + |
| + static inline const char* Current() { |
| + return reinterpret_cast<const char*>(TRACE_EVENT_API_ATOMIC_LOAD( |
| + g_trace_state[BucketNumber])); |
| + } |
| + |
| + static inline void Set(const char* category_and_name) { |
| + TRACE_EVENT_API_ATOMIC_STORE( |
| + g_trace_state[BucketNumber], |
| + reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>( |
| + const_cast<char*>(category_and_name))); |
| + } |
| + |
| + private: |
| + const char* previous_state_; |
| +}; |
| + |
| } // namespace trace_event_internal |
| namespace base { |