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

Side by Side Diff: base/debug/trace_event_impl.cc

Issue 22796009: Shrink trace_event buffers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Shrink non-ring-buffer also Created 7 years, 4 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
« no previous file with comments | « base/debug/trace_event_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/debug/trace_event_impl.h" 5 #include "base/debug/trace_event_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/base_switches.h" 9 #include "base/base_switches.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 }; 43 };
44 44
45 // The thread buckets for the sampling profiler. 45 // The thread buckets for the sampling profiler.
46 BASE_EXPORT TRACE_EVENT_API_ATOMIC_WORD g_trace_state[3]; 46 BASE_EXPORT TRACE_EVENT_API_ATOMIC_WORD g_trace_state[3];
47 47
48 namespace base { 48 namespace base {
49 namespace debug { 49 namespace debug {
50 50
51 // Controls the number of trace events we will buffer in-memory 51 // Controls the number of trace events we will buffer in-memory
52 // before throwing them away. 52 // before throwing them away.
53 const size_t kTraceEventBufferSize = 500000; 53 const size_t kTraceEventVectorBufferSize = 250000;
54 const size_t kTraceEventRingBufferSize = kTraceEventVectorBufferSize / 4;
54 const size_t kTraceEventBatchSize = 1000; 55 const size_t kTraceEventBatchSize = 1000;
55 const size_t kTraceEventInitialBufferSize = 1024; 56 const size_t kTraceEventInitialBufferSize = 1024;
56 57
57 #define MAX_CATEGORY_GROUPS 100 58 #define MAX_CATEGORY_GROUPS 100
58 59
59 namespace { 60 namespace {
60 61
61 // Parallel arrays g_category_groups and g_category_group_enabled are separate 62 // Parallel arrays g_category_groups and g_category_group_enabled are separate
62 // so that a pointer to a member of g_category_group_enabled can be easily 63 // so that a pointer to a member of g_category_group_enabled can be easily
63 // converted to an index into g_category_groups. This allows macros to deal 64 // converted to an index into g_category_groups. This allows macros to deal
(...skipping 17 matching lines...) Expand all
81 // The name of the current thread. This is used to decide if the current 82 // The name of the current thread. This is used to decide if the current
82 // thread name has changed. We combine all the seen thread names into the 83 // thread name has changed. We combine all the seen thread names into the
83 // output name for the thread. 84 // output name for the thread.
84 LazyInstance<ThreadLocalPointer<const char> >::Leaky 85 LazyInstance<ThreadLocalPointer<const char> >::Leaky
85 g_current_thread_name = LAZY_INSTANCE_INITIALIZER; 86 g_current_thread_name = LAZY_INSTANCE_INITIALIZER;
86 87
87 const char kRecordUntilFull[] = "record-until-full"; 88 const char kRecordUntilFull[] = "record-until-full";
88 const char kRecordContinuously[] = "record-continuously"; 89 const char kRecordContinuously[] = "record-continuously";
89 const char kEnableSampling[] = "enable-sampling"; 90 const char kEnableSampling[] = "enable-sampling";
90 91
91 size_t NextIndex(size_t index) {
92 index++;
93 if (index >= kTraceEventBufferSize)
94 index = 0;
95 return index;
96 }
97
98 } // namespace 92 } // namespace
99 93
100 class TraceBufferRingBuffer : public TraceBuffer { 94 class TraceBufferRingBuffer : public TraceBuffer {
101 public: 95 public:
102 TraceBufferRingBuffer() 96 TraceBufferRingBuffer()
103 : unused_event_index_(0), 97 : unused_event_index_(0),
104 oldest_event_index_(0) { 98 oldest_event_index_(0) {
105 logged_events_.reserve(kTraceEventInitialBufferSize); 99 logged_events_.reserve(kTraceEventInitialBufferSize);
106 } 100 }
107 101
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 147
154 virtual const TraceEvent& GetEventAt(size_t index) const OVERRIDE { 148 virtual const TraceEvent& GetEventAt(size_t index) const OVERRIDE {
155 DCHECK(index < logged_events_.size()); 149 DCHECK(index < logged_events_.size());
156 return logged_events_[index]; 150 return logged_events_[index];
157 } 151 }
158 152
159 virtual size_t Size() const OVERRIDE { 153 virtual size_t Size() const OVERRIDE {
160 return logged_events_.size(); 154 return logged_events_.size();
161 } 155 }
162 156
157 virtual size_t Capacity() const OVERRIDE {
158 return kTraceEventRingBufferSize;
159 }
160
163 private: 161 private:
162 static size_t NextIndex(size_t index) {
163 index++;
164 if (index >= kTraceEventRingBufferSize)
165 index = 0;
166 return index;
167 }
168
164 size_t unused_event_index_; 169 size_t unused_event_index_;
165 size_t oldest_event_index_; 170 size_t oldest_event_index_;
166 std::vector<TraceEvent> logged_events_; 171 std::vector<TraceEvent> logged_events_;
167 172
168 DISALLOW_COPY_AND_ASSIGN(TraceBufferRingBuffer); 173 DISALLOW_COPY_AND_ASSIGN(TraceBufferRingBuffer);
169 }; 174 };
170 175
171 class TraceBufferVector : public TraceBuffer { 176 class TraceBufferVector : public TraceBuffer {
172 public: 177 public:
173 TraceBufferVector() : current_iteration_index_(0) { 178 TraceBufferVector() : current_iteration_index_(0) {
(...skipping 15 matching lines...) Expand all
189 virtual bool HasMoreEvents() const OVERRIDE { 194 virtual bool HasMoreEvents() const OVERRIDE {
190 return current_iteration_index_ < Size(); 195 return current_iteration_index_ < Size();
191 } 196 }
192 197
193 virtual const TraceEvent& NextEvent() OVERRIDE { 198 virtual const TraceEvent& NextEvent() OVERRIDE {
194 DCHECK(HasMoreEvents()); 199 DCHECK(HasMoreEvents());
195 return GetEventAt(current_iteration_index_++); 200 return GetEventAt(current_iteration_index_++);
196 } 201 }
197 202
198 virtual bool IsFull() const OVERRIDE { 203 virtual bool IsFull() const OVERRIDE {
199 return Size() >= kTraceEventBufferSize; 204 return Size() >= kTraceEventVectorBufferSize;
200 } 205 }
201 206
202 virtual size_t CountEnabledByName( 207 virtual size_t CountEnabledByName(
203 const unsigned char* category, 208 const unsigned char* category,
204 const std::string& event_name) const OVERRIDE { 209 const std::string& event_name) const OVERRIDE {
205 size_t notify_count = 0; 210 size_t notify_count = 0;
206 for (size_t i = 0; i < Size(); i++) { 211 for (size_t i = 0; i < Size(); i++) {
207 const TraceEvent& event = GetEventAt(i); 212 const TraceEvent& event = GetEventAt(i);
208 if (category == event.category_group_enabled() && 213 if (category == event.category_group_enabled() &&
209 strcmp(event_name.c_str(), event.name()) == 0) { 214 strcmp(event_name.c_str(), event.name()) == 0) {
210 ++notify_count; 215 ++notify_count;
211 } 216 }
212 } 217 }
213 return notify_count; 218 return notify_count;
214 } 219 }
215 220
216 virtual const TraceEvent& GetEventAt(size_t index) const OVERRIDE { 221 virtual const TraceEvent& GetEventAt(size_t index) const OVERRIDE {
217 DCHECK(index < logged_events_.size()); 222 DCHECK(index < logged_events_.size());
218 return logged_events_[index]; 223 return logged_events_[index];
219 } 224 }
220 225
221 virtual size_t Size() const OVERRIDE { 226 virtual size_t Size() const OVERRIDE {
222 return logged_events_.size(); 227 return logged_events_.size();
223 } 228 }
224 229
230 virtual size_t Capacity() const OVERRIDE {
231 return kTraceEventVectorBufferSize;
232 }
233
225 private: 234 private:
226 size_t current_iteration_index_; 235 size_t current_iteration_index_;
227 std::vector<TraceEvent> logged_events_; 236 std::vector<TraceEvent> logged_events_;
228 237
229 DISALLOW_COPY_AND_ASSIGN(TraceBufferVector); 238 DISALLOW_COPY_AND_ASSIGN(TraceBufferVector);
230 }; 239 };
231 240
232 class TraceBufferDiscardsEvents : public TraceBuffer { 241 class TraceBufferDiscardsEvents : public TraceBuffer {
233 public: 242 public:
234 virtual ~TraceBufferDiscardsEvents() { } 243 virtual ~TraceBufferDiscardsEvents() { }
235 244
236 virtual void AddEvent(const TraceEvent& event) OVERRIDE {} 245 virtual void AddEvent(const TraceEvent& event) OVERRIDE {}
237 virtual bool HasMoreEvents() const OVERRIDE { return false; } 246 virtual bool HasMoreEvents() const OVERRIDE { return false; }
238 247
239 virtual const TraceEvent& NextEvent() OVERRIDE { 248 virtual const TraceEvent& NextEvent() OVERRIDE {
240 NOTREACHED(); 249 NOTREACHED();
241 return *static_cast<TraceEvent*>(NULL); 250 return *static_cast<TraceEvent*>(NULL);
242 } 251 }
243 252
244 virtual bool IsFull() const OVERRIDE { return false; } 253 virtual bool IsFull() const OVERRIDE { return false; }
245 254
246 virtual size_t CountEnabledByName( 255 virtual size_t CountEnabledByName(
247 const unsigned char* category, 256 const unsigned char* category,
248 const std::string& event_name) const OVERRIDE { 257 const std::string& event_name) const OVERRIDE {
249 return 0; 258 return 0;
250 } 259 }
251 260
252 virtual size_t Size() const OVERRIDE { return 0; } 261 virtual size_t Size() const OVERRIDE { return 0; }
253 262
263 // As this buffer is never full, we can return any positive number.
264 virtual size_t Capacity() const OVERRIDE { return 1; }
265
254 virtual const TraceEvent& GetEventAt(size_t index) const OVERRIDE { 266 virtual const TraceEvent& GetEventAt(size_t index) const OVERRIDE {
255 NOTREACHED(); 267 NOTREACHED();
256 return *static_cast<TraceEvent*>(NULL); 268 return *static_cast<TraceEvent*>(NULL);
257 } 269 }
258 }; 270 };
259 271
260 //////////////////////////////////////////////////////////////////////////////// 272 ////////////////////////////////////////////////////////////////////////////////
261 // 273 //
262 // TraceEvent 274 // TraceEvent
263 // 275 //
(...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 1093
1082 bool TraceLog::HasEnabledStateObserver(EnabledStateObserver* listener) const { 1094 bool TraceLog::HasEnabledStateObserver(EnabledStateObserver* listener) const {
1083 std::vector<EnabledStateObserver*>::const_iterator it = 1095 std::vector<EnabledStateObserver*>::const_iterator it =
1084 std::find(enabled_state_observer_list_.begin(), 1096 std::find(enabled_state_observer_list_.begin(),
1085 enabled_state_observer_list_.end(), 1097 enabled_state_observer_list_.end(),
1086 listener); 1098 listener);
1087 return it != enabled_state_observer_list_.end(); 1099 return it != enabled_state_observer_list_.end();
1088 } 1100 }
1089 1101
1090 float TraceLog::GetBufferPercentFull() const { 1102 float TraceLog::GetBufferPercentFull() const {
1091 return (float)((double)logged_events_->Size()/(double)kTraceEventBufferSize); 1103 return static_cast<float>(static_cast<double>(logged_events_->Size()) /
1104 logged_events_->Capacity());
1092 } 1105 }
1093 1106
1094 void TraceLog::SetNotificationCallback( 1107 void TraceLog::SetNotificationCallback(
1095 const TraceLog::NotificationCallback& cb) { 1108 const TraceLog::NotificationCallback& cb) {
1096 AutoLock lock(lock_); 1109 AutoLock lock(lock_);
1097 notification_callback_ = cb; 1110 notification_callback_ = cb;
1098 } 1111 }
1099 1112
1100 TraceBuffer* TraceLog::GetTraceBuffer() { 1113 TraceBuffer* TraceLog::GetTraceBuffer() {
1101 if (trace_options_ & RECORD_CONTINUOUSLY) 1114 if (trace_options_ & RECORD_CONTINUOUSLY)
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
1683 0, // num_args 1696 0, // num_args
1684 NULL, // arg_names 1697 NULL, // arg_names
1685 NULL, // arg_types 1698 NULL, // arg_types
1686 NULL, // arg_values 1699 NULL, // arg_values
1687 NULL, // convertable values 1700 NULL, // convertable values
1688 TRACE_EVENT_FLAG_NONE); // flags 1701 TRACE_EVENT_FLAG_NONE); // flags
1689 } 1702 }
1690 } 1703 }
1691 1704
1692 } // namespace trace_event_internal 1705 } // namespace trace_event_internal
OLDNEW
« no previous file with comments | « base/debug/trace_event_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698