File: postmortem_report_collector.h

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (115 lines) | stat: -rw-r--r-- 4,622 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Following an unclean shutdown, a stability report can be collected and
// submitted for upload to a reporter.

#ifndef COMPONENTS_BROWSER_WATCHER_POSTMORTEM_REPORT_COLLECTOR_H_
#define COMPONENTS_BROWSER_WATCHER_POSTMORTEM_REPORT_COLLECTOR_H_

#include <stdio.h>

#include <memory>
#include <set>
#include <string>
#include <vector>

#include "base/debug/activity_analyzer.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/strings/string16.h"
#include "components/browser_watcher/stability_report.pb.h"
#include "third_party/crashpad/crashpad/client/crash_report_database.h"

namespace browser_watcher {

// Collects unclean shutdown information and creates Crashpad minidumps.
// TODO(manzagop): throttling, graceful handling of accumulating data.
// TODO(manzagop): UMA metrics and some error logging.
class PostmortemReportCollector {
 public:
  // DO NOT CHANGE VALUES. This is logged persistently in a histogram.
  enum CollectionStatus {
    NONE = 0,
    SUCCESS = 1,  // Successfully registered a report with Crashpad.
    ANALYZER_CREATION_FAILED = 2,
    DEBUG_FILE_NO_DATA = 3,
    PREPARE_NEW_CRASH_REPORT_FAILED = 4,
    WRITE_TO_MINIDUMP_FAILED = 5,
    DEBUG_FILE_DELETION_FAILED = 6,
    FINISHED_WRITING_CRASH_REPORT_FAILED = 7,
    COLLECTION_STATUS_MAX = 8
  };

  PostmortemReportCollector(const std::string& product_name,
                            const std::string& version_number,
                            const std::string& channel_name);
  virtual ~PostmortemReportCollector() = default;

  // Collects postmortem stability reports from files found in |debug_info_dir|,
  // relying on |debug_file_pattern| and |excluded_debug_files|. Reports are
  // then wrapped in Crashpad reports, manufactured via |report_database|.
  // Returns the number crash reports successfully registered with the reporter.
  // TODO(manzagop): consider mechanisms for partial collection if this is to be
  //     used on a critical path.
  int CollectAndSubmitForUpload(
      const base::FilePath& debug_info_dir,
      const base::FilePath::StringType& debug_file_pattern,
      const std::set<base::FilePath>& excluded_debug_files,
      crashpad::CrashReportDatabase* report_database);

  const std::string& product_name() const { return product_name_; }
  const std::string& version_number() const { return version_number_; }
  const std::string& channel_name() const { return channel_name_; }

 private:
  FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorTest,
                           GetDebugStateFilePaths);
  FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorTest, CollectEmptyFile);
  FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorTest, CollectRandomFile);
  FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorCollectionTest,
                           CollectSuccess);
  FRIEND_TEST_ALL_PREFIXES(
      PostmortemReportCollectorCollectionFromGlobalTrackerTest,
      LogCollection);
  FRIEND_TEST_ALL_PREFIXES(
      PostmortemReportCollectorCollectionFromGlobalTrackerTest,
      GlobalUserDataCollection);

  // Virtual for unittesting.
  virtual std::vector<base::FilePath> GetDebugStateFilePaths(
      const base::FilePath& debug_info_dir,
      const base::FilePath::StringType& debug_file_pattern,
      const std::set<base::FilePath>& excluded_debug_files);

  CollectionStatus CollectAndSubmit(
      const crashpad::UUID& client_id,
      const base::FilePath& file,
      crashpad::CrashReportDatabase* report_database);

  // Virtual for unittesting.
  // TODO(manzagop): move this for reuse in live scenario.
  virtual CollectionStatus Collect(const base::FilePath& debug_state_file,
                                   std::unique_ptr<StabilityReport>* report);
  void CollectThread(
      const base::debug::ThreadActivityAnalyzer::Snapshot& snapshot,
      ThreadState* thread_state);

  virtual bool WriteReportToMinidump(const StabilityReport& report,
                                     const crashpad::UUID& client_id,
                                     const crashpad::UUID& report_id,
                                     base::PlatformFile minidump_file);

  std::string product_name_;
  std::string version_number_;
  std::string channel_name_;

  DISALLOW_COPY_AND_ASSIGN(PostmortemReportCollector);
};

}  // namespace browser_watcher

#endif  // COMPONENTS_BROWSER_WATCHER_POSTMORTEM_REPORT_COLLECTOR_H_