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 42c11dc8b7b17eb1f6697fc45aa4605a1ac477d1..6b740b038931b92db6d7eddc93b64eb59859c010 100644 |
| --- a/base/debug/trace_event_impl.h |
| +++ b/base/debug/trace_event_impl.h |
| @@ -12,6 +12,7 @@ |
| #include "base/callback.h" |
| #include "base/hash_tables.h" |
| #include "base/memory/ref_counted_memory.h" |
| +#include "base/memory/scoped_vector.h" |
| #include "base/observer_list.h" |
| #include "base/string_util.h" |
| #include "base/synchronization/condition_variable.h" |
| @@ -114,6 +115,33 @@ class BASE_EXPORT TraceEvent { |
| unsigned char arg_types_[kTraceMaxNumArgs]; |
| }; |
| +// TraceBuffer holds the events as they are collected. |
| +class BASE_EXPORT TraceBuffer { |
| + public: |
| + TraceBuffer(); |
| + virtual ~TraceBuffer(); |
| + |
| + virtual void AddEvent(const TraceEvent& event) = 0; |
| + virtual bool HasMoreEvents() const = 0; |
| + virtual const TraceEvent& NextEvent() = 0; |
| + virtual bool IsFull() const = 0; |
| + virtual size_t CountEnabledByName(const unsigned char* category, |
| + const std::string& event_name) const = 0; |
| + |
| + size_t Size() const { |
| + return logged_events_.size(); |
| + }; |
| + |
| + const TraceEvent& GetEventAt(size_t index) const { |
| + DCHECK(index < logged_events_.size()); |
| + return logged_events_[index]; |
| + } |
| + |
| + protected: |
| + std::vector<TraceEvent> logged_events_; |
|
jar (doing other things)
2013/03/13 18:42:30
Data members should be private. Methods can be ma
dsinclair
2013/03/13 19:27:27
Done.
|
| + |
| + DISALLOW_COPY_AND_ASSIGN(TraceBuffer); |
|
jar (doing other things)
2013/03/13 18:42:30
nit: this should be in a private section.
dsinclair
2013/03/13 19:27:27
Done.
|
| +}; |
| // TraceResultBuffer collects and converts trace fragments returned by TraceLog |
| // to JSON output. |
| @@ -174,9 +202,15 @@ class BASE_EXPORT TraceLog { |
| // Options determines how the trace buffer stores data. |
| enum Options { |
| + // Record until the trace buffer is full. |
| RECORD_UNTIL_FULL = 1 << 0, |
| + |
| + // 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. |
| - ENABLE_SAMPLING = 1 << 1, |
| + ENABLE_SAMPLING = 1 << 2 |
| }; |
| static TraceLog* GetInstance(); |
| @@ -342,10 +376,9 @@ class BASE_EXPORT TraceLog { |
| static void Resurrect(); |
| // Allow tests to inspect TraceEvents. |
| - size_t GetEventsSize() const { return logged_events_.size(); } |
| + size_t GetEventsSize() const { return logged_events_->Size(); } |
| const TraceEvent& GetEventAt(size_t index) const { |
| - DCHECK(index < logged_events_.size()); |
| - return logged_events_[index]; |
| + return logged_events_->GetEventAt(index); |
| } |
| void SetProcessID(int process_id); |
| @@ -409,14 +442,16 @@ class BASE_EXPORT TraceLog { |
| static void ApplyATraceEnabledFlag(unsigned char* category_enabled); |
| #endif |
| + TraceBuffer* GetTraceBuffer(); |
| + |
| // TODO(nduca): switch to per-thread trace buffers to reduce thread |
| // synchronization. |
| // This lock protects TraceLog member accesses from arbitrary threads. |
| Lock lock_; |
| int enable_count_; |
| NotificationCallback notification_callback_; |
| + scoped_ptr<TraceBuffer> logged_events_; |
| EventCallback event_callback_; |
| - std::vector<TraceEvent> logged_events_; |
| std::vector<std::string> included_categories_; |
| std::vector<std::string> excluded_categories_; |
| bool dispatching_to_observer_list_; |