OLD | NEW |
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 //------------------------------------------------------------------------------ | 5 //------------------------------------------------------------------------------ |
6 // Description of the life cycle of a instance of MetricsService. | 6 // Description of the life cycle of a instance of MetricsService. |
7 // | 7 // |
8 // OVERVIEW | 8 // OVERVIEW |
9 // | 9 // |
10 // A MetricsService instance is typically created at application startup. It is | 10 // A MetricsService instance is typically created at application startup. It is |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 //------------------------------------------------------------------------------ | 162 //------------------------------------------------------------------------------ |
163 | 163 |
164 #include "chrome/browser/metrics/metrics_service.h" | 164 #include "chrome/browser/metrics/metrics_service.h" |
165 | 165 |
166 #include <algorithm> | 166 #include <algorithm> |
167 | 167 |
168 #include "base/bind.h" | 168 #include "base/bind.h" |
169 #include "base/callback.h" | 169 #include "base/callback.h" |
170 #include "base/command_line.h" | 170 #include "base/command_line.h" |
171 #include "base/metrics/histogram.h" | 171 #include "base/metrics/histogram.h" |
| 172 #include "base/metrics/histogram_base.h" |
| 173 #include "base/metrics/histogram_samples.h" |
172 #include "base/metrics/sparse_histogram.h" | 174 #include "base/metrics/sparse_histogram.h" |
173 #include "base/metrics/statistics_recorder.h" | 175 #include "base/metrics/statistics_recorder.h" |
174 #include "base/prefs/pref_registry_simple.h" | 176 #include "base/prefs/pref_registry_simple.h" |
175 #include "base/prefs/pref_service.h" | 177 #include "base/prefs/pref_service.h" |
176 #include "base/prefs/scoped_user_pref_update.h" | 178 #include "base/prefs/scoped_user_pref_update.h" |
177 #include "base/strings/string_number_conversions.h" | 179 #include "base/strings/string_number_conversions.h" |
178 #include "base/strings/utf_string_conversions.h" | 180 #include "base/strings/utf_string_conversions.h" |
179 #include "base/threading/platform_thread.h" | 181 #include "base/threading/platform_thread.h" |
180 #include "base/threading/thread.h" | 182 #include "base/threading/thread.h" |
181 #include "base/threading/thread_restrictions.h" | 183 #include "base/threading/thread_restrictions.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 | 279 |
278 // If an upload fails, and the transmission was over this byte count, then we | 280 // If an upload fails, and the transmission was over this byte count, then we |
279 // will discard the log, and not try to retransmit it. We also don't persist | 281 // will discard the log, and not try to retransmit it. We also don't persist |
280 // the log to the prefs for transmission during the next chrome session if this | 282 // the log to the prefs for transmission during the next chrome session if this |
281 // limit is exceeded. | 283 // limit is exceeded. |
282 const size_t kUploadLogAvoidRetransmitSize = 50000; | 284 const size_t kUploadLogAvoidRetransmitSize = 50000; |
283 | 285 |
284 // Interval, in minutes, between state saves. | 286 // Interval, in minutes, between state saves. |
285 const int kSaveStateIntervalMinutes = 5; | 287 const int kSaveStateIntervalMinutes = 5; |
286 | 288 |
| 289 // The metrics server's URL. |
| 290 const char kServerUrl[] = "https://clients4.google.com/uma/v2"; |
| 291 |
| 292 // The MIME type for the uploaded metrics data. |
| 293 const char kMimeType[] = "application/vnd.chrome.uma"; |
| 294 |
287 enum ResponseStatus { | 295 enum ResponseStatus { |
288 UNKNOWN_FAILURE, | 296 UNKNOWN_FAILURE, |
289 SUCCESS, | 297 SUCCESS, |
290 BAD_REQUEST, // Invalid syntax or log too large. | 298 BAD_REQUEST, // Invalid syntax or log too large. |
291 NO_RESPONSE, | 299 NO_RESPONSE, |
292 NUM_RESPONSE_STATUSES | 300 NUM_RESPONSE_STATUSES |
293 }; | 301 }; |
294 | 302 |
295 ResponseStatus ResponseCodeToStatus(int response_code) { | 303 ResponseStatus ResponseCodeToStatus(int response_code) { |
296 switch (response_code) { | 304 switch (response_code) { |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 registry->RegisterInt64Pref(prefs::kUninstallLastLaunchTimeSec, 0); | 461 registry->RegisterInt64Pref(prefs::kUninstallLastLaunchTimeSec, 0); |
454 registry->RegisterInt64Pref(prefs::kUninstallLastObservedRunTimeSec, 0); | 462 registry->RegisterInt64Pref(prefs::kUninstallLastObservedRunTimeSec, 0); |
455 | 463 |
456 #if defined(OS_ANDROID) | 464 #if defined(OS_ANDROID) |
457 RegisterPrefsAndroid(registry); | 465 RegisterPrefsAndroid(registry); |
458 #endif // defined(OS_ANDROID) | 466 #endif // defined(OS_ANDROID) |
459 } | 467 } |
460 | 468 |
461 MetricsService::MetricsService(metrics::MetricsStateManager* state_manager, | 469 MetricsService::MetricsService(metrics::MetricsStateManager* state_manager, |
462 metrics::MetricsServiceClient* client) | 470 metrics::MetricsServiceClient* client) |
463 : MetricsServiceBase(g_browser_process->local_state(), | 471 : log_manager_(g_browser_process->local_state(), |
464 kUploadLogAvoidRetransmitSize), | 472 kUploadLogAvoidRetransmitSize), |
| 473 histogram_snapshot_manager_(this), |
465 state_manager_(state_manager), | 474 state_manager_(state_manager), |
466 client_(client), | 475 client_(client), |
467 recording_active_(false), | 476 recording_active_(false), |
468 reporting_active_(false), | 477 reporting_active_(false), |
469 test_mode_active_(false), | 478 test_mode_active_(false), |
470 state_(INITIALIZED), | 479 state_(INITIALIZED), |
471 has_initial_stability_log_(false), | 480 has_initial_stability_log_(false), |
472 idle_since_last_transmission_(false), | 481 idle_since_last_transmission_(false), |
473 session_id_(-1), | 482 session_id_(-1), |
474 next_window_id_(0), | 483 next_window_id_(0), |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 registrar->Add(observer, content::NOTIFICATION_LOAD_STOP, | 619 registrar->Add(observer, content::NOTIFICATION_LOAD_STOP, |
611 content::NotificationService::AllSources()); | 620 content::NotificationService::AllSources()); |
612 registrar->Add(observer, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 621 registrar->Add(observer, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
613 content::NotificationService::AllSources()); | 622 content::NotificationService::AllSources()); |
614 registrar->Add(observer, content::NOTIFICATION_RENDER_WIDGET_HOST_HANG, | 623 registrar->Add(observer, content::NOTIFICATION_RENDER_WIDGET_HOST_HANG, |
615 content::NotificationService::AllSources()); | 624 content::NotificationService::AllSources()); |
616 registrar->Add(observer, chrome::NOTIFICATION_OMNIBOX_OPENED_URL, | 625 registrar->Add(observer, chrome::NOTIFICATION_OMNIBOX_OPENED_URL, |
617 content::NotificationService::AllSources()); | 626 content::NotificationService::AllSources()); |
618 } | 627 } |
619 | 628 |
| 629 void MetricsService::RecordDelta(const base::HistogramBase& histogram, |
| 630 const base::HistogramSamples& snapshot) { |
| 631 log_manager_.current_log()->RecordHistogramDelta(histogram.histogram_name(), |
| 632 snapshot); |
| 633 } |
| 634 |
| 635 void MetricsService::InconsistencyDetected( |
| 636 base::HistogramBase::Inconsistency problem) { |
| 637 UMA_HISTOGRAM_ENUMERATION("Histogram.InconsistenciesBrowser", |
| 638 problem, base::HistogramBase::NEVER_EXCEEDED_VALUE); |
| 639 } |
| 640 |
| 641 void MetricsService::UniqueInconsistencyDetected( |
| 642 base::HistogramBase::Inconsistency problem) { |
| 643 UMA_HISTOGRAM_ENUMERATION("Histogram.InconsistenciesBrowserUnique", |
| 644 problem, base::HistogramBase::NEVER_EXCEEDED_VALUE); |
| 645 } |
| 646 |
| 647 void MetricsService::InconsistencyDetectedInLoggedCount(int amount) { |
| 648 UMA_HISTOGRAM_COUNTS("Histogram.InconsistentSnapshotBrowser", |
| 649 std::abs(amount)); |
| 650 } |
| 651 |
620 void MetricsService::BrowserChildProcessHostConnected( | 652 void MetricsService::BrowserChildProcessHostConnected( |
621 const content::ChildProcessData& data) { | 653 const content::ChildProcessData& data) { |
622 GetChildProcessStats(data).process_launches++; | 654 GetChildProcessStats(data).process_launches++; |
623 } | 655 } |
624 | 656 |
625 void MetricsService::BrowserChildProcessCrashed( | 657 void MetricsService::BrowserChildProcessCrashed( |
626 const content::ChildProcessData& data) { | 658 const content::ChildProcessData& data) { |
627 GetChildProcessStats(data).process_crashes++; | 659 GetChildProcessStats(data).process_crashes++; |
628 // Exclude plugin crashes from the count below because we report them via | 660 // Exclude plugin crashes from the count below because we report them via |
629 // a separate UMA metric. | 661 // a separate UMA metric. |
(...skipping 1141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1771 DCHECK(synthetic_trials); | 1803 DCHECK(synthetic_trials); |
1772 synthetic_trials->clear(); | 1804 synthetic_trials->clear(); |
1773 const MetricsLog* current_log = | 1805 const MetricsLog* current_log = |
1774 static_cast<const MetricsLog*>(log_manager_.current_log()); | 1806 static_cast<const MetricsLog*>(log_manager_.current_log()); |
1775 for (size_t i = 0; i < synthetic_trial_groups_.size(); ++i) { | 1807 for (size_t i = 0; i < synthetic_trial_groups_.size(); ++i) { |
1776 if (synthetic_trial_groups_[i].start_time <= current_log->creation_time()) | 1808 if (synthetic_trial_groups_[i].start_time <= current_log->creation_time()) |
1777 synthetic_trials->push_back(synthetic_trial_groups_[i].id); | 1809 synthetic_trials->push_back(synthetic_trial_groups_[i].id); |
1778 } | 1810 } |
1779 } | 1811 } |
1780 | 1812 |
| 1813 void MetricsService::RecordCurrentHistograms() { |
| 1814 DCHECK(log_manager_.current_log()); |
| 1815 histogram_snapshot_manager_.PrepareDeltas( |
| 1816 base::Histogram::kNoFlags, base::Histogram::kUmaTargetedHistogramFlag); |
| 1817 } |
| 1818 |
| 1819 void MetricsService::RecordCurrentStabilityHistograms() { |
| 1820 DCHECK(log_manager_.current_log()); |
| 1821 histogram_snapshot_manager_.PrepareDeltas( |
| 1822 base::Histogram::kNoFlags, base::Histogram::kUmaStabilityHistogramFlag); |
| 1823 } |
| 1824 |
1781 void MetricsService::LogCleanShutdown() { | 1825 void MetricsService::LogCleanShutdown() { |
1782 // Redundant hack to write pref ASAP. | 1826 // Redundant hack to write pref ASAP. |
1783 MarkAppCleanShutdownAndCommit(); | 1827 MarkAppCleanShutdownAndCommit(); |
1784 | 1828 |
1785 // Redundant setting to assure that we always reset this value at shutdown | 1829 // Redundant setting to assure that we always reset this value at shutdown |
1786 // (and that we don't use some alternate path, and not call LogCleanShutdown). | 1830 // (and that we don't use some alternate path, and not call LogCleanShutdown). |
1787 clean_shutdown_status_ = CLEANLY_SHUTDOWN; | 1831 clean_shutdown_status_ = CLEANLY_SHUTDOWN; |
1788 | 1832 |
1789 RecordBooleanPrefValue(prefs::kStabilityExitedCleanly, true); | 1833 RecordBooleanPrefValue(prefs::kStabilityExitedCleanly, true); |
1790 PrefService* pref = g_browser_process->local_state(); | 1834 PrefService* pref = g_browser_process->local_state(); |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1995 if (metrics_service) | 2039 if (metrics_service) |
1996 metrics_service->AddObserver(observer); | 2040 metrics_service->AddObserver(observer); |
1997 } | 2041 } |
1998 | 2042 |
1999 void MetricsServiceHelper::RemoveMetricsServiceObserver( | 2043 void MetricsServiceHelper::RemoveMetricsServiceObserver( |
2000 MetricsServiceObserver* observer) { | 2044 MetricsServiceObserver* observer) { |
2001 MetricsService* metrics_service = g_browser_process->metrics_service(); | 2045 MetricsService* metrics_service = g_browser_process->metrics_service(); |
2002 if (metrics_service) | 2046 if (metrics_service) |
2003 metrics_service->RemoveObserver(observer); | 2047 metrics_service->RemoveObserver(observer); |
2004 } | 2048 } |
OLD | NEW |