blob: e4bf853acc7021fe3d0d43c3c260e09f7e7090ac [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
5#ifndef METRICS_DAEMON_H_
6#define METRICS_DAEMON_H_
7
Darin Petkov703ec972010-04-27 11:02:18 -07008#include <dbus/dbus.h>
Darin Petkov41e06232010-05-03 16:45:37 -07009#include <glib.h>
Ken Mixter4c5daa42010-08-26 18:35:06 -070010#include <map>
Darin Petkov65b01462010-04-14 13:32:20 -070011
Ben Chan2e6543d2014-02-05 23:26:25 -080012#include <base/files/file_path.h>
Chris Masone817016a2011-05-12 14:14:48 -070013#include <base/memory/scoped_ptr.h>
Ben Chan2e6543d2014-02-05 23:26:25 -080014#include <base/time/time.h>
Darin Petkovf1e85e42010-06-10 15:59:53 -070015#include <gtest/gtest_prod.h> // for FRIEND_TEST
16
Darin Petkovfc91b422010-05-12 13:05:45 -070017#include "metrics_library.h"
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -080018#include "persistent_integer.h"
Darin Petkovfc91b422010-05-12 13:05:45 -070019
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -080020using chromeos_metrics::PersistentInteger;
Darin Petkov2ccef012010-05-05 16:06:37 -070021
Darin Petkov65b01462010-04-14 13:32:20 -070022class MetricsDaemon {
23
24 public:
Darin Petkovf1e85e42010-06-10 15:59:53 -070025 MetricsDaemon();
26 ~MetricsDaemon();
Darin Petkov65b01462010-04-14 13:32:20 -070027
Darin Petkov11b8eb32010-05-18 11:00:59 -070028 // Initializes.
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -080029 void Init(bool testing, MetricsLibraryInterface* metrics_lib,
Luigi Semenzato5bd764f2011-10-14 12:03:35 -070030 const std::string& diskstats_path,
Luigi Semenzatofb3a8212013-05-07 16:55:00 -070031 const std::string& vmstats_path,
32 const std::string& cpuinfo_max_freq_path,
33 const std::string& scaling_max_freq_path);
Darin Petkov11b8eb32010-05-18 11:00:59 -070034
Darin Petkov703ec972010-04-27 11:02:18 -070035 // Does all the work. If |run_as_daemon| is true, daemonizes by
Darin Petkov2ccef012010-05-05 16:06:37 -070036 // forking.
37 void Run(bool run_as_daemon);
Darin Petkov65b01462010-04-14 13:32:20 -070038
39 private:
Darin Petkov2ccef012010-05-05 16:06:37 -070040 friend class MetricsDaemonTest;
Ken Mixterccd84c02010-08-16 19:57:13 -070041 FRIEND_TEST(MetricsDaemonTest, CheckSystemCrash);
Ken Mixter4c5daa42010-08-26 18:35:06 -070042 FRIEND_TEST(MetricsDaemonTest, ComputeEpochNoCurrent);
43 FRIEND_TEST(MetricsDaemonTest, ComputeEpochNoLast);
44 FRIEND_TEST(MetricsDaemonTest, GetHistogramPath);
45 FRIEND_TEST(MetricsDaemonTest, IsNewEpoch);
Darin Petkov2ccef012010-05-05 16:06:37 -070046 FRIEND_TEST(MetricsDaemonTest, LookupPowerState);
47 FRIEND_TEST(MetricsDaemonTest, LookupScreenSaverState);
48 FRIEND_TEST(MetricsDaemonTest, LookupSessionState);
Darin Petkove579d662010-05-05 16:19:39 -070049 FRIEND_TEST(MetricsDaemonTest, MessageFilter);
Luigi Semenzato5bd764f2011-10-14 12:03:35 -070050 FRIEND_TEST(MetricsDaemonTest, ParseVmStats);
Darin Petkov2ccef012010-05-05 16:06:37 -070051 FRIEND_TEST(MetricsDaemonTest, PowerStateChanged);
Darin Petkov38d5cb02010-06-24 12:10:26 -070052 FRIEND_TEST(MetricsDaemonTest, ProcessKernelCrash);
Luigi Semenzato29c7ef92011-04-12 14:12:35 -070053 FRIEND_TEST(MetricsDaemonTest, ProcessMeminfo);
54 FRIEND_TEST(MetricsDaemonTest, ProcessMeminfo2);
Ken Mixterccd84c02010-08-16 19:57:13 -070055 FRIEND_TEST(MetricsDaemonTest, ProcessUncleanShutdown);
Darin Petkov1bb904e2010-06-16 15:58:06 -070056 FRIEND_TEST(MetricsDaemonTest, ProcessUserCrash);
Ken Mixterccd84c02010-08-16 19:57:13 -070057 FRIEND_TEST(MetricsDaemonTest, ReportCrashesDailyFrequency);
Luigi Semenzatofb3a8212013-05-07 16:55:00 -070058 FRIEND_TEST(MetricsDaemonTest, ReadFreqToInt);
Ken Mixterccd84c02010-08-16 19:57:13 -070059 FRIEND_TEST(MetricsDaemonTest, ReportDailyUse);
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -080060 FRIEND_TEST(MetricsDaemonTest, ReportDiskStats);
Ken Mixterccd84c02010-08-16 19:57:13 -070061 FRIEND_TEST(MetricsDaemonTest, ReportKernelCrashInterval);
62 FRIEND_TEST(MetricsDaemonTest, ReportUncleanShutdownInterval);
63 FRIEND_TEST(MetricsDaemonTest, ReportUserCrashInterval);
Darin Petkov2ccef012010-05-05 16:06:37 -070064 FRIEND_TEST(MetricsDaemonTest, ScreenSaverStateChanged);
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -080065 FRIEND_TEST(MetricsDaemonTest, SendSample);
Luigi Semenzatofb3a8212013-05-07 16:55:00 -070066 FRIEND_TEST(MetricsDaemonTest, SendCpuThrottleMetrics);
Darin Petkov2ccef012010-05-05 16:06:37 -070067 FRIEND_TEST(MetricsDaemonTest, SessionStateChanged);
Darin Petkovf1e85e42010-06-10 15:59:53 -070068 FRIEND_TEST(MetricsDaemonTest, SetUserActiveState);
Darin Petkovf27f0362010-06-04 13:14:19 -070069 FRIEND_TEST(MetricsDaemonTest, SetUserActiveStateTimeJump);
Darin Petkov2ccef012010-05-05 16:06:37 -070070
Darin Petkov703ec972010-04-27 11:02:18 -070071 // The power states (see power_states.h).
72 enum PowerState {
73 kUnknownPowerState = -1, // Initial/unknown power state.
74#define STATE(name, capname) kPowerState ## capname,
75#include "power_states.h"
76 kNumberPowerStates
77 };
Darin Petkov65b01462010-04-14 13:32:20 -070078
Darin Petkov41e06232010-05-03 16:45:37 -070079 // The user session states (see session_states.h).
80 enum SessionState {
81 kUnknownSessionState = -1, // Initial/unknown user session state.
82#define STATE(name, capname) kSessionState ## capname,
83#include "session_states.h"
84 kNumberSessionStates
85 };
86
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -080087 // State for disk stats collector callback.
Luigi Semenzato5bd764f2011-10-14 12:03:35 -070088 enum StatsState {
89 kStatsShort, // short wait before short interval collection
90 kStatsLong, // final wait before new collection
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -080091 };
92
Darin Petkov41e06232010-05-03 16:45:37 -070093 // Data record for aggregating daily usage.
94 class UseRecord {
95 public:
96 UseRecord() : day_(0), seconds_(0) {}
97 int day_;
98 int seconds_;
99 };
100
Luigi Semenzato3ccca062013-02-04 19:50:45 -0800101 // Type of scale to use for meminfo histograms. For most of them we use
102 // percent of total RAM, but for some we use absolute numbers, usually in
103 // megabytes, on a log scale from 0 to 4000, and 0 to 8000 for compressed
104 // swap (since it can be larger than total RAM).
Luigi Semenzato942cbab2013-02-12 13:17:07 -0800105 enum MeminfoOp {
106 kMeminfoOp_HistPercent = 0,
107 kMeminfoOp_HistLog,
108 kMeminfoOp_SwapTotal,
109 kMeminfoOp_SwapFree,
Luigi Semenzato3ccca062013-02-04 19:50:45 -0800110 };
111
Luigi Semenzato8accd332011-05-17 16:37:18 -0700112 // Record for retrieving and reporting values from /proc/meminfo.
113 struct MeminfoRecord {
Luigi Semenzato3ccca062013-02-04 19:50:45 -0800114 const char* name; // print name
115 const char* match; // string to match in output of /proc/meminfo
Luigi Semenzato942cbab2013-02-12 13:17:07 -0800116 MeminfoOp op; // histogram scale selector, or other operator
Luigi Semenzato3ccca062013-02-04 19:50:45 -0800117 int value; // value from /proc/meminfo
Luigi Semenzato8accd332011-05-17 16:37:18 -0700118 };
119
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700120 // Record for retrieving and reporting values from /proc/vmstat
121 struct VmstatRecord {
122 uint64_t page_faults_; // major faults
123 uint64_t swap_in_; // pages swapped in
124 uint64_t swap_out_; // pages swapped out
125 };
126
Darin Petkov2ccef012010-05-05 16:06:37 -0700127 // Metric parameters.
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800128 static const char kMetricReadSectorsLongName[];
129 static const char kMetricReadSectorsShortName[];
130 static const char kMetricWriteSectorsLongName[];
131 static const char kMetricWriteSectorsShortName[];
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700132 static const char kMetricPageFaultsShortName[];
133 static const char kMetricPageFaultsLongName[];
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700134 static const char kMetricSwapInLongName[];
135 static const char kMetricSwapInShortName[];
136 static const char kMetricSwapOutLongName[];
137 static const char kMetricSwapOutShortName[];
Luigi Semenzatofb3a8212013-05-07 16:55:00 -0700138 static const char kMetricScaledCpuFrequencyName[];
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700139 static const int kMetricStatsShortInterval;
140 static const int kMetricStatsLongInterval;
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700141 static const int kMetricMeminfoInterval;
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800142 static const int kMetricSectorsIOMax;
143 static const int kMetricSectorsBuckets;
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700144 static const int kMetricPageFaultsMax;
145 static const int kMetricPageFaultsBuckets;
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800146 static const char kMetricsDiskStatsPath[];
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700147 static const char kMetricsVmStatsPath[];
Darin Petkov2ccef012010-05-05 16:06:37 -0700148
Darin Petkov41e06232010-05-03 16:45:37 -0700149 // Array of power states.
150 static const char* kPowerStates_[kNumberPowerStates];
151
Darin Petkov41e06232010-05-03 16:45:37 -0700152 // Array of user session states.
153 static const char* kSessionStates_[kNumberSessionStates];
154
Luigi Semenzato8accd332011-05-17 16:37:18 -0700155 // Returns the active time since boot (uptime minus sleep time) in seconds.
156 double GetActiveTime();
157
Darin Petkov65b01462010-04-14 13:32:20 -0700158 // Creates the event loop and enters it.
159 void Loop();
160
Darin Petkov703ec972010-04-27 11:02:18 -0700161 // D-Bus filter callback.
162 static DBusHandlerResult MessageFilter(DBusConnection* connection,
163 DBusMessage* message,
164 void* user_data);
Darin Petkov65b01462010-04-14 13:32:20 -0700165
Darin Petkov703ec972010-04-27 11:02:18 -0700166 // Processes power state change.
Darin Petkovf27f0362010-06-04 13:14:19 -0700167 void PowerStateChanged(const char* state_name, base::Time now);
Darin Petkov703ec972010-04-27 11:02:18 -0700168
169 // Given the state name, returns the state id.
170 PowerState LookupPowerState(const char* state_name);
Darin Petkov65b01462010-04-14 13:32:20 -0700171
Darin Petkov41e06232010-05-03 16:45:37 -0700172 // Processes user session state change.
Darin Petkovf27f0362010-06-04 13:14:19 -0700173 void SessionStateChanged(const char* state_name, base::Time now);
Darin Petkov41e06232010-05-03 16:45:37 -0700174
175 // Given the state name, returns the state id.
176 SessionState LookupSessionState(const char* state_name);
177
178 // Updates the user-active state to |active| and logs the usage data
179 // since the last update. If the user has just become active,
180 // reschedule the daily use monitor for more frequent updates --
181 // this is followed by an exponential back-off (see UseMonitor).
Darin Petkovf27f0362010-06-04 13:14:19 -0700182 // While in active use, this method should be called at intervals no
183 // longer than kUseMonitorIntervalMax otherwise new use time will be
184 // discarded.
185 void SetUserActiveState(bool active, base::Time now);
Darin Petkov41e06232010-05-03 16:45:37 -0700186
187 // Updates the daily usage file, if necessary, by adding |seconds|
188 // of active use to the |day| since Epoch. If there's usage data for
189 // day in the past in the usage file, that data is sent to UMA and
190 // removed from the file. If there's already usage data for |day| in
191 // the usage file, the |seconds| are accumulated.
192 void LogDailyUseRecord(int day, int seconds);
193
Darin Petkov1bb904e2010-06-16 15:58:06 -0700194 // Updates the active use time and logs time between user-space
195 // process crashes.
196 void ProcessUserCrash();
197
Darin Petkov38d5cb02010-06-24 12:10:26 -0700198 // Updates the active use time and logs time between kernel crashes.
199 void ProcessKernelCrash();
200
Ken Mixterccd84c02010-08-16 19:57:13 -0700201 // Updates the active use time and logs time between unclean shutdowns.
202 void ProcessUncleanShutdown();
203
204 // Checks if a kernel crash has been detected and returns true if
205 // so. The method assumes that a kernel crash has happened if
206 // |crash_file| exists. It removes the file immediately if it
207 // exists, so it must not be called more than once.
208 bool CheckSystemCrash(const std::string& crash_file);
Darin Petkov38d5cb02010-06-24 12:10:26 -0700209
Darin Petkov41e06232010-05-03 16:45:37 -0700210 // Callbacks for the daily use monitor. The daily use monitor uses
211 // LogDailyUseRecord to aggregate current usage data and send it to
212 // UMA, if necessary. It also reschedules itself using an
213 // exponentially bigger interval (up to a certain maximum) -- so
214 // usage is monitored less frequently with longer active use.
215 static gboolean UseMonitorStatic(gpointer data);
216 bool UseMonitor();
217
218 // Schedules or reschedules a daily use monitor for |interval|
219 // seconds from now. |backoff| mode is used by the use monitor to
220 // reschedule itself. If there's a monitor scheduled already and
221 // |backoff| is false, unschedules it first. Doesn't schedule a
222 // monitor for more than kUseMonitorIntervalMax seconds in the
223 // future (see metrics_daemon.cc). Returns true if a new use monitor
224 // was scheduled, false otherwise (note that if |backoff| is false a
225 // new use monitor will always be scheduled).
226 bool ScheduleUseMonitor(int interval, bool backoff);
227
228 // Unschedules a scheduled use monitor, if any.
229 void UnscheduleUseMonitor();
230
Ken Mixter4c5daa42010-08-26 18:35:06 -0700231 // Report daily use through UMA.
Luigi Semenzato859b3f02014-02-05 15:33:19 -0800232 static void ReportDailyUse(void* handle, int count);
Ken Mixter4c5daa42010-08-26 18:35:06 -0700233
Darin Petkov11b8eb32010-05-18 11:00:59 -0700234 // Sends a regular (exponential) histogram sample to Chrome for
235 // transport to UMA. See MetricsLibrary::SendToUMA in
236 // metrics_library.h for a description of the arguments.
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800237 void SendSample(const std::string& name, int sample,
Darin Petkov11b8eb32010-05-18 11:00:59 -0700238 int min, int max, int nbuckets);
Darin Petkov65b01462010-04-14 13:32:20 -0700239
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700240 // Sends a linear histogram sample to Chrome for transport to UMA. See
241 // MetricsLibrary::SendToUMA in metrics_library.h for a description of the
242 // arguments.
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800243 void SendLinearSample(const std::string& name, int sample,
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700244 int max, int nbuckets);
245
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800246 // Sends a histogram sample with the total number of kernel crashes since the
247 // last version update.
248 void SendKernelCrashesCumulativeCountSample();
249
250 // Sends a sample representing a time interval between two crashes of the
251 // same type.
252 void SendCrashIntervalSample(const scoped_ptr<PersistentInteger>& interval);
253
254 // Sends a sample representing a frequency of crashes of some type.
255 void SendCrashFrequencySample(const scoped_ptr<PersistentInteger>& frequency);
256
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700257 // Initializes vm and disk stats reporting.
258 void StatsReporterInit();
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800259
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700260 // Schedules a callback for the next vm and disk stats collection.
261 void ScheduleStatsCallback(int wait);
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800262
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700263 // Reads cumulative disk statistics from sysfs. Returns true for success.
264 bool DiskStatsReadStats(long int* read_sectors, long int* write_sectors);
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800265
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700266 // Reads cumulative vm statistics from procfs. Returns true for success.
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700267 bool VmStatsReadStats(struct VmstatRecord* stats);
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800268
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700269 // Parse cumulative vm statistics from a C string. Returns true for success.
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700270 bool VmStatsParseStats(const char* stats, struct VmstatRecord* record);
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700271
272 // Reports disk and vm statistics (static version for glib). Arguments are a
273 // glib artifact.
274 static gboolean StatsCallbackStatic(void* handle);
275
276 // Reports disk and vm statistics.
277 void StatsCallback();
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800278
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700279 // Schedules meminfo collection callback.
280 void ScheduleMeminfoCallback(int wait);
281
282 // Reports memory statistics (static version for glib). Argument is a glib
283 // artifact.
284 static gboolean MeminfoCallbackStatic(void* handle);
285
286 // Reports memory statistics. Returns false on failure.
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700287 bool MeminfoCallback();
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700288
289 // Parses content of /proc/meminfo and sends fields of interest to UMA.
Luigi Semenzato8accd332011-05-17 16:37:18 -0700290 // Returns false on errors. |meminfo_raw| contains the content of
291 // /proc/meminfo.
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700292 bool ProcessMeminfo(const std::string& meminfo_raw);
Luigi Semenzato8accd332011-05-17 16:37:18 -0700293
294 // Parses meminfo data from |meminfo_raw|. |fields| is a vector containing
295 // the fields of interest. The order of the fields must be the same in which
296 // /proc/meminfo prints them. The result of parsing fields[i] is placed in
297 // fields[i].value.
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700298 bool FillMeminfo(const std::string& meminfo_raw,
299 std::vector<MeminfoRecord>* fields);
Luigi Semenzato8accd332011-05-17 16:37:18 -0700300
Luigi Semenzato0d9a9c92013-12-05 15:55:12 -0800301 // Schedule a memory use callback in |interval| seconds.
302 void ScheduleMemuseCallback(double interval);
Luigi Semenzato8accd332011-05-17 16:37:18 -0700303
304 // Static wrapper for MemuseCallback. Always returns false.
305 static gboolean MemuseCallbackStatic(void* handle);
306
307 // Calls MemuseCallbackWork, and possibly schedules next callback, if enough
308 // active time has passed. Otherwise reschedules itself to simulate active
309 // time callbacks (i.e. wall clock time minus sleep time).
310 void MemuseCallback();
311
312 // Reads /proc/meminfo and sends total anonymous memory usage to UMA.
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700313 bool MemuseCallbackWork();
Luigi Semenzato8accd332011-05-17 16:37:18 -0700314
Luigi Semenzatofb3a8212013-05-07 16:55:00 -0700315 // Parses meminfo data and sends it to UMA.
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700316 bool ProcessMemuse(const std::string& meminfo_raw);
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700317
Luigi Semenzatofb3a8212013-05-07 16:55:00 -0700318 // Sends stats for thermal CPU throttling.
319 void SendCpuThrottleMetrics();
320
321 // Reads an integer CPU frequency value from sysfs.
322 bool ReadFreqToInt(const std::string& sysfs_file_name, int* value);
323
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800324 // Report UMA stats when cycles (daily or weekly) have changed.
325 void ReportStats(base::Time now);
326
Luigi Semenzato859b3f02014-02-05 15:33:19 -0800327 // Reads the current OS version from /etc/lsb-release and hashes it
328 // to a unsigned 32-bit int.
329 uint32 GetOsVersionHash();
330
Darin Petkov2ccef012010-05-05 16:06:37 -0700331 // Test mode.
Darin Petkov41e06232010-05-03 16:45:37 -0700332 bool testing_;
Darin Petkov65b01462010-04-14 13:32:20 -0700333
Darin Petkovfc91b422010-05-12 13:05:45 -0700334 // The metrics library handle.
335 MetricsLibraryInterface* metrics_lib_;
336
Darin Petkovf27f0362010-06-04 13:14:19 -0700337 // Timestamps last network state update. This timestamp is used to
338 // sample the time from the network going online to going offline so
339 // TimeTicks ensures a monotonically increasing TimeDelta.
340 base::TimeTicks network_state_last_;
Darin Petkov65b01462010-04-14 13:32:20 -0700341
Darin Petkov41e06232010-05-03 16:45:37 -0700342 // Current power state.
343 PowerState power_state_;
344
Darin Petkov41e06232010-05-03 16:45:37 -0700345 // Current user session state.
346 SessionState session_state_;
347
348 // Is the user currently active: power is on, user session has
349 // started, screen is not locked.
350 bool user_active_;
351
Darin Petkov1bb904e2010-06-16 15:58:06 -0700352 // Timestamps last user active update. Active use time is aggregated
353 // each day before sending to UMA so using time since the epoch as
354 // the timestamp.
Darin Petkovf27f0362010-06-04 13:14:19 -0700355 base::Time user_active_last_;
Darin Petkov41e06232010-05-03 16:45:37 -0700356
Darin Petkov41e06232010-05-03 16:45:37 -0700357 // Sleep period until the next daily usage aggregation performed by
358 // the daily use monitor (see ScheduleUseMonitor).
359 int usemon_interval_;
360
361 // Scheduled daily use monitor source (see ScheduleUseMonitor).
362 GSource* usemon_source_;
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800363
Luigi Semenzato0d9a9c92013-12-05 15:55:12 -0800364 // End time of current memuse stat collection interval.
365 double memuse_final_time_;
Luigi Semenzato8accd332011-05-17 16:37:18 -0700366
367 // Selects the wait time for the next memory use callback.
368 unsigned int memuse_interval_index_;
369
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700370 // Contain the most recent disk and vm cumulative stats.
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800371 long int read_sectors_;
372 long int write_sectors_;
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700373 struct VmstatRecord vmstats_;
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800374
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700375 StatsState stats_state_;
376 double stats_initial_time_;
377
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800378 // Persistent counters for crash statistics.
379 scoped_ptr<PersistentInteger> daily_cycle_;
380 scoped_ptr<PersistentInteger> weekly_cycle_;
381 scoped_ptr<PersistentInteger> version_cycle_;
382
383 scoped_ptr<PersistentInteger> daily_use_;
384
385 scoped_ptr<PersistentInteger> user_crash_interval_;
386 scoped_ptr<PersistentInteger> kernel_crash_interval_;
387 scoped_ptr<PersistentInteger> unclean_shutdown_interval_;
388
389 scoped_ptr<PersistentInteger> any_crashes_daily_count_;
390 scoped_ptr<PersistentInteger> any_crashes_weekly_count_;
391 scoped_ptr<PersistentInteger> user_crashes_daily_count_;
392 scoped_ptr<PersistentInteger> user_crashes_weekly_count_;
393 scoped_ptr<PersistentInteger> kernel_crashes_daily_count_;
394 scoped_ptr<PersistentInteger> kernel_crashes_weekly_count_;
395 scoped_ptr<PersistentInteger> kernel_crashes_version_count_;
396 scoped_ptr<PersistentInteger> unclean_shutdowns_daily_count_;
397 scoped_ptr<PersistentInteger> unclean_shutdowns_weekly_count_;
398
Luigi Semenzato0f132bb2011-02-28 11:17:43 -0800399 std::string diskstats_path_;
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700400 std::string vmstats_path_;
Luigi Semenzatofb3a8212013-05-07 16:55:00 -0700401 std::string scaling_max_freq_path_;
402 std::string cpuinfo_max_freq_path_;
Darin Petkov65b01462010-04-14 13:32:20 -0700403};
404
405#endif // METRICS_DAEMON_H_