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 | 10 // A MetricsService instance is typically created at application startup. It |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 #include "chrome/browser/metrics/metrics_reporting_scheduler.h" | 180 #include "chrome/browser/metrics/metrics_reporting_scheduler.h" |
181 #include "chrome/browser/metrics/tracking_synchronizer.h" | 181 #include "chrome/browser/metrics/tracking_synchronizer.h" |
182 #include "chrome/browser/net/http_pipelining_compatibility_client.h" | 182 #include "chrome/browser/net/http_pipelining_compatibility_client.h" |
183 #include "chrome/browser/net/network_stats.h" | 183 #include "chrome/browser/net/network_stats.h" |
184 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 184 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
185 #include "chrome/browser/profiles/profile.h" | 185 #include "chrome/browser/profiles/profile.h" |
186 #include "chrome/browser/search_engines/template_url_service.h" | 186 #include "chrome/browser/search_engines/template_url_service.h" |
187 #include "chrome/browser/ui/browser_list.h" | 187 #include "chrome/browser/ui/browser_list.h" |
188 #include "chrome/browser/ui/browser_otr_state.h" | 188 #include "chrome/browser/ui/browser_otr_state.h" |
189 #include "chrome/common/child_process_logging.h" | 189 #include "chrome/common/child_process_logging.h" |
| 190 #include "chrome/common/chrome_process_type.h" |
190 #include "chrome/common/chrome_notification_types.h" | 191 #include "chrome/common/chrome_notification_types.h" |
191 #include "chrome/common/chrome_result_codes.h" | 192 #include "chrome/common/chrome_result_codes.h" |
192 #include "chrome/common/chrome_switches.h" | 193 #include "chrome/common/chrome_switches.h" |
193 #include "chrome/common/metrics/entropy_provider.h" | 194 #include "chrome/common/metrics/entropy_provider.h" |
194 #include "chrome/common/metrics/metrics_log_manager.h" | 195 #include "chrome/common/metrics/metrics_log_manager.h" |
195 #include "chrome/common/net/test_server_locations.h" | 196 #include "chrome/common/net/test_server_locations.h" |
196 #include "chrome/common/pref_names.h" | 197 #include "chrome/common/pref_names.h" |
197 #include "chrome/common/render_messages.h" | 198 #include "chrome/common/render_messages.h" |
198 #include "content/public/browser/child_process_data.h" | 199 #include "content/public/browser/child_process_data.h" |
199 #include "content/public/browser/histogram_fetcher.h" | 200 #include "content/public/browser/histogram_fetcher.h" |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 // static | 329 // static |
329 MetricsService::ShutdownCleanliness MetricsService::clean_shutdown_status_ = | 330 MetricsService::ShutdownCleanliness MetricsService::clean_shutdown_status_ = |
330 MetricsService::CLEANLY_SHUTDOWN; | 331 MetricsService::CLEANLY_SHUTDOWN; |
331 | 332 |
332 // This is used to quickly log stats from child process related notifications in | 333 // This is used to quickly log stats from child process related notifications in |
333 // MetricsService::child_stats_buffer_. The buffer's contents are transferred | 334 // MetricsService::child_stats_buffer_. The buffer's contents are transferred |
334 // out when Local State is periodically saved. The information is then | 335 // out when Local State is periodically saved. The information is then |
335 // reported to the UMA server on next launch. | 336 // reported to the UMA server on next launch. |
336 struct MetricsService::ChildProcessStats { | 337 struct MetricsService::ChildProcessStats { |
337 public: | 338 public: |
338 explicit ChildProcessStats(content::ProcessType type) | 339 explicit ChildProcessStats(int process_type) |
339 : process_launches(0), | 340 : process_launches(0), |
340 process_crashes(0), | 341 process_crashes(0), |
341 instances(0), | 342 instances(0), |
342 loading_errors(0), | 343 loading_errors(0), |
343 process_type(type) {} | 344 process_type(process_type) {} |
344 | 345 |
345 // This constructor is only used by the map to return some default value for | 346 // This constructor is only used by the map to return some default value for |
346 // an index for which no value has been assigned. | 347 // an index for which no value has been assigned. |
347 ChildProcessStats() | 348 ChildProcessStats() |
348 : process_launches(0), | 349 : process_launches(0), |
349 process_crashes(0), | 350 process_crashes(0), |
350 instances(0), | 351 instances(0), |
351 loading_errors(0), | 352 loading_errors(0), |
352 process_type(content::PROCESS_TYPE_UNKNOWN) {} | 353 process_type(content::PROCESS_TYPE_UNKNOWN) {} |
353 | 354 |
354 // The number of times that the given child process has been launched | 355 // The number of times that the given child process has been launched |
355 int process_launches; | 356 int process_launches; |
356 | 357 |
357 // The number of times that the given child process has crashed | 358 // The number of times that the given child process has crashed |
358 int process_crashes; | 359 int process_crashes; |
359 | 360 |
360 // The number of instances of this child process that have been created. | 361 // The number of instances of this child process that have been created. |
361 // An instance is a DOM object rendered by this child process during a page | 362 // An instance is a DOM object rendered by this child process during a page |
362 // load. | 363 // load. |
363 int instances; | 364 int instances; |
364 | 365 |
365 // The number of times there was an error loading an instance of this child | 366 // The number of times there was an error loading an instance of this child |
366 // process. | 367 // process. |
367 int loading_errors; | 368 int loading_errors; |
368 | 369 |
369 content::ProcessType process_type; | 370 int process_type; |
370 }; | 371 }; |
371 | 372 |
372 // Handles asynchronous fetching of memory details. | 373 // Handles asynchronous fetching of memory details. |
373 // Will run the provided task after finished. | 374 // Will run the provided task after finished. |
374 class MetricsMemoryDetails : public MemoryDetails { | 375 class MetricsMemoryDetails : public MemoryDetails { |
375 public: | 376 public: |
376 explicit MetricsMemoryDetails(const base::Closure& callback) | 377 explicit MetricsMemoryDetails(const base::Closure& callback) |
377 : callback_(callback) {} | 378 : callback_(callback) {} |
378 | 379 |
379 virtual void OnDetailsAvailable() OVERRIDE { | 380 virtual void OnDetailsAvailable() OVERRIDE { |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 void MetricsService::BrowserChildProcessHostConnected( | 643 void MetricsService::BrowserChildProcessHostConnected( |
643 const content::ChildProcessData& data) { | 644 const content::ChildProcessData& data) { |
644 GetChildProcessStats(data).process_launches++; | 645 GetChildProcessStats(data).process_launches++; |
645 } | 646 } |
646 | 647 |
647 void MetricsService::BrowserChildProcessCrashed( | 648 void MetricsService::BrowserChildProcessCrashed( |
648 const content::ChildProcessData& data) { | 649 const content::ChildProcessData& data) { |
649 GetChildProcessStats(data).process_crashes++; | 650 GetChildProcessStats(data).process_crashes++; |
650 // Exclude plugin crashes from the count below because we report them via | 651 // Exclude plugin crashes from the count below because we report them via |
651 // a separate UMA metric. | 652 // a separate UMA metric. |
652 if (!IsPluginProcess(data.type)) | 653 if (!IsPluginProcess(data.process_type)) |
653 IncrementPrefValue(prefs::kStabilityChildProcessCrashCount); | 654 IncrementPrefValue(prefs::kStabilityChildProcessCrashCount); |
654 } | 655 } |
655 | 656 |
656 void MetricsService::BrowserChildProcessInstanceCreated( | 657 void MetricsService::BrowserChildProcessInstanceCreated( |
657 const content::ChildProcessData& data) { | 658 const content::ChildProcessData& data) { |
658 GetChildProcessStats(data).instances++; | 659 GetChildProcessStats(data).instances++; |
659 } | 660 } |
660 | 661 |
661 void MetricsService::Observe(int type, | 662 void MetricsService::Observe(int type, |
662 const content::NotificationSource& source, | 663 const content::NotificationSource& source, |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1001 void MetricsService::OnUserAction(const std::string& action) { | 1002 void MetricsService::OnUserAction(const std::string& action) { |
1002 if (!CanLogNotification()) | 1003 if (!CanLogNotification()) |
1003 return; | 1004 return; |
1004 | 1005 |
1005 log_manager_.current_log()->RecordUserAction(action.c_str()); | 1006 log_manager_.current_log()->RecordUserAction(action.c_str()); |
1006 HandleIdleSinceLastTransmission(false); | 1007 HandleIdleSinceLastTransmission(false); |
1007 } | 1008 } |
1008 | 1009 |
1009 void MetricsService::ReceivedProfilerData( | 1010 void MetricsService::ReceivedProfilerData( |
1010 const tracked_objects::ProcessDataSnapshot& process_data, | 1011 const tracked_objects::ProcessDataSnapshot& process_data, |
1011 content::ProcessType process_type) { | 1012 int process_type) { |
1012 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); | 1013 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); |
1013 | 1014 |
1014 // Upon the first callback, create the initial log so that we can immediately | 1015 // Upon the first callback, create the initial log so that we can immediately |
1015 // save the profiler data. | 1016 // save the profiler data. |
1016 if (!initial_log_.get()) | 1017 if (!initial_log_.get()) |
1017 initial_log_.reset(new MetricsLog(client_id_, session_id_)); | 1018 initial_log_.reset(new MetricsLog(client_id_, session_id_)); |
1018 | 1019 |
1019 initial_log_->RecordProfilerData(process_data, process_type); | 1020 initial_log_->RecordProfilerData(process_data, process_type); |
1020 } | 1021 } |
1021 | 1022 |
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1716 stats.process_type = content::PROCESS_TYPE_PLUGIN; | 1717 stats.process_type = content::PROCESS_TYPE_PLUGIN; |
1717 } else { | 1718 } else { |
1718 DCHECK(IsPluginProcess(stats.process_type)); | 1719 DCHECK(IsPluginProcess(stats.process_type)); |
1719 } | 1720 } |
1720 stats.loading_errors++; | 1721 stats.loading_errors++; |
1721 } | 1722 } |
1722 | 1723 |
1723 MetricsService::ChildProcessStats& MetricsService::GetChildProcessStats( | 1724 MetricsService::ChildProcessStats& MetricsService::GetChildProcessStats( |
1724 const content::ChildProcessData& data) { | 1725 const content::ChildProcessData& data) { |
1725 const string16& child_name = data.name; | 1726 const string16& child_name = data.name; |
1726 if (!ContainsKey(child_process_stats_buffer_, child_name)) | 1727 if (!ContainsKey(child_process_stats_buffer_, child_name)) { |
1727 child_process_stats_buffer_[child_name] = ChildProcessStats(data.type); | 1728 child_process_stats_buffer_[child_name] = |
| 1729 ChildProcessStats(data.process_type); |
| 1730 } |
1728 return child_process_stats_buffer_[child_name]; | 1731 return child_process_stats_buffer_[child_name]; |
1729 } | 1732 } |
1730 | 1733 |
1731 void MetricsService::LogKeywordCount(size_t keyword_count) { | 1734 void MetricsService::LogKeywordCount(size_t keyword_count) { |
1732 PrefService* pref = g_browser_process->local_state(); | 1735 PrefService* pref = g_browser_process->local_state(); |
1733 DCHECK(pref); | 1736 DCHECK(pref); |
1734 pref->SetInteger(prefs::kNumKeywords, static_cast<int>(keyword_count)); | 1737 pref->SetInteger(prefs::kNumKeywords, static_cast<int>(keyword_count)); |
1735 ScheduleNextStateSave(); | 1738 ScheduleNextStateSave(); |
1736 } | 1739 } |
1737 | 1740 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1840 RecordCurrentState(pref); | 1843 RecordCurrentState(pref); |
1841 } | 1844 } |
1842 | 1845 |
1843 void MetricsService::RecordCurrentState(PrefService* pref) { | 1846 void MetricsService::RecordCurrentState(PrefService* pref) { |
1844 pref->SetInt64(prefs::kStabilityLastTimestampSec, Time::Now().ToTimeT()); | 1847 pref->SetInt64(prefs::kStabilityLastTimestampSec, Time::Now().ToTimeT()); |
1845 | 1848 |
1846 RecordPluginChanges(pref); | 1849 RecordPluginChanges(pref); |
1847 } | 1850 } |
1848 | 1851 |
1849 // static | 1852 // static |
1850 bool MetricsService::IsPluginProcess(content::ProcessType type) { | 1853 bool MetricsService::IsPluginProcess(int process_type) { |
1851 return (type == content::PROCESS_TYPE_PLUGIN || | 1854 return (process_type == content::PROCESS_TYPE_PLUGIN || |
1852 type == content::PROCESS_TYPE_PPAPI_PLUGIN || | 1855 process_type == content::PROCESS_TYPE_PPAPI_PLUGIN || |
1853 type == content::PROCESS_TYPE_PPAPI_BROKER); | 1856 process_type == content::PROCESS_TYPE_PPAPI_BROKER); |
1854 } | 1857 } |
1855 | 1858 |
1856 #if defined(OS_CHROMEOS) | 1859 #if defined(OS_CHROMEOS) |
1857 void MetricsService::StartExternalMetrics() { | 1860 void MetricsService::StartExternalMetrics() { |
1858 external_metrics_ = new chromeos::ExternalMetrics; | 1861 external_metrics_ = new chromeos::ExternalMetrics; |
1859 external_metrics_->Start(); | 1862 external_metrics_->Start(); |
1860 } | 1863 } |
1861 #endif | 1864 #endif |
1862 | 1865 |
1863 // static | 1866 // static |
1864 bool MetricsServiceHelper::IsMetricsReportingEnabled() { | 1867 bool MetricsServiceHelper::IsMetricsReportingEnabled() { |
1865 bool result = false; | 1868 bool result = false; |
1866 const PrefService* local_state = g_browser_process->local_state(); | 1869 const PrefService* local_state = g_browser_process->local_state(); |
1867 if (local_state) { | 1870 if (local_state) { |
1868 const PrefService::Preference* uma_pref = | 1871 const PrefService::Preference* uma_pref = |
1869 local_state->FindPreference(prefs::kMetricsReportingEnabled); | 1872 local_state->FindPreference(prefs::kMetricsReportingEnabled); |
1870 if (uma_pref) { | 1873 if (uma_pref) { |
1871 bool success = uma_pref->GetValue()->GetAsBoolean(&result); | 1874 bool success = uma_pref->GetValue()->GetAsBoolean(&result); |
1872 DCHECK(success); | 1875 DCHECK(success); |
1873 } | 1876 } |
1874 } | 1877 } |
1875 return result; | 1878 return result; |
1876 } | 1879 } |
OLD | NEW |