blob: 205ea699587d02ccdf849bca08431c6f0b119061 [file] [log] [blame]
Darin Petkov65b01462010-04-14 13:32:20 -07001// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Luigi Semenzato4a6c9422014-06-30 18:12:28 -07005#ifndef METRICS_METRICS_DAEMON_H_
6#define METRICS_METRICS_DAEMON_H_
Darin Petkov65b01462010-04-14 13:32:20 -07007
Ben Chanf05ab402014-08-07 00:54:59 -07008#include <stdint.h>
9
Darin Petkov703ec972010-04-27 11:02:18 -070010#include <dbus/dbus.h>
Darin Petkov41e06232010-05-03 16:45:37 -070011#include <glib.h>
Ken Mixter4c5daa42010-08-26 18:35:06 -070012#include <map>
Luigi Semenzato4a6c9422014-06-30 18:12:28 -070013#include <string>
14#include <vector>
Darin Petkov65b01462010-04-14 13:32:20 -070015
Ben Chan2e6543d2014-02-05 23:26:25 -080016#include <base/files/file_path.h>
Chris Masone817016a2011-05-12 14:14:48 -070017#include <base/memory/scoped_ptr.h>
Ben Chan2e6543d2014-02-05 23:26:25 -080018#include <base/time/time.h>
Darin Petkovf1e85e42010-06-10 15:59:53 -070019#include <gtest/gtest_prod.h> // for FRIEND_TEST
20
Luigi Semenzato4a6c9422014-06-30 18:12:28 -070021#include "metrics/metrics_library.h"
22#include "metrics/persistent_integer.h"
Bertrand SIMONNET46b49da2014-06-25 14:38:07 -070023#include "uploader/upload_service.h"
Darin Petkovfc91b422010-05-12 13:05:45 -070024
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -080025using chromeos_metrics::PersistentInteger;
Darin Petkov2ccef012010-05-05 16:06:37 -070026
Darin Petkov65b01462010-04-14 13:32:20 -070027class MetricsDaemon {
Darin Petkov65b01462010-04-14 13:32:20 -070028 public:
Darin Petkovf1e85e42010-06-10 15:59:53 -070029 MetricsDaemon();
30 ~MetricsDaemon();
Darin Petkov65b01462010-04-14 13:32:20 -070031
Darin Petkov11b8eb32010-05-18 11:00:59 -070032 // Initializes.
Bertrand SIMONNET46b49da2014-06-25 14:38:07 -070033 void Init(bool testing,
34 bool uploader_active,
35 MetricsLibraryInterface* metrics_lib,
Luigi Semenzato5bd764f2011-10-14 12:03:35 -070036 const std::string& diskstats_path,
Luigi Semenzatofb3a8212013-05-07 16:55:00 -070037 const std::string& vmstats_path,
38 const std::string& cpuinfo_max_freq_path,
39 const std::string& scaling_max_freq_path);
Darin Petkov11b8eb32010-05-18 11:00:59 -070040
Darin Petkov703ec972010-04-27 11:02:18 -070041 // Does all the work. If |run_as_daemon| is true, daemonizes by
Darin Petkov2ccef012010-05-05 16:06:37 -070042 // forking.
43 void Run(bool run_as_daemon);
Darin Petkov65b01462010-04-14 13:32:20 -070044
Bertrand SIMONNET46b49da2014-06-25 14:38:07 -070045 // Triggers an upload event and exit. (Used to test UploadService)
46 void RunUploaderTest();
47
Luigi Semenzato96360192014-06-04 10:53:35 -070048 protected:
49 // Used also by the unit tests.
50 static const char kComprDataSizeName[];
51 static const char kOrigDataSizeName[];
52 static const char kZeroPagesName[];
53
Darin Petkov65b01462010-04-14 13:32:20 -070054 private:
Darin Petkov2ccef012010-05-05 16:06:37 -070055 friend class MetricsDaemonTest;
Ken Mixterccd84c02010-08-16 19:57:13 -070056 FRIEND_TEST(MetricsDaemonTest, CheckSystemCrash);
Ken Mixter4c5daa42010-08-26 18:35:06 -070057 FRIEND_TEST(MetricsDaemonTest, ComputeEpochNoCurrent);
58 FRIEND_TEST(MetricsDaemonTest, ComputeEpochNoLast);
59 FRIEND_TEST(MetricsDaemonTest, GetHistogramPath);
60 FRIEND_TEST(MetricsDaemonTest, IsNewEpoch);
Darin Petkove579d662010-05-05 16:19:39 -070061 FRIEND_TEST(MetricsDaemonTest, MessageFilter);
Luigi Semenzato5bd764f2011-10-14 12:03:35 -070062 FRIEND_TEST(MetricsDaemonTest, ParseVmStats);
Darin Petkov38d5cb02010-06-24 12:10:26 -070063 FRIEND_TEST(MetricsDaemonTest, ProcessKernelCrash);
Luigi Semenzato29c7ef92011-04-12 14:12:35 -070064 FRIEND_TEST(MetricsDaemonTest, ProcessMeminfo);
65 FRIEND_TEST(MetricsDaemonTest, ProcessMeminfo2);
Ken Mixterccd84c02010-08-16 19:57:13 -070066 FRIEND_TEST(MetricsDaemonTest, ProcessUncleanShutdown);
Darin Petkov1bb904e2010-06-16 15:58:06 -070067 FRIEND_TEST(MetricsDaemonTest, ProcessUserCrash);
Ken Mixterccd84c02010-08-16 19:57:13 -070068 FRIEND_TEST(MetricsDaemonTest, ReportCrashesDailyFrequency);
Luigi Semenzatofb3a8212013-05-07 16:55:00 -070069 FRIEND_TEST(MetricsDaemonTest, ReadFreqToInt);
Ken Mixterccd84c02010-08-16 19:57:13 -070070 FRIEND_TEST(MetricsDaemonTest, ReportDailyUse);
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -080071 FRIEND_TEST(MetricsDaemonTest, ReportDiskStats);
Ken Mixterccd84c02010-08-16 19:57:13 -070072 FRIEND_TEST(MetricsDaemonTest, ReportKernelCrashInterval);
73 FRIEND_TEST(MetricsDaemonTest, ReportUncleanShutdownInterval);
74 FRIEND_TEST(MetricsDaemonTest, ReportUserCrashInterval);
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -080075 FRIEND_TEST(MetricsDaemonTest, SendSample);
Luigi Semenzatofb3a8212013-05-07 16:55:00 -070076 FRIEND_TEST(MetricsDaemonTest, SendCpuThrottleMetrics);
Luigi Semenzato96360192014-06-04 10:53:35 -070077 FRIEND_TEST(MetricsDaemonTest, SendZramMetrics);
Darin Petkov41e06232010-05-03 16:45:37 -070078
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -080079 // State for disk stats collector callback.
Luigi Semenzato5bd764f2011-10-14 12:03:35 -070080 enum StatsState {
81 kStatsShort, // short wait before short interval collection
82 kStatsLong, // final wait before new collection
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -080083 };
84
Darin Petkov41e06232010-05-03 16:45:37 -070085 // Data record for aggregating daily usage.
86 class UseRecord {
87 public:
88 UseRecord() : day_(0), seconds_(0) {}
89 int day_;
90 int seconds_;
91 };
92
Luigi Semenzato3ccca062013-02-04 19:50:45 -080093 // Type of scale to use for meminfo histograms. For most of them we use
94 // percent of total RAM, but for some we use absolute numbers, usually in
95 // megabytes, on a log scale from 0 to 4000, and 0 to 8000 for compressed
96 // swap (since it can be larger than total RAM).
Luigi Semenzato942cbab2013-02-12 13:17:07 -080097 enum MeminfoOp {
98 kMeminfoOp_HistPercent = 0,
99 kMeminfoOp_HistLog,
100 kMeminfoOp_SwapTotal,
101 kMeminfoOp_SwapFree,
Luigi Semenzato3ccca062013-02-04 19:50:45 -0800102 };
103
Luigi Semenzato8accd332011-05-17 16:37:18 -0700104 // Record for retrieving and reporting values from /proc/meminfo.
105 struct MeminfoRecord {
Luigi Semenzato3ccca062013-02-04 19:50:45 -0800106 const char* name; // print name
107 const char* match; // string to match in output of /proc/meminfo
Luigi Semenzato942cbab2013-02-12 13:17:07 -0800108 MeminfoOp op; // histogram scale selector, or other operator
Luigi Semenzato3ccca062013-02-04 19:50:45 -0800109 int value; // value from /proc/meminfo
Luigi Semenzato8accd332011-05-17 16:37:18 -0700110 };
111
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700112 // Record for retrieving and reporting values from /proc/vmstat
113 struct VmstatRecord {
114 uint64_t page_faults_; // major faults
115 uint64_t swap_in_; // pages swapped in
116 uint64_t swap_out_; // pages swapped out
117 };
118
Darin Petkov2ccef012010-05-05 16:06:37 -0700119 // Metric parameters.
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800120 static const char kMetricReadSectorsLongName[];
121 static const char kMetricReadSectorsShortName[];
122 static const char kMetricWriteSectorsLongName[];
123 static const char kMetricWriteSectorsShortName[];
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700124 static const char kMetricPageFaultsShortName[];
125 static const char kMetricPageFaultsLongName[];
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700126 static const char kMetricSwapInLongName[];
127 static const char kMetricSwapInShortName[];
128 static const char kMetricSwapOutLongName[];
129 static const char kMetricSwapOutShortName[];
Luigi Semenzatofb3a8212013-05-07 16:55:00 -0700130 static const char kMetricScaledCpuFrequencyName[];
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700131 static const int kMetricStatsShortInterval;
132 static const int kMetricStatsLongInterval;
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700133 static const int kMetricMeminfoInterval;
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800134 static const int kMetricSectorsIOMax;
135 static const int kMetricSectorsBuckets;
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700136 static const int kMetricPageFaultsMax;
137 static const int kMetricPageFaultsBuckets;
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800138 static const char kMetricsDiskStatsPath[];
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700139 static const char kMetricsVmStatsPath[];
Luigi Semenzatoba0c65d2014-03-17 12:28:38 -0700140 static const char kMetricsProcStatFileName[];
141 static const int kMetricsProcStatFirstLineItemsCount;
Darin Petkov2ccef012010-05-05 16:06:37 -0700142
Luigi Semenzato8accd332011-05-17 16:37:18 -0700143 // Returns the active time since boot (uptime minus sleep time) in seconds.
144 double GetActiveTime();
145
Darin Petkov65b01462010-04-14 13:32:20 -0700146 // Creates the event loop and enters it.
147 void Loop();
148
Darin Petkov703ec972010-04-27 11:02:18 -0700149 // D-Bus filter callback.
150 static DBusHandlerResult MessageFilter(DBusConnection* connection,
151 DBusMessage* message,
152 void* user_data);
Darin Petkov65b01462010-04-14 13:32:20 -0700153
Darin Petkov41e06232010-05-03 16:45:37 -0700154 // Updates the daily usage file, if necessary, by adding |seconds|
155 // of active use to the |day| since Epoch. If there's usage data for
156 // day in the past in the usage file, that data is sent to UMA and
157 // removed from the file. If there's already usage data for |day| in
158 // the usage file, the |seconds| are accumulated.
159 void LogDailyUseRecord(int day, int seconds);
160
Darin Petkov1bb904e2010-06-16 15:58:06 -0700161 // Updates the active use time and logs time between user-space
162 // process crashes.
163 void ProcessUserCrash();
164
Darin Petkov38d5cb02010-06-24 12:10:26 -0700165 // Updates the active use time and logs time between kernel crashes.
166 void ProcessKernelCrash();
167
Ken Mixterccd84c02010-08-16 19:57:13 -0700168 // Updates the active use time and logs time between unclean shutdowns.
169 void ProcessUncleanShutdown();
170
171 // Checks if a kernel crash has been detected and returns true if
172 // so. The method assumes that a kernel crash has happened if
173 // |crash_file| exists. It removes the file immediately if it
174 // exists, so it must not be called more than once.
175 bool CheckSystemCrash(const std::string& crash_file);
Darin Petkov38d5cb02010-06-24 12:10:26 -0700176
Ken Mixter4c5daa42010-08-26 18:35:06 -0700177 // Report daily use through UMA.
Luigi Semenzato5ef2e392014-04-15 15:15:02 -0700178 void ReportDailyUse(int use_seconds);
Ken Mixter4c5daa42010-08-26 18:35:06 -0700179
Darin Petkov11b8eb32010-05-18 11:00:59 -0700180 // Sends a regular (exponential) histogram sample to Chrome for
181 // transport to UMA. See MetricsLibrary::SendToUMA in
182 // metrics_library.h for a description of the arguments.
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800183 void SendSample(const std::string& name, int sample,
Darin Petkov11b8eb32010-05-18 11:00:59 -0700184 int min, int max, int nbuckets);
Darin Petkov65b01462010-04-14 13:32:20 -0700185
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700186 // Sends a linear histogram sample to Chrome for transport to UMA. See
187 // MetricsLibrary::SendToUMA in metrics_library.h for a description of the
188 // arguments.
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800189 void SendLinearSample(const std::string& name, int sample,
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700190 int max, int nbuckets);
191
Luigi Semenzatoba0c65d2014-03-17 12:28:38 -0700192 // Sends various cumulative kernel crash-related stats, for instance the
193 // total number of kernel crashes since the last version update.
Luigi Semenzatoe5883fa2014-04-18 17:00:35 -0700194 void SendKernelCrashesCumulativeCountStats();
Luigi Semenzatoba0c65d2014-03-17 12:28:38 -0700195
196 // Returns the total (system-wide) CPU usage between the time of the most
197 // recent call to this function and now.
198 base::TimeDelta GetIncrementalCpuUse();
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800199
Luigi Semenzatoe5883fa2014-04-18 17:00:35 -0700200 // Sends a sample representing the number of seconds of active use
201 // for a 24-hour period.
202 void SendDailyUseSample(const scoped_ptr<PersistentInteger>& use);
203
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800204 // Sends a sample representing a time interval between two crashes of the
205 // same type.
206 void SendCrashIntervalSample(const scoped_ptr<PersistentInteger>& interval);
207
208 // Sends a sample representing a frequency of crashes of some type.
209 void SendCrashFrequencySample(const scoped_ptr<PersistentInteger>& frequency);
210
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700211 // Initializes vm and disk stats reporting.
212 void StatsReporterInit();
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800213
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700214 // Schedules a callback for the next vm and disk stats collection.
215 void ScheduleStatsCallback(int wait);
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800216
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700217 // Reads cumulative disk statistics from sysfs. Returns true for success.
Ben Chanf05ab402014-08-07 00:54:59 -0700218 bool DiskStatsReadStats(uint64_t* read_sectors, uint64_t* write_sectors);
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800219
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700220 // Reads cumulative vm statistics from procfs. Returns true for success.
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700221 bool VmStatsReadStats(struct VmstatRecord* stats);
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800222
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700223 // Parse cumulative vm statistics from a C string. Returns true for success.
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700224 bool VmStatsParseStats(const char* stats, struct VmstatRecord* record);
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700225
226 // Reports disk and vm statistics (static version for glib). Arguments are a
227 // glib artifact.
228 static gboolean StatsCallbackStatic(void* handle);
229
230 // Reports disk and vm statistics.
231 void StatsCallback();
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800232
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700233 // Schedules meminfo collection callback.
234 void ScheduleMeminfoCallback(int wait);
235
236 // Reports memory statistics (static version for glib). Argument is a glib
237 // artifact.
238 static gboolean MeminfoCallbackStatic(void* handle);
239
240 // Reports memory statistics. Returns false on failure.
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700241 bool MeminfoCallback();
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700242
243 // Parses content of /proc/meminfo and sends fields of interest to UMA.
Luigi Semenzato8accd332011-05-17 16:37:18 -0700244 // Returns false on errors. |meminfo_raw| contains the content of
245 // /proc/meminfo.
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700246 bool ProcessMeminfo(const std::string& meminfo_raw);
Luigi Semenzato8accd332011-05-17 16:37:18 -0700247
248 // Parses meminfo data from |meminfo_raw|. |fields| is a vector containing
249 // the fields of interest. The order of the fields must be the same in which
250 // /proc/meminfo prints them. The result of parsing fields[i] is placed in
251 // fields[i].value.
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700252 bool FillMeminfo(const std::string& meminfo_raw,
253 std::vector<MeminfoRecord>* fields);
Luigi Semenzato8accd332011-05-17 16:37:18 -0700254
Luigi Semenzato0d9a9c92013-12-05 15:55:12 -0800255 // Schedule a memory use callback in |interval| seconds.
256 void ScheduleMemuseCallback(double interval);
Luigi Semenzato8accd332011-05-17 16:37:18 -0700257
258 // Static wrapper for MemuseCallback. Always returns false.
259 static gboolean MemuseCallbackStatic(void* handle);
260
261 // Calls MemuseCallbackWork, and possibly schedules next callback, if enough
262 // active time has passed. Otherwise reschedules itself to simulate active
263 // time callbacks (i.e. wall clock time minus sleep time).
264 void MemuseCallback();
265
266 // Reads /proc/meminfo and sends total anonymous memory usage to UMA.
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700267 bool MemuseCallbackWork();
Luigi Semenzato8accd332011-05-17 16:37:18 -0700268
Luigi Semenzatofb3a8212013-05-07 16:55:00 -0700269 // Parses meminfo data and sends it to UMA.
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700270 bool ProcessMemuse(const std::string& meminfo_raw);
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700271
Luigi Semenzatofb3a8212013-05-07 16:55:00 -0700272 // Sends stats for thermal CPU throttling.
273 void SendCpuThrottleMetrics();
274
275 // Reads an integer CPU frequency value from sysfs.
276 bool ReadFreqToInt(const std::string& sysfs_file_name, int* value);
277
Luigi Semenzato859b3f02014-02-05 15:33:19 -0800278 // Reads the current OS version from /etc/lsb-release and hashes it
279 // to a unsigned 32-bit int.
Ben Chanf05ab402014-08-07 00:54:59 -0700280 uint32_t GetOsVersionHash();
Luigi Semenzato859b3f02014-02-05 15:33:19 -0800281
Daniel Eratc83975a2014-04-04 08:53:44 -0700282 // Updates stats, additionally sending them to UMA if enough time has elapsed
283 // since the last report.
284 void UpdateStats(base::TimeTicks now_ticks, base::Time now_wall_time);
285
286 // Invoked periodically by |update_stats_timeout_id_| to call UpdateStats().
287 static gboolean HandleUpdateStatsTimeout(gpointer data);
288
Luigi Semenzato96360192014-06-04 10:53:35 -0700289 // Reports zram statistics.
290 bool ReportZram(const base::FilePath& zram_dir);
291
Ben Chanf05ab402014-08-07 00:54:59 -0700292 // Reads a string from a file and converts it to uint64_t.
293 static bool ReadFileToUint64(const base::FilePath& path, uint64_t* value);
Luigi Semenzato96360192014-06-04 10:53:35 -0700294
295 // VARIABLES
296
Darin Petkov2ccef012010-05-05 16:06:37 -0700297 // Test mode.
Darin Petkov41e06232010-05-03 16:45:37 -0700298 bool testing_;
Darin Petkov65b01462010-04-14 13:32:20 -0700299
Darin Petkovfc91b422010-05-12 13:05:45 -0700300 // The metrics library handle.
301 MetricsLibraryInterface* metrics_lib_;
302
Darin Petkovf27f0362010-06-04 13:14:19 -0700303 // Timestamps last network state update. This timestamp is used to
304 // sample the time from the network going online to going offline so
305 // TimeTicks ensures a monotonically increasing TimeDelta.
306 base::TimeTicks network_state_last_;
Darin Petkov65b01462010-04-14 13:32:20 -0700307
Daniel Eratc83975a2014-04-04 08:53:44 -0700308 // The last time that UpdateStats() was called.
309 base::TimeTicks last_update_stats_time_;
Darin Petkov41e06232010-05-03 16:45:37 -0700310
Daniel Eratc83975a2014-04-04 08:53:44 -0700311 // ID of a GLib timeout that repeatedly runs UpdateStats().
312 gint update_stats_timeout_id_;
Darin Petkov41e06232010-05-03 16:45:37 -0700313
Darin Petkov41e06232010-05-03 16:45:37 -0700314 // Sleep period until the next daily usage aggregation performed by
315 // the daily use monitor (see ScheduleUseMonitor).
316 int usemon_interval_;
317
318 // Scheduled daily use monitor source (see ScheduleUseMonitor).
319 GSource* usemon_source_;
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800320
Luigi Semenzato0d9a9c92013-12-05 15:55:12 -0800321 // End time of current memuse stat collection interval.
322 double memuse_final_time_;
Luigi Semenzato8accd332011-05-17 16:37:18 -0700323
324 // Selects the wait time for the next memory use callback.
325 unsigned int memuse_interval_index_;
326
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700327 // Contain the most recent disk and vm cumulative stats.
Ben Chanf05ab402014-08-07 00:54:59 -0700328 uint64_t read_sectors_;
329 uint64_t write_sectors_;
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700330 struct VmstatRecord vmstats_;
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800331
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700332 StatsState stats_state_;
333 double stats_initial_time_;
334
Luigi Semenzatoba0c65d2014-03-17 12:28:38 -0700335 // The system "HZ", or frequency of ticks. Some system data uses ticks as a
336 // unit, and this is used to convert to standard time units.
Ben Chanf05ab402014-08-07 00:54:59 -0700337 uint32_t ticks_per_second_;
Luigi Semenzatoba0c65d2014-03-17 12:28:38 -0700338 // Used internally by GetIncrementalCpuUse() to return the CPU utilization
339 // between calls.
Ben Chanf05ab402014-08-07 00:54:59 -0700340 uint64_t latest_cpu_use_ticks_;
Luigi Semenzatoba0c65d2014-03-17 12:28:38 -0700341
342 // Persistent values and accumulators for crash statistics.
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800343 scoped_ptr<PersistentInteger> daily_cycle_;
344 scoped_ptr<PersistentInteger> weekly_cycle_;
345 scoped_ptr<PersistentInteger> version_cycle_;
346
Luigi Semenzatoe5883fa2014-04-18 17:00:35 -0700347 // Active use accumulated in a day.
348 scoped_ptr<PersistentInteger> daily_active_use_;
349 // Active use accumulated since the latest version update.
350 scoped_ptr<PersistentInteger> version_cumulative_active_use_;
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800351
Luigi Semenzatoba0c65d2014-03-17 12:28:38 -0700352 // The CPU time accumulator. This contains the CPU time, in milliseconds,
353 // used by the system since the most recent OS version update.
354 scoped_ptr<PersistentInteger> version_cumulative_cpu_use_;
355
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800356 scoped_ptr<PersistentInteger> user_crash_interval_;
357 scoped_ptr<PersistentInteger> kernel_crash_interval_;
358 scoped_ptr<PersistentInteger> unclean_shutdown_interval_;
359
360 scoped_ptr<PersistentInteger> any_crashes_daily_count_;
361 scoped_ptr<PersistentInteger> any_crashes_weekly_count_;
362 scoped_ptr<PersistentInteger> user_crashes_daily_count_;
363 scoped_ptr<PersistentInteger> user_crashes_weekly_count_;
364 scoped_ptr<PersistentInteger> kernel_crashes_daily_count_;
365 scoped_ptr<PersistentInteger> kernel_crashes_weekly_count_;
366 scoped_ptr<PersistentInteger> kernel_crashes_version_count_;
367 scoped_ptr<PersistentInteger> unclean_shutdowns_daily_count_;
368 scoped_ptr<PersistentInteger> unclean_shutdowns_weekly_count_;
369
Luigi Semenzato0f132bb2011-02-28 11:17:43 -0800370 std::string diskstats_path_;
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700371 std::string vmstats_path_;
Luigi Semenzatofb3a8212013-05-07 16:55:00 -0700372 std::string scaling_max_freq_path_;
373 std::string cpuinfo_max_freq_path_;
Bertrand SIMONNET46b49da2014-06-25 14:38:07 -0700374
375 scoped_ptr<UploadService> upload_service_;
Darin Petkov65b01462010-04-14 13:32:20 -0700376};
377
Luigi Semenzato4a6c9422014-06-30 18:12:28 -0700378#endif // METRICS_METRICS_DAEMON_H_