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

Side by Side Diff: chrome/browser/metrics/metrics_service.h

Issue 81603002: Send UMA stability stats in a separate UMA log on startup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium 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 // This file defines a service that collects information about the user 5 // This file defines a service that collects information about the user
6 // experience in order to help improve future versions of the app. 6 // experience in order to help improve future versions of the app.
7 7
8 #ifndef CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ 8 #ifndef CHROME_BROWSER_METRICS_METRICS_SERVICE_H_
9 #define CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ 9 #define CHROME_BROWSER_METRICS_METRICS_SERVICE_H_
10 10
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 UNINITIALIZED_PHASE = 0, 104 UNINITIALIZED_PHASE = 0,
105 START_METRICS_RECORDING = 100, 105 START_METRICS_RECORDING = 100,
106 CREATE_PROFILE = 200, 106 CREATE_PROFILE = 200,
107 STARTUP_TIMEBOMB_ARM = 300, 107 STARTUP_TIMEBOMB_ARM = 300,
108 THREAD_WATCHER_START = 400, 108 THREAD_WATCHER_START = 400,
109 MAIN_MESSAGE_LOOP_RUN = 500, 109 MAIN_MESSAGE_LOOP_RUN = 500,
110 SHUTDOWN_TIMEBOMB_ARM = 600, 110 SHUTDOWN_TIMEBOMB_ARM = 600,
111 SHUTDOWN_COMPLETE = 700, 111 SHUTDOWN_COMPLETE = 700,
112 }; 112 };
113 113
114 enum ReportingState {
115 REPORTING_ENABLED,
116 REPORTING_DISABLED,
117 };
118
114 MetricsService(); 119 MetricsService();
115 virtual ~MetricsService(); 120 virtual ~MetricsService();
116 121
122 // Initializes metrics recording state. Updates various bookkeeping values in
123 // prefs and sets up the scheduler. This is a separate function rather than
124 // being done by the constructor so that field trials could be created before
125 // this is run. Takes |reporting_state| parameter which specifies whether UMA
126 // is enabled.
127 void InitializeMetricsRecordingState(ReportingState reporting_state);
128
117 // Starts the metrics system, turning on recording and uploading of metrics. 129 // Starts the metrics system, turning on recording and uploading of metrics.
118 // Should be called when starting up with metrics enabled, or when metrics 130 // Should be called when starting up with metrics enabled, or when metrics
119 // are turned on. 131 // are turned on.
120 void Start(); 132 void Start();
121 133
122 // Starts the metrics system in a special test-only mode. Metrics won't ever 134 // Starts the metrics system in a special test-only mode. Metrics won't ever
123 // be uploaded or persisted in this mode, but metrics will be recorded in 135 // be uploaded or persisted in this mode, but metrics will be recorded in
124 // memory. 136 // memory.
125 void StartRecordingForTests(); 137 void StartRecordingForTests();
126 138
(...skipping 19 matching lines...) Expand all
146 // 158 //
147 // If |reporting_will_be_enabled| is true, this method returns an entropy 159 // If |reporting_will_be_enabled| is true, this method returns an entropy
148 // provider that has a high source of entropy, partially based on the client 160 // provider that has a high source of entropy, partially based on the client
149 // ID. Otherwise, an entropy provider that is based on a low entropy source 161 // ID. Otherwise, an entropy provider that is based on a low entropy source
150 // is returned. 162 // is returned.
151 // 163 //
152 // Note that this reporting state can not be checked by reporting_active() 164 // Note that this reporting state can not be checked by reporting_active()
153 // because this method may need to be called before the MetricsService needs 165 // because this method may need to be called before the MetricsService needs
154 // to be started. 166 // to be started.
155 scoped_ptr<const base::FieldTrial::EntropyProvider> CreateEntropyProvider( 167 scoped_ptr<const base::FieldTrial::EntropyProvider> CreateEntropyProvider(
156 bool reporting_will_be_enabled); 168 ReportingState reporting_state);
157 169
158 // Force the client ID to be generated. This is useful in case it's needed 170 // Force the client ID to be generated. This is useful in case it's needed
159 // before recording. 171 // before recording.
160 void ForceClientIdCreation(); 172 void ForceClientIdCreation();
161 173
162 // At startup, prefs needs to be called with a list of all the pref names and 174 // At startup, prefs needs to be called with a list of all the pref names and
163 // types we'll be using. 175 // types we'll be using.
164 static void RegisterPrefs(PrefRegistrySimple* registry); 176 static void RegisterPrefs(PrefRegistrySimple* registry);
165 177
166 // Set up notifications which indicate that a user is performing work. This is 178 // Set up notifications which indicate that a user is performing work. This is
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 // registered at a time for a given trial_name. Only the last group name that 258 // registered at a time for a given trial_name. Only the last group name that
247 // is registered for a given trial name will be recorded. The values passed 259 // is registered for a given trial name will be recorded. The values passed
248 // in must not correspond to any real field trial in the code. 260 // in must not correspond to any real field trial in the code.
249 // To use this method, SyntheticTrialGroup should friend your class. 261 // To use this method, SyntheticTrialGroup should friend your class.
250 void RegisterSyntheticFieldTrial(const SyntheticTrialGroup& trial_group); 262 void RegisterSyntheticFieldTrial(const SyntheticTrialGroup& trial_group);
251 263
252 private: 264 private:
253 // The MetricsService has a lifecycle that is stored as a state. 265 // The MetricsService has a lifecycle that is stored as a state.
254 // See metrics_service.cc for description of this lifecycle. 266 // See metrics_service.cc for description of this lifecycle.
255 enum State { 267 enum State {
256 INITIALIZED, // Constructor was called. 268 INITIALIZED, // Constructor was called.
257 INIT_TASK_SCHEDULED, // Waiting for deferred init tasks to complete. 269 INIT_TASK_SCHEDULED, // Waiting for deferred init tasks to
258 INIT_TASK_DONE, // Waiting for timer to send initial log. 270 // complete.
259 INITIAL_LOG_READY, // Initial log generated, and waiting for reply. 271 INIT_TASK_DONE, // Waiting for timer to send initial log.
260 SENDING_OLD_LOGS, // Sending unsent logs from previous session. 272 SENDING_INITIAL_STABILITY_LOG, // Initial stability log being sent.
261 SENDING_CURRENT_LOGS, // Sending standard current logs as they acrue. 273 SENDING_INITIAL_METRICS_LOG, // Initial metrics log being sent.
274 SENDING_OLD_LOGS, // Sending unsent logs from last session.
275 SENDING_CURRENT_LOGS, // Sending ongoing logs as they accrue.
262 }; 276 };
263 277
264 enum ShutdownCleanliness { 278 enum ShutdownCleanliness {
265 CLEANLY_SHUTDOWN = 0xdeadbeef, 279 CLEANLY_SHUTDOWN = 0xdeadbeef,
266 NEED_TO_SHUTDOWN = ~CLEANLY_SHUTDOWN 280 NEED_TO_SHUTDOWN = ~CLEANLY_SHUTDOWN
267 }; 281 };
268 282
269 // Designates which entropy source was returned from this MetricsService. 283 // Designates which entropy source was returned from this MetricsService.
270 // This is used for testing to validate that we return the correct source 284 // This is used for testing to validate that we return the correct source
271 // depending on the state of the service. 285 // depending on the state of the service.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 void EnableRecording(); 356 void EnableRecording();
343 void DisableRecording(); 357 void DisableRecording();
344 358
345 // If in_idle is true, sets idle_since_last_transmission to true. 359 // If in_idle is true, sets idle_since_last_transmission to true.
346 // If in_idle is false and idle_since_last_transmission_ is true, sets 360 // If in_idle is false and idle_since_last_transmission_ is true, sets
347 // idle_since_last_transmission to false and starts the timer (provided 361 // idle_since_last_transmission to false and starts the timer (provided
348 // starting the timer is permitted). 362 // starting the timer is permitted).
349 void HandleIdleSinceLastTransmission(bool in_idle); 363 void HandleIdleSinceLastTransmission(bool in_idle);
350 364
351 // Set up client ID, session ID, etc. 365 // Set up client ID, session ID, etc.
352 void InitializeMetricsState(); 366 void InitializeMetricsState(ReportingState reporting_state);
353 367
354 // Generates a new client ID to use to identify self to metrics server. 368 // Generates a new client ID to use to identify self to metrics server.
355 static std::string GenerateClientID(); 369 static std::string GenerateClientID();
356 370
357 // Schedule the next save of LocalState information. This is called 371 // Schedule the next save of LocalState information. This is called
358 // automatically by the task that performs each save to schedule the next one. 372 // automatically by the task that performs each save to schedule the next one.
359 void ScheduleNextStateSave(); 373 void ScheduleNextStateSave();
360 374
361 // Save the LocalState information immediately. This should not be called by 375 // Save the LocalState information immediately. This should not be called by
362 // anybody other than the scheduler to avoid doing too many writes. When you 376 // anybody other than the scheduler to avoid doing too many writes. When you
(...skipping 23 matching lines...) Expand all
386 // Callbacks for various stages of final log info collection. Do not call 400 // Callbacks for various stages of final log info collection. Do not call
387 // these directly. 401 // these directly.
388 void OnMemoryDetailCollectionDone(); 402 void OnMemoryDetailCollectionDone();
389 void OnHistogramSynchronizationDone(); 403 void OnHistogramSynchronizationDone();
390 void OnFinalLogInfoCollectionDone(); 404 void OnFinalLogInfoCollectionDone();
391 405
392 // Either closes the current log or creates and closes the initial log 406 // Either closes the current log or creates and closes the initial log
393 // (depending on |state_|), and stages it for upload. 407 // (depending on |state_|), and stages it for upload.
394 void StageNewLog(); 408 void StageNewLog();
395 409
396 // Record stats, client ID, Session ID, etc. in a special "first" log. 410 // Prepares the initial stability log, which is only logged when the previous
397 void PrepareInitialLog(); 411 // run of Chrome crashed. This log contains any stability metrics left over
412 // from that previous run, and only these stability metrics. It uses the
413 // system profile from the previous session.
414 void PrepareInitialStabilityLog();
415
416 // Prepares the initial metrics log, which includes startup histograms and
417 // profiler data, as well as incremental stability-related metrics.
418 void PrepareInitialMetricsLog(MetricsLog::LogType log_type);
398 419
399 // Uploads the currently staged log (which must be non-null). 420 // Uploads the currently staged log (which must be non-null).
400 void SendStagedLog(); 421 void SendStagedLog();
401 422
402 // Prepared the staged log to be passed to the server. Upon return, 423 // Prepared the staged log to be passed to the server. Upon return,
403 // current_fetch_ should be reset with its upload data set to a compressed 424 // current_fetch_ should be reset with its upload data set to a compressed
404 // copy of the staged log. 425 // copy of the staged log.
405 void PrepareFetchWithStagedLog(); 426 void PrepareFetchWithStagedLog();
406 427
407 // Implementation of net::URLFetcherDelegate. Called after transmission 428 // Implementation of net::URLFetcherDelegate. Called after transmission
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 // Indicate whether recording and reporting are currently happening. 485 // Indicate whether recording and reporting are currently happening.
465 // These should not be set directly, but by calling SetRecording and 486 // These should not be set directly, but by calling SetRecording and
466 // SetReporting. 487 // SetReporting.
467 bool recording_active_; 488 bool recording_active_;
468 bool reporting_active_; 489 bool reporting_active_;
469 490
470 // Indicate whether test mode is enabled, where the initial log should never 491 // Indicate whether test mode is enabled, where the initial log should never
471 // be cut, and logs are neither persisted nor uploaded. 492 // be cut, and logs are neither persisted nor uploaded.
472 bool test_mode_active_; 493 bool test_mode_active_;
473 494
474 // The progession of states made by the browser are recorded in the following 495 // The progression of states made by the browser are recorded in the following
475 // state. 496 // state.
476 State state_; 497 State state_;
477 498
499 // Whether the initial stability log has been recorded during startup.
500 bool has_initial_stability_log_;
501
478 // Chrome OS hardware class (e.g., hardware qualification ID). This 502 // Chrome OS hardware class (e.g., hardware qualification ID). This
479 // class identifies the configured system components such as CPU, 503 // class identifies the configured system components such as CPU,
480 // WiFi adapter, etc. For non Chrome OS hosts, this will be an 504 // WiFi adapter, etc. For non Chrome OS hosts, this will be an
481 // empty string. 505 // empty string.
482 std::string hardware_class_; 506 std::string hardware_class_;
483 507
484 // The list of plugins which was retrieved on the file thread. 508 // The list of plugins which was retrieved on the file thread.
485 std::vector<content::WebPluginInfo> plugins_; 509 std::vector<content::WebPluginInfo> plugins_;
486 510
487 // Google Update statistics, which were retrieved on a blocking pool thread. 511 // Google Update statistics, which were retrieved on a blocking pool thread.
488 GoogleUpdateMetrics google_update_metrics_; 512 GoogleUpdateMetrics google_update_metrics_;
489 513
490 // The initial log, used to record startup metrics. 514 // The initial metrics log, used to record startup metrics (histograms and
491 scoped_ptr<MetricsLog> initial_log_; 515 // profiler data). Note that if a crash occurred in the previous session, an
516 // initial stability log may be sent before this.
517 scoped_ptr<MetricsLog> initial_metrics_log_;
492 518
493 // The outstanding transmission appears as a URL Fetch operation. 519 // The outstanding transmission appears as a URL Fetch operation.
494 scoped_ptr<net::URLFetcher> current_fetch_; 520 scoped_ptr<net::URLFetcher> current_fetch_;
495 521
496 // The TCP/UDP echo server to collect network connectivity stats. 522 // The TCP/UDP echo server to collect network connectivity stats.
497 std::string network_stats_server_; 523 std::string network_stats_server_;
498 524
499 // The HTTP pipelining test server. 525 // The HTTP pipelining test server.
500 std::string http_pipelining_test_server_; 526 std::string http_pipelining_test_server_;
501 527
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 friend class extensions::ExtensionDownloader; 610 friend class extensions::ExtensionDownloader;
585 friend class extensions::ManifestFetchData; 611 friend class extensions::ManifestFetchData;
586 612
587 // Returns true if prefs::kMetricsReportingEnabled is set. 613 // Returns true if prefs::kMetricsReportingEnabled is set.
588 static bool IsMetricsReportingEnabled(); 614 static bool IsMetricsReportingEnabled();
589 615
590 DISALLOW_IMPLICIT_CONSTRUCTORS(MetricsServiceHelper); 616 DISALLOW_IMPLICIT_CONSTRUCTORS(MetricsServiceHelper);
591 }; 617 };
592 618
593 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ 619 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698