Chromium Code Reviews| Index: base/debug/activity_tracker.h |
| diff --git a/base/debug/activity_tracker.h b/base/debug/activity_tracker.h |
| index 789905e288ae980b241977dae9fb7ac6d285e7ab..6ae6b2d79f2101faf62289d8a43f6159eb912ca9 100644 |
| --- a/base/debug/activity_tracker.h |
| +++ b/base/debug/activity_tracker.h |
| @@ -636,6 +636,7 @@ class BASE_EXPORT GlobalActivityTracker { |
| enum : uint32_t { |
| kTypeIdActivityTracker = 0x5D7381AF + 3, // SHA1(ActivityTracker) v3 |
| kTypeIdUserDataRecord = 0x615EDDD7 + 2, // SHA1(UserDataRecord) v2 |
| + kTypeIdModuleInfoRecord = 0x05DB5F41 + 1, // SHA1(ModuleInfoRecord) v1 |
| kTypeIdGlobalLogMessage = 0x4CF434F9 + 1, // SHA1(GlobalLogMessage) v1 |
| kTypeIdGlobalDataRecord = kTypeIdUserDataRecord + 1000, |
| @@ -643,6 +644,25 @@ class BASE_EXPORT GlobalActivityTracker { |
| kTypeIdUserDataRecordFree = ~kTypeIdUserDataRecord, |
| }; |
| + struct BASE_EXPORT ModuleInfo { |
| + ModuleInfo(); |
| + ModuleInfo(ModuleInfo&& rhs); |
| + ModuleInfo(const ModuleInfo& rhs); |
| + ~ModuleInfo(); |
| + |
| + ModuleInfo& operator=(ModuleInfo&& rhs); |
| + ModuleInfo& operator=(const ModuleInfo& rhs); |
| + |
| + bool is_loaded = false; |
| + uintptr_t address = 0; |
| + size_t size = 0; |
| + std::string file; |
| + std::string version; |
| + std::string identifier; |
| + std::string debug_file; |
| + std::string debug_identifier; |
| + }; |
| + |
| // This is a thin wrapper around the thread-tracker's ScopedActivity that |
| // accesses the global tracker to provide some of the information, notably |
| // which thread-tracker to use. It is safe to create even if activity |
| @@ -746,10 +766,15 @@ class BASE_EXPORT GlobalActivityTracker { |
| // only store critical messages such as FATAL ones. |
| void RecordLogMessage(StringPiece message); |
| + // Records a module load/unload event. This is safe to call multiple times |
| + // even with the same information. |
| + void RecordModuleInfo(const ModuleInfo& info); |
| + |
| // Accesses the global data record for storing arbitrary key/value pairs. |
| ActivityUserData& user_data() { return user_data_; } |
| private: |
| + friend class GlobalActivityAnalyzer; |
| friend class ScopedThreadActivity; |
| friend class ActivityTrackerTest; |
| @@ -761,6 +786,31 @@ class BASE_EXPORT GlobalActivityTracker { |
| kCachedUserDataMemories = 10, |
| }; |
| + // State of a module as stored in persistent memory. |
| + struct BASE_EXPORT ModuleInfoRecord { |
| + // Expected size for 32/64-bit check. |
|
manzagop (departed)
2016/12/16 16:09:31
Mention this is PMA requirement?
bcwhite
2016/12/16 18:35:15
Done.
|
| + static constexpr size_t kExpectedInstanceSize = 24; |
| + |
| + uint64_t address; // The base address of the module. |
| + uint64_t size; // The size of the module in bytes. |
| + uint16_t pickle_size; // The size of the following pickle. |
| + uint8_t loaded; // Flag indicating if module is loaded or not. |
| + char pickle[5]; // Other strings; may allocate larger. |
| + |
| + // Decodes/encodes storage structure from more generic info structure. |
| + bool DecodeTo(GlobalActivityTracker::ModuleInfo* info, |
| + size_t record_size) const; |
| + bool EncodeFrom(const GlobalActivityTracker::ModuleInfo& info, |
| + size_t record_size); |
| + |
| + // Updates the core information without changing the encoded strings. This |
| + // is useful when a known module changes state (i.e. new load or unload). |
| + bool UpdateFrom(const GlobalActivityTracker::ModuleInfo& info); |
| + |
| + // Determines the required memory size for the encoded storage. |
| + static size_t EncodedSize(const GlobalActivityTracker::ModuleInfo& info); |
| + }; |
| + |
| // A thin wrapper around the main thread-tracker that keeps additional |
| // information that the global tracker needs to handle joined threads. |
| class ManagedActivityTracker : public ThreadActivityTracker { |
| @@ -822,6 +872,10 @@ class BASE_EXPORT GlobalActivityTracker { |
| // be written from the main UI thread. |
| ActivityUserData user_data_; |
| + // A map of global module information, keyed by module path. |
| + std::map<const std::string, PersistentMemoryAllocator::Reference> modules_; |
| + base::Lock modules_lock_; |
| + |
| // The active global activity tracker. |
| static GlobalActivityTracker* g_tracker_; |