Chromium Code Reviews| Index: base/debug/trace_event_impl.h |
| diff --git a/base/debug/trace_event_impl.h b/base/debug/trace_event_impl.h |
| index 7b191b8a403f2bbf7baf25bde779ba691478db26..7904a88f5f9f3c0e94ae89df37f27c286f74b25d 100644 |
| --- a/base/debug/trace_event_impl.h |
| +++ b/base/debug/trace_event_impl.h |
| @@ -364,28 +364,56 @@ class BASE_EXPORT CategoryFilter { |
| class TraceSamplingThread; |
| -class BASE_EXPORT TraceLog { |
| - public: |
| - enum Mode { |
| - DISABLED = 0, |
| - RECORDING_MODE, |
| - MONITORING_MODE, |
| - }; |
| +struct BASE_EXPORT TraceOptions { |
| // Options determines how the trace buffer stores data. |
| - enum Options { |
| + enum RecordMode { |
|
nduca
2014/07/29 00:15:00
you could hoist this to be parallel to trace optio
nednguyen
2014/07/29 19:33:20
Done.
|
| // Record until the trace buffer is full. |
| - RECORD_UNTIL_FULL = 1 << 0, |
| + RECORD_UNTIL_FULL, |
| // Record until the user ends the trace. The trace buffer is a fixed size |
| // and we use it as a ring buffer during recording. |
| - RECORD_CONTINUOUSLY = 1 << 1, |
| - |
| - // Enable the sampling profiler in the recording mode. |
| - ENABLE_SAMPLING = 1 << 2, |
| + RECORD_CONTINUOUSLY, |
| // Echo to console. Events are discarded. |
| - ECHO_TO_CONSOLE = 1 << 3, |
| + ECHO_TO_CONSOLE, |
| + }; |
| + |
| + TraceOptions() |
| + : record_mode(RECORD_UNTIL_FULL), |
| + enable_sampling(false), |
| + enable_systrace(false) {} |
| + |
| + TraceOptions(RecordMode record_mode) |
| + : record_mode(record_mode), |
| + enable_sampling(false), |
| + enable_systrace(false) {} |
| + |
| + TraceOptions& EnableSampling(bool option) { |
|
nduca
2014/07/29 00:15:01
you've exposed the fields so you don't need these
nednguyen
2014/07/29 19:33:20
This allow inlining TraceOptions(...).EnableSampli
|
| + enable_sampling = option; |
| + return *this; |
| + } |
| + |
| + TraceOptions& EnableSystrace(bool option) { |
| + enable_systrace = option; |
| + return *this; |
| + } |
| + |
| + explicit TraceOptions(StringPiece options); |
|
nduca
2014/07/29 00:15:00
std::string
nednguyen
2014/07/29 19:33:20
Done.
|
| + |
| + std::string ToString() const; |
| + |
| + RecordMode record_mode; |
| + bool enable_sampling; |
| + bool enable_systrace; |
| +}; |
| + |
| +class BASE_EXPORT TraceLog { |
| + public: |
| + enum Mode { |
| + DISABLED = 0, |
| + RECORDING_MODE, |
| + MONITORING_MODE, |
| }; |
| // The pointer returned from GetCategoryGroupEnabledInternal() points to a |
| @@ -410,16 +438,15 @@ class BASE_EXPORT TraceLog { |
| // Retrieves a copy (for thread-safety) of the current CategoryFilter. |
| CategoryFilter GetCurrentCategoryFilter(); |
| - Options trace_options() const { |
| - return static_cast<Options>(subtle::NoBarrier_Load(&trace_options_)); |
| - } |
| + // Retrieves a copy (for thread-safety) of the current TraceOptions. |
| + TraceOptions GetCurrentTraceOptions() const; |
| // Enables normal tracing (recording trace events in the trace buffer). |
| // See CategoryFilter comments for details on how to control what categories |
| // will be traced. If tracing has already been enabled, |category_filter| will |
| // be merged into the current category filter. |
| void SetEnabled(const CategoryFilter& category_filter, |
| - Mode mode, Options options); |
| + Mode mode, TraceOptions options); |
| // Disables normal tracing for all categories. |
| void SetDisabled(); |
| @@ -599,6 +626,8 @@ class BASE_EXPORT TraceLog { |
| void SetCurrentThreadBlocksMessageLoop(); |
| private: |
| + typedef unsigned int InternalTraceOptions; |
| + |
| FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture, |
| TraceBufferRingBufferGetReturnChunk); |
| FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture, |
| @@ -607,6 +636,9 @@ class BASE_EXPORT TraceLog { |
| TraceBufferRingBufferFullIteration); |
| FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture, |
| TraceBufferVectorReportFull); |
| + FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture, |
| + ConvertTraceOptionsToInternalOptions); |
| + |
| // This allows constructor and destructor to be private and usable only |
| // by the Singleton class. |
| @@ -624,6 +656,9 @@ class BASE_EXPORT TraceLog { |
| // category filter. |
| void UpdateSyntheticDelaysFromCategoryFilter(); |
| + InternalTraceOptions GetInternalOptionsFromTraceOptions( |
| + const TraceOptions& options); |
| + |
| class ThreadLocalEventBuffer; |
| class OptionalAutoLock; |
| @@ -632,6 +667,11 @@ class BASE_EXPORT TraceLog { |
| const unsigned char* GetCategoryGroupEnabledInternal(const char* name); |
| void AddMetadataEventsWhileLocked(); |
| + InternalTraceOptions trace_options() const { |
| + return static_cast<InternalTraceOptions>( |
| + subtle::NoBarrier_Load(&trace_options_)); |
| + } |
| + |
| TraceBuffer* trace_buffer() const { return logged_events_.get(); } |
| TraceBuffer* CreateTraceBuffer(); |
| TraceBuffer* CreateTraceBufferVectorOfSize(size_t max_chunks); |
| @@ -671,6 +711,14 @@ class BASE_EXPORT TraceLog { |
| return timestamp - time_offset_; |
| } |
| + // Internal representation of trace options since we store the currently used |
| + // trace option as an AtomicWord. |
| + static const InternalTraceOptions NONE; |
| + static const InternalTraceOptions RECORD_UNTIL_FULL; |
| + static const InternalTraceOptions RECORD_CONTINUOUSLY; |
| + static const InternalTraceOptions ENABLE_SAMPLING; |
| + static const InternalTraceOptions ECHO_TO_CONSOLE; |
| + |
| // This lock protects TraceLog member accesses (except for members protected |
| // by thread_info_lock_) from arbitrary threads. |
| mutable Lock lock_; |