Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: base/trace_event/trace_buffer.cc

Issue 1900223003: [tracing] Ignore tracing allocations in heap profiler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/trace_event/malloc_dump_provider.h"
12 #include "base/trace_event/trace_event_impl.h" 13 #include "base/trace_event/trace_event_impl.h"
13 14
14 namespace base { 15 namespace base {
15 namespace trace_event { 16 namespace trace_event {
16 17
17 namespace { 18 namespace {
18 19
19 class TraceBufferRingBuffer : public TraceBuffer { 20 class TraceBufferRingBuffer : public TraceBuffer {
20 public: 21 public:
21 TraceBufferRingBuffer(size_t max_chunks) 22 TraceBufferRingBuffer(size_t max_chunks)
22 : max_chunks_(max_chunks), 23 : max_chunks_(max_chunks),
23 recyclable_chunks_queue_(new size_t[queue_capacity()]), 24 recyclable_chunks_queue_(new size_t[queue_capacity()]),
24 queue_head_(0), 25 queue_head_(0),
25 queue_tail_(max_chunks), 26 queue_tail_(max_chunks),
26 current_iteration_index_(0), 27 current_iteration_index_(0),
27 current_chunk_seq_(1) { 28 current_chunk_seq_(1) {
28 chunks_.reserve(max_chunks); 29 chunks_.reserve(max_chunks);
29 for (size_t i = 0; i < max_chunks; ++i) 30 for (size_t i = 0; i < max_chunks; ++i)
30 recyclable_chunks_queue_[i] = i; 31 recyclable_chunks_queue_[i] = i;
31 } 32 }
32 33
33 std::unique_ptr<TraceBufferChunk> GetChunk(size_t* index) override { 34 std::unique_ptr<TraceBufferChunk> GetChunk(size_t* index) override {
35 SCOPED_HEAP_PROFILER_IGNORE_MALLOC_EVENT;
Primiano Tucci (use gerrit) 2016/04/20 16:34:57 I think you want to move this only to line 52 whic
ssid 2016/04/21 01:07:46 There is a chunks_.resize call too. When we can ca
Primiano Tucci (use gerrit) 2016/04/21 19:47:31 ahh right
34 // Because the number of threads is much less than the number of chunks, 36 // Because the number of threads is much less than the number of chunks,
35 // the queue should never be empty. 37 // the queue should never be empty.
36 DCHECK(!QueueIsEmpty()); 38 DCHECK(!QueueIsEmpty());
37 39
38 *index = recyclable_chunks_queue_[queue_head_]; 40 *index = recyclable_chunks_queue_[queue_head_];
39 queue_head_ = NextQueueIndex(queue_head_); 41 queue_head_ = NextQueueIndex(queue_head_);
40 current_iteration_index_ = queue_head_; 42 current_iteration_index_ = queue_head_;
41 43
42 if (*index >= chunks_.size()) 44 if (*index >= chunks_.size())
43 chunks_.resize(*index + 1); 45 chunks_.resize(*index + 1);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 152
151 class TraceBufferVector : public TraceBuffer { 153 class TraceBufferVector : public TraceBuffer {
152 public: 154 public:
153 TraceBufferVector(size_t max_chunks) 155 TraceBufferVector(size_t max_chunks)
154 : in_flight_chunk_count_(0), 156 : in_flight_chunk_count_(0),
155 current_iteration_index_(0), 157 current_iteration_index_(0),
156 max_chunks_(max_chunks) { 158 max_chunks_(max_chunks) {
157 chunks_.reserve(max_chunks_); 159 chunks_.reserve(max_chunks_);
158 } 160 }
159 161
160 std::unique_ptr<TraceBufferChunk> GetChunk(size_t* index) override { 162 std::unique_ptr<TraceBufferChunk> GetChunk(size_t* index) override {
ssid 2016/04/21 01:07:46 I am sure that a ghost had removed this line from
Primiano Tucci (use gerrit) 2016/04/21 19:47:31 uh? right you need one here
161 // This function may be called when adding normal events or indirectly from 163 // This function may be called when adding normal events or indirectly from
162 // AddMetadataEventsWhileLocked(). We can not DECHECK(!IsFull()) because we 164 // AddMetadataEventsWhileLocked(). We can not DECHECK(!IsFull()) because we
163 // have to add the metadata events and flush thread-local buffers even if 165 // have to add the metadata events and flush thread-local buffers even if
164 // the buffer is full. 166 // the buffer is full.
165 *index = chunks_.size(); 167 *index = chunks_.size();
166 chunks_.push_back(NULL); // Put NULL in the slot of a in-flight chunk. 168 chunks_.push_back(NULL); // Put NULL in the slot of a in-flight chunk.
167 ++in_flight_chunk_count_; 169 ++in_flight_chunk_count_;
168 // + 1 because zero chunk_seq is not allowed. 170 // + 1 because zero chunk_seq is not allowed.
169 return std::unique_ptr<TraceBufferChunk>( 171 return std::unique_ptr<TraceBufferChunk>(
170 new TraceBufferChunk(static_cast<uint32_t>(*index) + 1)); 172 new TraceBufferChunk(static_cast<uint32_t>(*index) + 1));
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 TraceBuffer* TraceBuffer::CreateTraceBufferRingBuffer(size_t max_chunks) { 332 TraceBuffer* TraceBuffer::CreateTraceBufferRingBuffer(size_t max_chunks) {
331 return new TraceBufferRingBuffer(max_chunks); 333 return new TraceBufferRingBuffer(max_chunks);
332 } 334 }
333 335
334 TraceBuffer* TraceBuffer::CreateTraceBufferVectorOfSize(size_t max_chunks) { 336 TraceBuffer* TraceBuffer::CreateTraceBufferVectorOfSize(size_t max_chunks) {
335 return new TraceBufferVector(max_chunks); 337 return new TraceBufferVector(max_chunks);
336 } 338 }
337 339
338 } // namespace trace_event 340 } // namespace trace_event
339 } // namespace base 341 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698