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 #include "base/trace_event/trace_buffer.h" | 5 #include "base/trace_event/trace_buffer.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
8 #include "base/trace_event/trace_event_impl.h" | 10 #include "base/trace_event/trace_event_impl.h" |
9 | 11 |
10 namespace base { | 12 namespace base { |
11 namespace trace_event { | 13 namespace trace_event { |
12 | 14 |
13 namespace { | 15 namespace { |
14 | 16 |
15 class TraceBufferRingBuffer : public TraceBuffer { | 17 class TraceBufferRingBuffer : public TraceBuffer { |
16 public: | 18 public: |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 scoped_ptr<TraceBuffer> CloneForIteration() const override { | 100 scoped_ptr<TraceBuffer> CloneForIteration() const override { |
99 scoped_ptr<ClonedTraceBuffer> cloned_buffer(new ClonedTraceBuffer()); | 101 scoped_ptr<ClonedTraceBuffer> cloned_buffer(new ClonedTraceBuffer()); |
100 for (size_t queue_index = queue_head_; queue_index != queue_tail_; | 102 for (size_t queue_index = queue_head_; queue_index != queue_tail_; |
101 queue_index = NextQueueIndex(queue_index)) { | 103 queue_index = NextQueueIndex(queue_index)) { |
102 size_t chunk_index = recyclable_chunks_queue_[queue_index]; | 104 size_t chunk_index = recyclable_chunks_queue_[queue_index]; |
103 if (chunk_index >= chunks_.size()) // Skip uninitialized chunks. | 105 if (chunk_index >= chunks_.size()) // Skip uninitialized chunks. |
104 continue; | 106 continue; |
105 TraceBufferChunk* chunk = chunks_[chunk_index]; | 107 TraceBufferChunk* chunk = chunks_[chunk_index]; |
106 cloned_buffer->chunks_.push_back(chunk ? chunk->Clone().release() : NULL); | 108 cloned_buffer->chunks_.push_back(chunk ? chunk->Clone().release() : NULL); |
107 } | 109 } |
108 return cloned_buffer.Pass(); | 110 return std::move(cloned_buffer); |
109 } | 111 } |
110 | 112 |
111 void EstimateTraceMemoryOverhead( | 113 void EstimateTraceMemoryOverhead( |
112 TraceEventMemoryOverhead* overhead) override { | 114 TraceEventMemoryOverhead* overhead) override { |
113 overhead->Add("TraceBufferRingBuffer", sizeof(*this)); | 115 overhead->Add("TraceBufferRingBuffer", sizeof(*this)); |
114 for (size_t queue_index = queue_head_; queue_index != queue_tail_; | 116 for (size_t queue_index = queue_head_; queue_index != queue_tail_; |
115 queue_index = NextQueueIndex(queue_index)) { | 117 queue_index = NextQueueIndex(queue_index)) { |
116 size_t chunk_index = recyclable_chunks_queue_[queue_index]; | 118 size_t chunk_index = recyclable_chunks_queue_[queue_index]; |
117 if (chunk_index >= chunks_.size()) // Skip uninitialized chunks. | 119 if (chunk_index >= chunks_.size()) // Skip uninitialized chunks. |
118 continue; | 120 continue; |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 DCHECK(!IsFull()); | 304 DCHECK(!IsFull()); |
303 *event_index = next_free_++; | 305 *event_index = next_free_++; |
304 return &chunk_[*event_index]; | 306 return &chunk_[*event_index]; |
305 } | 307 } |
306 | 308 |
307 scoped_ptr<TraceBufferChunk> TraceBufferChunk::Clone() const { | 309 scoped_ptr<TraceBufferChunk> TraceBufferChunk::Clone() const { |
308 scoped_ptr<TraceBufferChunk> cloned_chunk(new TraceBufferChunk(seq_)); | 310 scoped_ptr<TraceBufferChunk> cloned_chunk(new TraceBufferChunk(seq_)); |
309 cloned_chunk->next_free_ = next_free_; | 311 cloned_chunk->next_free_ = next_free_; |
310 for (size_t i = 0; i < next_free_; ++i) | 312 for (size_t i = 0; i < next_free_; ++i) |
311 cloned_chunk->chunk_[i].CopyFrom(chunk_[i]); | 313 cloned_chunk->chunk_[i].CopyFrom(chunk_[i]); |
312 return cloned_chunk.Pass(); | 314 return cloned_chunk; |
313 } | 315 } |
314 | 316 |
315 void TraceBufferChunk::EstimateTraceMemoryOverhead( | 317 void TraceBufferChunk::EstimateTraceMemoryOverhead( |
316 TraceEventMemoryOverhead* overhead) { | 318 TraceEventMemoryOverhead* overhead) { |
317 if (!cached_overhead_estimate_) { | 319 if (!cached_overhead_estimate_) { |
318 cached_overhead_estimate_.reset(new TraceEventMemoryOverhead); | 320 cached_overhead_estimate_.reset(new TraceEventMemoryOverhead); |
319 | 321 |
320 // When estimating the size of TraceBufferChunk, exclude the array of trace | 322 // When estimating the size of TraceBufferChunk, exclude the array of trace |
321 // events, as they are computed individually below. | 323 // events, as they are computed individually below. |
322 cached_overhead_estimate_->Add("TraceBufferChunk", | 324 cached_overhead_estimate_->Add("TraceBufferChunk", |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 TraceBuffer* TraceBuffer::CreateTraceBufferRingBuffer(size_t max_chunks) { | 389 TraceBuffer* TraceBuffer::CreateTraceBufferRingBuffer(size_t max_chunks) { |
388 return new TraceBufferRingBuffer(max_chunks); | 390 return new TraceBufferRingBuffer(max_chunks); |
389 } | 391 } |
390 | 392 |
391 TraceBuffer* TraceBuffer::CreateTraceBufferVectorOfSize(size_t max_chunks) { | 393 TraceBuffer* TraceBuffer::CreateTraceBufferVectorOfSize(size_t max_chunks) { |
392 return new TraceBufferVector(max_chunks); | 394 return new TraceBufferVector(max_chunks); |
393 } | 395 } |
394 | 396 |
395 } // namespace trace_event | 397 } // namespace trace_event |
396 } // namespace base | 398 } // namespace base |
OLD | NEW |