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 #include "components/browser_watcher/postmortem_report_extractor.h" | 5 #include "components/browser_watcher/postmortem_report_extractor.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 | 209 |
210 // Create a global analyzer. | 210 // Create a global analyzer. |
211 std::unique_ptr<GlobalActivityAnalyzer> global_analyzer = | 211 std::unique_ptr<GlobalActivityAnalyzer> global_analyzer = |
212 GlobalActivityAnalyzer::CreateWithFile(stability_file); | 212 GlobalActivityAnalyzer::CreateWithFile(stability_file); |
213 if (!global_analyzer) | 213 if (!global_analyzer) |
214 return ANALYZER_CREATION_FAILED; | 214 return ANALYZER_CREATION_FAILED; |
215 | 215 |
216 // Early exit if there is no data. | 216 // Early exit if there is no data. |
217 std::vector<std::string> log_messages = global_analyzer->GetLogMessages(); | 217 std::vector<std::string> log_messages = global_analyzer->GetLogMessages(); |
218 ActivityUserData::Snapshot global_data_snapshot = | 218 ActivityUserData::Snapshot global_data_snapshot = |
219 global_analyzer->GetGlobalUserDataSnapshot(); | 219 global_analyzer->GetGlobalDataSnapshot(); |
220 ThreadActivityAnalyzer* thread_analyzer = global_analyzer->GetFirstAnalyzer(); | 220 |
| 221 // Extract data for only the first process. |
| 222 // TODO(manzagop): Extend this to all processes. |
| 223 int64_t pid = global_analyzer->GetFirstProcess(); |
| 224 ThreadActivityAnalyzer* thread_analyzer = |
| 225 global_analyzer->GetFirstAnalyzer(pid); |
221 if (log_messages.empty() && global_data_snapshot.empty() && | 226 if (log_messages.empty() && global_data_snapshot.empty() && |
222 !thread_analyzer) { | 227 !thread_analyzer) { |
223 return DEBUG_FILE_NO_DATA; | 228 return DEBUG_FILE_NO_DATA; |
224 } | 229 } |
225 | 230 |
226 // Collect log messages. | 231 // Collect log messages. |
227 for (const std::string& message : log_messages) { | 232 for (const std::string& message : log_messages) { |
228 report->add_log_messages(message); | 233 report->add_log_messages(message); |
229 } | 234 } |
230 | 235 |
231 // Collect global user data. | 236 // Collect global user data. |
232 google::protobuf::Map<std::string, TypedValue>& global_data = | 237 google::protobuf::Map<std::string, TypedValue>& global_data = |
233 *(report->mutable_global_data()); | 238 *(report->mutable_global_data()); |
234 CollectUserData(global_data_snapshot, &global_data, report); | 239 CollectUserData(global_data_snapshot, &global_data, report); |
235 | 240 |
236 // Collect thread activity data. | 241 // Collect thread activity data. |
237 // Note: a single process is instrumented. | 242 // Note: a single process is instrumented. |
238 ProcessState* process_state = report->add_process_states(); | 243 ProcessState* process_state = report->add_process_states(); |
239 for (; thread_analyzer != nullptr; | 244 for (; thread_analyzer != nullptr; |
240 thread_analyzer = global_analyzer->GetNextAnalyzer()) { | 245 thread_analyzer = global_analyzer->GetNextAnalyzer(pid)) { |
241 // Only valid analyzers are expected per contract of GetFirstAnalyzer / | 246 // Only valid analyzers are expected per contract of GetFirstAnalyzer / |
242 // GetNextAnalyzer. | 247 // GetNextAnalyzer. |
243 DCHECK(thread_analyzer->IsValid()); | 248 DCHECK(thread_analyzer->IsValid()); |
244 | 249 |
245 if (!process_state->has_process_id()) { | 250 if (!process_state->has_process_id()) { |
246 process_state->set_process_id( | 251 process_state->set_process_id( |
247 thread_analyzer->activity_snapshot().process_id); | 252 thread_analyzer->activity_snapshot().process_id); |
248 } | 253 } |
249 DCHECK_EQ(thread_analyzer->activity_snapshot().process_id, | 254 DCHECK_EQ(thread_analyzer->activity_snapshot().process_id, |
250 process_state->process_id()); | 255 process_state->process_id()); |
251 | 256 |
252 ThreadState* thread_state = process_state->add_threads(); | 257 ThreadState* thread_state = process_state->add_threads(); |
253 CollectThread(thread_analyzer->activity_snapshot(), thread_state); | 258 CollectThread(thread_analyzer->activity_snapshot(), thread_state); |
254 } | 259 } |
255 | 260 |
256 // Collect module information. | 261 // Collect module information. |
257 CollectModuleInformation(global_analyzer->GetModules(), process_state); | 262 CollectModuleInformation(global_analyzer->GetModules(), process_state); |
258 | 263 |
259 return SUCCESS; | 264 return SUCCESS; |
260 } | 265 } |
261 | 266 |
262 } // namespace browser_watcher | 267 } // namespace browser_watcher |
OLD | NEW |