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

Side by Side Diff: components/browser_watcher/postmortem_report_collector.cc

Issue 2554423002: Collect log messages from stability files (Closed)
Patch Set: Revise comments Created 4 years 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
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 #include "components/browser_watcher/postmortem_report_collector.h" 5 #include "components/browser_watcher/postmortem_report_collector.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/debug/activity_analyzer.h" 9 #include "base/debug/activity_analyzer.h"
10 #include "base/files/file_enumerator.h" 10 #include "base/files/file_enumerator.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 PostmortemReportCollector::CollectionStatus 93 PostmortemReportCollector::CollectionStatus
94 PostmortemReportCollector::CollectAndSubmit( 94 PostmortemReportCollector::CollectAndSubmit(
95 const crashpad::UUID& client_id, 95 const crashpad::UUID& client_id,
96 const FilePath& file, 96 const FilePath& file,
97 crashpad::CrashReportDatabase* report_database) { 97 crashpad::CrashReportDatabase* report_database) {
98 DCHECK_NE(nullptr, report_database); 98 DCHECK_NE(nullptr, report_database);
99 99
100 // Note: the code below involves two notions of report: chrome internal state 100 // Note: the code below involves two notions of report: chrome internal state
101 // reports and the crashpad reports they get wrapped into. 101 // reports and the crashpad reports they get wrapped into.
102 102
103 // Collect the data from the debug file to a proto. 103 // Collect the data from the debug file to a proto. Note: a non-empty report
104 // is interpreted here as an unclean exit.
104 std::unique_ptr<StabilityReport> report_proto; 105 std::unique_ptr<StabilityReport> report_proto;
105 CollectionStatus status = Collect(file, &report_proto); 106 CollectionStatus status = Collect(file, &report_proto);
106 if (status != SUCCESS) { 107 if (status != SUCCESS) {
107 // The file was empty, or there was an error collecting the data. Detailed 108 // The file was empty, or there was an error collecting the data. Detailed
108 // logging happens within the Collect function. 109 // logging happens within the Collect function.
109 if (!base::DeleteFile(file, false)) 110 if (!base::DeleteFile(file, false))
110 LOG(ERROR) << "Failed to delete " << file.value(); 111 LOG(ERROR) << "Failed to delete " << file.value();
111 return status; 112 return status;
112 } 113 }
113 DCHECK_NE(nullptr, report_proto.get()); 114 DCHECK_NE(nullptr, report_proto.get());
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 DCHECK_NE(nullptr, report); 161 DCHECK_NE(nullptr, report);
161 report->reset(); 162 report->reset();
162 163
163 // Create a global analyzer. 164 // Create a global analyzer.
164 std::unique_ptr<GlobalActivityAnalyzer> global_analyzer = 165 std::unique_ptr<GlobalActivityAnalyzer> global_analyzer =
165 GlobalActivityAnalyzer::CreateWithFile(debug_state_file); 166 GlobalActivityAnalyzer::CreateWithFile(debug_state_file);
166 if (!global_analyzer) 167 if (!global_analyzer)
167 return ANALYZER_CREATION_FAILED; 168 return ANALYZER_CREATION_FAILED;
168 169
169 // Early exit if there is no data. 170 // Early exit if there is no data.
171 std::vector<std::string> log_messages = global_analyzer->GetLogMessages();
170 ThreadActivityAnalyzer* thread_analyzer = global_analyzer->GetFirstAnalyzer(); 172 ThreadActivityAnalyzer* thread_analyzer = global_analyzer->GetFirstAnalyzer();
171 if (!thread_analyzer) { 173 if (log_messages.empty() && !thread_analyzer) {
172 // No data. This case happens in the case of a clean exit.
173 return DEBUG_FILE_NO_DATA; 174 return DEBUG_FILE_NO_DATA;
174 } 175 }
175 176
176 // Iterate through the thread analyzers, fleshing out the report. 177 // Create the report, then flesh it out.
177 report->reset(new StabilityReport()); 178 report->reset(new StabilityReport());
179
180 // Collect log messages.
181 for (const std::string& message : log_messages) {
182 (*report)->add_log_messages(message);
183 }
184
185 // Collect thread activity data.
178 // Note: a single process is instrumented. 186 // Note: a single process is instrumented.
179 ProcessState* process_state = (*report)->add_process_states(); 187 ProcessState* process_state = (*report)->add_process_states();
180
181 for (; thread_analyzer != nullptr; 188 for (; thread_analyzer != nullptr;
182 thread_analyzer = global_analyzer->GetNextAnalyzer()) { 189 thread_analyzer = global_analyzer->GetNextAnalyzer()) {
183 // Only valid analyzers are expected per contract of GetFirstAnalyzer / 190 // Only valid analyzers are expected per contract of GetFirstAnalyzer /
184 // GetNextAnalyzer. 191 // GetNextAnalyzer.
185 DCHECK(thread_analyzer->IsValid()); 192 DCHECK(thread_analyzer->IsValid());
186 193
187 if (!process_state->has_process_id()) { 194 if (!process_state->has_process_id()) {
188 process_state->set_process_id( 195 process_state->set_process_id(
189 thread_analyzer->activity_snapshot().process_id); 196 thread_analyzer->activity_snapshot().process_id);
190 } 197 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 #if defined(ARCH_CPU_X86) 262 #if defined(ARCH_CPU_X86)
256 minidump_info.platform = std::string("Win32"); 263 minidump_info.platform = std::string("Win32");
257 #elif defined(ARCH_CPU_X86_64) 264 #elif defined(ARCH_CPU_X86_64)
258 minidump_info.platform = std::string("Win64"); 265 minidump_info.platform = std::string("Win64");
259 #endif 266 #endif
260 267
261 return WritePostmortemDump(minidump_file, report, minidump_info); 268 return WritePostmortemDump(minidump_file, report, minidump_info);
262 } 269 }
263 270
264 } // namespace browser_watcher 271 } // namespace browser_watcher
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698