Bertrand SIMONNET | 52e5b99 | 2015-08-10 15:18:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 16 | |
Bertrand SIMONNET | 608e428 | 2015-11-12 17:52:17 -0800 | [diff] [blame] | 17 | #ifndef METRICS_METRICS_COLLECTOR_H_ |
| 18 | #define METRICS_METRICS_COLLECTOR_H_ |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 19 | |
Ben Chan | f05ab40 | 2014-08-07 00:54:59 -0700 | [diff] [blame] | 20 | #include <stdint.h> |
| 21 | |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 22 | #include <map> |
Bertrand SIMONNET | 6c9fbb9 | 2015-12-21 14:56:40 -0800 | [diff] [blame] | 23 | #include <memory> |
Luigi Semenzato | 4a6c942 | 2014-06-30 18:12:28 -0700 | [diff] [blame] | 24 | #include <string> |
| 25 | #include <vector> |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 26 | |
Ben Chan | 2e6543d | 2014-02-05 23:26:25 -0800 | [diff] [blame] | 27 | #include <base/files/file_path.h> |
Alex Vakulenko | 53ca76f | 2015-12-29 15:02:00 -0800 | [diff] [blame] | 28 | #include <base/memory/weak_ptr.h> |
Ben Chan | 2e6543d | 2014-02-05 23:26:25 -0800 | [diff] [blame] | 29 | #include <base/time/time.h> |
Alex Vakulenko | 53ca76f | 2015-12-29 15:02:00 -0800 | [diff] [blame] | 30 | #include <brillo/binder_watcher.h> |
Alex Vakulenko | eca14e3 | 2016-01-28 14:39:27 -0800 | [diff] [blame] | 31 | #include <brillo/daemons/daemon.h> |
Alex Vakulenko | 82b02de | 2015-10-09 20:07:47 -0700 | [diff] [blame] | 32 | #include <libweaved/command.h> |
Alex Vakulenko | 53ca76f | 2015-12-29 15:02:00 -0800 | [diff] [blame] | 33 | #include <libweaved/service.h> |
Darin Petkov | f1e85e4 | 2010-06-10 15:59:53 -0700 | [diff] [blame] | 34 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
| 35 | |
Bertrand SIMONNET | 7a96405 | 2015-09-29 11:07:24 -0700 | [diff] [blame] | 36 | #include "collectors/averaged_statistics_collector.h" |
Bertrand SIMONNET | 0ada2ca | 2015-11-02 14:08:44 -0800 | [diff] [blame] | 37 | #include "collectors/cpu_usage_collector.h" |
Bertrand SIMONNET | 5658dc5 | 2015-09-18 13:38:10 -0700 | [diff] [blame] | 38 | #include "collectors/disk_usage_collector.h" |
Luigi Semenzato | 4a6c942 | 2014-06-30 18:12:28 -0700 | [diff] [blame] | 39 | #include "metrics/metrics_library.h" |
Bertrand SIMONNET | 4b915ae | 2015-07-28 15:38:14 -0700 | [diff] [blame] | 40 | #include "persistent_integer.h" |
Darin Petkov | fc91b42 | 2010-05-12 13:05:45 -0700 | [diff] [blame] | 41 | |
Luigi Semenzato | 2fd51cc | 2014-02-26 11:53:16 -0800 | [diff] [blame] | 42 | using chromeos_metrics::PersistentInteger; |
Bertrand SIMONNET | 6c9fbb9 | 2015-12-21 14:56:40 -0800 | [diff] [blame] | 43 | using std::unique_ptr; |
Darin Petkov | 2ccef01 | 2010-05-05 16:06:37 -0700 | [diff] [blame] | 44 | |
Alex Vakulenko | eca14e3 | 2016-01-28 14:39:27 -0800 | [diff] [blame] | 45 | class MetricsCollector : public brillo::Daemon { |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 46 | public: |
Bertrand SIMONNET | 608e428 | 2015-11-12 17:52:17 -0800 | [diff] [blame] | 47 | MetricsCollector(); |
| 48 | ~MetricsCollector(); |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 49 | |
Steve Fung | e86591e | 2014-12-01 13:38:21 -0800 | [diff] [blame] | 50 | // Initializes metrics class variables. |
Bertrand SIMONNET | 46b49da | 2014-06-25 14:38:07 -0700 | [diff] [blame] | 51 | void Init(bool testing, |
Bertrand SIMONNET | 46b49da | 2014-06-25 14:38:07 -0700 | [diff] [blame] | 52 | MetricsLibraryInterface* metrics_lib, |
Bertrand SIMONNET | ebbe35c | 2015-09-08 10:13:35 -0700 | [diff] [blame] | 53 | const std::string& diskstats_path, |
Bertrand SIMONNET | 9d3a4ae | 2015-11-25 13:49:12 -0800 | [diff] [blame] | 54 | const base::FilePath& private_metrics_directory, |
| 55 | const base::FilePath& shared_metrics_directory); |
Darin Petkov | 11b8eb3 | 2010-05-18 11:00:59 -0700 | [diff] [blame] | 56 | |
Alex Vakulenko | eca14e3 | 2016-01-28 14:39:27 -0800 | [diff] [blame] | 57 | // Initializes the daemon. |
Steve Fung | e86591e | 2014-12-01 13:38:21 -0800 | [diff] [blame] | 58 | int OnInit() override; |
| 59 | |
Steve Fung | e86591e | 2014-12-01 13:38:21 -0800 | [diff] [blame] | 60 | // Does all the work. |
| 61 | int Run() override; |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 62 | |
Bertrand SIMONNET | 7a96405 | 2015-09-29 11:07:24 -0700 | [diff] [blame] | 63 | // Returns the active time since boot (uptime minus sleep time) in seconds. |
| 64 | static double GetActiveTime(); |
| 65 | |
Todd Poynor | 694553d | 2015-12-03 11:05:45 -0800 | [diff] [blame] | 66 | // Updates the active use time and logs time between user-space |
| 67 | // process crashes. Called via MetricsCollectorServiceTrampoline. |
| 68 | void ProcessUserCrash(); |
| 69 | |
Luigi Semenzato | 9636019 | 2014-06-04 10:53:35 -0700 | [diff] [blame] | 70 | protected: |
| 71 | // Used also by the unit tests. |
| 72 | static const char kComprDataSizeName[]; |
| 73 | static const char kOrigDataSizeName[]; |
| 74 | static const char kZeroPagesName[]; |
| 75 | |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 76 | private: |
Bertrand SIMONNET | 608e428 | 2015-11-12 17:52:17 -0800 | [diff] [blame] | 77 | friend class MetricsCollectorTest; |
| 78 | FRIEND_TEST(MetricsCollectorTest, CheckSystemCrash); |
| 79 | FRIEND_TEST(MetricsCollectorTest, ComputeEpochNoCurrent); |
| 80 | FRIEND_TEST(MetricsCollectorTest, ComputeEpochNoLast); |
| 81 | FRIEND_TEST(MetricsCollectorTest, GetHistogramPath); |
| 82 | FRIEND_TEST(MetricsCollectorTest, IsNewEpoch); |
| 83 | FRIEND_TEST(MetricsCollectorTest, MessageFilter); |
| 84 | FRIEND_TEST(MetricsCollectorTest, ProcessKernelCrash); |
| 85 | FRIEND_TEST(MetricsCollectorTest, ProcessMeminfo); |
| 86 | FRIEND_TEST(MetricsCollectorTest, ProcessMeminfo2); |
| 87 | FRIEND_TEST(MetricsCollectorTest, ProcessUncleanShutdown); |
| 88 | FRIEND_TEST(MetricsCollectorTest, ProcessUserCrash); |
| 89 | FRIEND_TEST(MetricsCollectorTest, ReportCrashesDailyFrequency); |
| 90 | FRIEND_TEST(MetricsCollectorTest, ReportKernelCrashInterval); |
| 91 | FRIEND_TEST(MetricsCollectorTest, ReportUncleanShutdownInterval); |
| 92 | FRIEND_TEST(MetricsCollectorTest, ReportUserCrashInterval); |
| 93 | FRIEND_TEST(MetricsCollectorTest, SendSample); |
| 94 | FRIEND_TEST(MetricsCollectorTest, SendZramMetrics); |
Darin Petkov | 41e0623 | 2010-05-03 16:45:37 -0700 | [diff] [blame] | 95 | |
Luigi Semenzato | 3ccca06 | 2013-02-04 19:50:45 -0800 | [diff] [blame] | 96 | // Type of scale to use for meminfo histograms. For most of them we use |
| 97 | // percent of total RAM, but for some we use absolute numbers, usually in |
| 98 | // megabytes, on a log scale from 0 to 4000, and 0 to 8000 for compressed |
| 99 | // swap (since it can be larger than total RAM). |
Luigi Semenzato | 942cbab | 2013-02-12 13:17:07 -0800 | [diff] [blame] | 100 | enum MeminfoOp { |
| 101 | kMeminfoOp_HistPercent = 0, |
| 102 | kMeminfoOp_HistLog, |
| 103 | kMeminfoOp_SwapTotal, |
| 104 | kMeminfoOp_SwapFree, |
Luigi Semenzato | 3ccca06 | 2013-02-04 19:50:45 -0800 | [diff] [blame] | 105 | }; |
| 106 | |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 107 | // Record for retrieving and reporting values from /proc/meminfo. |
| 108 | struct MeminfoRecord { |
Luigi Semenzato | 3ccca06 | 2013-02-04 19:50:45 -0800 | [diff] [blame] | 109 | const char* name; // print name |
| 110 | const char* match; // string to match in output of /proc/meminfo |
Luigi Semenzato | 942cbab | 2013-02-12 13:17:07 -0800 | [diff] [blame] | 111 | MeminfoOp op; // histogram scale selector, or other operator |
Luigi Semenzato | 3ccca06 | 2013-02-04 19:50:45 -0800 | [diff] [blame] | 112 | int value; // value from /proc/meminfo |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 113 | }; |
| 114 | |
Bertrand SIMONNET | 59890e2 | 2015-10-02 16:45:18 -0700 | [diff] [blame] | 115 | // Enables metrics reporting. |
Alex Vakulenko | 53ca76f | 2015-12-29 15:02:00 -0800 | [diff] [blame] | 116 | void OnEnableMetrics(std::unique_ptr<weaved::Command> command); |
Bertrand SIMONNET | 59890e2 | 2015-10-02 16:45:18 -0700 | [diff] [blame] | 117 | |
| 118 | // Disables metrics reporting. |
Alex Vakulenko | 53ca76f | 2015-12-29 15:02:00 -0800 | [diff] [blame] | 119 | void OnDisableMetrics(std::unique_ptr<weaved::Command> command); |
Bertrand SIMONNET | 59890e2 | 2015-10-02 16:45:18 -0700 | [diff] [blame] | 120 | |
| 121 | // Updates the weave device state. |
Alex Vakulenko | 82b02de | 2015-10-09 20:07:47 -0700 | [diff] [blame] | 122 | void UpdateWeaveState(); |
Bertrand SIMONNET | 59890e2 | 2015-10-02 16:45:18 -0700 | [diff] [blame] | 123 | |
Darin Petkov | 38d5cb0 | 2010-06-24 12:10:26 -0700 | [diff] [blame] | 124 | // Updates the active use time and logs time between kernel crashes. |
| 125 | void ProcessKernelCrash(); |
| 126 | |
Ken Mixter | ccd84c0 | 2010-08-16 19:57:13 -0700 | [diff] [blame] | 127 | // Updates the active use time and logs time between unclean shutdowns. |
| 128 | void ProcessUncleanShutdown(); |
| 129 | |
| 130 | // Checks if a kernel crash has been detected and returns true if |
| 131 | // so. The method assumes that a kernel crash has happened if |
| 132 | // |crash_file| exists. It removes the file immediately if it |
| 133 | // exists, so it must not be called more than once. |
| 134 | bool CheckSystemCrash(const std::string& crash_file); |
Darin Petkov | 38d5cb0 | 2010-06-24 12:10:26 -0700 | [diff] [blame] | 135 | |
Darin Petkov | 11b8eb3 | 2010-05-18 11:00:59 -0700 | [diff] [blame] | 136 | // Sends a regular (exponential) histogram sample to Chrome for |
| 137 | // transport to UMA. See MetricsLibrary::SendToUMA in |
| 138 | // metrics_library.h for a description of the arguments. |
Luigi Semenzato | 2fd51cc | 2014-02-26 11:53:16 -0800 | [diff] [blame] | 139 | void SendSample(const std::string& name, int sample, |
Darin Petkov | 11b8eb3 | 2010-05-18 11:00:59 -0700 | [diff] [blame] | 140 | int min, int max, int nbuckets); |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 141 | |
Luigi Semenzato | 29c7ef9 | 2011-04-12 14:12:35 -0700 | [diff] [blame] | 142 | // Sends a linear histogram sample to Chrome for transport to UMA. See |
| 143 | // MetricsLibrary::SendToUMA in metrics_library.h for a description of the |
| 144 | // arguments. |
Luigi Semenzato | 2fd51cc | 2014-02-26 11:53:16 -0800 | [diff] [blame] | 145 | void SendLinearSample(const std::string& name, int sample, |
Luigi Semenzato | 29c7ef9 | 2011-04-12 14:12:35 -0700 | [diff] [blame] | 146 | int max, int nbuckets); |
| 147 | |
Luigi Semenzato | ba0c65d | 2014-03-17 12:28:38 -0700 | [diff] [blame] | 148 | // Sends various cumulative kernel crash-related stats, for instance the |
| 149 | // total number of kernel crashes since the last version update. |
Luigi Semenzato | e5883fa | 2014-04-18 17:00:35 -0700 | [diff] [blame] | 150 | void SendKernelCrashesCumulativeCountStats(); |
Luigi Semenzato | ba0c65d | 2014-03-17 12:28:38 -0700 | [diff] [blame] | 151 | |
Luigi Semenzato | e5883fa | 2014-04-18 17:00:35 -0700 | [diff] [blame] | 152 | // Sends a sample representing the number of seconds of active use |
Bertrand SIMONNET | 2d03783 | 2015-09-16 17:11:51 -0700 | [diff] [blame] | 153 | // for a 24-hour period and reset |use|. |
Bertrand SIMONNET | 6c9fbb9 | 2015-12-21 14:56:40 -0800 | [diff] [blame] | 154 | void SendAndResetDailyUseSample(const unique_ptr<PersistentInteger>& use); |
Luigi Semenzato | e5883fa | 2014-04-18 17:00:35 -0700 | [diff] [blame] | 155 | |
Luigi Semenzato | 2fd51cc | 2014-02-26 11:53:16 -0800 | [diff] [blame] | 156 | // Sends a sample representing a time interval between two crashes of the |
Bertrand SIMONNET | 2d03783 | 2015-09-16 17:11:51 -0700 | [diff] [blame] | 157 | // same type and reset |interval|. |
| 158 | void SendAndResetCrashIntervalSample( |
Bertrand SIMONNET | 6c9fbb9 | 2015-12-21 14:56:40 -0800 | [diff] [blame] | 159 | const unique_ptr<PersistentInteger>& interval); |
Luigi Semenzato | 2fd51cc | 2014-02-26 11:53:16 -0800 | [diff] [blame] | 160 | |
Bertrand SIMONNET | 2d03783 | 2015-09-16 17:11:51 -0700 | [diff] [blame] | 161 | // Sends a sample representing a frequency of crashes of some type and reset |
| 162 | // |frequency|. |
| 163 | void SendAndResetCrashFrequencySample( |
Bertrand SIMONNET | 6c9fbb9 | 2015-12-21 14:56:40 -0800 | [diff] [blame] | 164 | const unique_ptr<PersistentInteger>& frequency); |
Luigi Semenzato | 2fd51cc | 2014-02-26 11:53:16 -0800 | [diff] [blame] | 165 | |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 166 | // Initializes vm and disk stats reporting. |
| 167 | void StatsReporterInit(); |
Luigi Semenzato | c88e42d | 2011-02-17 10:21:16 -0800 | [diff] [blame] | 168 | |
Luigi Semenzato | 29c7ef9 | 2011-04-12 14:12:35 -0700 | [diff] [blame] | 169 | // Schedules meminfo collection callback. |
| 170 | void ScheduleMeminfoCallback(int wait); |
| 171 | |
Steve Fung | e86591e | 2014-12-01 13:38:21 -0800 | [diff] [blame] | 172 | // Reports memory statistics. Reschedules callback on success. |
| 173 | void MeminfoCallback(base::TimeDelta wait); |
Luigi Semenzato | 29c7ef9 | 2011-04-12 14:12:35 -0700 | [diff] [blame] | 174 | |
| 175 | // Parses content of /proc/meminfo and sends fields of interest to UMA. |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 176 | // Returns false on errors. |meminfo_raw| contains the content of |
| 177 | // /proc/meminfo. |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 178 | bool ProcessMeminfo(const std::string& meminfo_raw); |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 179 | |
| 180 | // Parses meminfo data from |meminfo_raw|. |fields| is a vector containing |
| 181 | // the fields of interest. The order of the fields must be the same in which |
| 182 | // /proc/meminfo prints them. The result of parsing fields[i] is placed in |
| 183 | // fields[i].value. |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 184 | bool FillMeminfo(const std::string& meminfo_raw, |
| 185 | std::vector<MeminfoRecord>* fields); |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 186 | |
Luigi Semenzato | 0d9a9c9 | 2013-12-05 15:55:12 -0800 | [diff] [blame] | 187 | // Schedule a memory use callback in |interval| seconds. |
| 188 | void ScheduleMemuseCallback(double interval); |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 189 | |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 190 | // Calls MemuseCallbackWork, and possibly schedules next callback, if enough |
| 191 | // active time has passed. Otherwise reschedules itself to simulate active |
| 192 | // time callbacks (i.e. wall clock time minus sleep time). |
| 193 | void MemuseCallback(); |
| 194 | |
| 195 | // Reads /proc/meminfo and sends total anonymous memory usage to UMA. |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 196 | bool MemuseCallbackWork(); |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 197 | |
Luigi Semenzato | fb3a821 | 2013-05-07 16:55:00 -0700 | [diff] [blame] | 198 | // Parses meminfo data and sends it to UMA. |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 199 | bool ProcessMemuse(const std::string& meminfo_raw); |
Luigi Semenzato | 29c7ef9 | 2011-04-12 14:12:35 -0700 | [diff] [blame] | 200 | |
Luigi Semenzato | 859b3f0 | 2014-02-05 15:33:19 -0800 | [diff] [blame] | 201 | // Reads the current OS version from /etc/lsb-release and hashes it |
| 202 | // to a unsigned 32-bit int. |
Ben Chan | f05ab40 | 2014-08-07 00:54:59 -0700 | [diff] [blame] | 203 | uint32_t GetOsVersionHash(); |
Luigi Semenzato | 859b3f0 | 2014-02-05 15:33:19 -0800 | [diff] [blame] | 204 | |
Daniel Erat | c83975a | 2014-04-04 08:53:44 -0700 | [diff] [blame] | 205 | // Updates stats, additionally sending them to UMA if enough time has elapsed |
| 206 | // since the last report. |
| 207 | void UpdateStats(base::TimeTicks now_ticks, base::Time now_wall_time); |
| 208 | |
| 209 | // Invoked periodically by |update_stats_timeout_id_| to call UpdateStats(). |
Steve Fung | e86591e | 2014-12-01 13:38:21 -0800 | [diff] [blame] | 210 | void HandleUpdateStatsTimeout(); |
Daniel Erat | c83975a | 2014-04-04 08:53:44 -0700 | [diff] [blame] | 211 | |
Luigi Semenzato | 9636019 | 2014-06-04 10:53:35 -0700 | [diff] [blame] | 212 | // Reports zram statistics. |
| 213 | bool ReportZram(const base::FilePath& zram_dir); |
| 214 | |
Ben Chan | f05ab40 | 2014-08-07 00:54:59 -0700 | [diff] [blame] | 215 | // Reads a string from a file and converts it to uint64_t. |
| 216 | static bool ReadFileToUint64(const base::FilePath& path, uint64_t* value); |
Luigi Semenzato | 9636019 | 2014-06-04 10:53:35 -0700 | [diff] [blame] | 217 | |
Alex Vakulenko | 53ca76f | 2015-12-29 15:02:00 -0800 | [diff] [blame] | 218 | // Callback invoked when a connection to weaved's service is established |
| 219 | // over Binder interface. |
| 220 | void OnWeaveServiceConnected(const std::weak_ptr<weaved::Service>& service); |
| 221 | |
Luigi Semenzato | 9636019 | 2014-06-04 10:53:35 -0700 | [diff] [blame] | 222 | // VARIABLES |
| 223 | |
Darin Petkov | 2ccef01 | 2010-05-05 16:06:37 -0700 | [diff] [blame] | 224 | // Test mode. |
Darin Petkov | 41e0623 | 2010-05-03 16:45:37 -0700 | [diff] [blame] | 225 | bool testing_; |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 226 | |
Bertrand SIMONNET | 9d3a4ae | 2015-11-25 13:49:12 -0800 | [diff] [blame] | 227 | // Publicly readable metrics directory. |
| 228 | base::FilePath shared_metrics_directory_; |
Bertrand SIMONNET | 71a62ef | 2014-10-07 11:26:25 -0700 | [diff] [blame] | 229 | |
Darin Petkov | fc91b42 | 2010-05-12 13:05:45 -0700 | [diff] [blame] | 230 | // The metrics library handle. |
| 231 | MetricsLibraryInterface* metrics_lib_; |
| 232 | |
Daniel Erat | c83975a | 2014-04-04 08:53:44 -0700 | [diff] [blame] | 233 | // The last time that UpdateStats() was called. |
| 234 | base::TimeTicks last_update_stats_time_; |
Darin Petkov | 41e0623 | 2010-05-03 16:45:37 -0700 | [diff] [blame] | 235 | |
Luigi Semenzato | 0d9a9c9 | 2013-12-05 15:55:12 -0800 | [diff] [blame] | 236 | // End time of current memuse stat collection interval. |
| 237 | double memuse_final_time_; |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 238 | |
| 239 | // Selects the wait time for the next memory use callback. |
| 240 | unsigned int memuse_interval_index_; |
| 241 | |
Luigi Semenzato | ba0c65d | 2014-03-17 12:28:38 -0700 | [diff] [blame] | 242 | // Used internally by GetIncrementalCpuUse() to return the CPU utilization |
| 243 | // between calls. |
Bertrand SIMONNET | 0ada2ca | 2015-11-02 14:08:44 -0800 | [diff] [blame] | 244 | base::TimeDelta latest_cpu_use_microseconds_; |
Luigi Semenzato | ba0c65d | 2014-03-17 12:28:38 -0700 | [diff] [blame] | 245 | |
| 246 | // Persistent values and accumulators for crash statistics. |
Bertrand SIMONNET | 6c9fbb9 | 2015-12-21 14:56:40 -0800 | [diff] [blame] | 247 | unique_ptr<PersistentInteger> daily_cycle_; |
| 248 | unique_ptr<PersistentInteger> weekly_cycle_; |
| 249 | unique_ptr<PersistentInteger> version_cycle_; |
Luigi Semenzato | 2fd51cc | 2014-02-26 11:53:16 -0800 | [diff] [blame] | 250 | |
Luigi Semenzato | e5883fa | 2014-04-18 17:00:35 -0700 | [diff] [blame] | 251 | // Active use accumulated in a day. |
Bertrand SIMONNET | 6c9fbb9 | 2015-12-21 14:56:40 -0800 | [diff] [blame] | 252 | unique_ptr<PersistentInteger> daily_active_use_; |
Luigi Semenzato | e5883fa | 2014-04-18 17:00:35 -0700 | [diff] [blame] | 253 | // Active use accumulated since the latest version update. |
Bertrand SIMONNET | 6c9fbb9 | 2015-12-21 14:56:40 -0800 | [diff] [blame] | 254 | unique_ptr<PersistentInteger> version_cumulative_active_use_; |
Luigi Semenzato | 2fd51cc | 2014-02-26 11:53:16 -0800 | [diff] [blame] | 255 | |
Luigi Semenzato | ba0c65d | 2014-03-17 12:28:38 -0700 | [diff] [blame] | 256 | // The CPU time accumulator. This contains the CPU time, in milliseconds, |
| 257 | // used by the system since the most recent OS version update. |
Bertrand SIMONNET | 6c9fbb9 | 2015-12-21 14:56:40 -0800 | [diff] [blame] | 258 | unique_ptr<PersistentInteger> version_cumulative_cpu_use_; |
Luigi Semenzato | ba0c65d | 2014-03-17 12:28:38 -0700 | [diff] [blame] | 259 | |
Bertrand SIMONNET | 6c9fbb9 | 2015-12-21 14:56:40 -0800 | [diff] [blame] | 260 | unique_ptr<PersistentInteger> user_crash_interval_; |
| 261 | unique_ptr<PersistentInteger> kernel_crash_interval_; |
| 262 | unique_ptr<PersistentInteger> unclean_shutdown_interval_; |
Luigi Semenzato | 2fd51cc | 2014-02-26 11:53:16 -0800 | [diff] [blame] | 263 | |
Bertrand SIMONNET | 6c9fbb9 | 2015-12-21 14:56:40 -0800 | [diff] [blame] | 264 | unique_ptr<PersistentInteger> any_crashes_daily_count_; |
| 265 | unique_ptr<PersistentInteger> any_crashes_weekly_count_; |
| 266 | unique_ptr<PersistentInteger> user_crashes_daily_count_; |
| 267 | unique_ptr<PersistentInteger> user_crashes_weekly_count_; |
| 268 | unique_ptr<PersistentInteger> kernel_crashes_daily_count_; |
| 269 | unique_ptr<PersistentInteger> kernel_crashes_weekly_count_; |
| 270 | unique_ptr<PersistentInteger> kernel_crashes_version_count_; |
| 271 | unique_ptr<PersistentInteger> unclean_shutdowns_daily_count_; |
| 272 | unique_ptr<PersistentInteger> unclean_shutdowns_weekly_count_; |
Bertrand SIMONNET | 0ada2ca | 2015-11-02 14:08:44 -0800 | [diff] [blame] | 273 | |
Bertrand SIMONNET | 6c9fbb9 | 2015-12-21 14:56:40 -0800 | [diff] [blame] | 274 | unique_ptr<CpuUsageCollector> cpu_usage_collector_; |
| 275 | unique_ptr<DiskUsageCollector> disk_usage_collector_; |
| 276 | unique_ptr<AveragedStatisticsCollector> averaged_stats_collector_; |
Luigi Semenzato | 2fd51cc | 2014-02-26 11:53:16 -0800 | [diff] [blame] | 277 | |
Alex Vakulenko | 53ca76f | 2015-12-29 15:02:00 -0800 | [diff] [blame] | 278 | unique_ptr<weaved::Service::Subscription> weave_service_subscription_; |
| 279 | std::weak_ptr<weaved::Service> service_; |
| 280 | |
| 281 | base::WeakPtrFactory<MetricsCollector> weak_ptr_factory_{this}; |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 282 | }; |
| 283 | |
Bertrand SIMONNET | 608e428 | 2015-11-12 17:52:17 -0800 | [diff] [blame] | 284 | #endif // METRICS_METRICS_COLLECTOR_H_ |