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

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

Issue 2753573002: Remove 'global' user-data in favor of 'process' user-data. (Closed)
Patch Set: rebased Created 3 years, 8 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/activity_analyzer_unittest.cc ('k') | base/debug/activity_tracker.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 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 746 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 // identified during extraction; the first 4 bytes of the SHA1 of the name 757 // identified during extraction; the first 4 bytes of the SHA1 of the name
758 // is used as a unique integer. A "version number" is added to the base 758 // is used as a unique integer. A "version number" is added to the base
759 // so that, if the structure of that object changes, stored older versions 759 // so that, if the structure of that object changes, stored older versions
760 // will be safely ignored. These are public so that an external process 760 // will be safely ignored. These are public so that an external process
761 // can recognize records of this type within an allocator. 761 // can recognize records of this type within an allocator.
762 enum : uint32_t { 762 enum : uint32_t {
763 kTypeIdActivityTracker = 0x5D7381AF + 4, // SHA1(ActivityTracker) v4 763 kTypeIdActivityTracker = 0x5D7381AF + 4, // SHA1(ActivityTracker) v4
764 kTypeIdUserDataRecord = 0x615EDDD7 + 3, // SHA1(UserDataRecord) v3 764 kTypeIdUserDataRecord = 0x615EDDD7 + 3, // SHA1(UserDataRecord) v3
765 kTypeIdGlobalLogMessage = 0x4CF434F9 + 1, // SHA1(GlobalLogMessage) v1 765 kTypeIdGlobalLogMessage = 0x4CF434F9 + 1, // SHA1(GlobalLogMessage) v1
766 kTypeIdProcessDataRecord = kTypeIdUserDataRecord + 0x100, 766 kTypeIdProcessDataRecord = kTypeIdUserDataRecord + 0x100,
767 kTypeIdGlobalDataRecord = kTypeIdUserDataRecord + 0x200,
768 767
769 kTypeIdActivityTrackerFree = ~kTypeIdActivityTracker, 768 kTypeIdActivityTrackerFree = ~kTypeIdActivityTracker,
770 kTypeIdUserDataRecordFree = ~kTypeIdUserDataRecord, 769 kTypeIdUserDataRecordFree = ~kTypeIdUserDataRecord,
771 kTypeIdProcessDataRecordFree = ~kTypeIdProcessDataRecord, 770 kTypeIdProcessDataRecordFree = ~kTypeIdProcessDataRecord,
772 }; 771 };
773 772
774 // An enumeration of common process life stages. All entries are given an 773 // An enumeration of common process life stages. All entries are given an
775 // explicit number so they are known and remain constant; this allows for 774 // explicit number so they are known and remain constant; this allows for
776 // cross-version analysis either locally or on a server. 775 // cross-version analysis either locally or on a server.
777 enum ProcessPhase : int { 776 enum ProcessPhase : int {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 // many times a module may be loaded and unloaded. 818 // many times a module may be loaded and unloaded.
820 size_t size = 0; // The size of the loaded module. 819 size_t size = 0; // The size of the loaded module.
821 uint32_t timestamp = 0; // Opaque "timestamp" for the module. 820 uint32_t timestamp = 0; // Opaque "timestamp" for the module.
822 uint32_t age = 0; // Opaque "age" for the module. 821 uint32_t age = 0; // Opaque "age" for the module.
823 uint8_t identifier[16]; // Opaque identifier (GUID, etc.) for the module. 822 uint8_t identifier[16]; // Opaque identifier (GUID, etc.) for the module.
824 std::string file; // The full path to the file. (UTF-8) 823 std::string file; // The full path to the file. (UTF-8)
825 std::string debug_file; // The full path to the debug file. 824 std::string debug_file; // The full path to the debug file.
826 }; 825 };
827 826
828 // This is a thin wrapper around the thread-tracker's ScopedActivity that 827 // This is a thin wrapper around the thread-tracker's ScopedActivity that
829 // accesses the global tracker to provide some of the information, notably 828 // allows thread-safe access to data values. It is safe to use even if
830 // which thread-tracker to use. It is safe to create even if activity 829 // activity tracking is not enabled.
831 // tracking is not enabled.
832 class BASE_EXPORT ScopedThreadActivity 830 class BASE_EXPORT ScopedThreadActivity
833 : public ThreadActivityTracker::ScopedActivity { 831 : public ThreadActivityTracker::ScopedActivity {
834 public: 832 public:
835 ScopedThreadActivity(const void* program_counter, 833 ScopedThreadActivity(const void* program_counter,
836 const void* origin, 834 const void* origin,
837 Activity::Type type, 835 Activity::Type type,
838 const ActivityData& data, 836 const ActivityData& data,
839 bool lock_allowed); 837 bool lock_allowed);
840 ~ScopedThreadActivity(); 838 ~ScopedThreadActivity();
841 839
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 } 1023 }
1026 1024
1027 // Gets the process ID used for tracking. This is typically the same as what 1025 // Gets the process ID used for tracking. This is typically the same as what
1028 // the OS thinks is the current process but can be overridden for testing. 1026 // the OS thinks is the current process but can be overridden for testing.
1029 int64_t process_id() { return process_id_; }; 1027 int64_t process_id() { return process_id_; };
1030 1028
1031 // Accesses the process data record for storing arbitrary key/value pairs. 1029 // Accesses the process data record for storing arbitrary key/value pairs.
1032 // Updates to this are thread-safe. 1030 // Updates to this are thread-safe.
1033 ActivityUserData& process_data() { return process_data_; } 1031 ActivityUserData& process_data() { return process_data_; }
1034 1032
1035 // Accesses the global data record for storing arbitrary key/value pairs.
1036 // Updates to this are thread-safe.
1037 ActivityUserData& global_data() { return global_data_; }
1038
1039 private: 1033 private:
1040 friend class GlobalActivityAnalyzer; 1034 friend class GlobalActivityAnalyzer;
1041 friend class ScopedThreadActivity; 1035 friend class ScopedThreadActivity;
1042 friend class ActivityTrackerTest; 1036 friend class ActivityTrackerTest;
1043 1037
1044 enum : int { 1038 enum : int {
1045 // The maximum number of threads that can be tracked within a process. If 1039 // The maximum number of threads that can be tracked within a process. If
1046 // more than this number run concurrently, tracking of new ones may cease. 1040 // more than this number run concurrently, tracking of new ones may cease.
1047 kMaxThreadCount = 100, 1041 kMaxThreadCount = 100,
1048 kCachedThreadMemories = 10, 1042 kCachedThreadMemories = 10,
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 // A caching memory allocator for thread-tracker objects. 1177 // A caching memory allocator for thread-tracker objects.
1184 ActivityTrackerMemoryAllocator thread_tracker_allocator_; 1178 ActivityTrackerMemoryAllocator thread_tracker_allocator_;
1185 base::Lock thread_tracker_allocator_lock_; 1179 base::Lock thread_tracker_allocator_lock_;
1186 1180
1187 // A caching memory allocator for user data attached to activity data. 1181 // A caching memory allocator for user data attached to activity data.
1188 ActivityTrackerMemoryAllocator user_data_allocator_; 1182 ActivityTrackerMemoryAllocator user_data_allocator_;
1189 base::Lock user_data_allocator_lock_; 1183 base::Lock user_data_allocator_lock_;
1190 1184
1191 // An object for holding arbitrary key value pairs with thread-safe access. 1185 // An object for holding arbitrary key value pairs with thread-safe access.
1192 ThreadSafeUserData process_data_; 1186 ThreadSafeUserData process_data_;
1193 ThreadSafeUserData global_data_;
1194 1187
1195 // A map of global module information, keyed by module path. 1188 // A map of global module information, keyed by module path.
1196 std::map<const std::string, ModuleInfoRecord*> modules_; 1189 std::map<const std::string, ModuleInfoRecord*> modules_;
1197 base::Lock modules_lock_; 1190 base::Lock modules_lock_;
1198 1191
1199 // The active global activity tracker. 1192 // The active global activity tracker.
1200 static subtle::AtomicWord g_tracker_; 1193 static subtle::AtomicWord g_tracker_;
1201 1194
1202 // A lock that is used to protect access to the following fields. 1195 // A lock that is used to protect access to the following fields.
1203 base::Lock global_tracker_lock_; 1196 base::Lock global_tracker_lock_;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1341 ScopedProcessWaitActivity(const void* program_counter, 1334 ScopedProcessWaitActivity(const void* program_counter,
1342 const base::Process* process); 1335 const base::Process* process);
1343 DISALLOW_COPY_AND_ASSIGN(ScopedProcessWaitActivity); 1336 DISALLOW_COPY_AND_ASSIGN(ScopedProcessWaitActivity);
1344 }; 1337 };
1345 #endif 1338 #endif
1346 1339
1347 } // namespace debug 1340 } // namespace debug
1348 } // namespace base 1341 } // namespace base
1349 1342
1350 #endif // BASE_DEBUG_ACTIVITY_TRACKER_H_ 1343 #endif // BASE_DEBUG_ACTIVITY_TRACKER_H_
OLDNEW
« no previous file with comments | « base/debug/activity_analyzer_unittest.cc ('k') | base/debug/activity_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698