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

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

Issue 2754483002: Add analyzer support for multiple processes. (Closed)
Patch Set: rebased Created 3 years, 9 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 | « no previous file | base/debug/activity_analyzer.cc » ('j') | base/debug/activity_analyzer.cc » ('J')
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 #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 #include <vector>
12 13
13 #include "base/base_export.h" 14 #include "base/base_export.h"
14 #include "base/debug/activity_tracker.h" 15 #include "base/debug/activity_tracker.h"
15 16
16 namespace base { 17 namespace base {
17 namespace debug { 18 namespace debug {
18 19
19 class GlobalActivityAnalyzer; 20 class GlobalActivityAnalyzer;
20 21
21 // This class provides analysis of data captured from a ThreadActivityTracker. 22 // This class provides analysis of data captured from a ThreadActivityTracker.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 71
71 ~ThreadActivityAnalyzer(); 72 ~ThreadActivityAnalyzer();
72 73
73 // Adds information from the global analyzer. 74 // Adds information from the global analyzer.
74 void AddGlobalInformation(GlobalActivityAnalyzer* global); 75 void AddGlobalInformation(GlobalActivityAnalyzer* global);
75 76
76 // Returns true iff the contained data is valid. Results from all other 77 // Returns true iff the contained data is valid. Results from all other
77 // methods are undefined if this returns false. 78 // methods are undefined if this returns false.
78 bool IsValid() { return activity_snapshot_valid_; } 79 bool IsValid() { return activity_snapshot_valid_; }
79 80
81 // Gets the process id and its creation stamp.
82 int64_t GetProcessId(int64_t* out_stamp = nullptr) {
83 if (out_stamp)
84 *out_stamp = activity_snapshot_.create_stamp;
85 return activity_snapshot_.process_id;
86 }
87
80 // Gets the name of the thread. 88 // Gets the name of the thread.
81 const std::string& GetThreadName() { 89 const std::string& GetThreadName() {
82 return activity_snapshot_.thread_name; 90 return activity_snapshot_.thread_name;
83 } 91 }
84 92
85 // Gets the TheadKey for this thread. 93 // Gets the TheadKey for this thread.
86 ThreadKey GetThreadKey() { 94 ThreadKey GetThreadKey() {
87 return ThreadKey(activity_snapshot_.process_id, 95 return ThreadKey(activity_snapshot_.process_id,
88 activity_snapshot_.thread_id); 96 activity_snapshot_.thread_id);
89 } 97 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 137
130 ~GlobalActivityAnalyzer(); 138 ~GlobalActivityAnalyzer();
131 139
132 #if !defined(OS_NACL) 140 #if !defined(OS_NACL)
133 // Creates a global analyzer using the contents of a file given in 141 // Creates a global analyzer using the contents of a file given in
134 // |file_path|. 142 // |file_path|.
135 static std::unique_ptr<GlobalActivityAnalyzer> CreateWithFile( 143 static std::unique_ptr<GlobalActivityAnalyzer> CreateWithFile(
136 const FilePath& file_path); 144 const FilePath& file_path);
137 #endif // !defined(OS_NACL) 145 #endif // !defined(OS_NACL)
138 146
139 // Iterates over all known valid analyzers or returns null if there are no 147 // Iterates over all known valid processes and returns their PIDs or zero if
manzagop (departed) 2017/03/21 21:10:05 So... can zero be a valid pid? (just checking)
bcwhite 2017/03/29 22:00:51 No.
manzagop (departed) 2017/03/30 18:13:24 On windows it's a valid pid, but not one we'll hav
bcwhite 2017/03/30 22:20:51 Acknowledged.
140 // more. Ownership stays with the global analyzer object and all existing 148 // there are no more. Calls to GetFirstProcess() will perform a global
141 // analyzer pointers are invalidated when GetFirstAnalyzer() is called. 149 // snapshot in order to provide a relatively consistent state across the
142 ThreadActivityAnalyzer* GetFirstAnalyzer(); 150 // future calls to GetNextProcess() and GetFirst/NextAnalyzer().
143 ThreadActivityAnalyzer* GetNextAnalyzer(); 151 int64_t GetFirstProcess();
152 int64_t GetNextProcess();
153
154 // Iterates over all known valid analyzers for the a given process or returns
155 // null if there are no more.
156 //
157 // GetFirstProcess() must be called first in order to capture a global
158 // snapshot! Ownership stays with the global analyzer object and all existing
159 // analyzer pointers are invalidated when GetFirstProcess() is called.
manzagop (departed) 2017/03/21 21:10:05 May be worth mentioning GetNextAnalyzer calls for
bcwhite 2017/03/29 22:00:51 Better to get rid of the parameter altogether so i
160 ThreadActivityAnalyzer* GetFirstAnalyzer(int64_t pid);
161 ThreadActivityAnalyzer* GetNextAnalyzer(int64_t pid);
144 162
145 // Gets the analyzer for a specific thread or null if there is none. 163 // Gets the analyzer for a specific thread or null if there is none.
146 // Ownership stays with the global analyzer object. 164 // Ownership stays with the global analyzer object.
147 ThreadActivityAnalyzer* GetAnalyzerForThread(const ThreadKey& key); 165 ThreadActivityAnalyzer* GetAnalyzerForThread(const ThreadKey& key);
148 166
149 // Extract user data based on a reference and its identifier. 167 // Extract user data based on a reference and its identifier.
150 ActivityUserData::Snapshot GetUserDataSnapshot(uint32_t ref, uint32_t id); 168 ActivityUserData::Snapshot GetUserDataSnapshot(int64_t pid,
169 uint32_t ref,
170 uint32_t id);
151 171
152 // Extract the global user data. 172 // Extract the data for a specific process. An empty snapshot will be
153 ActivityUserData::Snapshot GetGlobalUserDataSnapshot(); 173 // returned if the process is not known.
174 const ActivityUserData::Snapshot& GetProcessDataSnapshot(int64_t pid);
175
176 // Extract the global data.
177 const ActivityUserData::Snapshot& GetGlobalDataSnapshot();
154 178
155 // Gets all log messages stored within. 179 // Gets all log messages stored within.
156 std::vector<std::string> GetLogMessages(); 180 std::vector<std::string> GetLogMessages();
157 181
158 // Gets all the known modules. 182 // Gets all the known modules.
159 std::vector<GlobalActivityTracker::ModuleInfo> GetModules(); 183 std::vector<GlobalActivityTracker::ModuleInfo> GetModules();
160 184
161 // Gets the corresponding "program location" for a given "program counter". 185 // Gets the corresponding "program location" for a given "program counter".
162 // This will return {0,0} if no mapping could be found. 186 // This will return {0,0} if no mapping could be found.
163 ProgramLocation GetProgramLocationFromAddress(uint64_t address); 187 ProgramLocation GetProgramLocationFromAddress(uint64_t address);
164 188
165 private: 189 private:
166 using AnalyzerMap = 190 using AnalyzerMap =
167 std::map<ThreadKey, std::unique_ptr<ThreadActivityAnalyzer>>; 191 std::map<ThreadKey, std::unique_ptr<ThreadActivityAnalyzer>>;
168 192
193 struct UserDataSnapshot {
194 // Complex class needs out-of-line ctor/dtor.
195 UserDataSnapshot();
196 UserDataSnapshot(const UserDataSnapshot& rhs);
197 UserDataSnapshot(UserDataSnapshot&& rhs);
198 ~UserDataSnapshot();
199
200 int64_t process_id;
201 int64_t create_stamp;
202 ActivityUserData::Snapshot data;
203 };
204
169 // Finds, creates, and indexes analyzers for all known processes and threads. 205 // Finds, creates, and indexes analyzers for all known processes and threads.
170 void PrepareAllAnalyzers(); 206 void PrepareAllAnalyzers();
171 207
172 // The persistent memory allocator holding all tracking data. 208 // The persistent memory allocator holding all tracking data.
173 std::unique_ptr<PersistentMemoryAllocator> allocator_; 209 std::unique_ptr<PersistentMemoryAllocator> allocator_;
174 210
211 // The time stamp when analysis began. This is used to prevent looking into
212 // process IDs that get reused when analyzing a live system.
213 int64_t analysis_stamp_;
214
175 // The iterator for finding tracking information in the allocator. 215 // The iterator for finding tracking information in the allocator.
176 PersistentMemoryAllocator::Iterator allocator_iterator_; 216 PersistentMemoryAllocator::Iterator allocator_iterator_;
177 217
178 // A set of all tracker memory references found within the allocator. 218 // A set of all interesting memory references found within the allocator.
179 std::set<PersistentMemoryAllocator::Reference> tracker_references_; 219 std::set<PersistentMemoryAllocator::Reference> memory_references_;
220
221 // A set of all process-data memory references found within the allocator.
222 std::map<int64_t, UserDataSnapshot> process_data_;
223
224 // A set of all known process IDs.
manzagop (departed) 2017/03/21 21:10:05 Looks like this empties itself as we iterate over
bcwhite 2017/03/29 22:00:51 Done.
225 std::vector<int64_t> process_ids_;
180 226
181 // A map, keyed by ThreadKey, of all valid activity analyzers. 227 // A map, keyed by ThreadKey, of all valid activity analyzers.
182 AnalyzerMap analyzers_; 228 AnalyzerMap analyzers_;
183 229
184 // The iterator within the analyzers_ map for returning analyzers through 230 // The iterator within the analyzers_ map for returning analyzers through
185 // first/next iteration. 231 // first/next iteration.
186 AnalyzerMap::iterator analyzers_iterator_; 232 AnalyzerMap::iterator analyzers_iterator_;
187 233
234 // Snapshot of the global data.
235 ActivityUserData::Snapshot global_data_snapshot_;
236
188 DISALLOW_COPY_AND_ASSIGN(GlobalActivityAnalyzer); 237 DISALLOW_COPY_AND_ASSIGN(GlobalActivityAnalyzer);
189 }; 238 };
190 239
191 } // namespace debug 240 } // namespace debug
192 } // namespace base 241 } // namespace base
193 242
194 #endif // BASE_DEBUG_ACTIVITY_ANALYZER_H_ 243 #endif // BASE_DEBUG_ACTIVITY_ANALYZER_H_
OLDNEW
« no previous file with comments | « no previous file | base/debug/activity_analyzer.cc » ('j') | base/debug/activity_analyzer.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698