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: |
24 // This class provides keys that uniquely identify a thread, even across | 26 // This class provides keys that uniquely identify a thread, even across |
25 // multiple processes. | 27 // multiple processes. |
26 class ThreadKey { | 28 class ThreadKey { |
27 public: | 29 public: |
28 ThreadKey(int64_t pid, int64_t tid) : pid_(pid), tid_(tid) {} | 30 ThreadKey(int64_t pid, int64_t tid) : pid_(pid), tid_(tid) {} |
(...skipping 23 matching lines...) Expand all Loading... |
52 ThreadActivityAnalyzer(void* base, size_t size); | 54 ThreadActivityAnalyzer(void* base, size_t size); |
53 | 55 |
54 // Creates an analyzer for a block of memory held within a persistent-memory | 56 // 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 | 57 // |allocator| at the given |reference|. A snapshot is taken immediately and |
56 // the memory is not referenced again. | 58 // the memory is not referenced again. |
57 ThreadActivityAnalyzer(PersistentMemoryAllocator* allocator, | 59 ThreadActivityAnalyzer(PersistentMemoryAllocator* allocator, |
58 PersistentMemoryAllocator::Reference reference); | 60 PersistentMemoryAllocator::Reference reference); |
59 | 61 |
60 ~ThreadActivityAnalyzer(); | 62 ~ThreadActivityAnalyzer(); |
61 | 63 |
| 64 // Adds information from the global analyzer. |
| 65 void AddGlobalInformation(GlobalActivityAnalyzer* global); |
| 66 |
62 // Returns true iff the contained data is valid. Results from all other | 67 // Returns true iff the contained data is valid. Results from all other |
63 // methods are undefined if this returns false. | 68 // methods are undefined if this returns false. |
64 bool IsValid() { return activity_snapshot_valid_; } | 69 bool IsValid() { return activity_snapshot_valid_; } |
65 | 70 |
66 // Gets the name of the thread. | 71 // Gets the name of the thread. |
67 const std::string& GetThreadName() { | 72 const std::string& GetThreadName() { |
68 return activity_snapshot_.thread_name; | 73 return activity_snapshot_.thread_name; |
69 } | 74 } |
70 | 75 |
71 // Gets the TheadKey for this thread. | 76 // Gets the TheadKey for this thread. |
72 ThreadKey GetThreadKey() { | 77 ThreadKey GetThreadKey() { |
73 return ThreadKey(activity_snapshot_.process_id, | 78 return ThreadKey(activity_snapshot_.process_id, |
74 activity_snapshot_.thread_id); | 79 activity_snapshot_.thread_id); |
75 } | 80 } |
76 | 81 |
| 82 // Gets the user-data snapshot for an activity based on its index in the |
| 83 // |activity_stack| field of the ActivitySnapshot. Ownership stays with |
| 84 // this instance. |
| 85 const ActivityUserData::Snapshot& GetUserDataSnapshot(size_t stack_index); |
| 86 |
77 const ActivitySnapshot& activity_snapshot() { return activity_snapshot_; } | 87 const ActivitySnapshot& activity_snapshot() { return activity_snapshot_; } |
78 | 88 |
79 private: | 89 private: |
80 friend class GlobalActivityAnalyzer; | 90 friend class GlobalActivityAnalyzer; |
81 | 91 |
82 // The snapshot of the activity tracker taken at the moment of construction. | 92 // The snapshot of the activity tracker taken at the moment of construction. |
83 ActivitySnapshot activity_snapshot_; | 93 ActivitySnapshot activity_snapshot_; |
84 | 94 |
85 // Flag indicating if the snapshot data is valid. | 95 // Flag indicating if the snapshot data is valid. |
86 bool activity_snapshot_valid_; | 96 bool activity_snapshot_valid_; |
87 | 97 |
| 98 // Copy of user-data associated with the stack. This is captured and held |
| 99 // because the data may change if used on a live system. |
| 100 std::vector<ActivityUserData::Snapshot> user_data_snapshots_; |
| 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 }; |
94 | 108 |
95 | 109 |
96 // This class manages analyzers for all known processes and threads as stored | 110 // This class manages analyzers for all known processes and threads as stored |
97 // in a persistent memory allocator. It supports retrieval of them through | 111 // in a persistent memory allocator. It supports retrieval of them through |
(...skipping 27 matching lines...) Expand all 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 the corresponding "program location" for a given "program counter". | 155 // Gets the corresponding "program location" for a given "program counter". |
136 // This will return {0,0} if no mapping could be found. | 156 // This will return {0,0} if no mapping could be found. |
137 ProgramLocation GetProgramLocationFromAddress(uint64_t address); | 157 ProgramLocation GetProgramLocationFromAddress(uint64_t address); |
138 | 158 |
139 private: | 159 private: |
140 using AnalyzerMap = | 160 using AnalyzerMap = |
141 std::map<ThreadKey, std::unique_ptr<ThreadActivityAnalyzer>>; | 161 std::map<ThreadKey, std::unique_ptr<ThreadActivityAnalyzer>>; |
142 | 162 |
143 // Finds, creates, and indexes analyzers for all known processes and threads. | 163 // Finds, creates, and indexes analyzers for all known processes and threads. |
144 void PrepareAllAnalyzers(); | 164 void PrepareAllAnalyzers(); |
(...skipping 14 matching lines...) Expand all Loading... |
159 // first/next iteration. | 179 // first/next iteration. |
160 AnalyzerMap::iterator analyzers_iterator_; | 180 AnalyzerMap::iterator analyzers_iterator_; |
161 | 181 |
162 DISALLOW_COPY_AND_ASSIGN(GlobalActivityAnalyzer); | 182 DISALLOW_COPY_AND_ASSIGN(GlobalActivityAnalyzer); |
163 }; | 183 }; |
164 | 184 |
165 } // namespace debug | 185 } // namespace debug |
166 } // namespace base | 186 } // namespace base |
167 | 187 |
168 #endif // BASE_DEBUG_ACTIVITY_ANALYZER_H_ | 188 #endif // BASE_DEBUG_ACTIVITY_ANALYZER_H_ |
OLD | NEW |