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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 #include "components/metrics/metrics_service_client.h" | 201 #include "components/metrics/metrics_service_client.h" |
202 #include "components/variations/entropy_provider.h" | 202 #include "components/variations/entropy_provider.h" |
203 #include "net/base/load_flags.h" | 203 #include "net/base/load_flags.h" |
204 #include "net/url_request/url_fetcher.h" | 204 #include "net/url_request/url_fetcher.h" |
205 | 205 |
206 #if defined(ENABLE_PLUGINS) | 206 #if defined(ENABLE_PLUGINS) |
207 // TODO(asvitkine): Move this out of MetricsService. | 207 // TODO(asvitkine): Move this out of MetricsService. |
208 #include "chrome/browser/metrics/plugin_metrics_provider.h" | 208 #include "chrome/browser/metrics/plugin_metrics_provider.h" |
209 #endif | 209 #endif |
210 | 210 |
211 #if defined(OS_CHROMEOS) | |
212 #include "chrome/browser/chromeos/settings/cros_settings.h" | |
213 #include "chrome/browser/metrics/chromeos_metrics_provider.h" | |
214 #include "chromeos/system/statistics_provider.h" | |
215 #endif | |
216 | |
217 #if defined(OS_WIN) | 211 #if defined(OS_WIN) |
218 #include "chrome/browser/metrics/google_update_metrics_provider_win.h" | 212 #include "chrome/browser/metrics/google_update_metrics_provider_win.h" |
219 #endif | 213 #endif |
220 | 214 |
221 #if defined(OS_ANDROID) | 215 #if defined(OS_ANDROID) |
222 // TODO(asvitkine): Move this out of MetricsService. | 216 // TODO(asvitkine): Move this out of MetricsService. |
223 #include "chrome/browser/metrics/android_metrics_provider.h" | 217 #include "chrome/browser/metrics/android_metrics_provider.h" |
224 #endif | 218 #endif |
225 | 219 |
226 using base::Time; | 220 using base::Time; |
227 using content::BrowserThread; | |
228 using metrics::MetricsLogManager; | 221 using metrics::MetricsLogManager; |
229 | 222 |
230 namespace { | 223 namespace { |
231 | 224 |
232 // Check to see that we're being called on only one thread. | 225 // Check to see that we're being called on only one thread. |
233 bool IsSingleThreaded() { | 226 bool IsSingleThreaded() { |
234 static base::PlatformThreadId thread_id = 0; | 227 static base::PlatformThreadId thread_id = 0; |
235 if (!thread_id) | 228 if (!thread_id) |
236 thread_id = base::PlatformThread::CurrentId(); | 229 thread_id = base::PlatformThread::CurrentId(); |
237 return base::PlatformThread::CurrentId() == thread_id; | 230 return base::PlatformThread::CurrentId() == thread_id; |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
411 RegisterMetricsProvider(scoped_ptr<metrics::MetricsProvider>( | 404 RegisterMetricsProvider(scoped_ptr<metrics::MetricsProvider>( |
412 google_update_metrics_provider_)); | 405 google_update_metrics_provider_)); |
413 #endif | 406 #endif |
414 | 407 |
415 #if defined(ENABLE_PLUGINS) | 408 #if defined(ENABLE_PLUGINS) |
416 plugin_metrics_provider_ = new PluginMetricsProvider(local_state_); | 409 plugin_metrics_provider_ = new PluginMetricsProvider(local_state_); |
417 RegisterMetricsProvider(scoped_ptr<metrics::MetricsProvider>( | 410 RegisterMetricsProvider(scoped_ptr<metrics::MetricsProvider>( |
418 plugin_metrics_provider_)); | 411 plugin_metrics_provider_)); |
419 #endif | 412 #endif |
420 | 413 |
421 #if defined(OS_CHROMEOS) | |
422 RegisterMetricsProvider( | |
423 scoped_ptr<metrics::MetricsProvider>(new ChromeOSMetricsProvider)); | |
424 #endif | |
425 } | 414 } |
426 | 415 |
427 MetricsService::~MetricsService() { | 416 MetricsService::~MetricsService() { |
428 DisableRecording(); | 417 DisableRecording(); |
429 } | 418 } |
430 | 419 |
431 void MetricsService::InitializeMetricsRecordingState() { | 420 void MetricsService::InitializeMetricsRecordingState() { |
432 InitializeMetricsState(); | 421 InitializeMetricsState(); |
433 | 422 |
434 base::Closure callback = base::Bind(&MetricsService::StartScheduledUpload, | 423 base::Closure callback = base::Bind(&MetricsService::StartScheduledUpload, |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
692 local_state_->SetInt64(prefs::kStabilityLaunchTimeSec, Time::Now().ToTimeT()); | 681 local_state_->SetInt64(prefs::kStabilityLaunchTimeSec, Time::Now().ToTimeT()); |
693 | 682 |
694 // Bookkeeping for the uninstall metrics. | 683 // Bookkeeping for the uninstall metrics. |
695 IncrementLongPrefsValue(prefs::kUninstallLaunchCount); | 684 IncrementLongPrefsValue(prefs::kUninstallLaunchCount); |
696 | 685 |
697 // Kick off the process of saving the state (so the uptime numbers keep | 686 // Kick off the process of saving the state (so the uptime numbers keep |
698 // getting updated) every n minutes. | 687 // getting updated) every n minutes. |
699 ScheduleNextStateSave(); | 688 ScheduleNextStateSave(); |
700 } | 689 } |
701 | 690 |
702 // static | 691 void MetricsService::OnInitTaskGotHardwareClass() { |
703 void MetricsService::InitTaskGetHardwareClass( | |
704 base::WeakPtr<MetricsService> self, | |
705 base::MessageLoopProxy* target_loop) { | |
706 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
707 | |
708 std::string hardware_class; | |
709 #if defined(OS_CHROMEOS) | |
710 chromeos::system::StatisticsProvider::GetInstance()->GetMachineStatistic( | |
711 "hardware_class", &hardware_class); | |
712 #endif // OS_CHROMEOS | |
713 | |
714 target_loop->PostTask(FROM_HERE, | |
715 base::Bind(&MetricsService::OnInitTaskGotHardwareClass, | |
716 self, hardware_class)); | |
717 } | |
718 | |
719 void MetricsService::OnInitTaskGotHardwareClass( | |
720 const std::string& hardware_class) { | |
721 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); | 692 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); |
722 hardware_class_ = hardware_class; | |
723 | 693 |
724 const base::Closure got_plugin_info_callback = | 694 const base::Closure got_plugin_info_callback = |
725 base::Bind(&MetricsService::OnInitTaskGotPluginInfo, | 695 base::Bind(&MetricsService::OnInitTaskGotPluginInfo, |
726 self_ptr_factory_.GetWeakPtr()); | 696 self_ptr_factory_.GetWeakPtr()); |
727 | 697 |
728 #if defined(ENABLE_PLUGINS) | 698 #if defined(ENABLE_PLUGINS) |
729 plugin_metrics_provider_->GetPluginInformation(got_plugin_info_callback); | 699 plugin_metrics_provider_->GetPluginInformation(got_plugin_info_callback); |
730 #else | 700 #else |
731 got_plugin_info_callback.Run(); | 701 got_plugin_info_callback.Run(); |
732 #endif | 702 #endif |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
850 void MetricsService::OpenNewLog() { | 820 void MetricsService::OpenNewLog() { |
851 DCHECK(!log_manager_.current_log()); | 821 DCHECK(!log_manager_.current_log()); |
852 | 822 |
853 log_manager_.BeginLoggingWithLog( | 823 log_manager_.BeginLoggingWithLog( |
854 CreateLog(MetricsLog::ONGOING_LOG).PassAs<metrics::MetricsLogBase>()); | 824 CreateLog(MetricsLog::ONGOING_LOG).PassAs<metrics::MetricsLogBase>()); |
855 NotifyOnDidCreateMetricsLog(); | 825 NotifyOnDidCreateMetricsLog(); |
856 if (state_ == INITIALIZED) { | 826 if (state_ == INITIALIZED) { |
857 // We only need to schedule that run once. | 827 // We only need to schedule that run once. |
858 state_ = INIT_TASK_SCHEDULED; | 828 state_ = INIT_TASK_SCHEDULED; |
859 | 829 |
860 // TODO(blundell): Change the callback to be | 830 // TODO(blundell): Move all initial metrics gathering to |
861 // FinishedReceivingProfilerData() when the initial metrics gathering is | 831 // ChromeMetricsServiceClient. |
862 // moved to ChromeMetricsServiceClient. | 832 client_->StartGatheringMetrics( |
863 client_->StartGatheringMetrics(base::Bind(&base::DoNothing)); | 833 base::Bind(&MetricsService::OnInitTaskGotHardwareClass, |
864 | 834 self_ptr_factory_.GetWeakPtr())); |
865 // Schedules a task on the file thread for execution of slower | |
866 // initialization steps (such as plugin list generation) necessary | |
867 // for sending the initial log. This avoids blocking the main UI | |
868 // thread. | |
869 BrowserThread::PostDelayedTask( | |
870 BrowserThread::FILE, | |
871 FROM_HERE, | |
872 base::Bind(&MetricsService::InitTaskGetHardwareClass, | |
873 self_ptr_factory_.GetWeakPtr(), | |
874 base::MessageLoop::current()->message_loop_proxy()), | |
875 base::TimeDelta::FromSeconds(kInitializationDelaySeconds)); | |
876 } | 835 } |
877 } | 836 } |
878 | 837 |
879 void MetricsService::CloseCurrentLog() { | 838 void MetricsService::CloseCurrentLog() { |
880 if (!log_manager_.current_log()) | 839 if (!log_manager_.current_log()) |
881 return; | 840 return; |
882 | 841 |
883 // TODO(jar): Integrate bounds on log recording more consistently, so that we | 842 // TODO(jar): Integrate bounds on log recording more consistently, so that we |
884 // can stop recording logs that are too big much sooner. | 843 // can stop recording logs that are too big much sooner. |
885 if (log_manager_.current_log()->num_events() > kEventLimit) { | 844 if (log_manager_.current_log()->num_events() > kEventLimit) { |
886 UMA_HISTOGRAM_COUNTS("UMA.Discarded Log Events", | 845 UMA_HISTOGRAM_COUNTS("UMA.Discarded Log Events", |
887 log_manager_.current_log()->num_events()); | 846 log_manager_.current_log()->num_events()); |
888 log_manager_.DiscardCurrentLog(); | 847 log_manager_.DiscardCurrentLog(); |
889 OpenNewLog(); // Start trivial log to hold our histograms. | 848 OpenNewLog(); // Start trivial log to hold our histograms. |
890 } | 849 } |
891 | 850 |
892 // Adds to ongoing logs. | |
893 log_manager_.current_log()->set_hardware_class(hardware_class_); | |
blundell
2014/05/27 13:14:19
Two questions here:
(1) The timing of these calls
Alexei Svitkine (slow)
2014/05/27 13:56:37
I don't think so.
blundell
2014/05/27 14:58:10
Done.
| |
894 | |
895 // Put incremental data (histogram deltas, and realtime stats deltas) at the | 851 // Put incremental data (histogram deltas, and realtime stats deltas) at the |
896 // end of all log transmissions (initial log handles this separately). | 852 // end of all log transmissions (initial log handles this separately). |
897 // RecordIncrementalStabilityElements only exists on the derived | 853 // RecordIncrementalStabilityElements only exists on the derived |
898 // MetricsLog class. | 854 // MetricsLog class. |
899 MetricsLog* current_log = | 855 MetricsLog* current_log = |
900 static_cast<MetricsLog*>(log_manager_.current_log()); | 856 static_cast<MetricsLog*>(log_manager_.current_log()); |
901 DCHECK(current_log); | 857 DCHECK(current_log); |
902 std::vector<variations::ActiveGroupId> synthetic_trials; | 858 std::vector<variations::ActiveGroupId> synthetic_trials; |
903 GetCurrentSyntheticFieldTrials(&synthetic_trials); | 859 GetCurrentSyntheticFieldTrials(&synthetic_trials); |
904 current_log->RecordEnvironment(metrics_providers_.get(), synthetic_trials); | 860 current_log->RecordEnvironment(metrics_providers_.get(), synthetic_trials); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1106 | 1062 |
1107 // Store unsent logs, including the stability log that was just saved, so | 1063 // Store unsent logs, including the stability log that was just saved, so |
1108 // that they're not lost in case of a crash before upload time. | 1064 // that they're not lost in case of a crash before upload time. |
1109 log_manager_.PersistUnsentLogs(); | 1065 log_manager_.PersistUnsentLogs(); |
1110 | 1066 |
1111 has_initial_stability_log_ = true; | 1067 has_initial_stability_log_ = true; |
1112 } | 1068 } |
1113 | 1069 |
1114 void MetricsService::PrepareInitialMetricsLog() { | 1070 void MetricsService::PrepareInitialMetricsLog() { |
1115 DCHECK(state_ == INIT_TASK_DONE || state_ == SENDING_INITIAL_STABILITY_LOG); | 1071 DCHECK(state_ == INIT_TASK_DONE || state_ == SENDING_INITIAL_STABILITY_LOG); |
1116 initial_metrics_log_->set_hardware_class(hardware_class_); | |
1117 | 1072 |
1118 std::vector<variations::ActiveGroupId> synthetic_trials; | 1073 std::vector<variations::ActiveGroupId> synthetic_trials; |
1119 GetCurrentSyntheticFieldTrials(&synthetic_trials); | 1074 GetCurrentSyntheticFieldTrials(&synthetic_trials); |
1120 initial_metrics_log_->RecordEnvironment(metrics_providers_.get(), | 1075 initial_metrics_log_->RecordEnvironment(metrics_providers_.get(), |
1121 synthetic_trials); | 1076 synthetic_trials); |
1122 base::TimeDelta incremental_uptime; | 1077 base::TimeDelta incremental_uptime; |
1123 base::TimeDelta uptime; | 1078 base::TimeDelta uptime; |
1124 GetUptimes(local_state_, &incremental_uptime, &uptime); | 1079 GetUptimes(local_state_, &incremental_uptime, &uptime); |
1125 | 1080 |
1126 // Histograms only get written to the current log, so make the new log current | 1081 // Histograms only get written to the current log, so make the new log current |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1411 RecordCurrentState(local_state_); | 1366 RecordCurrentState(local_state_); |
1412 } | 1367 } |
1413 | 1368 |
1414 void MetricsService::RecordCurrentState(PrefService* pref) { | 1369 void MetricsService::RecordCurrentState(PrefService* pref) { |
1415 pref->SetInt64(prefs::kStabilityLastTimestampSec, Time::Now().ToTimeT()); | 1370 pref->SetInt64(prefs::kStabilityLastTimestampSec, Time::Now().ToTimeT()); |
1416 | 1371 |
1417 #if defined(ENABLE_PLUGINS) | 1372 #if defined(ENABLE_PLUGINS) |
1418 plugin_metrics_provider_->RecordPluginChanges(); | 1373 plugin_metrics_provider_->RecordPluginChanges(); |
1419 #endif | 1374 #endif |
1420 } | 1375 } |
OLD | NEW |