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