blob: 03c5f3ccd3a3697d5996adb003c2c1f36f3824b4 [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
Ken Mixter4c5daa42010-08-26 18:35:06 -070012#include <base/file_path.h>
Chris Masone817016a2011-05-12 14:14:48 -070013#include <base/memory/scoped_ptr.h>
Darin Petkovf1e85e42010-06-10 15:59:53 -070014#include <base/time.h>
15#include <gtest/gtest_prod.h> // for FRIEND_TEST
16
Darin Petkovfc91b422010-05-12 13:05:45 -070017#include "metrics_library.h"
18
Ken Mixterccd84c02010-08-16 19:57:13 -070019namespace chromeos_metrics {
20class FrequencyCounter;
Ken Mixter4c5daa42010-08-26 18:35:06 -070021class TaggedCounter;
22class TaggedCounterReporter;
Ken Mixterccd84c02010-08-16 19:57:13 -070023}
Darin Petkov2ccef012010-05-05 16:06:37 -070024
Darin Petkov65b01462010-04-14 13:32:20 -070025class MetricsDaemon {
26
27 public:
Darin Petkovf1e85e42010-06-10 15:59:53 -070028 MetricsDaemon();
29 ~MetricsDaemon();
Darin Petkov65b01462010-04-14 13:32:20 -070030
Darin Petkov11b8eb32010-05-18 11:00:59 -070031 // Initializes.
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -080032 void Init(bool testing, MetricsLibraryInterface* metrics_lib,
Luigi Semenzato5bd764f2011-10-14 12:03:35 -070033 const std::string& diskstats_path,
Luigi Semenzatofb3a8212013-05-07 16:55:00 -070034 const std::string& vmstats_path,
35 const std::string& cpuinfo_max_freq_path,
36 const std::string& scaling_max_freq_path);
Darin Petkov11b8eb32010-05-18 11:00:59 -070037
Darin Petkov703ec972010-04-27 11:02:18 -070038 // Does all the work. If |run_as_daemon| is true, daemonizes by
Darin Petkov2ccef012010-05-05 16:06:37 -070039 // forking.
40 void Run(bool run_as_daemon);
Darin Petkov65b01462010-04-14 13:32:20 -070041
42 private:
Darin Petkov2ccef012010-05-05 16:06:37 -070043 friend class MetricsDaemonTest;
Ken Mixterccd84c02010-08-16 19:57:13 -070044 FRIEND_TEST(MetricsDaemonTest, CheckSystemCrash);
Ken Mixter4c5daa42010-08-26 18:35:06 -070045 FRIEND_TEST(MetricsDaemonTest, ComputeEpochNoCurrent);
46 FRIEND_TEST(MetricsDaemonTest, ComputeEpochNoLast);
47 FRIEND_TEST(MetricsDaemonTest, GetHistogramPath);
48 FRIEND_TEST(MetricsDaemonTest, IsNewEpoch);
Darin Petkov2ccef012010-05-05 16:06:37 -070049 FRIEND_TEST(MetricsDaemonTest, LookupPowerState);
50 FRIEND_TEST(MetricsDaemonTest, LookupScreenSaverState);
51 FRIEND_TEST(MetricsDaemonTest, LookupSessionState);
Darin Petkove579d662010-05-05 16:19:39 -070052 FRIEND_TEST(MetricsDaemonTest, MessageFilter);
Luigi Semenzato5bd764f2011-10-14 12:03:35 -070053 FRIEND_TEST(MetricsDaemonTest, ParseVmStats);
Darin Petkov2ccef012010-05-05 16:06:37 -070054 FRIEND_TEST(MetricsDaemonTest, PowerStateChanged);
Darin Petkov38d5cb02010-06-24 12:10:26 -070055 FRIEND_TEST(MetricsDaemonTest, ProcessKernelCrash);
Luigi Semenzato29c7ef92011-04-12 14:12:35 -070056 FRIEND_TEST(MetricsDaemonTest, ProcessMeminfo);
57 FRIEND_TEST(MetricsDaemonTest, ProcessMeminfo2);
Ken Mixterccd84c02010-08-16 19:57:13 -070058 FRIEND_TEST(MetricsDaemonTest, ProcessUncleanShutdown);
Darin Petkov1bb904e2010-06-16 15:58:06 -070059 FRIEND_TEST(MetricsDaemonTest, ProcessUserCrash);
Ken Mixterccd84c02010-08-16 19:57:13 -070060 FRIEND_TEST(MetricsDaemonTest, ReportCrashesDailyFrequency);
Luigi Semenzatofb3a8212013-05-07 16:55:00 -070061 FRIEND_TEST(MetricsDaemonTest, ReadFreqToInt);
Ken Mixterccd84c02010-08-16 19:57:13 -070062 FRIEND_TEST(MetricsDaemonTest, ReportDailyUse);
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -080063 FRIEND_TEST(MetricsDaemonTest, ReportDiskStats);
Ken Mixterccd84c02010-08-16 19:57:13 -070064 FRIEND_TEST(MetricsDaemonTest, ReportKernelCrashInterval);
65 FRIEND_TEST(MetricsDaemonTest, ReportUncleanShutdownInterval);
66 FRIEND_TEST(MetricsDaemonTest, ReportUserCrashInterval);
Darin Petkov2ccef012010-05-05 16:06:37 -070067 FRIEND_TEST(MetricsDaemonTest, ScreenSaverStateChanged);
Darin Petkov11b8eb32010-05-18 11:00:59 -070068 FRIEND_TEST(MetricsDaemonTest, SendMetric);
Luigi Semenzatofb3a8212013-05-07 16:55:00 -070069 FRIEND_TEST(MetricsDaemonTest, SendCpuThrottleMetrics);
Darin Petkov2ccef012010-05-05 16:06:37 -070070 FRIEND_TEST(MetricsDaemonTest, SessionStateChanged);
Darin Petkovf1e85e42010-06-10 15:59:53 -070071 FRIEND_TEST(MetricsDaemonTest, SetUserActiveState);
Darin Petkovf27f0362010-06-04 13:14:19 -070072 FRIEND_TEST(MetricsDaemonTest, SetUserActiveStateTimeJump);
Darin Petkov2ccef012010-05-05 16:06:37 -070073
Darin Petkov703ec972010-04-27 11:02:18 -070074 // The power states (see power_states.h).
75 enum PowerState {
76 kUnknownPowerState = -1, // Initial/unknown power state.
77#define STATE(name, capname) kPowerState ## capname,
78#include "power_states.h"
79 kNumberPowerStates
80 };
Darin Petkov65b01462010-04-14 13:32:20 -070081
Darin Petkov41e06232010-05-03 16:45:37 -070082 // The user session states (see session_states.h).
83 enum SessionState {
84 kUnknownSessionState = -1, // Initial/unknown user session state.
85#define STATE(name, capname) kSessionState ## capname,
86#include "session_states.h"
87 kNumberSessionStates
88 };
89
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -080090 // State for disk stats collector callback.
Luigi Semenzato5bd764f2011-10-14 12:03:35 -070091 enum StatsState {
92 kStatsShort, // short wait before short interval collection
93 kStatsLong, // final wait before new collection
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -080094 };
95
Darin Petkov41e06232010-05-03 16:45:37 -070096 // Data record for aggregating daily usage.
97 class UseRecord {
98 public:
99 UseRecord() : day_(0), seconds_(0) {}
100 int day_;
101 int seconds_;
102 };
103
Luigi Semenzato3ccca062013-02-04 19:50:45 -0800104 // Type of scale to use for meminfo histograms. For most of them we use
105 // percent of total RAM, but for some we use absolute numbers, usually in
106 // megabytes, on a log scale from 0 to 4000, and 0 to 8000 for compressed
107 // swap (since it can be larger than total RAM).
Luigi Semenzato942cbab2013-02-12 13:17:07 -0800108 enum MeminfoOp {
109 kMeminfoOp_HistPercent = 0,
110 kMeminfoOp_HistLog,
111 kMeminfoOp_SwapTotal,
112 kMeminfoOp_SwapFree,
Luigi Semenzato3ccca062013-02-04 19:50:45 -0800113 };
114
Luigi Semenzato8accd332011-05-17 16:37:18 -0700115 // Record for retrieving and reporting values from /proc/meminfo.
116 struct MeminfoRecord {
Luigi Semenzato3ccca062013-02-04 19:50:45 -0800117 const char* name; // print name
118 const char* match; // string to match in output of /proc/meminfo
Luigi Semenzato942cbab2013-02-12 13:17:07 -0800119 MeminfoOp op; // histogram scale selector, or other operator
Luigi Semenzato3ccca062013-02-04 19:50:45 -0800120 int value; // value from /proc/meminfo
Luigi Semenzato8accd332011-05-17 16:37:18 -0700121 };
122
Ken Mixter4c5daa42010-08-26 18:35:06 -0700123 typedef std::map<std::string, chromeos_metrics::FrequencyCounter*>
124 FrequencyCounters;
125
Darin Petkov2ccef012010-05-05 16:06:37 -0700126 // Metric parameters.
Ken Mixterccd84c02010-08-16 19:57:13 -0700127 static const char kMetricAnyCrashesDailyName[];
Ken Mixter4c5daa42010-08-26 18:35:06 -0700128 static const char kMetricAnyCrashesWeeklyName[];
129 static const char kMetricCrashFrequencyBuckets;
130 static const char kMetricCrashFrequencyMax;
131 static const char kMetricCrashFrequencyMin;
Ken Mixterccd84c02010-08-16 19:57:13 -0700132 static const int kMetricCrashIntervalBuckets;
133 static const int kMetricCrashIntervalMax;
134 static const int kMetricCrashIntervalMin;
135 static const int kMetricDailyUseTimeBuckets;
136 static const int kMetricDailyUseTimeMax;
137 static const int kMetricDailyUseTimeMin;
Darin Petkov2ccef012010-05-05 16:06:37 -0700138 static const char kMetricDailyUseTimeName[];
Ken Mixterccd84c02010-08-16 19:57:13 -0700139 static const char kMetricKernelCrashesDailyName[];
Ken Mixter4c5daa42010-08-26 18:35:06 -0700140 static const char kMetricKernelCrashesWeeklyName[];
Darin Petkov38d5cb02010-06-24 12:10:26 -0700141 static const char kMetricKernelCrashIntervalName[];
Ken Mixter4c5daa42010-08-26 18:35:06 -0700142 static const char kMetricsPath[];
Ken Mixterccd84c02010-08-16 19:57:13 -0700143 static const char kMetricUncleanShutdownIntervalName[];
144 static const char kMetricUncleanShutdownsDailyName[];
Ken Mixter4c5daa42010-08-26 18:35:06 -0700145 static const char kMetricUncleanShutdownsWeeklyName[];
Ken Mixterccd84c02010-08-16 19:57:13 -0700146 static const char kMetricUserCrashesDailyName[];
Ken Mixter4c5daa42010-08-26 18:35:06 -0700147 static const char kMetricUserCrashesWeeklyName[];
Darin Petkov1bb904e2010-06-16 15:58:06 -0700148 static const char kMetricUserCrashIntervalName[];
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800149 static const char kMetricReadSectorsLongName[];
150 static const char kMetricReadSectorsShortName[];
151 static const char kMetricWriteSectorsLongName[];
152 static const char kMetricWriteSectorsShortName[];
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700153 static const char kMetricPageFaultsShortName[];
154 static const char kMetricPageFaultsLongName[];
Luigi Semenzatofb3a8212013-05-07 16:55:00 -0700155 static const char kMetricScaledCpuFrequencyName[];
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700156 static const int kMetricStatsShortInterval;
157 static const int kMetricStatsLongInterval;
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700158 static const int kMetricMeminfoInterval;
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800159 static const int kMetricSectorsIOMax;
160 static const int kMetricSectorsBuckets;
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700161 static const int kMetricPageFaultsMax;
162 static const int kMetricPageFaultsBuckets;
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800163 static const char kMetricsDiskStatsPath[];
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700164 static const char kMetricsVmStatsPath[];
Darin Petkov2ccef012010-05-05 16:06:37 -0700165
Darin Petkov41e06232010-05-03 16:45:37 -0700166 // Array of power states.
167 static const char* kPowerStates_[kNumberPowerStates];
168
Darin Petkov41e06232010-05-03 16:45:37 -0700169 // Array of user session states.
170 static const char* kSessionStates_[kNumberSessionStates];
171
Luigi Semenzato8accd332011-05-17 16:37:18 -0700172 // Returns the active time since boot (uptime minus sleep time) in seconds.
173 double GetActiveTime();
174
Ken Mixter4c5daa42010-08-26 18:35:06 -0700175 // Clears and deletes the data contained in frequency_counters_.
176 void DeleteFrequencyCounters();
177
178 // Configures the given crash interval reporter.
179 void ConfigureCrashIntervalReporter(
180 const char* histogram_name,
181 scoped_ptr<chromeos_metrics::TaggedCounterReporter>* reporter);
182
183 // Configures the given frequency counter reporter.
184 void ConfigureCrashFrequencyReporter(const char* histogram_name);
185
186 // Returns file path to persistent file for generating given histogram.
187 FilePath GetHistogramPath(const char* histogram_name);
188
Darin Petkov65b01462010-04-14 13:32:20 -0700189 // Creates the event loop and enters it.
190 void Loop();
191
Darin Petkov703ec972010-04-27 11:02:18 -0700192 // D-Bus filter callback.
193 static DBusHandlerResult MessageFilter(DBusConnection* connection,
194 DBusMessage* message,
195 void* user_data);
Darin Petkov65b01462010-04-14 13:32:20 -0700196
Darin Petkov703ec972010-04-27 11:02:18 -0700197 // Processes power state change.
Darin Petkovf27f0362010-06-04 13:14:19 -0700198 void PowerStateChanged(const char* state_name, base::Time now);
Darin Petkov703ec972010-04-27 11:02:18 -0700199
200 // Given the state name, returns the state id.
201 PowerState LookupPowerState(const char* state_name);
Darin Petkov65b01462010-04-14 13:32:20 -0700202
Darin Petkov41e06232010-05-03 16:45:37 -0700203 // Processes user session state change.
Darin Petkovf27f0362010-06-04 13:14:19 -0700204 void SessionStateChanged(const char* state_name, base::Time now);
Darin Petkov41e06232010-05-03 16:45:37 -0700205
206 // Given the state name, returns the state id.
207 SessionState LookupSessionState(const char* state_name);
208
209 // Updates the user-active state to |active| and logs the usage data
210 // since the last update. If the user has just become active,
211 // reschedule the daily use monitor for more frequent updates --
212 // this is followed by an exponential back-off (see UseMonitor).
Darin Petkovf27f0362010-06-04 13:14:19 -0700213 // While in active use, this method should be called at intervals no
214 // longer than kUseMonitorIntervalMax otherwise new use time will be
215 // discarded.
216 void SetUserActiveState(bool active, base::Time now);
Darin Petkov41e06232010-05-03 16:45:37 -0700217
218 // Updates the daily usage file, if necessary, by adding |seconds|
219 // of active use to the |day| since Epoch. If there's usage data for
220 // day in the past in the usage file, that data is sent to UMA and
221 // removed from the file. If there's already usage data for |day| in
222 // the usage file, the |seconds| are accumulated.
223 void LogDailyUseRecord(int day, int seconds);
224
Darin Petkov1bb904e2010-06-16 15:58:06 -0700225 // Updates the active use time and logs time between user-space
226 // process crashes.
227 void ProcessUserCrash();
228
Darin Petkov38d5cb02010-06-24 12:10:26 -0700229 // Updates the active use time and logs time between kernel crashes.
230 void ProcessKernelCrash();
231
Ken Mixterccd84c02010-08-16 19:57:13 -0700232 // Updates the active use time and logs time between unclean shutdowns.
233 void ProcessUncleanShutdown();
234
235 // Checks if a kernel crash has been detected and returns true if
236 // so. The method assumes that a kernel crash has happened if
237 // |crash_file| exists. It removes the file immediately if it
238 // exists, so it must not be called more than once.
239 bool CheckSystemCrash(const std::string& crash_file);
Darin Petkov38d5cb02010-06-24 12:10:26 -0700240
Darin Petkov41e06232010-05-03 16:45:37 -0700241 // Callbacks for the daily use monitor. The daily use monitor uses
242 // LogDailyUseRecord to aggregate current usage data and send it to
243 // UMA, if necessary. It also reschedules itself using an
244 // exponentially bigger interval (up to a certain maximum) -- so
245 // usage is monitored less frequently with longer active use.
246 static gboolean UseMonitorStatic(gpointer data);
247 bool UseMonitor();
248
249 // Schedules or reschedules a daily use monitor for |interval|
250 // seconds from now. |backoff| mode is used by the use monitor to
251 // reschedule itself. If there's a monitor scheduled already and
252 // |backoff| is false, unschedules it first. Doesn't schedule a
253 // monitor for more than kUseMonitorIntervalMax seconds in the
254 // future (see metrics_daemon.cc). Returns true if a new use monitor
255 // was scheduled, false otherwise (note that if |backoff| is false a
256 // new use monitor will always be scheduled).
257 bool ScheduleUseMonitor(int interval, bool backoff);
258
259 // Unschedules a scheduled use monitor, if any.
260 void UnscheduleUseMonitor();
261
Ken Mixter4c5daa42010-08-26 18:35:06 -0700262 // Report daily use through UMA.
263 static void ReportDailyUse(void* handle, int tag, int count);
264
Darin Petkov11b8eb32010-05-18 11:00:59 -0700265 // Sends a regular (exponential) histogram sample to Chrome for
266 // transport to UMA. See MetricsLibrary::SendToUMA in
267 // metrics_library.h for a description of the arguments.
268 void SendMetric(const std::string& name, int sample,
269 int min, int max, int nbuckets);
Darin Petkov65b01462010-04-14 13:32:20 -0700270
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700271 // Sends a linear histogram sample to Chrome for transport to UMA. See
272 // MetricsLibrary::SendToUMA in metrics_library.h for a description of the
273 // arguments.
274 void SendLinearMetric(const std::string& name, int sample,
275 int max, int nbuckets);
276
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700277 // Initializes vm and disk stats reporting.
278 void StatsReporterInit();
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800279
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700280 // Schedules a callback for the next vm and disk stats collection.
281 void ScheduleStatsCallback(int wait);
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800282
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700283 // Reads cumulative disk statistics from sysfs. Returns true for success.
284 bool DiskStatsReadStats(long int* read_sectors, long int* write_sectors);
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800285
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700286 // Reads cumulative vm statistics from procfs. Returns true for success.
287 bool VmStatsReadStats(long int* page_faults);
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800288
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700289 // Parse cumulative vm statistics from a C string. Returns true for success.
290 bool VmStatsParseStats(char* stats, long int* page_faults);
291
292 // Reports disk and vm statistics (static version for glib). Arguments are a
293 // glib artifact.
294 static gboolean StatsCallbackStatic(void* handle);
295
296 // Reports disk and vm statistics.
297 void StatsCallback();
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800298
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700299 // Schedules meminfo collection callback.
300 void ScheduleMeminfoCallback(int wait);
301
302 // Reports memory statistics (static version for glib). Argument is a glib
303 // artifact.
304 static gboolean MeminfoCallbackStatic(void* handle);
305
306 // Reports memory statistics. Returns false on failure.
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700307 bool MeminfoCallback();
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700308
309 // Parses content of /proc/meminfo and sends fields of interest to UMA.
Luigi Semenzato8accd332011-05-17 16:37:18 -0700310 // Returns false on errors. |meminfo_raw| contains the content of
311 // /proc/meminfo.
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700312 bool ProcessMeminfo(const std::string& meminfo_raw);
Luigi Semenzato8accd332011-05-17 16:37:18 -0700313
314 // Parses meminfo data from |meminfo_raw|. |fields| is a vector containing
315 // the fields of interest. The order of the fields must be the same in which
316 // /proc/meminfo prints them. The result of parsing fields[i] is placed in
317 // fields[i].value.
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700318 bool FillMeminfo(const std::string& meminfo_raw,
319 std::vector<MeminfoRecord>* fields);
Luigi Semenzato8accd332011-05-17 16:37:18 -0700320
321 // Schedule a memory use callback. |new_callback| is true when this callback
322 // is scheduled for the first time. When |new_callback| is false,
323 // |time_elapsed| is the active (non-sleep) time that has passed between now
324 // and the original callback scheduling time. We use it to reschedule a
325 // callback that fired too early because we slept.
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700326 void ScheduleMemuseCallback(bool new_callback, double time_elapsed);
Luigi Semenzato8accd332011-05-17 16:37:18 -0700327
328 // Static wrapper for MemuseCallback. Always returns false.
329 static gboolean MemuseCallbackStatic(void* handle);
330
331 // Calls MemuseCallbackWork, and possibly schedules next callback, if enough
332 // active time has passed. Otherwise reschedules itself to simulate active
333 // time callbacks (i.e. wall clock time minus sleep time).
334 void MemuseCallback();
335
336 // Reads /proc/meminfo and sends total anonymous memory usage to UMA.
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700337 bool MemuseCallbackWork();
Luigi Semenzato8accd332011-05-17 16:37:18 -0700338
Luigi Semenzatofb3a8212013-05-07 16:55:00 -0700339 // Parses meminfo data and sends it to UMA.
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700340 bool ProcessMemuse(const std::string& meminfo_raw);
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700341
Luigi Semenzatofb3a8212013-05-07 16:55:00 -0700342 // Sends stats for thermal CPU throttling.
343 void SendCpuThrottleMetrics();
344
345 // Reads an integer CPU frequency value from sysfs.
346 bool ReadFreqToInt(const std::string& sysfs_file_name, int* value);
347
Darin Petkov2ccef012010-05-05 16:06:37 -0700348 // Test mode.
Darin Petkov41e06232010-05-03 16:45:37 -0700349 bool testing_;
Darin Petkov65b01462010-04-14 13:32:20 -0700350
Darin Petkovfc91b422010-05-12 13:05:45 -0700351 // The metrics library handle.
352 MetricsLibraryInterface* metrics_lib_;
353
Darin Petkovf27f0362010-06-04 13:14:19 -0700354 // Timestamps last network state update. This timestamp is used to
355 // sample the time from the network going online to going offline so
356 // TimeTicks ensures a monotonically increasing TimeDelta.
357 base::TimeTicks network_state_last_;
Darin Petkov65b01462010-04-14 13:32:20 -0700358
Darin Petkov41e06232010-05-03 16:45:37 -0700359 // Current power state.
360 PowerState power_state_;
361
Darin Petkov41e06232010-05-03 16:45:37 -0700362 // Current user session state.
363 SessionState session_state_;
364
365 // Is the user currently active: power is on, user session has
366 // started, screen is not locked.
367 bool user_active_;
368
Darin Petkov1bb904e2010-06-16 15:58:06 -0700369 // Timestamps last user active update. Active use time is aggregated
370 // each day before sending to UMA so using time since the epoch as
371 // the timestamp.
Darin Petkovf27f0362010-06-04 13:14:19 -0700372 base::Time user_active_last_;
Darin Petkov41e06232010-05-03 16:45:37 -0700373
Darin Petkov1bb904e2010-06-16 15:58:06 -0700374 // Daily active use time in seconds.
Ken Mixter4c5daa42010-08-26 18:35:06 -0700375 scoped_ptr<chromeos_metrics::TaggedCounter> daily_use_;
Darin Petkov41e06232010-05-03 16:45:37 -0700376
Darin Petkov1bb904e2010-06-16 15:58:06 -0700377 // Active use time between user-space process crashes.
Ken Mixter4c5daa42010-08-26 18:35:06 -0700378 scoped_ptr<chromeos_metrics::TaggedCounterReporter> user_crash_interval_;
Darin Petkov1bb904e2010-06-16 15:58:06 -0700379
Darin Petkov38d5cb02010-06-24 12:10:26 -0700380 // Active use time between kernel crashes.
Ken Mixter4c5daa42010-08-26 18:35:06 -0700381 scoped_ptr<chromeos_metrics::TaggedCounterReporter> kernel_crash_interval_;
Darin Petkov38d5cb02010-06-24 12:10:26 -0700382
Ken Mixterccd84c02010-08-16 19:57:13 -0700383 // Active use time between unclean shutdowns crashes.
Ken Mixter4c5daa42010-08-26 18:35:06 -0700384 scoped_ptr<chromeos_metrics::TaggedCounterReporter>
Ken Mixterccd84c02010-08-16 19:57:13 -0700385 unclean_shutdown_interval_;
386
Ken Mixter4c5daa42010-08-26 18:35:06 -0700387 // Map of all frequency counters, to simplify flushing them.
388 FrequencyCounters frequency_counters_;
Ken Mixterccd84c02010-08-16 19:57:13 -0700389
Darin Petkov41e06232010-05-03 16:45:37 -0700390 // Sleep period until the next daily usage aggregation performed by
391 // the daily use monitor (see ScheduleUseMonitor).
392 int usemon_interval_;
393
394 // Scheduled daily use monitor source (see ScheduleUseMonitor).
395 GSource* usemon_source_;
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800396
Luigi Semenzato8accd332011-05-17 16:37:18 -0700397 // Time of initial scheduling of memuse callback
398 double memuse_initial_time_;
399
400 // Selects the wait time for the next memory use callback.
401 unsigned int memuse_interval_index_;
402
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700403 // Contain the most recent disk and vm cumulative stats.
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800404 long int read_sectors_;
405 long int write_sectors_;
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700406 long int page_faults_;
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800407
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700408 StatsState stats_state_;
409 double stats_initial_time_;
410
Luigi Semenzato0f132bb2011-02-28 11:17:43 -0800411 std::string diskstats_path_;
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700412 std::string vmstats_path_;
Luigi Semenzatofb3a8212013-05-07 16:55:00 -0700413 std::string scaling_max_freq_path_;
414 std::string cpuinfo_max_freq_path_;
Darin Petkov65b01462010-04-14 13:32:20 -0700415};
416
417#endif // METRICS_DAEMON_H_