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

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

Issue 12096115: Update tracing framework to optionally use a ringbuffer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merging with master. Created 7 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | base/debug/trace_event_impl.cc » ('j') | base/debug/trace_event_impl.cc » ('J')
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 5
6 #ifndef BASE_DEBUG_TRACE_EVENT_IMPL_H_ 6 #ifndef BASE_DEBUG_TRACE_EVENT_IMPL_H_
7 #define BASE_DEBUG_TRACE_EVENT_IMPL_H_ 7 #define BASE_DEBUG_TRACE_EVENT_IMPL_H_
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/hash_tables.h" 13 #include "base/hash_tables.h"
14 #include "base/memory/ref_counted_memory.h" 14 #include "base/memory/ref_counted_memory.h"
15 #include "base/memory/scoped_vector.h"
15 #include "base/observer_list.h" 16 #include "base/observer_list.h"
16 #include "base/string_util.h" 17 #include "base/string_util.h"
17 #include "base/synchronization/condition_variable.h" 18 #include "base/synchronization/condition_variable.h"
18 #include "base/synchronization/lock.h" 19 #include "base/synchronization/lock.h"
19 #include "base/threading/thread.h" 20 #include "base/threading/thread.h"
20 #include "base/timer.h" 21 #include "base/timer.h"
21 22
22 // Older style trace macros with explicit id and extra data 23 // Older style trace macros with explicit id and extra data
23 // Only these macros result in publishing data to ETW as currently implemented. 24 // Only these macros result in publishing data to ETW as currently implemented.
24 #define TRACE_EVENT_BEGIN_ETW(name, id, extra) \ 25 #define TRACE_EVENT_BEGIN_ETW(name, id, extra) \
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 const char* arg_names_[kTraceMaxNumArgs]; 108 const char* arg_names_[kTraceMaxNumArgs];
108 const unsigned char* category_enabled_; 109 const unsigned char* category_enabled_;
109 const char* name_; 110 const char* name_;
110 scoped_refptr<base::RefCountedString> parameter_copy_storage_; 111 scoped_refptr<base::RefCountedString> parameter_copy_storage_;
111 int thread_id_; 112 int thread_id_;
112 char phase_; 113 char phase_;
113 unsigned char flags_; 114 unsigned char flags_;
114 unsigned char arg_types_[kTraceMaxNumArgs]; 115 unsigned char arg_types_[kTraceMaxNumArgs];
115 }; 116 };
116 117
118 // TraceBuffer holds the events as they are collected.
119 class BASE_EXPORT TraceBuffer {
120 public:
121 TraceBuffer();
122 virtual ~TraceBuffer();
123
124 virtual void AddEvent(const TraceEvent& event) = 0;
125 virtual bool HasMoreEvents() const = 0;
126 virtual const TraceEvent& NextEvent() = 0;
127 virtual bool IsFull() const = 0;
128 virtual size_t CountEnabledByName(const unsigned char* category,
129 const std::string& event_name) const = 0;
130
131 size_t Size() const {
132 return logged_events_.size();
133 };
134
135 const TraceEvent& GetEventAt(size_t index) const {
136 DCHECK(index < logged_events_.size());
137 return logged_events_[index];
138 }
139
140 protected:
141 std::vector<TraceEvent> logged_events_;
jar (doing other things) 2013/03/13 18:42:30 Data members should be private. Methods can be ma
dsinclair 2013/03/13 19:27:27 Done.
142
143 DISALLOW_COPY_AND_ASSIGN(TraceBuffer);
jar (doing other things) 2013/03/13 18:42:30 nit: this should be in a private section.
dsinclair 2013/03/13 19:27:27 Done.
144 };
117 145
118 // TraceResultBuffer collects and converts trace fragments returned by TraceLog 146 // TraceResultBuffer collects and converts trace fragments returned by TraceLog
119 // to JSON output. 147 // to JSON output.
120 class BASE_EXPORT TraceResultBuffer { 148 class BASE_EXPORT TraceResultBuffer {
121 public: 149 public:
122 typedef base::Callback<void(const std::string&)> OutputCallback; 150 typedef base::Callback<void(const std::string&)> OutputCallback;
123 151
124 // If you don't need to stream JSON chunks out efficiently, and just want to 152 // If you don't need to stream JSON chunks out efficiently, and just want to
125 // get a complete JSON string after calling Finish, use this struct to collect 153 // get a complete JSON string after calling Finish, use this struct to collect
126 // JSON trace output. 154 // JSON trace output.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 // The trace buffer does not flush dynamically, so when it fills up, 195 // The trace buffer does not flush dynamically, so when it fills up,
168 // subsequent trace events will be dropped. This callback is generated when 196 // subsequent trace events will be dropped. This callback is generated when
169 // the trace buffer is full. The callback must be thread safe. 197 // the trace buffer is full. The callback must be thread safe.
170 TRACE_BUFFER_FULL = 1 << 0, 198 TRACE_BUFFER_FULL = 1 << 0,
171 // A subscribed trace-event occurred. 199 // A subscribed trace-event occurred.
172 EVENT_WATCH_NOTIFICATION = 1 << 1 200 EVENT_WATCH_NOTIFICATION = 1 << 1
173 }; 201 };
174 202
175 // Options determines how the trace buffer stores data. 203 // Options determines how the trace buffer stores data.
176 enum Options { 204 enum Options {
205 // Record until the trace buffer is full.
177 RECORD_UNTIL_FULL = 1 << 0, 206 RECORD_UNTIL_FULL = 1 << 0,
207
208 // Record until the user ends the trace. The trace buffer is a fixed size
209 // and we use it as a ring buffer during recording.
210 RECORD_CONTINUOUSLY = 1 << 1,
211
178 // Enable the sampling profiler. 212 // Enable the sampling profiler.
179 ENABLE_SAMPLING = 1 << 1, 213 ENABLE_SAMPLING = 1 << 2
180 }; 214 };
181 215
182 static TraceLog* GetInstance(); 216 static TraceLog* GetInstance();
183 217
184 // Convert the given string to trace options. Defaults to RECORD_UNTIL_FULL if 218 // Convert the given string to trace options. Defaults to RECORD_UNTIL_FULL if
185 // the string does not provide valid options. 219 // the string does not provide valid options.
186 static Options TraceOptionsFromString(const std::string& str); 220 static Options TraceOptionsFromString(const std::string& str);
187 221
188 // Get set of known categories. This can change as new code paths are reached. 222 // Get set of known categories. This can change as new code paths are reached.
189 // The known categories are inserted into |categories|. 223 // The known categories are inserted into |categories|.
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 369
336 void InstallWaitableEventForSamplingTesting(WaitableEvent* waitable_event); 370 void InstallWaitableEventForSamplingTesting(WaitableEvent* waitable_event);
337 371
338 // Allows deleting our singleton instance. 372 // Allows deleting our singleton instance.
339 static void DeleteForTesting(); 373 static void DeleteForTesting();
340 374
341 // Allows resurrecting our singleton instance post-AtExit processing. 375 // Allows resurrecting our singleton instance post-AtExit processing.
342 static void Resurrect(); 376 static void Resurrect();
343 377
344 // Allow tests to inspect TraceEvents. 378 // Allow tests to inspect TraceEvents.
345 size_t GetEventsSize() const { return logged_events_.size(); } 379 size_t GetEventsSize() const { return logged_events_->Size(); }
346 const TraceEvent& GetEventAt(size_t index) const { 380 const TraceEvent& GetEventAt(size_t index) const {
347 DCHECK(index < logged_events_.size()); 381 return logged_events_->GetEventAt(index);
348 return logged_events_[index];
349 } 382 }
350 383
351 void SetProcessID(int process_id); 384 void SetProcessID(int process_id);
352 385
353 // Allow setting an offset between the current TimeTicks time and the time 386 // Allow setting an offset between the current TimeTicks time and the time
354 // that should be reported. 387 // that should be reported.
355 void SetTimeOffset(TimeDelta offset); 388 void SetTimeOffset(TimeDelta offset);
356 389
357 private: 390 private:
358 // This allows constructor and destructor to be private and usable only 391 // This allows constructor and destructor to be private and usable only
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 void SendToATrace(char phase, 435 void SendToATrace(char phase,
403 const char* category, 436 const char* category,
404 const char* name, 437 const char* name,
405 int num_args, 438 int num_args,
406 const char** arg_names, 439 const char** arg_names,
407 const unsigned char* arg_types, 440 const unsigned char* arg_types,
408 const unsigned long long* arg_values); 441 const unsigned long long* arg_values);
409 static void ApplyATraceEnabledFlag(unsigned char* category_enabled); 442 static void ApplyATraceEnabledFlag(unsigned char* category_enabled);
410 #endif 443 #endif
411 444
445 TraceBuffer* GetTraceBuffer();
446
412 // TODO(nduca): switch to per-thread trace buffers to reduce thread 447 // TODO(nduca): switch to per-thread trace buffers to reduce thread
413 // synchronization. 448 // synchronization.
414 // This lock protects TraceLog member accesses from arbitrary threads. 449 // This lock protects TraceLog member accesses from arbitrary threads.
415 Lock lock_; 450 Lock lock_;
416 int enable_count_; 451 int enable_count_;
417 NotificationCallback notification_callback_; 452 NotificationCallback notification_callback_;
453 scoped_ptr<TraceBuffer> logged_events_;
418 EventCallback event_callback_; 454 EventCallback event_callback_;
419 std::vector<TraceEvent> logged_events_;
420 std::vector<std::string> included_categories_; 455 std::vector<std::string> included_categories_;
421 std::vector<std::string> excluded_categories_; 456 std::vector<std::string> excluded_categories_;
422 bool dispatching_to_observer_list_; 457 bool dispatching_to_observer_list_;
423 ObserverList<EnabledStateChangedObserver> enabled_state_observer_list_; 458 ObserverList<EnabledStateChangedObserver> enabled_state_observer_list_;
424 459
425 base::hash_map<int, std::string> thread_names_; 460 base::hash_map<int, std::string> thread_names_;
426 461
427 // XORed with TraceID to make it unlikely to collide with other processes. 462 // XORed with TraceID to make it unlikely to collide with other processes.
428 unsigned long long process_id_hash_; 463 unsigned long long process_id_hash_;
429 464
(...skipping 11 matching lines...) Expand all
441 scoped_ptr<TraceSamplingThread> sampling_thread_; 476 scoped_ptr<TraceSamplingThread> sampling_thread_;
442 PlatformThreadHandle sampling_thread_handle_; 477 PlatformThreadHandle sampling_thread_handle_;
443 478
444 DISALLOW_COPY_AND_ASSIGN(TraceLog); 479 DISALLOW_COPY_AND_ASSIGN(TraceLog);
445 }; 480 };
446 481
447 } // namespace debug 482 } // namespace debug
448 } // namespace base 483 } // namespace base
449 484
450 #endif // BASE_DEBUG_TRACE_EVENT_IMPL_H_ 485 #endif // BASE_DEBUG_TRACE_EVENT_IMPL_H_
OLDNEW
« no previous file with comments | « no previous file | base/debug/trace_event_impl.cc » ('j') | base/debug/trace_event_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698