| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 #include "base/metrics/histogram.h" | 162 #include "base/metrics/histogram.h" |
| 163 #include "base/string_number_conversions.h" | 163 #include "base/string_number_conversions.h" |
| 164 #include "base/threading/thread.h" | 164 #include "base/threading/thread.h" |
| 165 #include "base/threading/platform_thread.h" | 165 #include "base/threading/platform_thread.h" |
| 166 #include "base/utf_string_conversions.h" | 166 #include "base/utf_string_conversions.h" |
| 167 #include "base/values.h" | 167 #include "base/values.h" |
| 168 #include "chrome/browser/bookmarks/bookmark_model.h" | 168 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 169 #include "chrome/browser/browser_list.h" | 169 #include "chrome/browser/browser_list.h" |
| 170 #include "chrome/browser/browser_process.h" | 170 #include "chrome/browser/browser_process.h" |
| 171 #include "chrome/browser/load_notification_details.h" | 171 #include "chrome/browser/load_notification_details.h" |
| 172 #include "chrome/browser/memory_details.h" | |
| 173 #include "chrome/browser/metrics/histogram_synchronizer.h" | 172 #include "chrome/browser/metrics/histogram_synchronizer.h" |
| 174 #include "chrome/browser/metrics/metrics_log.h" | 173 #include "chrome/browser/metrics/metrics_log.h" |
| 175 #include "chrome/browser/prefs/pref_service.h" | 174 #include "chrome/browser/prefs/pref_service.h" |
| 176 #include "chrome/browser/profiles/profile.h" | 175 #include "chrome/browser/profiles/profile.h" |
| 177 #include "chrome/browser/search_engines/template_url_model.h" | 176 #include "chrome/browser/search_engines/template_url_model.h" |
| 178 #include "chrome/common/child_process_info.h" | 177 #include "chrome/common/child_process_info.h" |
| 179 #include "chrome/common/child_process_logging.h" | 178 #include "chrome/common/child_process_logging.h" |
| 180 #include "chrome/common/chrome_switches.h" | 179 #include "chrome/common/chrome_switches.h" |
| 181 #include "chrome/common/guid.h" | 180 #include "chrome/common/guid.h" |
| 182 #include "chrome/common/notification_service.h" | 181 #include "chrome/common/notification_service.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 int process_crashes; | 308 int process_crashes; |
| 310 | 309 |
| 311 // The number of instances of this child process that have been created. | 310 // The number of instances of this child process that have been created. |
| 312 // An instance is a DOM object rendered by this child process during a page | 311 // An instance is a DOM object rendered by this child process during a page |
| 313 // load. | 312 // load. |
| 314 int instances; | 313 int instances; |
| 315 | 314 |
| 316 ChildProcessInfo::ProcessType process_type; | 315 ChildProcessInfo::ProcessType process_type; |
| 317 }; | 316 }; |
| 318 | 317 |
| 319 // Handles asynchronous fetching of memory details. | |
| 320 // Will run the provided task after finished. | |
| 321 class MetricsMemoryDetails : public MemoryDetails { | |
| 322 public: | |
| 323 explicit MetricsMemoryDetails(Task* completion) : completion_(completion) {} | |
| 324 | |
| 325 virtual void OnDetailsAvailable() { | |
| 326 MessageLoop::current()->PostTask(FROM_HERE, completion_); | |
| 327 } | |
| 328 | |
| 329 private: | |
| 330 ~MetricsMemoryDetails() {} | |
| 331 | |
| 332 Task* completion_; | |
| 333 DISALLOW_COPY_AND_ASSIGN(MetricsMemoryDetails); | |
| 334 }; | |
| 335 | |
| 336 class MetricsService::InitTaskComplete : public Task { | 318 class MetricsService::InitTaskComplete : public Task { |
| 337 public: | 319 public: |
| 338 explicit InitTaskComplete( | 320 explicit InitTaskComplete( |
| 339 const std::string& hardware_class, | 321 const std::string& hardware_class, |
| 340 const std::vector<webkit::npapi::WebPluginInfo>& plugins) | 322 const std::vector<webkit::npapi::WebPluginInfo>& plugins) |
| 341 : hardware_class_(hardware_class), plugins_(plugins) {} | 323 : hardware_class_(hardware_class), plugins_(plugins) {} |
| 342 | 324 |
| 343 virtual void Run() { | 325 virtual void Run() { |
| 344 g_browser_process->metrics_service()->OnInitTaskComplete( | 326 g_browser_process->metrics_service()->OnInitTaskComplete( |
| 345 hardware_class_, plugins_); | 327 hardware_class_, plugins_); |
| (...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 965 // If timer_pending is true because the fetch is waiting for a response, | 947 // If timer_pending is true because the fetch is waiting for a response, |
| 966 // we return for now and let the response handler start the timer. | 948 // we return for now and let the response handler start the timer. |
| 967 if (timer_pending_) | 949 if (timer_pending_) |
| 968 return; | 950 return; |
| 969 | 951 |
| 970 // Before starting the timer, set timer_pending_ to true. | 952 // Before starting the timer, set timer_pending_ to true. |
| 971 timer_pending_ = true; | 953 timer_pending_ = true; |
| 972 | 954 |
| 973 // Right before the UMA transmission gets started, there's one more thing we'd | 955 // Right before the UMA transmission gets started, there's one more thing we'd |
| 974 // like to record: the histogram of memory usage, so we spawn a task to | 956 // like to record: the histogram of memory usage, so we spawn a task to |
| 975 // collect the memory details and when that task is finished, it will call | 957 // collect histograms from all the renderers and when that task is finished, |
| 976 // OnMemoryDetailCollectionDone, which will call HistogramSynchronization to | 958 // it will call OnHistogramSynchronizationDone to continue processing. |
| 977 // collect histograms from all renderers and then we will call | |
| 978 // OnHistogramSynchronizationDone to continue processing. | |
| 979 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 959 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 980 log_sender_factory_. | 960 log_sender_factory_. |
| 981 NewRunnableMethod(&MetricsService::LogTransmissionTimerDone), | 961 NewRunnableMethod(&MetricsService::LogTransmissionTimerDone), |
| 982 interlog_duration_.InMilliseconds()); | 962 interlog_duration_.InMilliseconds()); |
| 983 } | 963 } |
| 984 | 964 |
| 985 void MetricsService::LogTransmissionTimerDone() { | 965 void MetricsService::LogTransmissionTimerDone() { |
| 986 Task* task = log_sender_factory_. | |
| 987 NewRunnableMethod(&MetricsService::OnMemoryDetailCollectionDone); | |
| 988 | |
| 989 scoped_refptr<MetricsMemoryDetails> details(new MetricsMemoryDetails(task)); | |
| 990 details->StartFetch(); | |
| 991 | |
| 992 // Collect WebCore cache information to put into a histogram. | |
| 993 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); | |
| 994 !i.IsAtEnd(); i.Advance()) | |
| 995 i.GetCurrentValue()->Send(new ViewMsg_GetCacheResourceStats()); | |
| 996 } | |
| 997 | |
| 998 void MetricsService::OnMemoryDetailCollectionDone() { | |
| 999 DCHECK(IsSingleThreaded()); | 966 DCHECK(IsSingleThreaded()); |
| 1000 | 967 |
| 1001 // HistogramSynchronizer will Collect histograms from all renderers and it | 968 // HistogramSynchronizer will Collect histograms from all renderers and it |
| 1002 // will call OnHistogramSynchronizationDone (if wait time elapses before it | 969 // will call OnHistogramSynchronizationDone (if wait time elapses before it |
| 1003 // heard from all renderers, then also it will call | 970 // heard from all renderers, then also it will call |
| 1004 // OnHistogramSynchronizationDone). | 971 // OnHistogramSynchronizationDone). |
| 1005 | 972 |
| 1006 // Create a callback_task for OnHistogramSynchronizationDone. | 973 // Create a callback_task for OnHistogramSynchronizationDone. |
| 1007 Task* callback_task = log_sender_factory_.NewRunnableMethod( | 974 Task* callback_task = log_sender_factory_.NewRunnableMethod( |
| 1008 &MetricsService::OnHistogramSynchronizationDone); | 975 &MetricsService::OnHistogramSynchronizationDone); |
| 1009 | 976 |
| 1010 // Set up the callback to task to call after we receive histograms from all | 977 // Set up the callback to task to call after we receive histograms from all |
| 1011 // renderer processes. Wait time specifies how long to wait before absolutely | 978 // renderer processes. Wait time specifies how long to wait before absolutely |
| 1012 // calling us back on the task. | 979 // calling us back on the task. |
| 1013 HistogramSynchronizer::FetchRendererHistogramsAsynchronously( | 980 HistogramSynchronizer::FetchRendererHistogramsAsynchronously( |
| 1014 MessageLoop::current(), callback_task, | 981 MessageLoop::current(), callback_task, |
| 1015 kMaxHistogramGatheringWaitDuration); | 982 kMaxHistogramGatheringWaitDuration); |
| 983 |
| 984 // Collect WebCore cache information to put into a histogram. |
| 985 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); |
| 986 !i.IsAtEnd(); i.Advance()) |
| 987 i.GetCurrentValue()->Send(new ViewMsg_GetCacheResourceStats()); |
| 1016 } | 988 } |
| 1017 | 989 |
| 1018 void MetricsService::OnHistogramSynchronizationDone() { | 990 void MetricsService::OnHistogramSynchronizationDone() { |
| 1019 DCHECK(IsSingleThreaded()); | 991 DCHECK(IsSingleThreaded()); |
| 1020 | 992 |
| 1021 // This function should only be called via timer, so timer_pending_ | 993 // This function should only be called via timer, so timer_pending_ |
| 1022 // should be true. | 994 // should be true. |
| 1023 DCHECK(timer_pending_); | 995 DCHECK(timer_pending_); |
| 1024 timer_pending_ = false; | 996 timer_pending_ = false; |
| 1025 | 997 |
| (...skipping 912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1938 thread_id = base::PlatformThread::CurrentId(); | 1910 thread_id = base::PlatformThread::CurrentId(); |
| 1939 return base::PlatformThread::CurrentId() == thread_id; | 1911 return base::PlatformThread::CurrentId() == thread_id; |
| 1940 } | 1912 } |
| 1941 | 1913 |
| 1942 #if defined(OS_CHROMEOS) | 1914 #if defined(OS_CHROMEOS) |
| 1943 void MetricsService::StartExternalMetrics() { | 1915 void MetricsService::StartExternalMetrics() { |
| 1944 external_metrics_ = new chromeos::ExternalMetrics; | 1916 external_metrics_ = new chromeos::ExternalMetrics; |
| 1945 external_metrics_->Start(); | 1917 external_metrics_->Start(); |
| 1946 } | 1918 } |
| 1947 #endif | 1919 #endif |
| OLD | NEW |