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
ash / components / arc / metrics / arc_daily_metrics.h [blame]
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_COMPONENTS_ARC_METRICS_ARC_DAILY_METRICS_H_
#define ASH_COMPONENTS_ARC_METRICS_ARC_DAILY_METRICS_H_
#include <memory>
#include <optional>
#include <string>
#include <unordered_set>
#include "ash/components/arc/mojom/process.mojom.h"
#include "base/memory/raw_ptr.h"
#include "base/values.h"
#include "chromeos/ash/components/dbus/vm_concierge/concierge_service.pb.h"
#include "components/metrics/daily_event.h"
class PrefService;
namespace arc {
namespace {
class KillCounts;
} // namespace
// Keeps track of daily metrics logged by ArcMetricsService, so that values can
// be restored after restarts.
class ArcDailyMetrics {
public:
explicit ArcDailyMetrics(PrefService* pref_service);
~ArcDailyMetrics();
ArcDailyMetrics(const ArcDailyMetrics&) = delete;
ArcDailyMetrics& operator=(const ArcDailyMetrics&) = delete;
// Receives the number of kills by priority since the last call.
void OnLowMemoryKillCounts(
std::optional<vm_tools::concierge::ListVmsResponse> vms_list,
int oom,
int foreground,
int perceptible,
int cached);
void OnDailyEvent(metrics::DailyEvent::IntervalType type);
void SetDailyEventForTesting(
std::unique_ptr<metrics::DailyEvent> daily_event);
metrics::DailyEvent* get_daily_event_for_testing() {
return daily_event_.get();
}
// The name of the histogram used to report that the daily event happened.
static const char kDailyEventHistogramName[];
private:
enum KillCountType {
kKillCountAll,
kKillCountOnlyArc,
// Background VMs are all treated the same, so name the first one.
kKillCountFirstBackgroundVm,
kKillCountCrostini = kKillCountFirstBackgroundVm,
kKillCountPluginVm,
kKillCountSteam,
kKillCountUnknownVm,
// Keep count last so we can easily iterate.
kKillCountNum,
};
const raw_ptr<PrefService> prefs_;
std::unique_ptr<metrics::DailyEvent> daily_event_;
// Members for tracking Android App kill counts.
std::unordered_set<vm_tools::concierge::VmInfo_VmType> kills_prev_vms_;
std::unique_ptr<KillCounts> kills_[kKillCountNum];
static const vm_tools::concierge::VmInfo_VmType
kKillCountTypeVm[kKillCountNum];
};
} // namespace arc
#endif // ASH_COMPONENTS_ARC_METRICS_ARC_DAILY_METRICS_H_