| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 // Activity tracking provides a low-overhead method of collecting information | 5 // Activity tracking provides a low-overhead method of collecting information |
| 6 // about the state of the application for analysis both while it is running | 6 // about the state of the application for analysis both while it is running |
| 7 // and after it has terminated unexpectedly. Its primary purpose is to help | 7 // and after it has terminated unexpectedly. Its primary purpose is to help |
| 8 // locate reasons the browser becomes unresponsive by providing insight into | 8 // locate reasons the browser becomes unresponsive by providing insight into |
| 9 // what all the various threads and processes are (or were) doing. | 9 // what all the various threads and processes are (or were) doing. |
| 10 | 10 |
| (...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 uint64_t id, | 744 uint64_t id, |
| 745 StringPiece name, | 745 StringPiece name, |
| 746 int stack_depth); | 746 int stack_depth); |
| 747 | 747 |
| 748 // Gets the global activity-tracker or null if none exists. | 748 // Gets the global activity-tracker or null if none exists. |
| 749 static GlobalActivityTracker* Get() { | 749 static GlobalActivityTracker* Get() { |
| 750 return reinterpret_cast<GlobalActivityTracker*>( | 750 return reinterpret_cast<GlobalActivityTracker*>( |
| 751 subtle::Acquire_Load(&g_tracker_)); | 751 subtle::Acquire_Load(&g_tracker_)); |
| 752 } | 752 } |
| 753 | 753 |
| 754 // Convenience method for determining if a global tracker is active. |
| 755 static bool IsEnabled() { return Get() != nullptr; } |
| 756 |
| 754 // Gets the persistent-memory-allocator in which data is stored. Callers | 757 // Gets the persistent-memory-allocator in which data is stored. Callers |
| 755 // can store additional records here to pass more information to the | 758 // can store additional records here to pass more information to the |
| 756 // analysis process. | 759 // analysis process. |
| 757 PersistentMemoryAllocator* allocator() { return allocator_.get(); } | 760 PersistentMemoryAllocator* allocator() { return allocator_.get(); } |
| 758 | 761 |
| 759 // Gets the thread's activity-tracker if it exists. This is inline for | 762 // Gets the thread's activity-tracker if it exists. This is inline for |
| 760 // performance reasons and it uses thread-local-storage (TLS) so that there | 763 // performance reasons and it uses thread-local-storage (TLS) so that there |
| 761 // is no significant lookup time required to find the one for the calling | 764 // is no significant lookup time required to find the one for the calling |
| 762 // thread. Ownership remains with the global tracker. | 765 // thread. Ownership remains with the global tracker. |
| 763 ThreadActivityTracker* GetTrackerForCurrentThread() { | 766 ThreadActivityTracker* GetTrackerForCurrentThread() { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 776 | 779 |
| 777 // Creates an activity-tracker for the current thread. | 780 // Creates an activity-tracker for the current thread. |
| 778 ThreadActivityTracker* CreateTrackerForCurrentThread(); | 781 ThreadActivityTracker* CreateTrackerForCurrentThread(); |
| 779 | 782 |
| 780 // Releases the activity-tracker for the current thread (for testing only). | 783 // Releases the activity-tracker for the current thread (for testing only). |
| 781 void ReleaseTrackerForCurrentThreadForTesting(); | 784 void ReleaseTrackerForCurrentThreadForTesting(); |
| 782 | 785 |
| 783 // Records a log message. The current implementation does NOT recycle these | 786 // Records a log message. The current implementation does NOT recycle these |
| 784 // only store critical messages such as FATAL ones. | 787 // only store critical messages such as FATAL ones. |
| 785 void RecordLogMessage(StringPiece message); | 788 void RecordLogMessage(StringPiece message); |
| 789 static void RecordLogMessageIfEnabled(StringPiece message) { |
| 790 GlobalActivityTracker* tracker = Get(); |
| 791 if (tracker) |
| 792 tracker->RecordLogMessage(message); |
| 793 } |
| 786 | 794 |
| 787 // Records a module load/unload event. This is safe to call multiple times | 795 // Records a module load/unload event. This is safe to call multiple times |
| 788 // even with the same information. | 796 // even with the same information. |
| 789 void RecordModuleInfo(const ModuleInfo& info); | 797 void RecordModuleInfo(const ModuleInfo& info); |
| 798 static void RecordModuleInfoIfEnabled(const ModuleInfo& info) { |
| 799 GlobalActivityTracker* tracker = Get(); |
| 800 if (tracker) |
| 801 tracker->RecordModuleInfo(info); |
| 802 } |
| 790 | 803 |
| 791 // Record field trial information. This call is thread-safe. In addition to | 804 // Record field trial information. This call is thread-safe. In addition to |
| 792 // this, construction of a GlobalActivityTracker will cause all existing | 805 // this, construction of a GlobalActivityTracker will cause all existing |
| 793 // active field trials to be fetched and recorded. | 806 // active field trials to be fetched and recorded. |
| 794 void RecordFieldTrial(const std::string& trial_name, StringPiece group_name); | 807 void RecordFieldTrial(const std::string& trial_name, StringPiece group_name); |
| 808 static void RecordFieldTrialIfEnabled(const std::string& trial_name, |
| 809 StringPiece group_name) { |
| 810 GlobalActivityTracker* tracker = Get(); |
| 811 if (tracker) |
| 812 tracker->RecordFieldTrial(trial_name, group_name); |
| 813 } |
| 795 | 814 |
| 796 // Accesses the global data record for storing arbitrary key/value pairs. | 815 // Accesses the global data record for storing arbitrary key/value pairs. |
| 797 ActivityUserData& global_data() { return global_data_; } | 816 ActivityUserData& global_data() { return global_data_; } |
| 798 | 817 |
| 799 private: | 818 private: |
| 800 friend class GlobalActivityAnalyzer; | 819 friend class GlobalActivityAnalyzer; |
| 801 friend class ScopedThreadActivity; | 820 friend class ScopedThreadActivity; |
| 802 friend class ActivityTrackerTest; | 821 friend class ActivityTrackerTest; |
| 803 | 822 |
| 804 enum : int { | 823 enum : int { |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1068 ScopedProcessWaitActivity(const void* program_counter, | 1087 ScopedProcessWaitActivity(const void* program_counter, |
| 1069 const base::Process* process); | 1088 const base::Process* process); |
| 1070 DISALLOW_COPY_AND_ASSIGN(ScopedProcessWaitActivity); | 1089 DISALLOW_COPY_AND_ASSIGN(ScopedProcessWaitActivity); |
| 1071 }; | 1090 }; |
| 1072 #endif | 1091 #endif |
| 1073 | 1092 |
| 1074 } // namespace debug | 1093 } // namespace debug |
| 1075 } // namespace base | 1094 } // namespace base |
| 1076 | 1095 |
| 1077 #endif // BASE_DEBUG_ACTIVITY_TRACKER_H_ | 1096 #endif // BASE_DEBUG_ACTIVITY_TRACKER_H_ |
| OLD | NEW |