Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: metrics_daemon.h

Issue 2731008: Implement a persistent storage aggregation counter class. (Closed) Base URL: ssh://git@chromiumos-git/metrics.git
Patch Set: Address kmixter's comments. Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « counter_test.cc ('k') | metrics_daemon.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 10
11 #include <base/scoped_ptr.h>
12 #include <base/time.h>
13 #include <gtest/gtest_prod.h> // for FRIEND_TEST
14
11 #include "metrics_library.h" 15 #include "metrics_library.h"
12 16
13 #include <gtest/gtest_prod.h> // for FRIEND_TEST 17 namespace chromeos_metrics { class TaggedCounterInterface; }
14 #include <base/time.h>
15 18
16 class MetricsDaemon { 19 class MetricsDaemon {
17 20
18 public: 21 public:
19 MetricsDaemon() 22 MetricsDaemon();
20 : daily_use_record_file_(NULL), 23 ~MetricsDaemon();
21 network_state_(kUnknownNetworkState),
22 power_state_(kUnknownPowerState),
23 session_state_(kUnknownSessionState),
24 user_active_(false),
25 daily_use_day_last_(0),
26 usemon_interval_(0),
27 usemon_source_(NULL) {}
28 ~MetricsDaemon() {}
29 24
30 // Initializes. 25 // Initializes.
31 void Init(bool testing, MetricsLibraryInterface* metrics_lib); 26 void Init(bool testing, MetricsLibraryInterface* metrics_lib);
32 27
33 // Does all the work. If |run_as_daemon| is true, daemonizes by 28 // Does all the work. If |run_as_daemon| is true, daemonizes by
34 // forking. 29 // forking.
35 void Run(bool run_as_daemon); 30 void Run(bool run_as_daemon);
36 31
37 private: 32 private:
38 friend class MetricsDaemonTest; 33 friend class MetricsDaemonTest;
39 FRIEND_TEST(MetricsDaemonTest, LogDailyUseRecordBadFileLocation); 34 FRIEND_TEST(MetricsDaemonTest, DailyUseReporter);
40 FRIEND_TEST(MetricsDaemonTest, LogDailyUseRecordOnLogin);
41 FRIEND_TEST(MetricsDaemonTest, LogDailyUseRecordRoundDown);
42 FRIEND_TEST(MetricsDaemonTest, LogDailyUseRecordRoundUp);
43 FRIEND_TEST(MetricsDaemonTest, LookupNetworkState); 35 FRIEND_TEST(MetricsDaemonTest, LookupNetworkState);
44 FRIEND_TEST(MetricsDaemonTest, LookupPowerState); 36 FRIEND_TEST(MetricsDaemonTest, LookupPowerState);
45 FRIEND_TEST(MetricsDaemonTest, LookupScreenSaverState); 37 FRIEND_TEST(MetricsDaemonTest, LookupScreenSaverState);
46 FRIEND_TEST(MetricsDaemonTest, LookupSessionState); 38 FRIEND_TEST(MetricsDaemonTest, LookupSessionState);
47 FRIEND_TEST(MetricsDaemonTest, MessageFilter); 39 FRIEND_TEST(MetricsDaemonTest, MessageFilter);
48 FRIEND_TEST(MetricsDaemonTest, NetStateChangedSimpleDrop); 40 FRIEND_TEST(MetricsDaemonTest, NetStateChangedSimpleDrop);
49 FRIEND_TEST(MetricsDaemonTest, NetStateChangedSuspend); 41 FRIEND_TEST(MetricsDaemonTest, NetStateChangedSuspend);
50 FRIEND_TEST(MetricsDaemonTest, PowerStateChanged); 42 FRIEND_TEST(MetricsDaemonTest, PowerStateChanged);
51 FRIEND_TEST(MetricsDaemonTest, ScreenSaverStateChanged); 43 FRIEND_TEST(MetricsDaemonTest, ScreenSaverStateChanged);
52 FRIEND_TEST(MetricsDaemonTest, SendMetric); 44 FRIEND_TEST(MetricsDaemonTest, SendMetric);
53 FRIEND_TEST(MetricsDaemonTest, SessionStateChanged); 45 FRIEND_TEST(MetricsDaemonTest, SessionStateChanged);
54 FRIEND_TEST(MetricsDaemonTest, SetUserActiveStateSendOnLogin); 46 FRIEND_TEST(MetricsDaemonTest, SetUserActiveState);
55 FRIEND_TEST(MetricsDaemonTest, SetUserActiveStateSendOnMonitor);
56 FRIEND_TEST(MetricsDaemonTest, SetUserActiveStateTimeJump); 47 FRIEND_TEST(MetricsDaemonTest, SetUserActiveStateTimeJump);
57 48
58 // The network states (see network_states.h). 49 // The network states (see network_states.h).
59 enum NetworkState { 50 enum NetworkState {
60 kUnknownNetworkState = -1, // Initial/unknown network state. 51 kUnknownNetworkState = -1, // Initial/unknown network state.
61 #define STATE(name, capname) kNetworkState ## capname, 52 #define STATE(name, capname) kNetworkState ## capname,
62 #include "network_states.h" 53 #include "network_states.h"
63 kNumberNetworkStates 54 kNumberNetworkStates
64 }; 55 };
65 56
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 162
172 // Unschedules a scheduled use monitor, if any. 163 // Unschedules a scheduled use monitor, if any.
173 void UnscheduleUseMonitor(); 164 void UnscheduleUseMonitor();
174 165
175 // Sends a regular (exponential) histogram sample to Chrome for 166 // Sends a regular (exponential) histogram sample to Chrome for
176 // transport to UMA. See MetricsLibrary::SendToUMA in 167 // transport to UMA. See MetricsLibrary::SendToUMA in
177 // metrics_library.h for a description of the arguments. 168 // metrics_library.h for a description of the arguments.
178 void SendMetric(const std::string& name, int sample, 169 void SendMetric(const std::string& name, int sample,
179 int min, int max, int nbuckets); 170 int min, int max, int nbuckets);
180 171
172 static void DailyUseReporter(void* data, int tag, int count);
173
181 // Test mode. 174 // Test mode.
182 bool testing_; 175 bool testing_;
183 176
184 // The metrics library handle. 177 // The metrics library handle.
185 MetricsLibraryInterface* metrics_lib_; 178 MetricsLibraryInterface* metrics_lib_;
186 179
187 const char* daily_use_record_file_;
188
189 // Current network state. 180 // Current network state.
190 NetworkState network_state_; 181 NetworkState network_state_;
191 182
192 // Timestamps last network state update. This timestamp is used to 183 // Timestamps last network state update. This timestamp is used to
193 // sample the time from the network going online to going offline so 184 // sample the time from the network going online to going offline so
194 // TimeTicks ensures a monotonically increasing TimeDelta. 185 // TimeTicks ensures a monotonically increasing TimeDelta.
195 base::TimeTicks network_state_last_; 186 base::TimeTicks network_state_last_;
196 187
197 // Current power state. 188 // Current power state.
198 PowerState power_state_; 189 PowerState power_state_;
199 190
200 // Current user session state. 191 // Current user session state.
201 SessionState session_state_; 192 SessionState session_state_;
202 193
203 // Is the user currently active: power is on, user session has 194 // Is the user currently active: power is on, user session has
204 // started, screen is not locked. 195 // started, screen is not locked.
205 bool user_active_; 196 bool user_active_;
206 197
207 // Timestamps last user active update. Active use time is 198 // Timestamps last user active update. Active use time is
208 // aggregated each day before sending to UMA so using time since the 199 // aggregated each day before sending to UMA so using time since the
209 // epoch as the timestamp. 200 // epoch as the timestamp.
210 base::Time user_active_last_; 201 base::Time user_active_last_;
211 202
212 // Last stored daily use day (since the epoch). 203 scoped_ptr<chromeos_metrics::TaggedCounterInterface> daily_use_;
213 int daily_use_day_last_;
214 204
215 // Sleep period until the next daily usage aggregation performed by 205 // Sleep period until the next daily usage aggregation performed by
216 // the daily use monitor (see ScheduleUseMonitor). 206 // the daily use monitor (see ScheduleUseMonitor).
217 int usemon_interval_; 207 int usemon_interval_;
218 208
219 // Scheduled daily use monitor source (see ScheduleUseMonitor). 209 // Scheduled daily use monitor source (see ScheduleUseMonitor).
220 GSource* usemon_source_; 210 GSource* usemon_source_;
221 }; 211 };
222 212
223 #endif // METRICS_DAEMON_H_ 213 #endif // METRICS_DAEMON_H_
OLDNEW
« no previous file with comments | « counter_test.cc ('k') | metrics_daemon.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698