File: crash_metrics_reporter_android.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (116 lines) | stat: -rw-r--r-- 4,716 bytes parent folder | download | duplicates (5)
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
116
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_METRICS_REPORTER_ANDROID_H_
#define COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_METRICS_REPORTER_ANDROID_H_

#include "base/containers/flat_set.h"
#include "base/observer_list_threadsafe.h"
#include "components/crash/content/browser/child_exit_observer_android.h"

namespace crash_reporter {

// Reports crash metrics about child processes to UMA, which is used as ground
// truth for child process stability. This class should be used by any code that
// wants to observe reason for the death of a child process.
class CrashMetricsReporter {
 public:
  // The status of the spare renderer when a process is killed.
  //
  // These values are persisted to logs. Entries should not be renumbered and
  // numeric values should never be reused.
  //
  // LINT.IfChange(SpareRendererAvailabilityWhenKilled)
  enum class SpareRendererAvailabilityWhenKilled {
    kKillSpareRenderer = 0,
    kKillNonSpareRendererWithoutSpareRenderer = 1,
    kKillNonSpareRendererWithSpareRender = 2,
    kMaxValue = kKillNonSpareRendererWithSpareRender,
  };
  // LINT.ThenChange(//tools/metrics/histograms/metadata/stability/enums.xml:SpareRendererAvailabilityWhenKilled)

  // This enum is used to back a UMA histogram, and must be treated as
  // append-only.
  enum ExitStatus {
    EMPTY_MINIDUMP_WHILE_RUNNING,
    EMPTY_MINIDUMP_WHILE_PAUSED,
    EMPTY_MINIDUMP_WHILE_BACKGROUND,
    VALID_MINIDUMP_WHILE_RUNNING,
    VALID_MINIDUMP_WHILE_PAUSED,
    VALID_MINIDUMP_WHILE_BACKGROUND,
    MINIDUMP_STATUS_COUNT
  };

  // These values are persisted to logs. Entries should not be renumbered and
  // numeric values should never be reused.
  enum class ProcessedCrashCounts {
    kGpuForegroundOom = 0,
    kRendererForegroundVisibleOom = 1,
    kRendererForegroundIntentionalKill = 2,
    kRendererForegroundVisibleSubframeOom = 3,
    kRendererForegroundVisibleSubframeIntentionalKill = 4,
    kRendererForegroundVisibleCrash = 5,
    kRendererForegroundVisibleSubframeCrash = 6,
    kGpuCrashAll = 7,
    kRendererCrashAll = 8,
    kRendererForegroundVisibleMainFrameIntentionalKill = 9,
    kRendererForegroundVisibleNormalTermNoMinidump = 10,
    kRendererForegroundInvisibleWithStrongBindingKilled = 11,
    kRendererForegroundInvisibleWithStrongBindingOom = 12,
    kRendererForegroundInvisibleWithModerateBindingKilled = 13,
    kRendererForegroundInvisibleWithModerateBindingOom = 14,
    kRendererForegroundVisibleAllocationFailure = 15,
    kRendererAllocationFailureAll = 16,
    kUtilityForegroundOom = 17,
    kUtilityCrashAll = 18,
    kRendererProcessHostShutdown = 19,
    kRendererForegroundInvisibleWithVisibleBindingKilled = 20,
    kRendererForegroundInvisibleWithVisibleBindingOom = 21,
    kRendererForegroundInvisibleWithNotPerceptibleBindingKilled = 22,
    kRendererForegroundInvisibleWithNotPerceptibleBindingOom = 23,
    kRendererForegroundInvisibleWithWaivedBindingOom = 24,
    kRendererForegroundInvisibleWithWaivedBindingKilled = 25,
    kMaxValue = kRendererForegroundInvisibleWithWaivedBindingKilled
  };
  using ReportedCrashTypeSet = base::flat_set<ProcessedCrashCounts>;

  // Careful note: the CrashMetricsReporter observers are asynchronous, and are
  // notified via PostTask. This could be problematic with a large number of
  // observers. Consider using a middle-layer observer to fan out synchronously
  // to leaf observers if you need many objects listening to these messages.
  class Observer {
   public:
    // Called when child process is dead and minidump was processed.
    // |reported_counts| is a set of recorded metrics about child process
    // crashes. It could be empty if no metrics were recorded.
    virtual void OnCrashDumpProcessed(
        int rph_id,
        const ReportedCrashTypeSet& reported_counts) = 0;
  };

  static CrashMetricsReporter* GetInstance();

  CrashMetricsReporter(const CrashMetricsReporter&) = delete;
  CrashMetricsReporter& operator=(const CrashMetricsReporter&) = delete;

  // Can be called on any thread.
  void AddObserver(Observer* observer);
  void RemoveObserver(Observer* observer);

  void ChildProcessExited(
      const crash_reporter::ChildExitObserver::TerminationInfo& info);

 private:
  CrashMetricsReporter();
  ~CrashMetricsReporter();

  void NotifyObservers(int rph_id, const ReportedCrashTypeSet& reported_counts);

  scoped_refptr<base::ObserverListThreadSafe<CrashMetricsReporter::Observer>>
      async_observers_;
};

}  // namespace crash_reporter

#endif  // COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_METRICS_REPORTER_ANDROID_H_