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