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

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

Issue 2503473002: tracing: split out ThreadLocalEventBuffer
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « base/trace_event/thread_local_event_buffer.cc ('k') | base/trace_event/trace_log.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <limits>
12
11 #include "base/base_export.h" 13 #include "base/base_export.h"
12 #include "base/trace_event/trace_event.h" 14 #include "base/trace_event/trace_event.h"
13 #include "base/trace_event/trace_event_impl.h" 15 #include "base/trace_event/trace_event_impl.h"
14 16
15 namespace base { 17 namespace base {
16 18
17 namespace trace_event { 19 namespace trace_event {
18 20
19 // TraceBufferChunk is the basic unit of TraceBuffer. 21 // TraceBufferChunk is the basic unit of TraceBuffer.
20 class BASE_EXPORT TraceBufferChunk { 22 class BASE_EXPORT TraceBufferChunk {
21 public: 23 public:
24 // These values must be kept consistent with the numbers of bits of
25 // chunk_index and event_index fields in TraceEventHandle
26 // (in trace_event_impl.h).
27 static const size_t kMaxChunkIndex = (1u << 26) - 1;
28 static const size_t kTraceBufferChunkSize = 64;
29
22 explicit TraceBufferChunk(uint32_t seq); 30 explicit TraceBufferChunk(uint32_t seq);
23 ~TraceBufferChunk(); 31 ~TraceBufferChunk();
24 32
25 void Reset(uint32_t new_seq); 33 void Reset(uint32_t new_seq);
26 TraceEvent* AddTraceEvent(size_t* event_index); 34 TraceEvent* AddTraceEvent(size_t* event_index);
27 bool IsFull() const { return next_free_ == kTraceBufferChunkSize; } 35 bool IsFull() const { return next_free_ == kTraceBufferChunkSize; }
28 36
29 uint32_t seq() const { return seq_; } 37 uint32_t seq() const { return seq_; }
30 size_t capacity() const { return kTraceBufferChunkSize; } 38 size_t capacity() const { return kTraceBufferChunkSize; }
31 size_t size() const { return next_free_; } 39 size_t size() const { return next_free_; }
32 40
33 TraceEvent* GetEventAt(size_t index) { 41 TraceEvent* GetEventAt(size_t index) {
34 DCHECK(index < size()); 42 DCHECK(index < size());
35 return &chunk_[index]; 43 return &chunk_[index];
36 } 44 }
37 const TraceEvent* GetEventAt(size_t index) const { 45 const TraceEvent* GetEventAt(size_t index) const {
38 DCHECK(index < size()); 46 DCHECK(index < size());
39 return &chunk_[index]; 47 return &chunk_[index];
40 } 48 }
41 49
50 void MakeHandle(size_t chunk_index,
51 size_t event_index,
52 TraceEventHandle* handle) {
53 DCHECK(seq_);
54 DCHECK(chunk_index <= kMaxChunkIndex);
55 DCHECK(event_index < kTraceBufferChunkSize);
56 DCHECK(chunk_index <= std::numeric_limits<uint16_t>::max());
57 handle->chunk_seq = seq_;
58 handle->chunk_index = static_cast<uint16_t>(chunk_index);
59 handle->event_index = static_cast<uint16_t>(event_index);
60 }
61
42 void EstimateTraceMemoryOverhead(TraceEventMemoryOverhead* overhead); 62 void EstimateTraceMemoryOverhead(TraceEventMemoryOverhead* overhead);
43 63
44 // These values must be kept consistent with the numbers of bits of
45 // chunk_index and event_index fields in TraceEventHandle
46 // (in trace_event_impl.h).
47 static const size_t kMaxChunkIndex = (1u << 26) - 1;
48 static const size_t kTraceBufferChunkSize = 64;
49
50 private: 64 private:
51 size_t next_free_; 65 size_t next_free_;
52 std::unique_ptr<TraceEventMemoryOverhead> cached_overhead_estimate_; 66 std::unique_ptr<TraceEventMemoryOverhead> cached_overhead_estimate_;
53 TraceEvent chunk_[kTraceBufferChunkSize]; 67 TraceEvent chunk_[kTraceBufferChunkSize];
54 uint32_t seq_; 68 uint32_t seq_;
55 }; 69 };
56 70
57 // TraceBuffer holds the events as they are collected. 71 // TraceBuffer holds the events as they are collected.
58 class BASE_EXPORT TraceBuffer { 72 class BASE_EXPORT TraceBuffer {
59 public: 73 public:
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 135
122 private: 136 private:
123 OutputCallback output_callback_; 137 OutputCallback output_callback_;
124 bool append_comma_; 138 bool append_comma_;
125 }; 139 };
126 140
127 } // namespace trace_event 141 } // namespace trace_event
128 } // namespace base 142 } // namespace base
129 143
130 #endif // BASE_TRACE_EVENT_TRACE_BUFFER_H_ 144 #endif // BASE_TRACE_EVENT_TRACE_BUFFER_H_
OLDNEW
« no previous file with comments | « base/trace_event/thread_local_event_buffer.cc ('k') | base/trace_event/trace_log.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698