OLD | NEW |
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef METRICS_DAEMON_H_ | 5 #ifndef METRICS_DAEMON_H_ |
6 #define METRICS_DAEMON_H_ | 6 #define METRICS_DAEMON_H_ |
7 | 7 |
8 #include <dbus/dbus.h> | 8 #include <dbus/dbus.h> |
9 #include <glib.h> | 9 #include <glib.h> |
10 #include <map> | 10 #include <map> |
(...skipping 11 matching lines...) Expand all Loading... |
22 class TaggedCounterReporter; | 22 class TaggedCounterReporter; |
23 } | 23 } |
24 | 24 |
25 class MetricsDaemon { | 25 class MetricsDaemon { |
26 | 26 |
27 public: | 27 public: |
28 MetricsDaemon(); | 28 MetricsDaemon(); |
29 ~MetricsDaemon(); | 29 ~MetricsDaemon(); |
30 | 30 |
31 // Initializes. | 31 // Initializes. |
32 void Init(bool testing, MetricsLibraryInterface* metrics_lib); | 32 void Init(bool testing, MetricsLibraryInterface* metrics_lib, |
| 33 const char* diskstats_path); |
33 | 34 |
34 // Does all the work. If |run_as_daemon| is true, daemonizes by | 35 // Does all the work. If |run_as_daemon| is true, daemonizes by |
35 // forking. | 36 // forking. |
36 void Run(bool run_as_daemon); | 37 void Run(bool run_as_daemon); |
37 | 38 |
38 private: | 39 private: |
39 friend class MetricsDaemonTest; | 40 friend class MetricsDaemonTest; |
40 FRIEND_TEST(MetricsDaemonTest, CheckSystemCrash); | 41 FRIEND_TEST(MetricsDaemonTest, CheckSystemCrash); |
41 FRIEND_TEST(MetricsDaemonTest, ComputeEpochNoCurrent); | 42 FRIEND_TEST(MetricsDaemonTest, ComputeEpochNoCurrent); |
42 FRIEND_TEST(MetricsDaemonTest, ComputeEpochNoLast); | 43 FRIEND_TEST(MetricsDaemonTest, ComputeEpochNoLast); |
43 FRIEND_TEST(MetricsDaemonTest, GetHistogramPath); | 44 FRIEND_TEST(MetricsDaemonTest, GetHistogramPath); |
44 FRIEND_TEST(MetricsDaemonTest, IsNewEpoch); | 45 FRIEND_TEST(MetricsDaemonTest, IsNewEpoch); |
45 FRIEND_TEST(MetricsDaemonTest, LookupPowerState); | 46 FRIEND_TEST(MetricsDaemonTest, LookupPowerState); |
46 FRIEND_TEST(MetricsDaemonTest, LookupScreenSaverState); | 47 FRIEND_TEST(MetricsDaemonTest, LookupScreenSaverState); |
47 FRIEND_TEST(MetricsDaemonTest, LookupSessionState); | 48 FRIEND_TEST(MetricsDaemonTest, LookupSessionState); |
48 FRIEND_TEST(MetricsDaemonTest, MessageFilter); | 49 FRIEND_TEST(MetricsDaemonTest, MessageFilter); |
49 FRIEND_TEST(MetricsDaemonTest, PowerStateChanged); | 50 FRIEND_TEST(MetricsDaemonTest, PowerStateChanged); |
50 FRIEND_TEST(MetricsDaemonTest, ProcessKernelCrash); | 51 FRIEND_TEST(MetricsDaemonTest, ProcessKernelCrash); |
51 FRIEND_TEST(MetricsDaemonTest, ProcessUncleanShutdown); | 52 FRIEND_TEST(MetricsDaemonTest, ProcessUncleanShutdown); |
52 FRIEND_TEST(MetricsDaemonTest, ProcessUserCrash); | 53 FRIEND_TEST(MetricsDaemonTest, ProcessUserCrash); |
53 FRIEND_TEST(MetricsDaemonTest, ReportCrashesDailyFrequency); | 54 FRIEND_TEST(MetricsDaemonTest, ReportCrashesDailyFrequency); |
54 FRIEND_TEST(MetricsDaemonTest, ReportDailyUse); | 55 FRIEND_TEST(MetricsDaemonTest, ReportDailyUse); |
| 56 FRIEND_TEST(MetricsDaemonTest, ReportDiskStats); |
55 FRIEND_TEST(MetricsDaemonTest, ReportKernelCrashInterval); | 57 FRIEND_TEST(MetricsDaemonTest, ReportKernelCrashInterval); |
56 FRIEND_TEST(MetricsDaemonTest, ReportUncleanShutdownInterval); | 58 FRIEND_TEST(MetricsDaemonTest, ReportUncleanShutdownInterval); |
57 FRIEND_TEST(MetricsDaemonTest, ReportUserCrashInterval); | 59 FRIEND_TEST(MetricsDaemonTest, ReportUserCrashInterval); |
58 FRIEND_TEST(MetricsDaemonTest, ScreenSaverStateChanged); | 60 FRIEND_TEST(MetricsDaemonTest, ScreenSaverStateChanged); |
59 FRIEND_TEST(MetricsDaemonTest, SendMetric); | 61 FRIEND_TEST(MetricsDaemonTest, SendMetric); |
60 FRIEND_TEST(MetricsDaemonTest, SessionStateChanged); | 62 FRIEND_TEST(MetricsDaemonTest, SessionStateChanged); |
61 FRIEND_TEST(MetricsDaemonTest, SetUserActiveState); | 63 FRIEND_TEST(MetricsDaemonTest, SetUserActiveState); |
62 FRIEND_TEST(MetricsDaemonTest, SetUserActiveStateTimeJump); | 64 FRIEND_TEST(MetricsDaemonTest, SetUserActiveStateTimeJump); |
63 | 65 |
64 // The power states (see power_states.h). | 66 // The power states (see power_states.h). |
65 enum PowerState { | 67 enum PowerState { |
66 kUnknownPowerState = -1, // Initial/unknown power state. | 68 kUnknownPowerState = -1, // Initial/unknown power state. |
67 #define STATE(name, capname) kPowerState ## capname, | 69 #define STATE(name, capname) kPowerState ## capname, |
68 #include "power_states.h" | 70 #include "power_states.h" |
69 kNumberPowerStates | 71 kNumberPowerStates |
70 }; | 72 }; |
71 | 73 |
72 // The user session states (see session_states.h). | 74 // The user session states (see session_states.h). |
73 enum SessionState { | 75 enum SessionState { |
74 kUnknownSessionState = -1, // Initial/unknown user session state. | 76 kUnknownSessionState = -1, // Initial/unknown user session state. |
75 #define STATE(name, capname) kSessionState ## capname, | 77 #define STATE(name, capname) kSessionState ## capname, |
76 #include "session_states.h" | 78 #include "session_states.h" |
77 kNumberSessionStates | 79 kNumberSessionStates |
78 }; | 80 }; |
79 | 81 |
| 82 // State for disk stats collector callback. |
| 83 enum DiskStatsState { |
| 84 kDiskStatsShort, // short wait before short interval collection |
| 85 kDiskStatsLong, // final wait before new collection |
| 86 }; |
| 87 |
80 // Data record for aggregating daily usage. | 88 // Data record for aggregating daily usage. |
81 class UseRecord { | 89 class UseRecord { |
82 public: | 90 public: |
83 UseRecord() : day_(0), seconds_(0) {} | 91 UseRecord() : day_(0), seconds_(0) {} |
84 int day_; | 92 int day_; |
85 int seconds_; | 93 int seconds_; |
86 }; | 94 }; |
87 | 95 |
88 typedef std::map<std::string, chromeos_metrics::FrequencyCounter*> | 96 typedef std::map<std::string, chromeos_metrics::FrequencyCounter*> |
89 FrequencyCounters; | 97 FrequencyCounters; |
(...skipping 14 matching lines...) Expand all Loading... |
104 static const char kMetricKernelCrashesDailyName[]; | 112 static const char kMetricKernelCrashesDailyName[]; |
105 static const char kMetricKernelCrashesWeeklyName[]; | 113 static const char kMetricKernelCrashesWeeklyName[]; |
106 static const char kMetricKernelCrashIntervalName[]; | 114 static const char kMetricKernelCrashIntervalName[]; |
107 static const char kMetricsPath[]; | 115 static const char kMetricsPath[]; |
108 static const char kMetricUncleanShutdownIntervalName[]; | 116 static const char kMetricUncleanShutdownIntervalName[]; |
109 static const char kMetricUncleanShutdownsDailyName[]; | 117 static const char kMetricUncleanShutdownsDailyName[]; |
110 static const char kMetricUncleanShutdownsWeeklyName[]; | 118 static const char kMetricUncleanShutdownsWeeklyName[]; |
111 static const char kMetricUserCrashesDailyName[]; | 119 static const char kMetricUserCrashesDailyName[]; |
112 static const char kMetricUserCrashesWeeklyName[]; | 120 static const char kMetricUserCrashesWeeklyName[]; |
113 static const char kMetricUserCrashIntervalName[]; | 121 static const char kMetricUserCrashIntervalName[]; |
| 122 static const char kMetricReadSectorsLongName[]; |
| 123 static const char kMetricReadSectorsShortName[]; |
| 124 static const char kMetricWriteSectorsLongName[]; |
| 125 static const char kMetricWriteSectorsShortName[]; |
| 126 static const int kMetricDiskStatsShortInterval; |
| 127 static const int kMetricDiskStatsLongInterval; |
| 128 static const int kMetricSectorsIOMax; |
| 129 static const int kMetricSectorsBuckets; |
| 130 static const char kMetricsDiskStatsPath[]; |
114 | 131 |
115 // D-Bus message match strings. | 132 // D-Bus message match strings. |
116 static const char* kDBusMatches_[]; | 133 static const char* kDBusMatches_[]; |
117 | 134 |
118 // Array of power states. | 135 // Array of power states. |
119 static const char* kPowerStates_[kNumberPowerStates]; | 136 static const char* kPowerStates_[kNumberPowerStates]; |
120 | 137 |
121 // Array of user session states. | 138 // Array of user session states. |
122 static const char* kSessionStates_[kNumberSessionStates]; | 139 static const char* kSessionStates_[kNumberSessionStates]; |
123 | 140 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 | 227 |
211 // Report daily use through UMA. | 228 // Report daily use through UMA. |
212 static void ReportDailyUse(void* handle, int tag, int count); | 229 static void ReportDailyUse(void* handle, int tag, int count); |
213 | 230 |
214 // Sends a regular (exponential) histogram sample to Chrome for | 231 // Sends a regular (exponential) histogram sample to Chrome for |
215 // transport to UMA. See MetricsLibrary::SendToUMA in | 232 // transport to UMA. See MetricsLibrary::SendToUMA in |
216 // metrics_library.h for a description of the arguments. | 233 // metrics_library.h for a description of the arguments. |
217 void SendMetric(const std::string& name, int sample, | 234 void SendMetric(const std::string& name, int sample, |
218 int min, int max, int nbuckets); | 235 int min, int max, int nbuckets); |
219 | 236 |
| 237 // Initializes disk stats reporting. |
| 238 void DiskStatsReporterInit(); |
| 239 |
| 240 // Schedules a callback for the next disk stats collection. |
| 241 void ScheduleDiskStatsCallback(int wait); |
| 242 |
| 243 // Reads cumulative disk statistics from sysfs. |
| 244 void DiskStatsReadStats(long int* read_sectors, long int* write_sectors); |
| 245 |
| 246 // Reports disk statistics (static version for glib). Arguments are a glib |
| 247 // artifact. |
| 248 static gboolean DiskStatsCallbackStatic(void* handle); |
| 249 |
| 250 // Reports disk statistics. |
| 251 void DiskStatsCallback(); |
| 252 |
220 // Test mode. | 253 // Test mode. |
221 bool testing_; | 254 bool testing_; |
222 | 255 |
223 // The metrics library handle. | 256 // The metrics library handle. |
224 MetricsLibraryInterface* metrics_lib_; | 257 MetricsLibraryInterface* metrics_lib_; |
225 | 258 |
226 // Timestamps last network state update. This timestamp is used to | 259 // Timestamps last network state update. This timestamp is used to |
227 // sample the time from the network going online to going offline so | 260 // sample the time from the network going online to going offline so |
228 // TimeTicks ensures a monotonically increasing TimeDelta. | 261 // TimeTicks ensures a monotonically increasing TimeDelta. |
229 base::TimeTicks network_state_last_; | 262 base::TimeTicks network_state_last_; |
(...skipping 28 matching lines...) Expand all Loading... |
258 | 291 |
259 // Map of all frequency counters, to simplify flushing them. | 292 // Map of all frequency counters, to simplify flushing them. |
260 FrequencyCounters frequency_counters_; | 293 FrequencyCounters frequency_counters_; |
261 | 294 |
262 // Sleep period until the next daily usage aggregation performed by | 295 // Sleep period until the next daily usage aggregation performed by |
263 // the daily use monitor (see ScheduleUseMonitor). | 296 // the daily use monitor (see ScheduleUseMonitor). |
264 int usemon_interval_; | 297 int usemon_interval_; |
265 | 298 |
266 // Scheduled daily use monitor source (see ScheduleUseMonitor). | 299 // Scheduled daily use monitor source (see ScheduleUseMonitor). |
267 GSource* usemon_source_; | 300 GSource* usemon_source_; |
| 301 |
| 302 // Contains the most recent disk stats. |
| 303 long int read_sectors_; |
| 304 long int write_sectors_; |
| 305 |
| 306 DiskStatsState diskstats_state_; |
| 307 const char* diskstats_path_; |
268 }; | 308 }; |
269 | 309 |
270 #endif // METRICS_DAEMON_H_ | 310 #endif // METRICS_DAEMON_H_ |
OLD | NEW |