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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 | 276 |
275 // If an upload fails, and the transmission was over this byte count, then we | 277 // If an upload fails, and the transmission was over this byte count, then we |
276 // will discard the log, and not try to retransmit it. We also don't persist | 278 // will discard the log, and not try to retransmit it. We also don't persist |
277 // the log to the prefs for transmission during the next chrome session if this | 279 // the log to the prefs for transmission during the next chrome session if this |
278 // limit is exceeded. | 280 // limit is exceeded. |
279 const size_t kUploadLogAvoidRetransmitSize = 50000; | 281 const size_t kUploadLogAvoidRetransmitSize = 50000; |
280 | 282 |
281 // Interval, in minutes, between state saves. | 283 // Interval, in minutes, between state saves. |
282 const int kSaveStateIntervalMinutes = 5; | 284 const int kSaveStateIntervalMinutes = 5; |
283 | 285 |
| 286 // The metrics server's URL. |
| 287 const char kServerUrl[] = "https://clients4.google.com/uma/v2"; |
| 288 |
| 289 // The MIME type for the uploaded metrics data. |
| 290 const char kMimeType[] = "application/vnd.chrome.uma"; |
| 291 |
284 enum ResponseStatus { | 292 enum ResponseStatus { |
285 UNKNOWN_FAILURE, | 293 UNKNOWN_FAILURE, |
286 SUCCESS, | 294 SUCCESS, |
287 BAD_REQUEST, // Invalid syntax or log too large. | 295 BAD_REQUEST, // Invalid syntax or log too large. |
288 NO_RESPONSE, | 296 NO_RESPONSE, |
289 NUM_RESPONSE_STATUSES | 297 NUM_RESPONSE_STATUSES |
290 }; | 298 }; |
291 | 299 |
292 ResponseStatus ResponseCodeToStatus(int response_code) { | 300 ResponseStatus ResponseCodeToStatus(int response_code) { |
293 switch (response_code) { | 301 switch (response_code) { |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 registry->RegisterInt64Pref(prefs::kUninstallLastObservedRunTimeSec, 0); | 459 registry->RegisterInt64Pref(prefs::kUninstallLastObservedRunTimeSec, 0); |
452 | 460 |
453 #if defined(OS_ANDROID) | 461 #if defined(OS_ANDROID) |
454 // TODO(asvitkine): Move this out of here. | 462 // TODO(asvitkine): Move this out of here. |
455 AndroidMetricsProvider::RegisterPrefs(registry); | 463 AndroidMetricsProvider::RegisterPrefs(registry); |
456 #endif // defined(OS_ANDROID) | 464 #endif // defined(OS_ANDROID) |
457 } | 465 } |
458 | 466 |
459 MetricsService::MetricsService(metrics::MetricsStateManager* state_manager, | 467 MetricsService::MetricsService(metrics::MetricsStateManager* state_manager, |
460 metrics::MetricsServiceClient* client) | 468 metrics::MetricsServiceClient* client) |
461 : MetricsServiceBase(g_browser_process->local_state(), | 469 : log_manager_(g_browser_process->local_state(), |
462 kUploadLogAvoidRetransmitSize), | 470 kUploadLogAvoidRetransmitSize), |
| 471 histogram_snapshot_manager_(this), |
463 state_manager_(state_manager), | 472 state_manager_(state_manager), |
464 client_(client), | 473 client_(client), |
465 recording_active_(false), | 474 recording_active_(false), |
466 reporting_active_(false), | 475 reporting_active_(false), |
467 test_mode_active_(false), | 476 test_mode_active_(false), |
468 state_(INITIALIZED), | 477 state_(INITIALIZED), |
469 has_initial_stability_log_(false), | 478 has_initial_stability_log_(false), |
470 idle_since_last_transmission_(false), | 479 idle_since_last_transmission_(false), |
471 session_id_(-1), | 480 session_id_(-1), |
472 next_window_id_(0), | 481 next_window_id_(0), |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 content::NotificationRegistrar* registrar, | 621 content::NotificationRegistrar* registrar, |
613 content::NotificationObserver* observer) { | 622 content::NotificationObserver* observer) { |
614 registrar->Add(observer, content::NOTIFICATION_LOAD_START, | 623 registrar->Add(observer, content::NOTIFICATION_LOAD_START, |
615 content::NotificationService::AllSources()); | 624 content::NotificationService::AllSources()); |
616 registrar->Add(observer, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 625 registrar->Add(observer, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
617 content::NotificationService::AllSources()); | 626 content::NotificationService::AllSources()); |
618 registrar->Add(observer, content::NOTIFICATION_RENDER_WIDGET_HOST_HANG, | 627 registrar->Add(observer, content::NOTIFICATION_RENDER_WIDGET_HOST_HANG, |
619 content::NotificationService::AllSources()); | 628 content::NotificationService::AllSources()); |
620 } | 629 } |
621 | 630 |
| 631 void MetricsService::RecordDelta(const base::HistogramBase& histogram, |
| 632 const base::HistogramSamples& snapshot) { |
| 633 log_manager_.current_log()->RecordHistogramDelta(histogram.histogram_name(), |
| 634 snapshot); |
| 635 } |
| 636 |
| 637 void MetricsService::InconsistencyDetected( |
| 638 base::HistogramBase::Inconsistency problem) { |
| 639 UMA_HISTOGRAM_ENUMERATION("Histogram.InconsistenciesBrowser", |
| 640 problem, base::HistogramBase::NEVER_EXCEEDED_VALUE); |
| 641 } |
| 642 |
| 643 void MetricsService::UniqueInconsistencyDetected( |
| 644 base::HistogramBase::Inconsistency problem) { |
| 645 UMA_HISTOGRAM_ENUMERATION("Histogram.InconsistenciesBrowserUnique", |
| 646 problem, base::HistogramBase::NEVER_EXCEEDED_VALUE); |
| 647 } |
| 648 |
| 649 void MetricsService::InconsistencyDetectedInLoggedCount(int amount) { |
| 650 UMA_HISTOGRAM_COUNTS("Histogram.InconsistentSnapshotBrowser", |
| 651 std::abs(amount)); |
| 652 } |
| 653 |
622 void MetricsService::BrowserChildProcessHostConnected( | 654 void MetricsService::BrowserChildProcessHostConnected( |
623 const content::ChildProcessData& data) { | 655 const content::ChildProcessData& data) { |
624 GetChildProcessStats(data).process_launches++; | 656 GetChildProcessStats(data).process_launches++; |
625 } | 657 } |
626 | 658 |
627 void MetricsService::BrowserChildProcessCrashed( | 659 void MetricsService::BrowserChildProcessCrashed( |
628 const content::ChildProcessData& data) { | 660 const content::ChildProcessData& data) { |
629 GetChildProcessStats(data).process_crashes++; | 661 GetChildProcessStats(data).process_crashes++; |
630 // Exclude plugin crashes from the count below because we report them via | 662 // Exclude plugin crashes from the count below because we report them via |
631 // a separate UMA metric. | 663 // a separate UMA metric. |
(...skipping 1051 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1683 if (synthetic_trial_groups_[i].start_time <= current_log->creation_time()) | 1715 if (synthetic_trial_groups_[i].start_time <= current_log->creation_time()) |
1684 synthetic_trials->push_back(synthetic_trial_groups_[i].id); | 1716 synthetic_trials->push_back(synthetic_trial_groups_[i].id); |
1685 } | 1717 } |
1686 } | 1718 } |
1687 | 1719 |
1688 scoped_ptr<MetricsLog> MetricsService::CreateLog(MetricsLog::LogType log_type) { | 1720 scoped_ptr<MetricsLog> MetricsService::CreateLog(MetricsLog::LogType log_type) { |
1689 return make_scoped_ptr(new MetricsLog( | 1721 return make_scoped_ptr(new MetricsLog( |
1690 state_manager_->client_id(), session_id_, log_type, client_)); | 1722 state_manager_->client_id(), session_id_, log_type, client_)); |
1691 } | 1723 } |
1692 | 1724 |
| 1725 void MetricsService::RecordCurrentHistograms() { |
| 1726 DCHECK(log_manager_.current_log()); |
| 1727 histogram_snapshot_manager_.PrepareDeltas( |
| 1728 base::Histogram::kNoFlags, base::Histogram::kUmaTargetedHistogramFlag); |
| 1729 } |
| 1730 |
| 1731 void MetricsService::RecordCurrentStabilityHistograms() { |
| 1732 DCHECK(log_manager_.current_log()); |
| 1733 histogram_snapshot_manager_.PrepareDeltas( |
| 1734 base::Histogram::kNoFlags, base::Histogram::kUmaStabilityHistogramFlag); |
| 1735 } |
| 1736 |
1693 void MetricsService::LogCleanShutdown() { | 1737 void MetricsService::LogCleanShutdown() { |
1694 // Redundant hack to write pref ASAP. | 1738 // Redundant hack to write pref ASAP. |
1695 MarkAppCleanShutdownAndCommit(); | 1739 MarkAppCleanShutdownAndCommit(); |
1696 | 1740 |
1697 // Redundant setting to assure that we always reset this value at shutdown | 1741 // Redundant setting to assure that we always reset this value at shutdown |
1698 // (and that we don't use some alternate path, and not call LogCleanShutdown). | 1742 // (and that we don't use some alternate path, and not call LogCleanShutdown). |
1699 clean_shutdown_status_ = CLEANLY_SHUTDOWN; | 1743 clean_shutdown_status_ = CLEANLY_SHUTDOWN; |
1700 | 1744 |
1701 RecordBooleanPrefValue(prefs::kStabilityExitedCleanly, true); | 1745 RecordBooleanPrefValue(prefs::kStabilityExitedCleanly, true); |
1702 PrefService* pref = g_browser_process->local_state(); | 1746 PrefService* pref = g_browser_process->local_state(); |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1907 if (metrics_service) | 1951 if (metrics_service) |
1908 metrics_service->AddObserver(observer); | 1952 metrics_service->AddObserver(observer); |
1909 } | 1953 } |
1910 | 1954 |
1911 void MetricsServiceHelper::RemoveMetricsServiceObserver( | 1955 void MetricsServiceHelper::RemoveMetricsServiceObserver( |
1912 MetricsServiceObserver* observer) { | 1956 MetricsServiceObserver* observer) { |
1913 MetricsService* metrics_service = g_browser_process->metrics_service(); | 1957 MetricsService* metrics_service = g_browser_process->metrics_service(); |
1914 if (metrics_service) | 1958 if (metrics_service) |
1915 metrics_service->RemoveObserver(observer); | 1959 metrics_service->RemoveObserver(observer); |
1916 } | 1960 } |
OLD | NEW |