File: guest_os_stability_monitor.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 (108 lines) | stat: -rw-r--r-- 4,178 bytes parent folder | download | duplicates (7)
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
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_ASH_GUEST_OS_GUEST_OS_STABILITY_MONITOR_H_
#define CHROME_BROWSER_ASH_GUEST_OS_GUEST_OS_STABILITY_MONITOR_H_

#include "base/memory/weak_ptr.h"
#include "base/scoped_observation.h"
#include "chromeos/ash/components/dbus/chunneld/chunneld_client.h"
#include "chromeos/ash/components/dbus/cicerone/cicerone_client.h"
#include "chromeos/ash/components/dbus/concierge/concierge_client.h"
#include "chromeos/ash/components/dbus/seneschal/seneschal_client.h"

namespace guest_os {

// These values are logged to UMA. Entries should not be renumbered and numeric
// values should never be reused. Please keep in sync with
// GuestOsFailureClasses in src/tools/metrics/histograms/enums.xml and the copy
// in src/platform2/vm_tools/cicerone/crash_listener_impl.cc
enum class FailureClasses {
  ConciergeStopped = 0,
  CiceroneStopped = 1,
  SeneschalStopped = 2,
  ChunneldStopped = 3,
  VmStopped = 4,
  VmSyslogStopped = 5,
  VshdStopped = 6,
  LxcFsStopped = 7,
  TremplinStopped = 8,
  NdproxydStopped = 9,
  McastdStopped = 10,
  LxdStopped = 11,
  GarconStopped = 12,
  SommelierStopped = 13,
  SommelierXStopped = 14,
  CrosSftpStopped = 15,
  CrosNotificationdStopped = 16,
  kMaxValue = CrosNotificationdStopped,
};

// Logs host-side VM service failures, and unexpected VM shutdowns.
//
// Each implementing VM type (Crostini, Borealis, etc.) should create its own
// instance of this class, and keep it alive for as long as any VMs of that
// type are running. During the instance's lifetime, it will log any failures
// of concierge, cicerone, seneschal, or chunneld and log them under the
// provided histogram with a value from |FailureClasses|.
//
// Effectively, if any host service fails, *all* currently running VMs are
// blamed. Note this overattributes blame, so analyze results accordingly.
//
// Implementers should also listen for VmStopped events from concierge, and
// call |LogUnexpectedVmShutdown| if any are considered unexpected.
// Take care to ignore VMs owned by other implementers.
class GuestOsStabilityMonitor : ash::ConciergeClient::Observer,
                                ash::CiceroneClient::Observer,
                                ash::SeneschalClient::Observer,
                                ash::ChunneldClient::Observer {
 public:
  explicit GuestOsStabilityMonitor(const std::string& histogram);
  ~GuestOsStabilityMonitor() override;

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

  void LogUnexpectedVmShutdown();

  void ConciergeStarted(bool is_available);
  void CiceroneStarted(bool is_available);
  void SeneschalStarted(bool is_available);
  void ChunneldStarted(bool is_available);

  //  ash::ConciergeClient::Observer::
  void ConciergeServiceStopped() override;
  void ConciergeServiceStarted() override;

  //  ash::CiceroneClient::Observer::
  void CiceroneServiceStopped() override;
  void CiceroneServiceStarted() override;

  //  ash::SeneschalClient::Observer::
  void SeneschalServiceStopped() override;
  void SeneschalServiceStarted() override;

  //  ash::ChunneldClient::Observer::
  void ChunneldServiceStopped() override;
  void ChunneldServiceStarted() override;

 private:
  std::string histogram_;
  base::ScopedObservation<ash::ConciergeClient, ash::ConciergeClient::Observer>
      concierge_observer_;
  base::ScopedObservation<ash::CiceroneClient, ash::CiceroneClient::Observer>
      cicerone_observer_;
  base::ScopedObservation<ash::SeneschalClient, ash::SeneschalClient::Observer>
      seneschal_observer_;
  base::ScopedObservation<ash::ChunneldClient, ash::ChunneldClient::Observer>
      chunneld_observer_;

  // Note: This should remain the last member so it'll be destroyed and
  // invalidate its weak pointers before any other members are destroyed.
  base::WeakPtrFactory<GuestOsStabilityMonitor> weak_ptr_factory_{this};
};

}  // namespace guest_os

#endif  // CHROME_BROWSER_ASH_GUEST_OS_GUEST_OS_STABILITY_MONITOR_H_