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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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/metrics/histogram.h" | 170 #include "base/metrics/histogram.h" |
171 #include "base/metrics/histogram_base.h" | 171 #include "base/metrics/histogram_base.h" |
172 #include "base/metrics/histogram_samples.h" | 172 #include "base/metrics/histogram_samples.h" |
173 #include "base/metrics/sparse_histogram.h" | 173 #include "base/metrics/sparse_histogram.h" |
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/prefs/scoped_user_pref_update.h" | |
178 #include "base/strings/string_number_conversions.h" | 177 #include "base/strings/string_number_conversions.h" |
179 #include "base/strings/utf_string_conversions.h" | 178 #include "base/strings/utf_string_conversions.h" |
180 #include "base/threading/platform_thread.h" | 179 #include "base/threading/platform_thread.h" |
181 #include "base/threading/thread.h" | 180 #include "base/threading/thread.h" |
182 #include "base/threading/thread_restrictions.h" | 181 #include "base/threading/thread_restrictions.h" |
183 #include "base/tracked_objects.h" | 182 #include "base/tracked_objects.h" |
184 #include "base/values.h" | 183 #include "base/values.h" |
185 #include "chrome/browser/browser_process.h" | 184 #include "chrome/browser/browser_process.h" |
186 #include "chrome/browser/chrome_notification_types.h" | 185 #include "chrome/browser/chrome_notification_types.h" |
187 #include "chrome/browser/io_thread.h" | 186 #include "chrome/browser/io_thread.h" |
188 #include "chrome/browser/metrics/chrome_stability_metrics_provider.h" | 187 #include "chrome/browser/metrics/chrome_stability_metrics_provider.h" |
189 #include "chrome/browser/metrics/compression_utils.h" | 188 #include "chrome/browser/metrics/compression_utils.h" |
190 #include "chrome/browser/metrics/metrics_log.h" | 189 #include "chrome/browser/metrics/metrics_log.h" |
191 #include "chrome/browser/metrics/metrics_state_manager.h" | 190 #include "chrome/browser/metrics/metrics_state_manager.h" |
192 #include "chrome/browser/metrics/network_metrics_provider.h" | 191 #include "chrome/browser/metrics/network_metrics_provider.h" |
193 #include "chrome/browser/metrics/omnibox_metrics_provider.h" | 192 #include "chrome/browser/metrics/omnibox_metrics_provider.h" |
194 #include "chrome/browser/metrics/tracking_synchronizer.h" | 193 #include "chrome/browser/metrics/tracking_synchronizer.h" |
195 #include "chrome/common/chrome_constants.h" | 194 #include "chrome/common/chrome_constants.h" |
196 #include "chrome/common/pref_names.h" | 195 #include "chrome/common/pref_names.h" |
197 #include "chrome/common/variations/variations_util.h" | 196 #include "chrome/common/variations/variations_util.h" |
198 #include "components/metrics/metrics_log_base.h" | 197 #include "components/metrics/metrics_log_base.h" |
199 #include "components/metrics/metrics_log_manager.h" | 198 #include "components/metrics/metrics_log_manager.h" |
200 #include "components/metrics/metrics_pref_names.h" | 199 #include "components/metrics/metrics_pref_names.h" |
201 #include "components/metrics/metrics_reporting_scheduler.h" | 200 #include "components/metrics/metrics_reporting_scheduler.h" |
202 #include "components/metrics/metrics_service_client.h" | 201 #include "components/metrics/metrics_service_client.h" |
203 #include "components/variations/entropy_provider.h" | 202 #include "components/variations/entropy_provider.h" |
204 #include "components/variations/metrics_util.h" | |
205 #include "content/public/browser/child_process_data.h" | 203 #include "content/public/browser/child_process_data.h" |
206 #include "content/public/browser/plugin_service.h" | |
207 #include "content/public/browser/render_process_host.h" | 204 #include "content/public/browser/render_process_host.h" |
208 #include "content/public/browser/user_metrics.h" | 205 #include "content/public/browser/user_metrics.h" |
209 #include "content/public/common/process_type.h" | |
210 #include "content/public/common/webplugininfo.h" | |
211 #include "net/base/load_flags.h" | 206 #include "net/base/load_flags.h" |
212 #include "net/url_request/url_fetcher.h" | 207 #include "net/url_request/url_fetcher.h" |
213 | 208 |
| 209 #if defined(ENABLE_PLUGINS) |
| 210 // TODO(asvitkine): Move this out of MetricsService. |
| 211 #include "chrome/browser/metrics/plugin_metrics_provider.h" |
| 212 #endif |
| 213 |
214 #if defined(OS_CHROMEOS) | 214 #if defined(OS_CHROMEOS) |
215 #include "chrome/browser/chromeos/settings/cros_settings.h" | 215 #include "chrome/browser/chromeos/settings/cros_settings.h" |
216 #include "chromeos/system/statistics_provider.h" | 216 #include "chromeos/system/statistics_provider.h" |
217 #endif | 217 #endif |
218 | 218 |
219 #if defined(OS_WIN) | 219 #if defined(OS_WIN) |
220 #include <windows.h> // Needed for STATUS_* codes | 220 #include <windows.h> // Needed for STATUS_* codes |
221 #include "base/win/registry.h" | 221 #include "base/win/registry.h" |
222 #include "chrome/browser/metrics/google_update_metrics_provider_win.h" | 222 #include "chrome/browser/metrics/google_update_metrics_provider_win.h" |
223 #endif | 223 #endif |
224 | 224 |
225 #if defined(OS_ANDROID) | 225 #if defined(OS_ANDROID) |
226 // TODO(asvitkine): Move this out of MetricsService. | 226 // TODO(asvitkine): Move this out of MetricsService. |
227 #include "chrome/browser/metrics/android_metrics_provider.h" | 227 #include "chrome/browser/metrics/android_metrics_provider.h" |
228 #endif | 228 #endif |
229 | 229 |
230 using base::Time; | 230 using base::Time; |
231 using content::BrowserThread; | 231 using content::BrowserThread; |
232 using content::ChildProcessData; | |
233 using content::PluginService; | |
234 using metrics::MetricsLogManager; | 232 using metrics::MetricsLogManager; |
235 | 233 |
236 namespace { | 234 namespace { |
237 | 235 |
238 // Check to see that we're being called on only one thread. | 236 // Check to see that we're being called on only one thread. |
239 bool IsSingleThreaded() { | 237 bool IsSingleThreaded() { |
240 static base::PlatformThreadId thread_id = 0; | 238 static base::PlatformThreadId thread_id = 0; |
241 if (!thread_id) | 239 if (!thread_id) |
242 thread_id = base::PlatformThread::CurrentId(); | 240 thread_id = base::PlatformThread::CurrentId(); |
243 return base::PlatformThread::CurrentId() == thread_id; | 241 return base::PlatformThread::CurrentId() == thread_id; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 SyntheticTrialGroup::~SyntheticTrialGroup() { | 312 SyntheticTrialGroup::~SyntheticTrialGroup() { |
315 } | 313 } |
316 | 314 |
317 // static | 315 // static |
318 MetricsService::ShutdownCleanliness MetricsService::clean_shutdown_status_ = | 316 MetricsService::ShutdownCleanliness MetricsService::clean_shutdown_status_ = |
319 MetricsService::CLEANLY_SHUTDOWN; | 317 MetricsService::CLEANLY_SHUTDOWN; |
320 | 318 |
321 MetricsService::ExecutionPhase MetricsService::execution_phase_ = | 319 MetricsService::ExecutionPhase MetricsService::execution_phase_ = |
322 MetricsService::UNINITIALIZED_PHASE; | 320 MetricsService::UNINITIALIZED_PHASE; |
323 | 321 |
324 // This is used to quickly log stats from child process related notifications in | |
325 // MetricsService::child_stats_buffer_. The buffer's contents are transferred | |
326 // out when Local State is periodically saved. The information is then | |
327 // reported to the UMA server on next launch. | |
328 struct MetricsService::ChildProcessStats { | |
329 public: | |
330 explicit ChildProcessStats(int process_type) | |
331 : process_launches(0), | |
332 process_crashes(0), | |
333 instances(0), | |
334 loading_errors(0), | |
335 process_type(process_type) {} | |
336 | |
337 // This constructor is only used by the map to return some default value for | |
338 // an index for which no value has been assigned. | |
339 ChildProcessStats() | |
340 : process_launches(0), | |
341 process_crashes(0), | |
342 instances(0), | |
343 loading_errors(0), | |
344 process_type(content::PROCESS_TYPE_UNKNOWN) {} | |
345 | |
346 // The number of times that the given child process has been launched | |
347 int process_launches; | |
348 | |
349 // The number of times that the given child process has crashed | |
350 int process_crashes; | |
351 | |
352 // The number of instances of this child process that have been created. | |
353 // An instance is a DOM object rendered by this child process during a page | |
354 // load. | |
355 int instances; | |
356 | |
357 // The number of times there was an error loading an instance of this child | |
358 // process. | |
359 int loading_errors; | |
360 | |
361 int process_type; | |
362 }; | |
363 | |
364 // static | 322 // static |
365 void MetricsService::RegisterPrefs(PrefRegistrySimple* registry) { | 323 void MetricsService::RegisterPrefs(PrefRegistrySimple* registry) { |
366 DCHECK(IsSingleThreaded()); | 324 DCHECK(IsSingleThreaded()); |
367 metrics::MetricsStateManager::RegisterPrefs(registry); | 325 metrics::MetricsStateManager::RegisterPrefs(registry); |
368 | 326 |
369 registry->RegisterInt64Pref(prefs::kStabilityLaunchTimeSec, 0); | 327 registry->RegisterInt64Pref(prefs::kStabilityLaunchTimeSec, 0); |
370 registry->RegisterInt64Pref(prefs::kStabilityLastTimestampSec, 0); | 328 registry->RegisterInt64Pref(prefs::kStabilityLastTimestampSec, 0); |
371 registry->RegisterStringPref(prefs::kStabilityStatsVersion, std::string()); | 329 registry->RegisterStringPref(prefs::kStabilityStatsVersion, std::string()); |
372 registry->RegisterInt64Pref(prefs::kStabilityStatsBuildTime, 0); | 330 registry->RegisterInt64Pref(prefs::kStabilityStatsBuildTime, 0); |
373 registry->RegisterBooleanPref(prefs::kStabilityExitedCleanly, true); | 331 registry->RegisterBooleanPref(prefs::kStabilityExitedCleanly, true); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 registry->RegisterInt64Pref(prefs::kUninstallMetricsPageLoadCount, 0); | 365 registry->RegisterInt64Pref(prefs::kUninstallMetricsPageLoadCount, 0); |
408 registry->RegisterInt64Pref(prefs::kUninstallLaunchCount, 0); | 366 registry->RegisterInt64Pref(prefs::kUninstallLaunchCount, 0); |
409 registry->RegisterInt64Pref(prefs::kUninstallMetricsUptimeSec, 0); | 367 registry->RegisterInt64Pref(prefs::kUninstallMetricsUptimeSec, 0); |
410 registry->RegisterInt64Pref(prefs::kUninstallLastLaunchTimeSec, 0); | 368 registry->RegisterInt64Pref(prefs::kUninstallLastLaunchTimeSec, 0); |
411 registry->RegisterInt64Pref(prefs::kUninstallLastObservedRunTimeSec, 0); | 369 registry->RegisterInt64Pref(prefs::kUninstallLastObservedRunTimeSec, 0); |
412 | 370 |
413 #if defined(OS_ANDROID) | 371 #if defined(OS_ANDROID) |
414 // TODO(asvitkine): Move this out of here. | 372 // TODO(asvitkine): Move this out of here. |
415 AndroidMetricsProvider::RegisterPrefs(registry); | 373 AndroidMetricsProvider::RegisterPrefs(registry); |
416 #endif // defined(OS_ANDROID) | 374 #endif // defined(OS_ANDROID) |
| 375 |
| 376 #if defined(ENABLE_PLUGINS) |
| 377 // TODO(asvitkine): Move this out of here. |
| 378 PluginMetricsProvider::RegisterPrefs(registry); |
| 379 #endif |
417 } | 380 } |
418 | 381 |
419 MetricsService::MetricsService(metrics::MetricsStateManager* state_manager, | 382 MetricsService::MetricsService(metrics::MetricsStateManager* state_manager, |
420 metrics::MetricsServiceClient* client) | 383 metrics::MetricsServiceClient* client) |
421 : log_manager_(g_browser_process->local_state(), | 384 : log_manager_(g_browser_process->local_state(), |
422 kUploadLogAvoidRetransmitSize), | 385 kUploadLogAvoidRetransmitSize), |
423 histogram_snapshot_manager_(this), | 386 histogram_snapshot_manager_(this), |
424 state_manager_(state_manager), | 387 state_manager_(state_manager), |
425 client_(client), | 388 client_(client), |
426 recording_active_(false), | 389 recording_active_(false), |
(...skipping 24 matching lines...) Expand all Loading... |
451 RegisterMetricsProvider( | 414 RegisterMetricsProvider( |
452 scoped_ptr<metrics::MetricsProvider>(new OmniboxMetricsProvider)); | 415 scoped_ptr<metrics::MetricsProvider>(new OmniboxMetricsProvider)); |
453 RegisterMetricsProvider( | 416 RegisterMetricsProvider( |
454 scoped_ptr<metrics::MetricsProvider>(new ChromeStabilityMetricsProvider)); | 417 scoped_ptr<metrics::MetricsProvider>(new ChromeStabilityMetricsProvider)); |
455 | 418 |
456 #if defined(OS_WIN) | 419 #if defined(OS_WIN) |
457 google_update_metrics_provider_ = new GoogleUpdateMetricsProviderWin; | 420 google_update_metrics_provider_ = new GoogleUpdateMetricsProviderWin; |
458 RegisterMetricsProvider(scoped_ptr<metrics::MetricsProvider>( | 421 RegisterMetricsProvider(scoped_ptr<metrics::MetricsProvider>( |
459 google_update_metrics_provider_)); | 422 google_update_metrics_provider_)); |
460 #endif | 423 #endif |
| 424 |
| 425 #if defined(ENABLE_PLUGINS) |
| 426 plugin_metrics_provider_ = new PluginMetricsProvider( |
| 427 g_browser_process->local_state()); |
| 428 RegisterMetricsProvider(scoped_ptr<metrics::MetricsProvider>( |
| 429 plugin_metrics_provider_)); |
| 430 #endif |
| 431 |
461 BrowserChildProcessObserver::Add(this); | 432 BrowserChildProcessObserver::Add(this); |
462 } | 433 } |
463 | 434 |
464 MetricsService::~MetricsService() { | 435 MetricsService::~MetricsService() { |
465 DisableRecording(); | 436 DisableRecording(); |
466 | 437 |
467 BrowserChildProcessObserver::Remove(this); | 438 BrowserChildProcessObserver::Remove(this); |
468 } | 439 } |
469 | 440 |
470 void MetricsService::InitializeMetricsRecordingState() { | 441 void MetricsService::InitializeMetricsRecordingState() { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 base::HistogramBase::Inconsistency problem) { | 556 base::HistogramBase::Inconsistency problem) { |
586 UMA_HISTOGRAM_ENUMERATION("Histogram.InconsistenciesBrowserUnique", | 557 UMA_HISTOGRAM_ENUMERATION("Histogram.InconsistenciesBrowserUnique", |
587 problem, base::HistogramBase::NEVER_EXCEEDED_VALUE); | 558 problem, base::HistogramBase::NEVER_EXCEEDED_VALUE); |
588 } | 559 } |
589 | 560 |
590 void MetricsService::InconsistencyDetectedInLoggedCount(int amount) { | 561 void MetricsService::InconsistencyDetectedInLoggedCount(int amount) { |
591 UMA_HISTOGRAM_COUNTS("Histogram.InconsistentSnapshotBrowser", | 562 UMA_HISTOGRAM_COUNTS("Histogram.InconsistentSnapshotBrowser", |
592 std::abs(amount)); | 563 std::abs(amount)); |
593 } | 564 } |
594 | 565 |
595 void MetricsService::BrowserChildProcessHostConnected( | |
596 const content::ChildProcessData& data) { | |
597 GetChildProcessStats(data).process_launches++; | |
598 } | |
599 | |
600 void MetricsService::BrowserChildProcessCrashed( | 566 void MetricsService::BrowserChildProcessCrashed( |
601 const content::ChildProcessData& data) { | 567 const content::ChildProcessData& data) { |
602 GetChildProcessStats(data).process_crashes++; | 568 // TODO(asvitkine): Move this into ChromeStabilityStatsProvider. |
| 569 #if defined(ENABLE_PLUGINS) |
603 // Exclude plugin crashes from the count below because we report them via | 570 // Exclude plugin crashes from the count below because we report them via |
604 // a separate UMA metric. | 571 // a separate UMA metric. |
605 if (!IsPluginProcess(data.process_type)) | 572 if (PluginMetricsProvider::IsPluginProcess(data.process_type)) |
606 IncrementPrefValue(prefs::kStabilityChildProcessCrashCount); | 573 return; |
607 } | 574 #endif |
608 | 575 |
609 void MetricsService::BrowserChildProcessInstanceCreated( | 576 IncrementPrefValue(prefs::kStabilityChildProcessCrashCount); |
610 const content::ChildProcessData& data) { | |
611 GetChildProcessStats(data).instances++; | |
612 } | 577 } |
613 | 578 |
614 void MetricsService::HandleIdleSinceLastTransmission(bool in_idle) { | 579 void MetricsService::HandleIdleSinceLastTransmission(bool in_idle) { |
615 // If there wasn't a lot of action, maybe the computer was asleep, in which | 580 // If there wasn't a lot of action, maybe the computer was asleep, in which |
616 // case, the log transmissions should have stopped. Here we start them up | 581 // case, the log transmissions should have stopped. Here we start them up |
617 // again. | 582 // again. |
618 if (!in_idle && idle_since_last_transmission_) | 583 if (!in_idle && idle_since_last_transmission_) |
619 StartSchedulerIfNecessary(); | 584 StartSchedulerIfNecessary(); |
620 idle_since_last_transmission_ = in_idle; | 585 idle_since_last_transmission_ = in_idle; |
621 } | 586 } |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 target_loop->PostTask(FROM_HERE, | 796 target_loop->PostTask(FROM_HERE, |
832 base::Bind(&MetricsService::OnInitTaskGotHardwareClass, | 797 base::Bind(&MetricsService::OnInitTaskGotHardwareClass, |
833 self, hardware_class)); | 798 self, hardware_class)); |
834 } | 799 } |
835 | 800 |
836 void MetricsService::OnInitTaskGotHardwareClass( | 801 void MetricsService::OnInitTaskGotHardwareClass( |
837 const std::string& hardware_class) { | 802 const std::string& hardware_class) { |
838 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); | 803 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); |
839 hardware_class_ = hardware_class; | 804 hardware_class_ = hardware_class; |
840 | 805 |
| 806 const base::Closure got_plugin_info_callback = |
| 807 base::Bind(&MetricsService::OnInitTaskGotPluginInfo, |
| 808 self_ptr_factory_.GetWeakPtr()); |
| 809 |
841 #if defined(ENABLE_PLUGINS) | 810 #if defined(ENABLE_PLUGINS) |
842 // Start the next part of the init task: loading plugin information. | 811 plugin_metrics_provider_->GetPluginInformation(got_plugin_info_callback); |
843 PluginService::GetInstance()->GetPlugins( | |
844 base::Bind(&MetricsService::OnInitTaskGotPluginInfo, | |
845 self_ptr_factory_.GetWeakPtr())); | |
846 #else | 812 #else |
847 std::vector<content::WebPluginInfo> plugin_list_empty; | 813 got_plugin_info_callback.Run(); |
848 OnInitTaskGotPluginInfo(plugin_list_empty); | 814 #endif |
849 #endif // defined(ENABLE_PLUGINS) | |
850 } | 815 } |
851 | 816 |
852 void MetricsService::OnInitTaskGotPluginInfo( | 817 void MetricsService::OnInitTaskGotPluginInfo() { |
853 const std::vector<content::WebPluginInfo>& plugins) { | |
854 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); | 818 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); |
855 plugins_ = plugins; | |
856 | 819 |
857 const base::Closure got_metrics_callback = | 820 const base::Closure got_metrics_callback = |
858 base::Bind(&MetricsService::OnInitTaskGotGoogleUpdateData, | 821 base::Bind(&MetricsService::OnInitTaskGotGoogleUpdateData, |
859 self_ptr_factory_.GetWeakPtr()); | 822 self_ptr_factory_.GetWeakPtr()); |
860 | 823 |
861 #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) | 824 #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) |
862 google_update_metrics_provider_->GetGoogleUpdateData(got_metrics_callback); | 825 google_update_metrics_provider_->GetGoogleUpdateData(got_metrics_callback); |
863 #else | 826 #else |
864 got_metrics_callback.Run(); | 827 got_metrics_callback.Run(); |
865 #endif | 828 #endif |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1012 | 975 |
1013 // Put incremental data (histogram deltas, and realtime stats deltas) at the | 976 // Put incremental data (histogram deltas, and realtime stats deltas) at the |
1014 // end of all log transmissions (initial log handles this separately). | 977 // end of all log transmissions (initial log handles this separately). |
1015 // RecordIncrementalStabilityElements only exists on the derived | 978 // RecordIncrementalStabilityElements only exists on the derived |
1016 // MetricsLog class. | 979 // MetricsLog class. |
1017 MetricsLog* current_log = | 980 MetricsLog* current_log = |
1018 static_cast<MetricsLog*>(log_manager_.current_log()); | 981 static_cast<MetricsLog*>(log_manager_.current_log()); |
1019 DCHECK(current_log); | 982 DCHECK(current_log); |
1020 std::vector<variations::ActiveGroupId> synthetic_trials; | 983 std::vector<variations::ActiveGroupId> synthetic_trials; |
1021 GetCurrentSyntheticFieldTrials(&synthetic_trials); | 984 GetCurrentSyntheticFieldTrials(&synthetic_trials); |
1022 current_log->RecordEnvironment(metrics_providers_.get(), plugins_, | 985 current_log->RecordEnvironment(metrics_providers_.get(), synthetic_trials); |
1023 synthetic_trials); | |
1024 PrefService* pref = g_browser_process->local_state(); | 986 PrefService* pref = g_browser_process->local_state(); |
1025 base::TimeDelta incremental_uptime; | 987 base::TimeDelta incremental_uptime; |
1026 base::TimeDelta uptime; | 988 base::TimeDelta uptime; |
1027 GetUptimes(pref, &incremental_uptime, &uptime); | 989 GetUptimes(pref, &incremental_uptime, &uptime); |
1028 current_log->RecordStabilityMetrics(metrics_providers_.get(), | 990 current_log->RecordStabilityMetrics(metrics_providers_.get(), |
1029 incremental_uptime, uptime); | 991 incremental_uptime, uptime); |
1030 | 992 |
1031 RecordCurrentHistograms(); | 993 RecordCurrentHistograms(); |
1032 current_log->RecordGeneralMetrics(metrics_providers_.get()); | 994 current_log->RecordGeneralMetrics(metrics_providers_.get()); |
1033 | 995 |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1231 | 1193 |
1232 has_initial_stability_log_ = true; | 1194 has_initial_stability_log_ = true; |
1233 } | 1195 } |
1234 | 1196 |
1235 void MetricsService::PrepareInitialMetricsLog() { | 1197 void MetricsService::PrepareInitialMetricsLog() { |
1236 DCHECK(state_ == INIT_TASK_DONE || state_ == SENDING_INITIAL_STABILITY_LOG); | 1198 DCHECK(state_ == INIT_TASK_DONE || state_ == SENDING_INITIAL_STABILITY_LOG); |
1237 initial_metrics_log_->set_hardware_class(hardware_class_); | 1199 initial_metrics_log_->set_hardware_class(hardware_class_); |
1238 | 1200 |
1239 std::vector<variations::ActiveGroupId> synthetic_trials; | 1201 std::vector<variations::ActiveGroupId> synthetic_trials; |
1240 GetCurrentSyntheticFieldTrials(&synthetic_trials); | 1202 GetCurrentSyntheticFieldTrials(&synthetic_trials); |
1241 initial_metrics_log_->RecordEnvironment(metrics_providers_.get(), plugins_, | 1203 initial_metrics_log_->RecordEnvironment(metrics_providers_.get(), |
1242 synthetic_trials); | 1204 synthetic_trials); |
1243 PrefService* pref = g_browser_process->local_state(); | 1205 PrefService* pref = g_browser_process->local_state(); |
1244 base::TimeDelta incremental_uptime; | 1206 base::TimeDelta incremental_uptime; |
1245 base::TimeDelta uptime; | 1207 base::TimeDelta uptime; |
1246 GetUptimes(pref, &incremental_uptime, &uptime); | 1208 GetUptimes(pref, &incremental_uptime, &uptime); |
1247 | 1209 |
1248 // Histograms only get written to the current log, so make the new log current | 1210 // Histograms only get written to the current log, so make the new log current |
1249 // before writing them. | 1211 // before writing them. |
1250 log_manager_.PauseCurrentLog(); | 1212 log_manager_.PauseCurrentLog(); |
1251 log_manager_.BeginLoggingWithLog( | 1213 log_manager_.BeginLoggingWithLog( |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1525 IncrementPrefValue(prefs::kStabilitySystemUncleanShutdownCount); | 1487 IncrementPrefValue(prefs::kStabilitySystemUncleanShutdownCount); |
1526 else | 1488 else |
1527 NOTREACHED() << "Unexpected Chrome OS crash type " << crash_type; | 1489 NOTREACHED() << "Unexpected Chrome OS crash type " << crash_type; |
1528 // Wake up metrics logs sending if necessary now that new | 1490 // Wake up metrics logs sending if necessary now that new |
1529 // log data is available. | 1491 // log data is available. |
1530 HandleIdleSinceLastTransmission(false); | 1492 HandleIdleSinceLastTransmission(false); |
1531 } | 1493 } |
1532 #endif // OS_CHROMEOS | 1494 #endif // OS_CHROMEOS |
1533 | 1495 |
1534 void MetricsService::LogPluginLoadingError(const base::FilePath& plugin_path) { | 1496 void MetricsService::LogPluginLoadingError(const base::FilePath& plugin_path) { |
1535 content::WebPluginInfo plugin; | 1497 #if defined(ENABLE_PLUGINS) |
1536 bool success = | 1498 // TODO(asvitkine): Move this out of here. |
1537 content::PluginService::GetInstance()->GetPluginInfoByPath(plugin_path, | 1499 plugin_metrics_provider_->LogPluginLoadingError(plugin_path); |
1538 &plugin); | 1500 #endif |
1539 DCHECK(success); | |
1540 ChildProcessStats& stats = child_process_stats_buffer_[plugin.name]; | |
1541 // Initialize the type if this entry is new. | |
1542 if (stats.process_type == content::PROCESS_TYPE_UNKNOWN) { | |
1543 // The plug-in process might not actually of type PLUGIN (which means | |
1544 // NPAPI), but we only care that it is *a* plug-in process. | |
1545 stats.process_type = content::PROCESS_TYPE_PLUGIN; | |
1546 } else { | |
1547 DCHECK(IsPluginProcess(stats.process_type)); | |
1548 } | |
1549 stats.loading_errors++; | |
1550 } | |
1551 | |
1552 MetricsService::ChildProcessStats& MetricsService::GetChildProcessStats( | |
1553 const content::ChildProcessData& data) { | |
1554 const base::string16& child_name = data.name; | |
1555 if (!ContainsKey(child_process_stats_buffer_, child_name)) { | |
1556 child_process_stats_buffer_[child_name] = | |
1557 ChildProcessStats(data.process_type); | |
1558 } | |
1559 return child_process_stats_buffer_[child_name]; | |
1560 } | |
1561 | |
1562 void MetricsService::RecordPluginChanges(PrefService* pref) { | |
1563 ListPrefUpdate update(pref, prefs::kStabilityPluginStats); | |
1564 base::ListValue* plugins = update.Get(); | |
1565 DCHECK(plugins); | |
1566 | |
1567 for (base::ListValue::iterator value_iter = plugins->begin(); | |
1568 value_iter != plugins->end(); ++value_iter) { | |
1569 if (!(*value_iter)->IsType(base::Value::TYPE_DICTIONARY)) { | |
1570 NOTREACHED(); | |
1571 continue; | |
1572 } | |
1573 | |
1574 base::DictionaryValue* plugin_dict = | |
1575 static_cast<base::DictionaryValue*>(*value_iter); | |
1576 std::string plugin_name; | |
1577 plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name); | |
1578 if (plugin_name.empty()) { | |
1579 NOTREACHED(); | |
1580 continue; | |
1581 } | |
1582 | |
1583 // TODO(viettrungluu): remove conversions | |
1584 base::string16 name16 = base::UTF8ToUTF16(plugin_name); | |
1585 if (child_process_stats_buffer_.find(name16) == | |
1586 child_process_stats_buffer_.end()) { | |
1587 continue; | |
1588 } | |
1589 | |
1590 ChildProcessStats stats = child_process_stats_buffer_[name16]; | |
1591 if (stats.process_launches) { | |
1592 int launches = 0; | |
1593 plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches); | |
1594 launches += stats.process_launches; | |
1595 plugin_dict->SetInteger(prefs::kStabilityPluginLaunches, launches); | |
1596 } | |
1597 if (stats.process_crashes) { | |
1598 int crashes = 0; | |
1599 plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes); | |
1600 crashes += stats.process_crashes; | |
1601 plugin_dict->SetInteger(prefs::kStabilityPluginCrashes, crashes); | |
1602 } | |
1603 if (stats.instances) { | |
1604 int instances = 0; | |
1605 plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances); | |
1606 instances += stats.instances; | |
1607 plugin_dict->SetInteger(prefs::kStabilityPluginInstances, instances); | |
1608 } | |
1609 if (stats.loading_errors) { | |
1610 int loading_errors = 0; | |
1611 plugin_dict->GetInteger(prefs::kStabilityPluginLoadingErrors, | |
1612 &loading_errors); | |
1613 loading_errors += stats.loading_errors; | |
1614 plugin_dict->SetInteger(prefs::kStabilityPluginLoadingErrors, | |
1615 loading_errors); | |
1616 } | |
1617 | |
1618 child_process_stats_buffer_.erase(name16); | |
1619 } | |
1620 | |
1621 // Now go through and add dictionaries for plugins that didn't already have | |
1622 // reports in Local State. | |
1623 for (std::map<base::string16, ChildProcessStats>::iterator cache_iter = | |
1624 child_process_stats_buffer_.begin(); | |
1625 cache_iter != child_process_stats_buffer_.end(); ++cache_iter) { | |
1626 ChildProcessStats stats = cache_iter->second; | |
1627 | |
1628 // Insert only plugins information into the plugins list. | |
1629 if (!IsPluginProcess(stats.process_type)) | |
1630 continue; | |
1631 | |
1632 // TODO(viettrungluu): remove conversion | |
1633 std::string plugin_name = base::UTF16ToUTF8(cache_iter->first); | |
1634 | |
1635 base::DictionaryValue* plugin_dict = new base::DictionaryValue; | |
1636 | |
1637 plugin_dict->SetString(prefs::kStabilityPluginName, plugin_name); | |
1638 plugin_dict->SetInteger(prefs::kStabilityPluginLaunches, | |
1639 stats.process_launches); | |
1640 plugin_dict->SetInteger(prefs::kStabilityPluginCrashes, | |
1641 stats.process_crashes); | |
1642 plugin_dict->SetInteger(prefs::kStabilityPluginInstances, | |
1643 stats.instances); | |
1644 plugin_dict->SetInteger(prefs::kStabilityPluginLoadingErrors, | |
1645 stats.loading_errors); | |
1646 plugins->Append(plugin_dict); | |
1647 } | |
1648 child_process_stats_buffer_.clear(); | |
1649 } | 1501 } |
1650 | 1502 |
1651 bool MetricsService::ShouldLogEvents() { | 1503 bool MetricsService::ShouldLogEvents() { |
1652 // We simply don't log events to UMA if there is a single incognito | 1504 // We simply don't log events to UMA if there is a single incognito |
1653 // session visible. The problem is that we always notify using the orginal | 1505 // session visible. The problem is that we always notify using the orginal |
1654 // profile in order to simplify notification processing. | 1506 // profile in order to simplify notification processing. |
1655 return !client_->IsOffTheRecordSessionActive(); | 1507 return !client_->IsOffTheRecordSessionActive(); |
1656 } | 1508 } |
1657 | 1509 |
1658 void MetricsService::RecordBooleanPrefValue(const char* path, bool value) { | 1510 void MetricsService::RecordBooleanPrefValue(const char* path, bool value) { |
1659 DCHECK(IsSingleThreaded()); | 1511 DCHECK(IsSingleThreaded()); |
1660 | 1512 |
1661 PrefService* pref = g_browser_process->local_state(); | 1513 PrefService* pref = g_browser_process->local_state(); |
1662 DCHECK(pref); | 1514 DCHECK(pref); |
1663 | 1515 |
1664 pref->SetBoolean(path, value); | 1516 pref->SetBoolean(path, value); |
1665 RecordCurrentState(pref); | 1517 RecordCurrentState(pref); |
1666 } | 1518 } |
1667 | 1519 |
1668 void MetricsService::RecordCurrentState(PrefService* pref) { | 1520 void MetricsService::RecordCurrentState(PrefService* pref) { |
1669 pref->SetInt64(prefs::kStabilityLastTimestampSec, Time::Now().ToTimeT()); | 1521 pref->SetInt64(prefs::kStabilityLastTimestampSec, Time::Now().ToTimeT()); |
1670 | 1522 |
1671 RecordPluginChanges(pref); | 1523 #if defined(ENABLE_PLUGINS) |
| 1524 plugin_metrics_provider_->RecordPluginChanges(); |
| 1525 #endif |
1672 } | 1526 } |
1673 | 1527 |
1674 // static | |
1675 bool MetricsService::IsPluginProcess(int process_type) { | |
1676 return (process_type == content::PROCESS_TYPE_PLUGIN || | |
1677 process_type == content::PROCESS_TYPE_PPAPI_PLUGIN || | |
1678 process_type == content::PROCESS_TYPE_PPAPI_BROKER); | |
1679 } | |
OLD | NEW |