| 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_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" |
| 11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "components/browser_watcher/postmortem_minidump_writer.h" | 16 #include "components/browser_watcher/postmortem_minidump_writer.h" |
| 17 #include "third_party/crashpad/crashpad/client/settings.h" | 17 #include "third_party/crashpad/crashpad/client/settings.h" |
| 18 #include "third_party/crashpad/crashpad/util/misc/uuid.h" | 18 #include "third_party/crashpad/crashpad/util/misc/uuid.h" |
| 19 | 19 |
| 20 using base::FilePath; | 20 using base::FilePath; |
| 21 | 21 |
| 22 namespace browser_watcher { | 22 namespace browser_watcher { |
| 23 | 23 |
| 24 using base::debug::ActivitySnapshot; |
| 24 using base::debug::GlobalActivityAnalyzer; | 25 using base::debug::GlobalActivityAnalyzer; |
| 25 using base::debug::ThreadActivityAnalyzer; | 26 using base::debug::ThreadActivityAnalyzer; |
| 26 using crashpad::CrashReportDatabase; | 27 using crashpad::CrashReportDatabase; |
| 27 | 28 |
| 28 PostmortemReportCollector::PostmortemReportCollector( | 29 PostmortemReportCollector::PostmortemReportCollector( |
| 29 const std::string& product_name, | 30 const std::string& product_name, |
| 30 const std::string& version_number, | 31 const std::string& version_number, |
| 31 const std::string& channel_name) | 32 const std::string& channel_name) |
| 32 : product_name_(product_name), | 33 : product_name_(product_name), |
| 33 version_number_(version_number), | 34 version_number_(version_number), |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 | 168 |
| 168 // Early exit if there is no data. | 169 // Early exit if there is no data. |
| 169 ThreadActivityAnalyzer* thread_analyzer = global_analyzer->GetFirstAnalyzer(); | 170 ThreadActivityAnalyzer* thread_analyzer = global_analyzer->GetFirstAnalyzer(); |
| 170 if (!thread_analyzer) { | 171 if (!thread_analyzer) { |
| 171 // No data. This case happens in the case of a clean exit. | 172 // No data. This case happens in the case of a clean exit. |
| 172 return DEBUG_FILE_NO_DATA; | 173 return DEBUG_FILE_NO_DATA; |
| 173 } | 174 } |
| 174 | 175 |
| 175 // Iterate through the thread analyzers, fleshing out the report. | 176 // Iterate through the thread analyzers, fleshing out the report. |
| 176 report->reset(new StabilityReport()); | 177 report->reset(new StabilityReport()); |
| 178 // Note: a single process is instrumented. |
| 177 ProcessState* process_state = (*report)->add_process_states(); | 179 ProcessState* process_state = (*report)->add_process_states(); |
| 178 | 180 |
| 179 for (; thread_analyzer != nullptr; | 181 for (; thread_analyzer != nullptr; |
| 180 thread_analyzer = global_analyzer->GetNextAnalyzer()) { | 182 thread_analyzer = global_analyzer->GetNextAnalyzer()) { |
| 181 // Only valid analyzers are expected per contract of GetFirstAnalyzer / | 183 // Only valid analyzers are expected per contract of GetFirstAnalyzer / |
| 182 // GetNextAnalyzer. | 184 // GetNextAnalyzer. |
| 183 DCHECK(thread_analyzer->IsValid()); | 185 DCHECK(thread_analyzer->IsValid()); |
| 184 | 186 |
| 187 if (!process_state->has_process_id()) { |
| 188 process_state->set_process_id( |
| 189 thread_analyzer->activity_snapshot().process_id); |
| 190 } |
| 191 DCHECK_EQ(thread_analyzer->activity_snapshot().process_id, |
| 192 process_state->process_id()); |
| 193 |
| 185 ThreadState* thread_state = process_state->add_threads(); | 194 ThreadState* thread_state = process_state->add_threads(); |
| 186 thread_state->set_thread_name(thread_analyzer->GetThreadName()); | 195 CollectThread(thread_analyzer->activity_snapshot(), thread_state); |
| 187 // TODO(manzagop): flesh this out. | |
| 188 } | 196 } |
| 189 | 197 |
| 190 return SUCCESS; | 198 return SUCCESS; |
| 191 } | 199 } |
| 192 | 200 |
| 201 void PostmortemReportCollector::CollectThread( |
| 202 const base::debug::ActivitySnapshot& snapshot, |
| 203 ThreadState* thread_state) { |
| 204 DCHECK(thread_state); |
| 205 |
| 206 thread_state->set_thread_name(snapshot.thread_name); |
| 207 thread_state->set_thread_id(snapshot.thread_id); |
| 208 thread_state->set_activity_cnt(snapshot.activity_stack_depth); |
| 209 |
| 210 for (const base::debug::Activity& recorded : snapshot.activity_stack) { |
| 211 Activity* collected = thread_state->add_activities(); |
| 212 switch (recorded.activity_type) { |
| 213 case base::debug::Activity::ACT_TASK_RUN: |
| 214 collected->set_type(Activity::ACT_TASK_RUN); |
| 215 collected->set_origin_address(recorded.origin_address); |
| 216 collected->set_task_sequence_id(recorded.data.task.sequence_id); |
| 217 break; |
| 218 case base::debug::Activity::ACT_LOCK_ACQUIRE: |
| 219 collected->set_type(Activity::ACT_LOCK_ACQUIRE); |
| 220 collected->set_lock_address(recorded.data.lock.lock_address); |
| 221 break; |
| 222 case base::debug::Activity::ACT_EVENT_WAIT: |
| 223 collected->set_type(Activity::ACT_EVENT_WAIT); |
| 224 collected->set_event_address(recorded.data.event.event_address); |
| 225 break; |
| 226 case base::debug::Activity::ACT_THREAD_JOIN: |
| 227 collected->set_type(Activity::ACT_THREAD_JOIN); |
| 228 collected->set_thread_id(recorded.data.thread.thread_id); |
| 229 break; |
| 230 case base::debug::Activity::ACT_PROCESS_WAIT: |
| 231 collected->set_type(Activity::ACT_PROCESS_WAIT); |
| 232 collected->set_process_id(recorded.data.process.process_id); |
| 233 break; |
| 234 default: |
| 235 break; |
| 236 } |
| 237 } |
| 238 } |
| 239 |
| 193 bool PostmortemReportCollector::WriteReportToMinidump( | 240 bool PostmortemReportCollector::WriteReportToMinidump( |
| 194 const StabilityReport& report, | 241 const StabilityReport& report, |
| 195 const crashpad::UUID& client_id, | 242 const crashpad::UUID& client_id, |
| 196 const crashpad::UUID& report_id, | 243 const crashpad::UUID& report_id, |
| 197 base::PlatformFile minidump_file) { | 244 base::PlatformFile minidump_file) { |
| 198 MinidumpInfo minidump_info; | 245 MinidumpInfo minidump_info; |
| 199 minidump_info.client_id = client_id; | 246 minidump_info.client_id = client_id; |
| 200 minidump_info.report_id = report_id; | 247 minidump_info.report_id = report_id; |
| 201 // TODO(manzagop): replace this information, i.e. the reporter's attributes, | 248 // TODO(manzagop): replace this information, i.e. the reporter's attributes, |
| 202 // by that of the reportee. Doing so requires adding this information to the | 249 // by that of the reportee. Doing so requires adding this information to the |
| 203 // stability report. In the meantime, there is a tolerable information | 250 // stability report. In the meantime, there is a tolerable information |
| 204 // mismatch after upgrades. | 251 // mismatch after upgrades. |
| 205 minidump_info.product_name = product_name(); | 252 minidump_info.product_name = product_name(); |
| 206 minidump_info.version_number = version_number(); | 253 minidump_info.version_number = version_number(); |
| 207 minidump_info.channel_name = channel_name(); | 254 minidump_info.channel_name = channel_name(); |
| 208 #if defined(ARCH_CPU_X86) | 255 #if defined(ARCH_CPU_X86) |
| 209 minidump_info.platform = std::string("Win32"); | 256 minidump_info.platform = std::string("Win32"); |
| 210 #elif defined(ARCH_CPU_X86_64) | 257 #elif defined(ARCH_CPU_X86_64) |
| 211 minidump_info.platform = std::string("Win64"); | 258 minidump_info.platform = std::string("Win64"); |
| 212 #endif | 259 #endif |
| 213 | 260 |
| 214 return WritePostmortemDump(minidump_file, report, minidump_info); | 261 return WritePostmortemDump(minidump_file, report, minidump_info); |
| 215 } | 262 } |
| 216 | 263 |
| 217 } // namespace browser_watcher | 264 } // namespace browser_watcher |
| OLD | NEW |