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

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: 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') | 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 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 virtual ~TraceBuffer() {}
122
123 virtual void AddEvent(const TraceEvent& event) = 0;
124 virtual bool HasMoreEvents() const = 0;
125 virtual const TraceEvent& NextEvent() = 0;
126 virtual bool IsFull() const = 0;
127 virtual size_t CountEnabledByName(const unsigned char* category,
128 const std::string& event_name) const = 0;
129 virtual size_t Size() const = 0;
130 virtual const TraceEvent& GetEventAt(size_t index) const = 0;
131 };
117 132
118 // TraceResultBuffer collects and converts trace fragments returned by TraceLog 133 // TraceResultBuffer collects and converts trace fragments returned by TraceLog
119 // to JSON output. 134 // to JSON output.
120 class BASE_EXPORT TraceResultBuffer { 135 class BASE_EXPORT TraceResultBuffer {
121 public: 136 public:
122 typedef base::Callback<void(const std::string&)> OutputCallback; 137 typedef base::Callback<void(const std::string&)> OutputCallback;
123 138
124 // If you don't need to stream JSON chunks out efficiently, and just want to 139 // 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 140 // get a complete JSON string after calling Finish, use this struct to collect
126 // JSON trace output. 141 // 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, 182 // The trace buffer does not flush dynamically, so when it fills up,
168 // subsequent trace events will be dropped. This callback is generated when 183 // subsequent trace events will be dropped. This callback is generated when
169 // the trace buffer is full. The callback must be thread safe. 184 // the trace buffer is full. The callback must be thread safe.
170 TRACE_BUFFER_FULL = 1 << 0, 185 TRACE_BUFFER_FULL = 1 << 0,
171 // A subscribed trace-event occurred. 186 // A subscribed trace-event occurred.
172 EVENT_WATCH_NOTIFICATION = 1 << 1 187 EVENT_WATCH_NOTIFICATION = 1 << 1
173 }; 188 };
174 189
175 // Options determines how the trace buffer stores data. 190 // Options determines how the trace buffer stores data.
176 enum Options { 191 enum Options {
192 // Record until the trace buffer is full.
177 RECORD_UNTIL_FULL = 1 << 0, 193 RECORD_UNTIL_FULL = 1 << 0,
194
195 // Record until the user ends the trace. The trace buffer is a fixed size
196 // and we use it as a ring buffer during recording.
197 RECORD_CONTINUOUSLY = 1 << 1,
198
178 // Enable the sampling profiler. 199 // Enable the sampling profiler.
179 ENABLE_SAMPLING = 1 << 1, 200 ENABLE_SAMPLING = 1 << 2
180 }; 201 };
181 202
182 static TraceLog* GetInstance(); 203 static TraceLog* GetInstance();
183 204
184 // Convert the given string to trace options. Defaults to RECORD_UNTIL_FULL if 205 // Convert the given string to trace options. Defaults to RECORD_UNTIL_FULL if
185 // the string does not provide valid options. 206 // the string does not provide valid options.
186 static Options TraceOptionsFromString(const std::string& str); 207 static Options TraceOptionsFromString(const std::string& str);
187 208
188 // Get set of known categories. This can change as new code paths are reached. 209 // Get set of known categories. This can change as new code paths are reached.
189 // The known categories are inserted into |categories|. 210 // The known categories are inserted into |categories|.
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 356
336 void InstallWaitableEventForSamplingTesting(WaitableEvent* waitable_event); 357 void InstallWaitableEventForSamplingTesting(WaitableEvent* waitable_event);
337 358
338 // Allows deleting our singleton instance. 359 // Allows deleting our singleton instance.
339 static void DeleteForTesting(); 360 static void DeleteForTesting();
340 361
341 // Allows resurrecting our singleton instance post-AtExit processing. 362 // Allows resurrecting our singleton instance post-AtExit processing.
342 static void Resurrect(); 363 static void Resurrect();
343 364
344 // Allow tests to inspect TraceEvents. 365 // Allow tests to inspect TraceEvents.
345 size_t GetEventsSize() const { return logged_events_.size(); } 366 size_t GetEventsSize() const { return logged_events_->Size(); }
346 const TraceEvent& GetEventAt(size_t index) const { 367 const TraceEvent& GetEventAt(size_t index) const {
347 DCHECK(index < logged_events_.size()); 368 return logged_events_->GetEventAt(index);
348 return logged_events_[index];
349 } 369 }
350 370
351 void SetProcessID(int process_id); 371 void SetProcessID(int process_id);
352 372
353 // Allow setting an offset between the current TimeTicks time and the time 373 // Allow setting an offset between the current TimeTicks time and the time
354 // that should be reported. 374 // that should be reported.
355 void SetTimeOffset(TimeDelta offset); 375 void SetTimeOffset(TimeDelta offset);
356 376
357 private: 377 private:
358 // This allows constructor and destructor to be private and usable only 378 // This allows constructor and destructor to be private and usable only
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 const char* name, 424 const char* name,
405 unsigned long long id, 425 unsigned long long id,
406 int num_args, 426 int num_args,
407 const char** arg_names, 427 const char** arg_names,
408 const unsigned char* arg_types, 428 const unsigned char* arg_types,
409 const unsigned long long* arg_values, 429 const unsigned long long* arg_values,
410 unsigned char flags); 430 unsigned char flags);
411 static void ApplyATraceEnabledFlag(unsigned char* category_enabled); 431 static void ApplyATraceEnabledFlag(unsigned char* category_enabled);
412 #endif 432 #endif
413 433
434 TraceBuffer* GetTraceBuffer();
435
414 // TODO(nduca): switch to per-thread trace buffers to reduce thread 436 // TODO(nduca): switch to per-thread trace buffers to reduce thread
415 // synchronization. 437 // synchronization.
416 // This lock protects TraceLog member accesses from arbitrary threads. 438 // This lock protects TraceLog member accesses from arbitrary threads.
417 Lock lock_; 439 Lock lock_;
418 int enable_count_; 440 int enable_count_;
419 NotificationCallback notification_callback_; 441 NotificationCallback notification_callback_;
442 scoped_ptr<TraceBuffer> logged_events_;
420 EventCallback event_callback_; 443 EventCallback event_callback_;
421 std::vector<TraceEvent> logged_events_;
422 std::vector<std::string> included_categories_; 444 std::vector<std::string> included_categories_;
423 std::vector<std::string> excluded_categories_; 445 std::vector<std::string> excluded_categories_;
424 bool dispatching_to_observer_list_; 446 bool dispatching_to_observer_list_;
425 ObserverList<EnabledStateChangedObserver> enabled_state_observer_list_; 447 ObserverList<EnabledStateChangedObserver> enabled_state_observer_list_;
426 448
427 base::hash_map<int, std::string> thread_names_; 449 base::hash_map<int, std::string> thread_names_;
428 450
429 // XORed with TraceID to make it unlikely to collide with other processes. 451 // XORed with TraceID to make it unlikely to collide with other processes.
430 unsigned long long process_id_hash_; 452 unsigned long long process_id_hash_;
431 453
(...skipping 11 matching lines...) Expand all
443 scoped_ptr<TraceSamplingThread> sampling_thread_; 465 scoped_ptr<TraceSamplingThread> sampling_thread_;
444 PlatformThreadHandle sampling_thread_handle_; 466 PlatformThreadHandle sampling_thread_handle_;
445 467
446 DISALLOW_COPY_AND_ASSIGN(TraceLog); 468 DISALLOW_COPY_AND_ASSIGN(TraceLog);
447 }; 469 };
448 470
449 } // namespace debug 471 } // namespace debug
450 } // namespace base 472 } // namespace base
451 473
452 #endif // BASE_DEBUG_TRACE_EVENT_IMPL_H_ 474 #endif // BASE_DEBUG_TRACE_EVENT_IMPL_H_
OLDNEW
« no previous file with comments | « no previous file | base/debug/trace_event_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698