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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 #include "base/metrics/statistics_recorder.h" | 174 #include "base/metrics/statistics_recorder.h" |
175 #include "base/prefs/pref_registry_simple.h" | 175 #include "base/prefs/pref_registry_simple.h" |
176 #include "base/prefs/pref_service.h" | 176 #include "base/prefs/pref_service.h" |
177 #include "base/strings/string_number_conversions.h" | 177 #include "base/strings/string_number_conversions.h" |
178 #include "base/strings/utf_string_conversions.h" | 178 #include "base/strings/utf_string_conversions.h" |
179 #include "base/threading/platform_thread.h" | 179 #include "base/threading/platform_thread.h" |
180 #include "base/threading/thread.h" | 180 #include "base/threading/thread.h" |
181 #include "base/threading/thread_restrictions.h" | 181 #include "base/threading/thread_restrictions.h" |
182 #include "base/tracked_objects.h" | 182 #include "base/tracked_objects.h" |
183 #include "base/values.h" | 183 #include "base/values.h" |
184 #include "chrome/browser/browser_process.h" | |
185 #include "chrome/browser/chrome_notification_types.h" | |
186 #include "chrome/browser/io_thread.h" | |
187 #include "chrome/browser/metrics/chrome_stability_metrics_provider.h" | 184 #include "chrome/browser/metrics/chrome_stability_metrics_provider.h" |
188 #include "chrome/browser/metrics/gpu_metrics_provider.h" | 185 #include "chrome/browser/metrics/gpu_metrics_provider.h" |
189 #include "chrome/browser/metrics/network_metrics_provider.h" | 186 #include "chrome/browser/metrics/network_metrics_provider.h" |
190 #include "chrome/browser/metrics/omnibox_metrics_provider.h" | 187 #include "chrome/browser/metrics/omnibox_metrics_provider.h" |
191 #include "chrome/browser/metrics/profiler_metrics_provider.h" | 188 #include "chrome/browser/metrics/profiler_metrics_provider.h" |
192 #include "chrome/browser/metrics/tracking_synchronizer.h" | 189 #include "chrome/browser/metrics/tracking_synchronizer.h" |
193 #include "chrome/common/pref_names.h" | 190 #include "chrome/common/pref_names.h" |
194 #include "chrome/common/variations/variations_util.h" | |
195 #include "components/metrics/metrics_log.h" | 191 #include "components/metrics/metrics_log.h" |
196 #include "components/metrics/metrics_log_base.h" | |
197 #include "components/metrics/metrics_log_manager.h" | 192 #include "components/metrics/metrics_log_manager.h" |
198 #include "components/metrics/metrics_log_uploader.h" | 193 #include "components/metrics/metrics_log_uploader.h" |
199 #include "components/metrics/metrics_pref_names.h" | 194 #include "components/metrics/metrics_pref_names.h" |
200 #include "components/metrics/metrics_reporting_scheduler.h" | 195 #include "components/metrics/metrics_reporting_scheduler.h" |
201 #include "components/metrics/metrics_service_client.h" | 196 #include "components/metrics/metrics_service_client.h" |
202 #include "components/metrics/metrics_state_manager.h" | 197 #include "components/metrics/metrics_state_manager.h" |
203 #include "components/variations/entropy_provider.h" | 198 #include "components/variations/entropy_provider.h" |
| 199 #include "content/public/browser/browser_thread.h" |
204 | 200 |
205 #if defined(ENABLE_PLUGINS) | 201 #if defined(ENABLE_PLUGINS) |
206 // TODO(asvitkine): Move this out of MetricsService. | 202 // TODO(asvitkine): Move this out of MetricsService. |
207 #include "chrome/browser/metrics/plugin_metrics_provider.h" | 203 #include "chrome/browser/metrics/plugin_metrics_provider.h" |
208 #endif | 204 #endif |
209 | 205 |
210 #if defined(OS_WIN) | 206 #if defined(OS_WIN) |
211 #include "chrome/browser/metrics/google_update_metrics_provider_win.h" | 207 #include "chrome/browser/metrics/google_update_metrics_provider_win.h" |
212 #endif | 208 #endif |
213 | 209 |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 ScheduleNextStateSave(); | 798 ScheduleNextStateSave(); |
803 } | 799 } |
804 | 800 |
805 | 801 |
806 //------------------------------------------------------------------------------ | 802 //------------------------------------------------------------------------------ |
807 // Recording control methods | 803 // Recording control methods |
808 | 804 |
809 void MetricsService::OpenNewLog() { | 805 void MetricsService::OpenNewLog() { |
810 DCHECK(!log_manager_.current_log()); | 806 DCHECK(!log_manager_.current_log()); |
811 | 807 |
812 log_manager_.BeginLoggingWithLog( | 808 log_manager_.BeginLoggingWithLog(CreateLog(MetricsLog::ONGOING_LOG)); |
813 CreateLog(MetricsLog::ONGOING_LOG).PassAs<metrics::MetricsLogBase>()); | |
814 NotifyOnDidCreateMetricsLog(); | 809 NotifyOnDidCreateMetricsLog(); |
815 if (state_ == INITIALIZED) { | 810 if (state_ == INITIALIZED) { |
816 // We only need to schedule that run once. | 811 // We only need to schedule that run once. |
817 state_ = INIT_TASK_SCHEDULED; | 812 state_ = INIT_TASK_SCHEDULED; |
818 | 813 |
819 content::BrowserThread::PostDelayedTask( | 814 content::BrowserThread::PostDelayedTask( |
820 content::BrowserThread::UI, | 815 content::BrowserThread::UI, |
821 FROM_HERE, | 816 FROM_HERE, |
822 base::Bind(&MetricsService::StartGatheringMetrics, | 817 base::Bind(&MetricsService::StartGatheringMetrics, |
823 self_ptr_factory_.GetWeakPtr()), | 818 self_ptr_factory_.GetWeakPtr()), |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1034 | 1029 |
1035 // Do not call NotifyOnDidCreateMetricsLog here because the stability | 1030 // Do not call NotifyOnDidCreateMetricsLog here because the stability |
1036 // log describes stats from the _previous_ session. | 1031 // log describes stats from the _previous_ session. |
1037 | 1032 |
1038 if (!initial_stability_log->LoadSavedEnvironmentFromPrefs()) | 1033 if (!initial_stability_log->LoadSavedEnvironmentFromPrefs()) |
1039 return; | 1034 return; |
1040 | 1035 |
1041 log_manager_.LoadPersistedUnsentLogs(); | 1036 log_manager_.LoadPersistedUnsentLogs(); |
1042 | 1037 |
1043 log_manager_.PauseCurrentLog(); | 1038 log_manager_.PauseCurrentLog(); |
1044 log_manager_.BeginLoggingWithLog( | 1039 log_manager_.BeginLoggingWithLog(initial_stability_log.Pass()); |
1045 initial_stability_log.PassAs<metrics::MetricsLogBase>()); | |
1046 | 1040 |
1047 // Note: Some stability providers may record stability stats via histograms, | 1041 // Note: Some stability providers may record stability stats via histograms, |
1048 // so this call has to be after BeginLoggingWithLog(). | 1042 // so this call has to be after BeginLoggingWithLog(). |
1049 MetricsLog* current_log = | 1043 log_manager_.current_log()->RecordStabilityMetrics( |
1050 static_cast<MetricsLog*>(log_manager_.current_log()); | 1044 metrics_providers_.get(), base::TimeDelta(), base::TimeDelta()); |
1051 current_log->RecordStabilityMetrics(metrics_providers_.get(), | |
1052 base::TimeDelta(), base::TimeDelta()); | |
1053 RecordCurrentStabilityHistograms(); | 1045 RecordCurrentStabilityHistograms(); |
1054 | 1046 |
1055 // Note: RecordGeneralMetrics() intentionally not called since this log is for | 1047 // Note: RecordGeneralMetrics() intentionally not called since this log is for |
1056 // stability stats from a previous session only. | 1048 // stability stats from a previous session only. |
1057 | 1049 |
1058 log_manager_.FinishCurrentLog(); | 1050 log_manager_.FinishCurrentLog(); |
1059 log_manager_.ResumePausedLog(); | 1051 log_manager_.ResumePausedLog(); |
1060 | 1052 |
1061 // Store unsent logs, including the stability log that was just saved, so | 1053 // Store unsent logs, including the stability log that was just saved, so |
1062 // that they're not lost in case of a crash before upload time. | 1054 // that they're not lost in case of a crash before upload time. |
1063 log_manager_.PersistUnsentLogs(); | 1055 log_manager_.PersistUnsentLogs(); |
1064 | 1056 |
1065 has_initial_stability_log_ = true; | 1057 has_initial_stability_log_ = true; |
1066 } | 1058 } |
1067 | 1059 |
1068 void MetricsService::PrepareInitialMetricsLog() { | 1060 void MetricsService::PrepareInitialMetricsLog() { |
1069 DCHECK(state_ == INIT_TASK_DONE || state_ == SENDING_INITIAL_STABILITY_LOG); | 1061 DCHECK(state_ == INIT_TASK_DONE || state_ == SENDING_INITIAL_STABILITY_LOG); |
1070 | 1062 |
1071 std::vector<variations::ActiveGroupId> synthetic_trials; | 1063 std::vector<variations::ActiveGroupId> synthetic_trials; |
1072 GetCurrentSyntheticFieldTrials(&synthetic_trials); | 1064 GetCurrentSyntheticFieldTrials(&synthetic_trials); |
1073 initial_metrics_log_->RecordEnvironment(metrics_providers_.get(), | 1065 initial_metrics_log_->RecordEnvironment(metrics_providers_.get(), |
1074 synthetic_trials); | 1066 synthetic_trials); |
1075 base::TimeDelta incremental_uptime; | 1067 base::TimeDelta incremental_uptime; |
1076 base::TimeDelta uptime; | 1068 base::TimeDelta uptime; |
1077 GetUptimes(local_state_, &incremental_uptime, &uptime); | 1069 GetUptimes(local_state_, &incremental_uptime, &uptime); |
1078 | 1070 |
1079 // Histograms only get written to the current log, so make the new log current | 1071 // Histograms only get written to the current log, so make the new log current |
1080 // before writing them. | 1072 // before writing them. |
1081 log_manager_.PauseCurrentLog(); | 1073 log_manager_.PauseCurrentLog(); |
1082 log_manager_.BeginLoggingWithLog( | 1074 log_manager_.BeginLoggingWithLog(initial_metrics_log_.Pass()); |
1083 initial_metrics_log_.PassAs<metrics::MetricsLogBase>()); | |
1084 | 1075 |
1085 // Note: Some stability providers may record stability stats via histograms, | 1076 // Note: Some stability providers may record stability stats via histograms, |
1086 // so this call has to be after BeginLoggingWithLog(). | 1077 // so this call has to be after BeginLoggingWithLog(). |
1087 MetricsLog* current_log = | 1078 MetricsLog* current_log = |
1088 static_cast<MetricsLog*>(log_manager_.current_log()); | 1079 static_cast<MetricsLog*>(log_manager_.current_log()); |
1089 current_log->RecordStabilityMetrics(metrics_providers_.get(), | 1080 current_log->RecordStabilityMetrics(metrics_providers_.get(), |
1090 base::TimeDelta(), base::TimeDelta()); | 1081 base::TimeDelta(), base::TimeDelta()); |
1091 RecordCurrentHistograms(); | 1082 RecordCurrentHistograms(); |
1092 | 1083 |
1093 current_log->RecordGeneralMetrics(metrics_providers_.get()); | 1084 current_log->RecordGeneralMetrics(metrics_providers_.get()); |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1321 local_state_->SetBoolean(path, value); | 1312 local_state_->SetBoolean(path, value); |
1322 RecordCurrentState(local_state_); | 1313 RecordCurrentState(local_state_); |
1323 } | 1314 } |
1324 | 1315 |
1325 void MetricsService::RecordCurrentState(PrefService* pref) { | 1316 void MetricsService::RecordCurrentState(PrefService* pref) { |
1326 pref->SetInt64(prefs::kStabilityLastTimestampSec, Time::Now().ToTimeT()); | 1317 pref->SetInt64(prefs::kStabilityLastTimestampSec, Time::Now().ToTimeT()); |
1327 | 1318 |
1328 for (size_t i = 0; i < metrics_providers_.size(); ++i) | 1319 for (size_t i = 0; i < metrics_providers_.size(); ++i) |
1329 metrics_providers_[i]->RecordCurrentState(); | 1320 metrics_providers_[i]->RecordCurrentState(); |
1330 } | 1321 } |
OLD | NEW |