| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_TRACE_EVENT_TRACE_BUFFER_H_ | 5 #ifndef BASE_TRACE_EVENT_TRACE_BUFFER_H_ |
| 6 #define BASE_TRACE_EVENT_TRACE_BUFFER_H_ | 6 #define BASE_TRACE_EVENT_TRACE_BUFFER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> |
| 9 #include <stdint.h> |
| 10 |
| 8 #include "base/base_export.h" | 11 #include "base/base_export.h" |
| 9 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
| 10 #include "base/trace_event/trace_event_impl.h" | 13 #include "base/trace_event/trace_event_impl.h" |
| 11 | 14 |
| 12 namespace base { | 15 namespace base { |
| 13 | 16 |
| 14 namespace trace_event { | 17 namespace trace_event { |
| 15 | 18 |
| 16 // TraceBufferChunk is the basic unit of TraceBuffer. | 19 // TraceBufferChunk is the basic unit of TraceBuffer. |
| 17 class BASE_EXPORT TraceBufferChunk { | 20 class BASE_EXPORT TraceBufferChunk { |
| 18 public: | 21 public: |
| 19 explicit TraceBufferChunk(uint32 seq); | 22 explicit TraceBufferChunk(uint32_t seq); |
| 20 ~TraceBufferChunk(); | 23 ~TraceBufferChunk(); |
| 21 | 24 |
| 22 void Reset(uint32 new_seq); | 25 void Reset(uint32_t new_seq); |
| 23 TraceEvent* AddTraceEvent(size_t* event_index); | 26 TraceEvent* AddTraceEvent(size_t* event_index); |
| 24 bool IsFull() const { return next_free_ == kTraceBufferChunkSize; } | 27 bool IsFull() const { return next_free_ == kTraceBufferChunkSize; } |
| 25 | 28 |
| 26 uint32 seq() const { return seq_; } | 29 uint32_t seq() const { return seq_; } |
| 27 size_t capacity() const { return kTraceBufferChunkSize; } | 30 size_t capacity() const { return kTraceBufferChunkSize; } |
| 28 size_t size() const { return next_free_; } | 31 size_t size() const { return next_free_; } |
| 29 | 32 |
| 30 TraceEvent* GetEventAt(size_t index) { | 33 TraceEvent* GetEventAt(size_t index) { |
| 31 DCHECK(index < size()); | 34 DCHECK(index < size()); |
| 32 return &chunk_[index]; | 35 return &chunk_[index]; |
| 33 } | 36 } |
| 34 const TraceEvent* GetEventAt(size_t index) const { | 37 const TraceEvent* GetEventAt(size_t index) const { |
| 35 DCHECK(index < size()); | 38 DCHECK(index < size()); |
| 36 return &chunk_[index]; | 39 return &chunk_[index]; |
| 37 } | 40 } |
| 38 | 41 |
| 39 scoped_ptr<TraceBufferChunk> Clone() const; | 42 scoped_ptr<TraceBufferChunk> Clone() const; |
| 40 | 43 |
| 41 void EstimateTraceMemoryOverhead(TraceEventMemoryOverhead* overhead); | 44 void EstimateTraceMemoryOverhead(TraceEventMemoryOverhead* overhead); |
| 42 | 45 |
| 43 // These values must be kept consistent with the numbers of bits of | 46 // These values must be kept consistent with the numbers of bits of |
| 44 // chunk_index and event_index fields in TraceEventHandle | 47 // chunk_index and event_index fields in TraceEventHandle |
| 45 // (in trace_event_impl.h). | 48 // (in trace_event_impl.h). |
| 46 static const size_t kMaxChunkIndex = (1u << 26) - 1; | 49 static const size_t kMaxChunkIndex = (1u << 26) - 1; |
| 47 static const size_t kTraceBufferChunkSize = 64; | 50 static const size_t kTraceBufferChunkSize = 64; |
| 48 | 51 |
| 49 private: | 52 private: |
| 50 size_t next_free_; | 53 size_t next_free_; |
| 51 scoped_ptr<TraceEventMemoryOverhead> cached_overhead_estimate_; | 54 scoped_ptr<TraceEventMemoryOverhead> cached_overhead_estimate_; |
| 52 TraceEvent chunk_[kTraceBufferChunkSize]; | 55 TraceEvent chunk_[kTraceBufferChunkSize]; |
| 53 uint32 seq_; | 56 uint32_t seq_; |
| 54 }; | 57 }; |
| 55 | 58 |
| 56 // TraceBuffer holds the events as they are collected. | 59 // TraceBuffer holds the events as they are collected. |
| 57 class BASE_EXPORT TraceBuffer { | 60 class BASE_EXPORT TraceBuffer { |
| 58 public: | 61 public: |
| 59 virtual ~TraceBuffer() {} | 62 virtual ~TraceBuffer() {} |
| 60 | 63 |
| 61 virtual scoped_ptr<TraceBufferChunk> GetChunk(size_t* index) = 0; | 64 virtual scoped_ptr<TraceBufferChunk> GetChunk(size_t* index) = 0; |
| 62 virtual void ReturnChunk(size_t index, | 65 virtual void ReturnChunk(size_t index, |
| 63 scoped_ptr<TraceBufferChunk> chunk) = 0; | 66 scoped_ptr<TraceBufferChunk> chunk) = 0; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 | 124 |
| 122 private: | 125 private: |
| 123 OutputCallback output_callback_; | 126 OutputCallback output_callback_; |
| 124 bool append_comma_; | 127 bool append_comma_; |
| 125 }; | 128 }; |
| 126 | 129 |
| 127 } // namespace trace_event | 130 } // namespace trace_event |
| 128 } // namespace base | 131 } // namespace base |
| 129 | 132 |
| 130 #endif // BASE_TRACE_EVENT_TRACE_BUFFER_H_ | 133 #endif // BASE_TRACE_EVENT_TRACE_BUFFER_H_ |
| OLD | NEW |