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

Side by Side Diff: metrics_daemon.h

Issue 2736008: Measure and report time between user-space process crashes. (Closed) Base URL: ssh://git@chromiumos-git/metrics.git
Patch Set: No need to start the back off again on crashes. 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
(...skipping 22 matching lines...) Expand all
33 friend class MetricsDaemonTest; 33 friend class MetricsDaemonTest;
34 FRIEND_TEST(MetricsDaemonTest, DailyUseReporter); 34 FRIEND_TEST(MetricsDaemonTest, DailyUseReporter);
35 FRIEND_TEST(MetricsDaemonTest, LookupNetworkState); 35 FRIEND_TEST(MetricsDaemonTest, LookupNetworkState);
36 FRIEND_TEST(MetricsDaemonTest, LookupPowerState); 36 FRIEND_TEST(MetricsDaemonTest, LookupPowerState);
37 FRIEND_TEST(MetricsDaemonTest, LookupScreenSaverState); 37 FRIEND_TEST(MetricsDaemonTest, LookupScreenSaverState);
38 FRIEND_TEST(MetricsDaemonTest, LookupSessionState); 38 FRIEND_TEST(MetricsDaemonTest, LookupSessionState);
39 FRIEND_TEST(MetricsDaemonTest, MessageFilter); 39 FRIEND_TEST(MetricsDaemonTest, MessageFilter);
40 FRIEND_TEST(MetricsDaemonTest, NetStateChangedSimpleDrop); 40 FRIEND_TEST(MetricsDaemonTest, NetStateChangedSimpleDrop);
41 FRIEND_TEST(MetricsDaemonTest, NetStateChangedSuspend); 41 FRIEND_TEST(MetricsDaemonTest, NetStateChangedSuspend);
42 FRIEND_TEST(MetricsDaemonTest, PowerStateChanged); 42 FRIEND_TEST(MetricsDaemonTest, PowerStateChanged);
43 FRIEND_TEST(MetricsDaemonTest, ProcessUserCrash);
43 FRIEND_TEST(MetricsDaemonTest, ScreenSaverStateChanged); 44 FRIEND_TEST(MetricsDaemonTest, ScreenSaverStateChanged);
44 FRIEND_TEST(MetricsDaemonTest, SendMetric); 45 FRIEND_TEST(MetricsDaemonTest, SendMetric);
45 FRIEND_TEST(MetricsDaemonTest, SessionStateChanged); 46 FRIEND_TEST(MetricsDaemonTest, SessionStateChanged);
46 FRIEND_TEST(MetricsDaemonTest, SetUserActiveState); 47 FRIEND_TEST(MetricsDaemonTest, SetUserActiveState);
47 FRIEND_TEST(MetricsDaemonTest, SetUserActiveStateTimeJump); 48 FRIEND_TEST(MetricsDaemonTest, SetUserActiveStateTimeJump);
49 FRIEND_TEST(MetricsDaemonTest, UserCrashIntervalReporter);
48 50
49 // The network states (see network_states.h). 51 // The network states (see network_states.h).
50 enum NetworkState { 52 enum NetworkState {
51 kUnknownNetworkState = -1, // Initial/unknown network state. 53 kUnknownNetworkState = -1, // Initial/unknown network state.
52 #define STATE(name, capname) kNetworkState ## capname, 54 #define STATE(name, capname) kNetworkState ## capname,
53 #include "network_states.h" 55 #include "network_states.h"
54 kNumberNetworkStates 56 kNumberNetworkStates
55 }; 57 };
56 58
57 // The power states (see power_states.h). 59 // The power states (see power_states.h).
(...skipping 22 matching lines...) Expand all
80 82
81 // Metric parameters. 83 // Metric parameters.
82 static const char kMetricDailyUseTimeName[]; 84 static const char kMetricDailyUseTimeName[];
83 static const int kMetricDailyUseTimeMin; 85 static const int kMetricDailyUseTimeMin;
84 static const int kMetricDailyUseTimeMax; 86 static const int kMetricDailyUseTimeMax;
85 static const int kMetricDailyUseTimeBuckets; 87 static const int kMetricDailyUseTimeBuckets;
86 static const char kMetricTimeToNetworkDropName[]; 88 static const char kMetricTimeToNetworkDropName[];
87 static const int kMetricTimeToNetworkDropMin; 89 static const int kMetricTimeToNetworkDropMin;
88 static const int kMetricTimeToNetworkDropMax; 90 static const int kMetricTimeToNetworkDropMax;
89 static const int kMetricTimeToNetworkDropBuckets; 91 static const int kMetricTimeToNetworkDropBuckets;
92 static const char kMetricUserCrashIntervalName[];
93 static const int kMetricUserCrashIntervalMin;
94 static const int kMetricUserCrashIntervalMax;
95 static const int kMetricUserCrashIntervalBuckets;
90 96
91 // D-Bus message match strings. 97 // D-Bus message match strings.
92 static const char* kDBusMatches_[]; 98 static const char* kDBusMatches_[];
93 99
94 // Array of network states. 100 // Array of network states.
95 static const char* kNetworkStates_[kNumberNetworkStates]; 101 static const char* kNetworkStates_[kNumberNetworkStates];
96 102
97 // Array of power states. 103 // Array of power states.
98 static const char* kPowerStates_[kNumberPowerStates]; 104 static const char* kPowerStates_[kNumberPowerStates];
99 105
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 // discarded. 141 // discarded.
136 void SetUserActiveState(bool active, base::Time now); 142 void SetUserActiveState(bool active, base::Time now);
137 143
138 // Updates the daily usage file, if necessary, by adding |seconds| 144 // Updates the daily usage file, if necessary, by adding |seconds|
139 // of active use to the |day| since Epoch. If there's usage data for 145 // of active use to the |day| since Epoch. If there's usage data for
140 // day in the past in the usage file, that data is sent to UMA and 146 // day in the past in the usage file, that data is sent to UMA and
141 // removed from the file. If there's already usage data for |day| in 147 // removed from the file. If there's already usage data for |day| in
142 // the usage file, the |seconds| are accumulated. 148 // the usage file, the |seconds| are accumulated.
143 void LogDailyUseRecord(int day, int seconds); 149 void LogDailyUseRecord(int day, int seconds);
144 150
151 // Updates the active use time and logs time between user-space
152 // process crashes.
153 void ProcessUserCrash();
154
145 // Callbacks for the daily use monitor. The daily use monitor uses 155 // Callbacks for the daily use monitor. The daily use monitor uses
146 // LogDailyUseRecord to aggregate current usage data and send it to 156 // LogDailyUseRecord to aggregate current usage data and send it to
147 // UMA, if necessary. It also reschedules itself using an 157 // UMA, if necessary. It also reschedules itself using an
148 // exponentially bigger interval (up to a certain maximum) -- so 158 // exponentially bigger interval (up to a certain maximum) -- so
149 // usage is monitored less frequently with longer active use. 159 // usage is monitored less frequently with longer active use.
150 static gboolean UseMonitorStatic(gpointer data); 160 static gboolean UseMonitorStatic(gpointer data);
151 bool UseMonitor(); 161 bool UseMonitor();
152 162
153 // Schedules or reschedules a daily use monitor for |interval| 163 // Schedules or reschedules a daily use monitor for |interval|
154 // seconds from now. |backoff| mode is used by the use monitor to 164 // seconds from now. |backoff| mode is used by the use monitor to
155 // reschedule itself. If there's a monitor scheduled already and 165 // reschedule itself. If there's a monitor scheduled already and
156 // |backoff| is false, unschedules it first. Doesn't schedule a 166 // |backoff| is false, unschedules it first. Doesn't schedule a
157 // monitor for more than kUseMonitorIntervalMax seconds in the 167 // monitor for more than kUseMonitorIntervalMax seconds in the
158 // future (see metrics_daemon.cc). Returns true if a new use monitor 168 // future (see metrics_daemon.cc). Returns true if a new use monitor
159 // was scheduled, false otherwise (note that if |backoff| is false a 169 // was scheduled, false otherwise (note that if |backoff| is false a
160 // new use monitor will always be scheduled). 170 // new use monitor will always be scheduled).
161 bool ScheduleUseMonitor(int interval, bool backoff); 171 bool ScheduleUseMonitor(int interval, bool backoff);
162 172
163 // Unschedules a scheduled use monitor, if any. 173 // Unschedules a scheduled use monitor, if any.
164 void UnscheduleUseMonitor(); 174 void UnscheduleUseMonitor();
165 175
166 // Sends a regular (exponential) histogram sample to Chrome for 176 // Sends a regular (exponential) histogram sample to Chrome for
167 // transport to UMA. See MetricsLibrary::SendToUMA in 177 // transport to UMA. See MetricsLibrary::SendToUMA in
168 // metrics_library.h for a description of the arguments. 178 // metrics_library.h for a description of the arguments.
169 void SendMetric(const std::string& name, int sample, 179 void SendMetric(const std::string& name, int sample,
170 int min, int max, int nbuckets); 180 int min, int max, int nbuckets);
171 181
182 // TaggedCounter callback to process aggregated daily usage data and
183 // send to UMA.
172 static void DailyUseReporter(void* data, int tag, int count); 184 static void DailyUseReporter(void* data, int tag, int count);
173 185
186 // TaggedCounter callback to process time between user-space process
187 // crashes and send to UMA.
188 static void UserCrashIntervalReporter(void* data, int tag, int count);
189
174 // Test mode. 190 // Test mode.
175 bool testing_; 191 bool testing_;
176 192
177 // The metrics library handle. 193 // The metrics library handle.
178 MetricsLibraryInterface* metrics_lib_; 194 MetricsLibraryInterface* metrics_lib_;
179 195
180 // Current network state. 196 // Current network state.
181 NetworkState network_state_; 197 NetworkState network_state_;
182 198
183 // Timestamps last network state update. This timestamp is used to 199 // Timestamps last network state update. This timestamp is used to
184 // sample the time from the network going online to going offline so 200 // sample the time from the network going online to going offline so
185 // TimeTicks ensures a monotonically increasing TimeDelta. 201 // TimeTicks ensures a monotonically increasing TimeDelta.
186 base::TimeTicks network_state_last_; 202 base::TimeTicks network_state_last_;
187 203
188 // Current power state. 204 // Current power state.
189 PowerState power_state_; 205 PowerState power_state_;
190 206
191 // Current user session state. 207 // Current user session state.
192 SessionState session_state_; 208 SessionState session_state_;
193 209
194 // Is the user currently active: power is on, user session has 210 // Is the user currently active: power is on, user session has
195 // started, screen is not locked. 211 // started, screen is not locked.
196 bool user_active_; 212 bool user_active_;
197 213
198 // Timestamps last user active update. Active use time is 214 // Timestamps last user active update. Active use time is aggregated
199 // aggregated each day before sending to UMA so using time since the 215 // each day before sending to UMA so using time since the epoch as
200 // epoch as the timestamp. 216 // the timestamp.
201 base::Time user_active_last_; 217 base::Time user_active_last_;
202 218
219 // Daily active use time in seconds.
203 scoped_ptr<chromeos_metrics::TaggedCounterInterface> daily_use_; 220 scoped_ptr<chromeos_metrics::TaggedCounterInterface> daily_use_;
204 221
222 // Active use time between user-space process crashes.
223 scoped_ptr<chromeos_metrics::TaggedCounterInterface> user_crash_interval_;
224
205 // Sleep period until the next daily usage aggregation performed by 225 // Sleep period until the next daily usage aggregation performed by
206 // the daily use monitor (see ScheduleUseMonitor). 226 // the daily use monitor (see ScheduleUseMonitor).
207 int usemon_interval_; 227 int usemon_interval_;
208 228
209 // Scheduled daily use monitor source (see ScheduleUseMonitor). 229 // Scheduled daily use monitor source (see ScheduleUseMonitor).
210 GSource* usemon_source_; 230 GSource* usemon_source_;
211 }; 231 };
212 232
213 #endif // METRICS_DAEMON_H_ 233 #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