| 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 #ifndef BASE_DEBUG_ACTIVITY_ANALYZER_H_ | 5 #ifndef BASE_DEBUG_ACTIVITY_ANALYZER_H_ |
| 6 #define BASE_DEBUG_ACTIVITY_ANALYZER_H_ | 6 #define BASE_DEBUG_ACTIVITY_ANALYZER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/base_export.h" | 13 #include "base/base_export.h" |
| 14 #include "base/debug/activity_tracker.h" | 14 #include "base/debug/activity_tracker.h" |
| 15 | 15 |
| 16 namespace base { | 16 namespace base { |
| 17 namespace debug { | 17 namespace debug { |
| 18 | 18 |
| 19 class GlobalActivityAnalyzer; |
| 20 |
| 19 // This class provides analysis of data captured from a ThreadActivityTracker. | 21 // This class provides analysis of data captured from a ThreadActivityTracker. |
| 20 // When created, it takes a snapshot of the data held by the tracker and | 22 // When created, it takes a snapshot of the data held by the tracker and |
| 21 // makes that information available to other code. | 23 // makes that information available to other code. |
| 22 class BASE_EXPORT ThreadActivityAnalyzer { | 24 class BASE_EXPORT ThreadActivityAnalyzer { |
| 23 public: | 25 public: |
| 26 struct BASE_EXPORT Snapshot : ThreadActivityTracker::Snapshot { |
| 27 Snapshot(); |
| 28 ~Snapshot(); |
| 29 |
| 30 // The user-data snapshot for an activity, matching the |activity_stack| |
| 31 // of ThreadActivityTracker::Snapshot, if any. |
| 32 std::vector<ActivityUserData::Snapshot> user_data_stack; |
| 33 }; |
| 34 |
| 24 // This class provides keys that uniquely identify a thread, even across | 35 // This class provides keys that uniquely identify a thread, even across |
| 25 // multiple processes. | 36 // multiple processes. |
| 26 class ThreadKey { | 37 class ThreadKey { |
| 27 public: | 38 public: |
| 28 ThreadKey(int64_t pid, int64_t tid) : pid_(pid), tid_(tid) {} | 39 ThreadKey(int64_t pid, int64_t tid) : pid_(pid), tid_(tid) {} |
| 29 | 40 |
| 30 bool operator<(const ThreadKey& rhs) const { | 41 bool operator<(const ThreadKey& rhs) const { |
| 31 if (pid_ != rhs.pid_) | 42 if (pid_ != rhs.pid_) |
| 32 return pid_ < rhs.pid_; | 43 return pid_ < rhs.pid_; |
| 33 return tid_ < rhs.tid_; | 44 return tid_ < rhs.tid_; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 52 ThreadActivityAnalyzer(void* base, size_t size); | 63 ThreadActivityAnalyzer(void* base, size_t size); |
| 53 | 64 |
| 54 // Creates an analyzer for a block of memory held within a persistent-memory | 65 // Creates an analyzer for a block of memory held within a persistent-memory |
| 55 // |allocator| at the given |reference|. A snapshot is taken immediately and | 66 // |allocator| at the given |reference|. A snapshot is taken immediately and |
| 56 // the memory is not referenced again. | 67 // the memory is not referenced again. |
| 57 ThreadActivityAnalyzer(PersistentMemoryAllocator* allocator, | 68 ThreadActivityAnalyzer(PersistentMemoryAllocator* allocator, |
| 58 PersistentMemoryAllocator::Reference reference); | 69 PersistentMemoryAllocator::Reference reference); |
| 59 | 70 |
| 60 ~ThreadActivityAnalyzer(); | 71 ~ThreadActivityAnalyzer(); |
| 61 | 72 |
| 73 // Adds information from the global analyzer. |
| 74 void AddGlobalInformation(GlobalActivityAnalyzer* global); |
| 75 |
| 62 // Returns true iff the contained data is valid. Results from all other | 76 // Returns true iff the contained data is valid. Results from all other |
| 63 // methods are undefined if this returns false. | 77 // methods are undefined if this returns false. |
| 64 bool IsValid() { return activity_snapshot_valid_; } | 78 bool IsValid() { return activity_snapshot_valid_; } |
| 65 | 79 |
| 66 // Gets the name of the thread. | 80 // Gets the name of the thread. |
| 67 const std::string& GetThreadName() { | 81 const std::string& GetThreadName() { |
| 68 return activity_snapshot_.thread_name; | 82 return activity_snapshot_.thread_name; |
| 69 } | 83 } |
| 70 | 84 |
| 71 // Gets the TheadKey for this thread. | 85 // Gets the TheadKey for this thread. |
| 72 ThreadKey GetThreadKey() { | 86 ThreadKey GetThreadKey() { |
| 73 return ThreadKey(activity_snapshot_.process_id, | 87 return ThreadKey(activity_snapshot_.process_id, |
| 74 activity_snapshot_.thread_id); | 88 activity_snapshot_.thread_id); |
| 75 } | 89 } |
| 76 | 90 |
| 77 const ActivitySnapshot& activity_snapshot() { return activity_snapshot_; } | 91 const Snapshot& activity_snapshot() { return activity_snapshot_; } |
| 78 | 92 |
| 79 private: | 93 private: |
| 80 friend class GlobalActivityAnalyzer; | 94 friend class GlobalActivityAnalyzer; |
| 81 | 95 |
| 82 // The snapshot of the activity tracker taken at the moment of construction. | 96 // The snapshot of the activity tracker taken at the moment of construction. |
| 83 ActivitySnapshot activity_snapshot_; | 97 Snapshot activity_snapshot_; |
| 84 | 98 |
| 85 // Flag indicating if the snapshot data is valid. | 99 // Flag indicating if the snapshot data is valid. |
| 86 bool activity_snapshot_valid_; | 100 bool activity_snapshot_valid_; |
| 87 | 101 |
| 88 // A reference into a persistent memory allocator, used by the global | 102 // A reference into a persistent memory allocator, used by the global |
| 89 // analyzer to know where this tracker came from. | 103 // analyzer to know where this tracker came from. |
| 90 PersistentMemoryAllocator::Reference allocator_reference_ = 0; | 104 PersistentMemoryAllocator::Reference allocator_reference_ = 0; |
| 91 | 105 |
| 92 DISALLOW_COPY_AND_ASSIGN(ThreadActivityAnalyzer); | 106 DISALLOW_COPY_AND_ASSIGN(ThreadActivityAnalyzer); |
| 93 }; | 107 }; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 // Iterates over all known valid analyzers or returns null if there are no | 139 // Iterates over all known valid analyzers or returns null if there are no |
| 126 // more. Ownership stays with the global analyzer object and all existing | 140 // more. Ownership stays with the global analyzer object and all existing |
| 127 // analyzer pointers are invalidated when GetFirstAnalyzer() is called. | 141 // analyzer pointers are invalidated when GetFirstAnalyzer() is called. |
| 128 ThreadActivityAnalyzer* GetFirstAnalyzer(); | 142 ThreadActivityAnalyzer* GetFirstAnalyzer(); |
| 129 ThreadActivityAnalyzer* GetNextAnalyzer(); | 143 ThreadActivityAnalyzer* GetNextAnalyzer(); |
| 130 | 144 |
| 131 // Gets the analyzer for a specific thread or null if there is none. | 145 // Gets the analyzer for a specific thread or null if there is none. |
| 132 // Ownership stays with the global analyzer object. | 146 // Ownership stays with the global analyzer object. |
| 133 ThreadActivityAnalyzer* GetAnalyzerForThread(const ThreadKey& key); | 147 ThreadActivityAnalyzer* GetAnalyzerForThread(const ThreadKey& key); |
| 134 | 148 |
| 149 // Extract user data based on a reference and its identifier. |
| 150 ActivityUserData::Snapshot GetUserDataSnapshot(uint32_t ref, uint32_t id); |
| 151 |
| 152 // Extract the global user data. |
| 153 ActivityUserData::Snapshot GetGlobalUserDataSnapshot(); |
| 154 |
| 135 // Gets all log messages stored within. | 155 // Gets all log messages stored within. |
| 136 std::vector<std::string> GetLogMessages(); | 156 std::vector<std::string> GetLogMessages(); |
| 137 | 157 |
| 138 // Gets the corresponding "program location" for a given "program counter". | 158 // Gets the corresponding "program location" for a given "program counter". |
| 139 // This will return {0,0} if no mapping could be found. | 159 // This will return {0,0} if no mapping could be found. |
| 140 ProgramLocation GetProgramLocationFromAddress(uint64_t address); | 160 ProgramLocation GetProgramLocationFromAddress(uint64_t address); |
| 141 | 161 |
| 142 private: | 162 private: |
| 143 using AnalyzerMap = | 163 using AnalyzerMap = |
| 144 std::map<ThreadKey, std::unique_ptr<ThreadActivityAnalyzer>>; | 164 std::map<ThreadKey, std::unique_ptr<ThreadActivityAnalyzer>>; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 162 // first/next iteration. | 182 // first/next iteration. |
| 163 AnalyzerMap::iterator analyzers_iterator_; | 183 AnalyzerMap::iterator analyzers_iterator_; |
| 164 | 184 |
| 165 DISALLOW_COPY_AND_ASSIGN(GlobalActivityAnalyzer); | 185 DISALLOW_COPY_AND_ASSIGN(GlobalActivityAnalyzer); |
| 166 }; | 186 }; |
| 167 | 187 |
| 168 } // namespace debug | 188 } // namespace debug |
| 169 } // namespace base | 189 } // namespace base |
| 170 | 190 |
| 171 #endif // BASE_DEBUG_ACTIVITY_ANALYZER_H_ | 191 #endif // BASE_DEBUG_ACTIVITY_ANALYZER_H_ |
| OLD | NEW |