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

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

Issue 109933006: Implement sampling profiler (chromium side change) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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
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 <stack> 9 #include <stack>
10 #include <string> 10 #include <string>
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 347
348 StringList included_; 348 StringList included_;
349 StringList disabled_; 349 StringList disabled_;
350 StringList excluded_; 350 StringList excluded_;
351 }; 351 };
352 352
353 class TraceSamplingThread; 353 class TraceSamplingThread;
354 354
355 class BASE_EXPORT TraceLog { 355 class BASE_EXPORT TraceLog {
356 public: 356 public:
357 enum Mode {
358 DISABLED = 0,
359 RECORDING_MODE,
360 MONITORING_MODE,
361 };
362
357 // Options determines how the trace buffer stores data. 363 // Options determines how the trace buffer stores data.
358 enum Options { 364 enum Options {
359 // Record until the trace buffer is full. 365 // Record until the trace buffer is full.
360 RECORD_UNTIL_FULL = 1 << 0, 366 RECORD_UNTIL_FULL = 1 << 0,
361 367
362 // Record until the user ends the trace. The trace buffer is a fixed size 368 // Record until the user ends the trace. The trace buffer is a fixed size
363 // and we use it as a ring buffer during recording. 369 // and we use it as a ring buffer during recording.
364 RECORD_CONTINUOUSLY = 1 << 1, 370 RECORD_CONTINUOUSLY = 1 << 1,
365 371
366 // Enable the sampling profiler in the recording mode. 372 // Enable the sampling profiler in the recording mode.
367 ENABLE_SAMPLING = 1 << 2, 373 ENABLE_SAMPLING = 1 << 2,
368 374
369 // Enable the sampling profiler in the monitoring mode.
370 MONITOR_SAMPLING = 1 << 3,
371
372 // Echo to console. Events are discarded. 375 // Echo to console. Events are discarded.
373 ECHO_TO_CONSOLE = 1 << 4, 376 ECHO_TO_CONSOLE = 1 << 3,
374 }; 377 };
375 378
376 // The pointer returned from GetCategoryGroupEnabledInternal() points to a 379 // The pointer returned from GetCategoryGroupEnabledInternal() points to a
377 // value with zero or more of the following bits. Used in this class only. 380 // value with zero or more of the following bits. Used in this class only.
378 // The TRACE_EVENT macros should only use the value as a bool. 381 // The TRACE_EVENT macros should only use the value as a bool.
382 // These values must be in sync with macro values in TraceEvent.h in Blink.
379 enum CategoryGroupEnabledFlags { 383 enum CategoryGroupEnabledFlags {
380 // Normal enabled flag for category groups enabled by SetEnabled(). 384 // Category group enabled for the recording mode.
381 ENABLED_FOR_RECORDING = 1 << 0, 385 ENABLED_FOR_RECORDING = 1 << 0,
386 // Category group enabled for the monitoring mode.
387 ENABLED_FOR_MONITORING = 1 << 1,
382 // Category group enabled by SetEventCallbackEnabled(). 388 // Category group enabled by SetEventCallbackEnabled().
383 ENABLED_FOR_EVENT_CALLBACK = 1 << 1, 389 ENABLED_FOR_EVENT_CALLBACK = 1 << 2,
384 }; 390 };
385 391
386 static TraceLog* GetInstance(); 392 static TraceLog* GetInstance();
387 393
388 // Get set of known category groups. This can change as new code paths are 394 // Get set of known category groups. This can change as new code paths are
389 // reached. The known category groups are inserted into |category_groups|. 395 // reached. The known category groups are inserted into |category_groups|.
390 void GetKnownCategoryGroups(std::vector<std::string>* category_groups); 396 void GetKnownCategoryGroups(std::vector<std::string>* category_groups);
391 397
392 // Retrieves a copy (for thread-safety) of the current CategoryFilter. 398 // Retrieves a copy (for thread-safety) of the current CategoryFilter.
393 CategoryFilter GetCurrentCategoryFilter(); 399 CategoryFilter GetCurrentCategoryFilter();
394 400
395 Options trace_options() const { 401 Options trace_options() const {
396 return static_cast<Options>(subtle::NoBarrier_Load(&trace_options_)); 402 return static_cast<Options>(subtle::NoBarrier_Load(&trace_options_));
397 } 403 }
398 404
399 // Enables normal tracing (recording trace events in the trace buffer). 405 // Enables normal tracing (recording trace events in the trace buffer).
400 // See CategoryFilter comments for details on how to control what categories 406 // See CategoryFilter comments for details on how to control what categories
401 // will be traced. If tracing has already been enabled, |category_filter| will 407 // will be traced. If tracing has already been enabled, |category_filter| will
402 // be merged into the current category filter. 408 // be merged into the current category filter.
403 void SetEnabled(const CategoryFilter& category_filter, Options options); 409 void SetEnabled(const CategoryFilter& category_filter,
410 Mode mode, Options options);
404 411
405 // Disables normal tracing for all categories. 412 // Disables normal tracing for all categories.
406 void SetDisabled(); 413 void SetDisabled();
407 414
408 bool IsEnabled() { return enabled_; } 415 bool IsEnabled() { return mode_ != DISABLED; }
409 416
410 // The number of times we have begun recording traces. If tracing is off, 417 // The number of times we have begun recording traces. If tracing is off,
411 // returns -1. If tracing is on, then it returns the number of times we have 418 // returns -1. If tracing is on, then it returns the number of times we have
412 // recorded a trace. By watching for this number to increment, you can 419 // recorded a trace. By watching for this number to increment, you can
413 // passively discover when a new trace has begun. This is then used to 420 // passively discover when a new trace has begun. This is then used to
414 // implement the TRACE_EVENT_IS_NEW_TRACE() primitive. 421 // implement the TRACE_EVENT_IS_NEW_TRACE() primitive.
415 int GetNumTracesRecorded(); 422 int GetNumTracesRecorded();
416 423
417 #if defined(OS_ANDROID) 424 #if defined(OS_ANDROID)
418 void StartATrace(); 425 void StartATrace();
419 void StopATrace(); 426 void StopATrace();
420 void AddClockSyncMetadataEvent(); 427 void AddClockSyncMetadataEvent();
421 #endif 428 #endif
422 429
423 // Enabled state listeners give a callback when tracing is enabled or 430 // Enabled state listeners give a callback when tracing is enabled or
424 // disabled. This can be used to tie into other library's tracing systems 431 // disabled. This can be used to tie into other library's tracing systems
425 // on-demand. 432 // on-demand.
426 class EnabledStateObserver { 433 class EnabledStateObserver {
427 public: 434 public:
428 // Called just after the tracing system becomes enabled, outside of the 435 // Called just after the tracing system becomes enabled, outside of the
429 // |lock_|. TraceLog::IsEnabled() is true at this point. 436 // |lock_|. TraceLog::IsEnabled() is true at this point.
430 virtual void OnTraceLogEnabled() = 0; 437 virtual void OnTraceLogEnabled() = 0;
431 438
432 // Called just after the tracing system disables, outside of the |lock_|. 439 // Called just after the tracing system disables, outside of the |lock_|.
433 // TraceLog::IsEnabled() is false at this point. 440 // TraceLog::IsEnabled() is false at this point.
434 virtual void OnTraceLogDisabled() = 0; 441 virtual void OnTraceLogDisabled() = 0;
435 }; 442 };
436 void AddEnabledStateObserver(EnabledStateObserver* listener); 443 void AddEnabledStateObserver(EnabledStateObserver* listener);
437 void RemoveEnabledStateObserver(EnabledStateObserver* listener); 444 void RemoveEnabledStateObserver(EnabledStateObserver* listener);
438 bool HasEnabledStateObserver(EnabledStateObserver* listener) const; 445 bool HasEnabledStateObserver(EnabledStateObserver* listener) const;
439 446
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 TraceBufferRingBufferGetReturnChunk); 591 TraceBufferRingBufferGetReturnChunk);
585 FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture, 592 FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture,
586 TraceBufferRingBufferHalfIteration); 593 TraceBufferRingBufferHalfIteration);
587 FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture, 594 FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture,
588 TraceBufferRingBufferFullIteration); 595 TraceBufferRingBufferFullIteration);
589 596
590 // This allows constructor and destructor to be private and usable only 597 // This allows constructor and destructor to be private and usable only
591 // by the Singleton class. 598 // by the Singleton class.
592 friend struct DefaultSingletonTraits<TraceLog>; 599 friend struct DefaultSingletonTraits<TraceLog>;
593 600
594 // Enable/disable each category group based on the current enabled_, 601 // Enable/disable each category group based on the current mode_,
595 // category_filter_, event_callback_ and event_callback_category_filter_. 602 // category_filter_, event_callback_ and event_callback_category_filter_.
596 // Enable the category group if enabled_ is true and category_filter_ matches 603 // Enable the category group in the enabled mode if category_filter_ matches
597 // the category group, or event_callback_ is not null and 604 // the category group, or event_callback_ is not null and
598 // event_callback_category_filter_ matches the category group. 605 // event_callback_category_filter_ matches the category group.
599 void UpdateCategoryGroupEnabledFlags(); 606 void UpdateCategoryGroupEnabledFlags();
600 void UpdateCategoryGroupEnabledFlag(int category_index); 607 void UpdateCategoryGroupEnabledFlag(int category_index);
601 608
602 class ThreadLocalEventBuffer; 609 class ThreadLocalEventBuffer;
603 class OptionalAutoLock; 610 class OptionalAutoLock;
604 611
605 TraceLog(); 612 TraceLog();
606 ~TraceLog(); 613 ~TraceLog();
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 return timestamp - time_offset_; 652 return timestamp - time_offset_;
646 } 653 }
647 654
648 // This lock protects TraceLog member accesses (except for members protected 655 // This lock protects TraceLog member accesses (except for members protected
649 // by thread_info_lock_) from arbitrary threads. 656 // by thread_info_lock_) from arbitrary threads.
650 mutable Lock lock_; 657 mutable Lock lock_;
651 // This lock protects accesses to thread_names_, thread_event_start_times_ 658 // This lock protects accesses to thread_names_, thread_event_start_times_
652 // and thread_colors_. 659 // and thread_colors_.
653 Lock thread_info_lock_; 660 Lock thread_info_lock_;
654 int locked_line_; 661 int locked_line_;
655 bool enabled_; 662 Mode mode_;
656 int num_traces_recorded_; 663 int num_traces_recorded_;
657 scoped_ptr<TraceBuffer> logged_events_; 664 scoped_ptr<TraceBuffer> logged_events_;
658 subtle::AtomicWord /* EventCallback */ event_callback_; 665 subtle::AtomicWord /* EventCallback */ event_callback_;
659 bool dispatching_to_observer_list_; 666 bool dispatching_to_observer_list_;
660 std::vector<EnabledStateObserver*> enabled_state_observer_list_; 667 std::vector<EnabledStateObserver*> enabled_state_observer_list_;
661 668
662 std::string process_name_; 669 std::string process_name_;
663 base::hash_map<int, std::string> process_labels_; 670 base::hash_map<int, std::string> process_labels_;
664 int process_sort_index_; 671 int process_sort_index_;
665 base::hash_map<int, int> thread_sort_indices_; 672 base::hash_map<int, int> thread_sort_indices_;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 scoped_refptr<MessageLoopProxy> flush_message_loop_proxy_; 716 scoped_refptr<MessageLoopProxy> flush_message_loop_proxy_;
710 subtle::AtomicWord generation_; 717 subtle::AtomicWord generation_;
711 718
712 DISALLOW_COPY_AND_ASSIGN(TraceLog); 719 DISALLOW_COPY_AND_ASSIGN(TraceLog);
713 }; 720 };
714 721
715 } // namespace debug 722 } // namespace debug
716 } // namespace base 723 } // namespace base
717 724
718 #endif // BASE_DEBUG_TRACE_EVENT_IMPL_H_ 725 #endif // BASE_DEBUG_TRACE_EVENT_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698