Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: chrome/browser/metrics/metrics_service.cc

Issue 42496: histogram synchronizer code between renderer and browser for UMA and about_histogram (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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 6
7 //------------------------------------------------------------------------------ 7 //------------------------------------------------------------------------------
8 // Description of the life cycle of a instance of MetricsService. 8 // Description of the life cycle of a instance of MetricsService.
9 // 9 //
10 // OVERVIEW 10 // OVERVIEW
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 #include "chrome/browser/browser_process.h" 174 #include "chrome/browser/browser_process.h"
175 #include "chrome/browser/load_notification_details.h" 175 #include "chrome/browser/load_notification_details.h"
176 #include "chrome/browser/memory_details.h" 176 #include "chrome/browser/memory_details.h"
177 #include "chrome/browser/plugin_service.h" 177 #include "chrome/browser/plugin_service.h"
178 #include "chrome/browser/profile.h" 178 #include "chrome/browser/profile.h"
179 #include "chrome/browser/renderer_host/render_process_host.h" 179 #include "chrome/browser/renderer_host/render_process_host.h"
180 #include "chrome/browser/search_engines/template_url.h" 180 #include "chrome/browser/search_engines/template_url.h"
181 #include "chrome/browser/search_engines/template_url_model.h" 181 #include "chrome/browser/search_engines/template_url_model.h"
182 #include "chrome/common/child_process_info.h" 182 #include "chrome/common/child_process_info.h"
183 #include "chrome/common/chrome_paths.h" 183 #include "chrome/common/chrome_paths.h"
184 #include "chrome/common/histogram_synchronizer.h"
184 #include "chrome/common/libxml_utils.h" 185 #include "chrome/common/libxml_utils.h"
185 #include "chrome/common/notification_service.h" 186 #include "chrome/common/notification_service.h"
186 #include "chrome/common/pref_names.h" 187 #include "chrome/common/pref_names.h"
187 #include "chrome/common/pref_service.h" 188 #include "chrome/common/pref_service.h"
188 #include "chrome/common/render_messages.h" 189 #include "chrome/common/render_messages.h"
189 #include "googleurl/src/gurl.h" 190 #include "googleurl/src/gurl.h"
190 #include "net/base/load_flags.h" 191 #include "net/base/load_flags.h"
191 #include "third_party/bzip2/bzlib.h" 192 #include "third_party/bzip2/bzlib.h"
192 193
193 #if defined(OS_POSIX) 194 #if defined(OS_POSIX)
194 // TODO(port): Move these headers above as they are ported. 195 // TODO(port): Move these headers above as they are ported.
195 #include "chrome/common/temp_scaffolding_stubs.h" 196 #include "chrome/common/temp_scaffolding_stubs.h"
196 #else 197 #else
197 #include "chrome/installer/util/browser_distribution.h" 198 #include "chrome/installer/util/browser_distribution.h"
198 #include "chrome/installer/util/google_update_settings.h" 199 #include "chrome/installer/util/google_update_settings.h"
199 #endif 200 #endif
200 201
201 using base::Time; 202 using base::Time;
202 using base::TimeDelta; 203 using base::TimeDelta;
203 204
204 // Check to see that we're being called on only one thread. 205 // Check to see that we're being called on only one thread.
205 static bool IsSingleThreaded(); 206 static bool IsSingleThreaded();
206 207
207 static const char kMetricsType[] = "application/vnd.mozilla.metrics.bz2"; 208 static const char kMetricsType[] = "application/vnd.mozilla.metrics.bz2";
208 209
209 // The delay, in seconds, after startup before sending the first log message. 210 // The delay, in seconds, after startup before sending the first log message.
210 static const int kInitialInterlogDuration = 60; // one minute 211 static const int kInitialInterlogDuration = 60; // one minute
211 212
213 // This specifies the amount of time to wait for all renderers to send their
214 // data.
215 static const int kMaxHistogramGatheringWaitDuration = 3000; // 3 seconds
216
212 // The default maximum number of events in a log uploaded to the UMA server. 217 // The default maximum number of events in a log uploaded to the UMA server.
213 static const int kInitialEventLimit = 2400; 218 static const int kInitialEventLimit = 2400;
214 219
215 // If an upload fails, and the transmission was over this byte count, then we 220 // If an upload fails, and the transmission was over this byte count, then we
216 // will discard the log, and not try to retransmit it. We also don't persist 221 // will discard the log, and not try to retransmit it. We also don't persist
217 // the log to the prefs for transmission during the next chrome session if this 222 // the log to the prefs for transmission during the next chrome session if this
218 // limit is exceeded. 223 // limit is exceeded.
219 static const int kUploadLogAvoidRetransmitSize = 50000; 224 static const int kUploadLogAvoidRetransmitSize = 50000;
220 225
221 // When we have logs from previous Chrome sessions to send, how long should we 226 // When we have logs from previous Chrome sessions to send, how long should we
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 // If timer_pending is true because the fetch is waiting for a response, 888 // If timer_pending is true because the fetch is waiting for a response,
884 // we return for now and let the response handler start the timer. 889 // we return for now and let the response handler start the timer.
885 if (timer_pending_) 890 if (timer_pending_)
886 return; 891 return;
887 892
888 // Before starting the timer, set timer_pending_ to true. 893 // Before starting the timer, set timer_pending_ to true.
889 timer_pending_ = true; 894 timer_pending_ = true;
890 895
891 // Right before the UMA transmission gets started, there's one more thing we'd 896 // Right before the UMA transmission gets started, there's one more thing we'd
892 // like to record: the histogram of memory usage, so we spawn a task to 897 // like to record: the histogram of memory usage, so we spawn a task to
893 // collect the memory details and when that task is finished, we arrange for 898 // collect the memory details and when that task is finished, it will call
894 // TryToStartTransmission to take over. 899 // OnMemoryDetailCollectionDone, which will call HistogramSynchronization to
900 // collect histograms from all renderers and then we will call
901 // OnHistogramSynchronizationDone to continue processing.
895 MessageLoop::current()->PostDelayedTask(FROM_HERE, 902 MessageLoop::current()->PostDelayedTask(FROM_HERE,
896 log_sender_factory_. 903 log_sender_factory_.
897 NewRunnableMethod(&MetricsService::CollectMemoryDetails), 904 NewRunnableMethod(&MetricsService::LogTransmissionTimerDone),
898 static_cast<int>(interlog_duration_.InMilliseconds())); 905 static_cast<int>(interlog_duration_.InMilliseconds()));
899 } 906 }
900 907
901 void MetricsService::TryToStartTransmission() { 908 void MetricsService::LogTransmissionTimerDone() {
909 Task* task = log_sender_factory_.
910 NewRunnableMethod(&MetricsService::OnMemoryDetailCollectionDone);
911
912 MetricsMemoryDetails* details = new MetricsMemoryDetails(task);
913 details->StartFetch();
914
915 // Collect WebCore cache information to put into a histogram.
916 for (RenderProcessHost::iterator it = RenderProcessHost::begin();
917 it != RenderProcessHost::end(); ++it) {
918 it->second->Send(new ViewMsg_GetCacheResourceStats());
919 }
920 }
921
922 void MetricsService::OnMemoryDetailCollectionDone() {
923 DCHECK(IsSingleThreaded());
924
925 // HistogramSynchronizer will Collect histograms from all renderers and it
926 // will call OnHistogramSynchronizationDone (if wait time elapses before it
927 // heard from all renderers, then also it will call
928 // OnHistogramSynchronizationDone).
929
930 // Create a callback_task for OnHistogramSynchronizationDone.
931 Task* callback_task = log_sender_factory_.NewRunnableMethod(
932 &MetricsService::OnHistogramSynchronizationDone);
933
934 // Set up the callback to task to call after we receive histograms from all
935 // renderer processes. Wait time specifies how long to wait before absolutely
936 // calling us back on the task.
937 HistogramSynchronizer::FetchRendererHistogramsAsynchronously(
938 MessageLoop::current(), callback_task,
939 kMaxHistogramGatheringWaitDuration);
940 }
941
942 void MetricsService::OnHistogramSynchronizationDone() {
902 DCHECK(IsSingleThreaded()); 943 DCHECK(IsSingleThreaded());
903 944
904 // This function should only be called via timer, so timer_pending_ 945 // This function should only be called via timer, so timer_pending_
905 // should be true. 946 // should be true.
906 DCHECK(timer_pending_); 947 DCHECK(timer_pending_);
907 timer_pending_ = false; 948 timer_pending_ = false;
908 949
909 DCHECK(!current_fetch_.get()); 950 DCHECK(!current_fetch_.get());
910 951
911 // If we're getting no notifications, then the log won't have much in it, and 952 // If we're getting no notifications, then the log won't have much in it, and
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 case SEND_OLD_INITIAL_LOGS: 1078 case SEND_OLD_INITIAL_LOGS:
1038 case SENDING_OLD_LOGS: 1079 case SENDING_OLD_LOGS:
1039 return true; 1080 return true;
1040 1081
1041 case SENDING_CURRENT_LOGS: 1082 case SENDING_CURRENT_LOGS:
1042 default: 1083 default:
1043 return false; 1084 return false;
1044 } 1085 }
1045 } 1086 }
1046 1087
1047 void MetricsService::CollectMemoryDetails() {
1048 Task* task = log_sender_factory_.
1049 NewRunnableMethod(&MetricsService::TryToStartTransmission);
1050 MetricsMemoryDetails* details = new MetricsMemoryDetails(task);
1051 details->StartFetch();
1052
1053 // Collect WebCore cache information to put into a histogram.
1054 for (RenderProcessHost::iterator it = RenderProcessHost::begin();
1055 it != RenderProcessHost::end(); ++it) {
1056 it->second->Send(new ViewMsg_GetCacheResourceStats());
1057 }
1058 }
1059
1060 void MetricsService::PrepareInitialLog() { 1088 void MetricsService::PrepareInitialLog() {
1061 DCHECK(state_ == PLUGIN_LIST_ARRIVED); 1089 DCHECK(state_ == PLUGIN_LIST_ARRIVED);
1062 std::vector<WebPluginInfo> plugins; 1090 std::vector<WebPluginInfo> plugins;
1063 PluginService::GetInstance()->GetPlugins(false, &plugins); 1091 PluginService::GetInstance()->GetPlugins(false, &plugins);
1064 1092
1065 MetricsLog* log = new MetricsLog(client_id_, session_id_); 1093 MetricsLog* log = new MetricsLog(client_id_, session_id_);
1066 log->RecordEnvironment(plugins, profile_dictionary_.get()); 1094 log->RecordEnvironment(plugins, profile_dictionary_.get());
1067 1095
1068 // Histograms only get written to current_log_, so setup for the write. 1096 // Histograms only get written to current_log_, so setup for the write.
1069 MetricsLog* save_log = current_log_; 1097 MetricsLog* save_log = current_log_;
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after
1783 pref->SetBoolean(path, value); 1811 pref->SetBoolean(path, value);
1784 RecordCurrentState(pref); 1812 RecordCurrentState(pref);
1785 } 1813 }
1786 1814
1787 void MetricsService::RecordCurrentState(PrefService* pref) { 1815 void MetricsService::RecordCurrentState(PrefService* pref) {
1788 pref->SetInt64(prefs::kStabilityLastTimestampSec, Time::Now().ToTimeT()); 1816 pref->SetInt64(prefs::kStabilityLastTimestampSec, Time::Now().ToTimeT());
1789 1817
1790 RecordPluginChanges(pref); 1818 RecordPluginChanges(pref);
1791 } 1819 }
1792 1820
1793 void MetricsService::CollectRendererHistograms() {
1794 for (RenderProcessHost::iterator it = RenderProcessHost::begin();
1795 it != RenderProcessHost::end(); ++it) {
1796 it->second->Send(new ViewMsg_GetRendererHistograms());
1797 }
1798 }
1799
1800 void MetricsService::RecordCurrentHistograms() { 1821 void MetricsService::RecordCurrentHistograms() {
1801 DCHECK(current_log_); 1822 DCHECK(current_log_);
1802 1823
1803 CollectRendererHistograms();
1804
1805 // TODO(raman): Delay the metrics collection activities until we get all the
1806 // updates from the renderers, or we time out (1 second? 3 seconds?).
1807
1808 StatisticsRecorder::Histograms histograms; 1824 StatisticsRecorder::Histograms histograms;
1809 StatisticsRecorder::GetHistograms(&histograms); 1825 StatisticsRecorder::GetHistograms(&histograms);
1810 for (StatisticsRecorder::Histograms::iterator it = histograms.begin(); 1826 for (StatisticsRecorder::Histograms::iterator it = histograms.begin();
1811 histograms.end() != it; 1827 histograms.end() != it;
1812 ++it) { 1828 ++it) {
1813 if ((*it)->flags() & kUmaTargetedHistogramFlag) 1829 if ((*it)->flags() & kUmaTargetedHistogramFlag)
1814 // TODO(petersont): Only record historgrams if they are not precluded by 1830 // TODO(petersont): Only record historgrams if they are not precluded by
1815 // the UMA response data. 1831 // the UMA response data.
1816 // Bug http://code.google.com/p/chromium/issues/detail?id=2739. 1832 // Bug http://code.google.com/p/chromium/issues/detail?id=2739.
1817 RecordHistogram(**it); 1833 RecordHistogram(**it);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1871 L"." + key; 1887 L"." + key;
1872 prof_prefs->SetInteger(pref_key.c_str(), value); 1888 prof_prefs->SetInteger(pref_key.c_str(), value);
1873 } 1889 }
1874 1890
1875 static bool IsSingleThreaded() { 1891 static bool IsSingleThreaded() {
1876 static PlatformThreadId thread_id = 0; 1892 static PlatformThreadId thread_id = 0;
1877 if (!thread_id) 1893 if (!thread_id)
1878 thread_id = PlatformThread::CurrentId(); 1894 thread_id = PlatformThread::CurrentId();
1879 return PlatformThread::CurrentId() == thread_id; 1895 return PlatformThread::CurrentId() == thread_id;
1880 } 1896 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/metrics_service.h ('k') | chrome/browser/renderer_host/resource_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698