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

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

Issue 9702015: [UMA] Add performance profile data to UMA uploads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Extract unrelated changes to separate CLs Created 8 years, 8 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) 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 #include "chrome/browser/metrics/metrics_service.h" 145 #include "chrome/browser/metrics/metrics_service.h"
146 146
147 #include "base/bind.h" 147 #include "base/bind.h"
148 #include "base/callback.h" 148 #include "base/callback.h"
149 #include "base/command_line.h" 149 #include "base/command_line.h"
150 #include "base/md5.h" 150 #include "base/md5.h"
151 #include "base/metrics/histogram.h" 151 #include "base/metrics/histogram.h"
152 #include "base/string_number_conversions.h" 152 #include "base/string_number_conversions.h"
153 #include "base/threading/platform_thread.h" 153 #include "base/threading/platform_thread.h"
154 #include "base/threading/thread.h" 154 #include "base/threading/thread.h"
155 #include "base/tracked_objects.h"
155 #include "base/utf_string_conversions.h" 156 #include "base/utf_string_conversions.h"
156 #include "base/values.h" 157 #include "base/values.h"
157 #include "chrome/browser/bookmarks/bookmark_model.h" 158 #include "chrome/browser/bookmarks/bookmark_model.h"
158 #include "chrome/browser/browser_process.h" 159 #include "chrome/browser/browser_process.h"
159 #include "chrome/browser/extensions/extension_service.h" 160 #include "chrome/browser/extensions/extension_service.h"
160 #include "chrome/browser/extensions/process_map.h" 161 #include "chrome/browser/extensions/process_map.h"
161 #include "chrome/browser/memory_details.h" 162 #include "chrome/browser/memory_details.h"
162 #include "chrome/browser/metrics/histogram_synchronizer.h" 163 #include "chrome/browser/metrics/histogram_synchronizer.h"
163 #include "chrome/browser/metrics/metrics_log.h" 164 #include "chrome/browser/metrics/metrics_log.h"
164 #include "chrome/browser/metrics/metrics_log_serializer.h" 165 #include "chrome/browser/metrics/metrics_log_serializer.h"
165 #include "chrome/browser/metrics/metrics_reporting_scheduler.h" 166 #include "chrome/browser/metrics/metrics_reporting_scheduler.h"
167 #include "chrome/browser/metrics/tracking_synchronizer.h"
166 #include "chrome/browser/net/http_pipelining_compatibility_client.h" 168 #include "chrome/browser/net/http_pipelining_compatibility_client.h"
167 #include "chrome/browser/net/network_stats.h" 169 #include "chrome/browser/net/network_stats.h"
168 #include "chrome/browser/prefs/pref_service.h" 170 #include "chrome/browser/prefs/pref_service.h"
169 #include "chrome/browser/prefs/scoped_user_pref_update.h" 171 #include "chrome/browser/prefs/scoped_user_pref_update.h"
170 #include "chrome/browser/profiles/profile.h" 172 #include "chrome/browser/profiles/profile.h"
171 #include "chrome/browser/search_engines/template_url_service.h" 173 #include "chrome/browser/search_engines/template_url_service.h"
172 #include "chrome/browser/ui/browser_list.h" 174 #include "chrome/browser/ui/browser_list.h"
173 #include "chrome/common/child_process_logging.h" 175 #include "chrome/common/child_process_logging.h"
174 #include "chrome/common/chrome_notification_types.h" 176 #include "chrome/common/chrome_notification_types.h"
175 #include "chrome/common/chrome_switches.h" 177 #include "chrome/common/chrome_switches.h"
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 "hardware_class", &hardware_class); 768 "hardware_class", &hardware_class);
767 #endif // OS_CHROMEOS 769 #endif // OS_CHROMEOS
768 770
769 target_loop->PostTask(FROM_HERE, 771 target_loop->PostTask(FROM_HERE,
770 base::Bind(&MetricsService::OnInitTaskGotHardwareClass, 772 base::Bind(&MetricsService::OnInitTaskGotHardwareClass,
771 self, hardware_class)); 773 self, hardware_class));
772 } 774 }
773 775
774 void MetricsService::OnInitTaskGotHardwareClass( 776 void MetricsService::OnInitTaskGotHardwareClass(
775 const std::string& hardware_class) { 777 const std::string& hardware_class) {
776 DCHECK_EQ(state_, INIT_TASK_SCHEDULED); 778 DCHECK_EQ(INIT_TASK_SCHEDULED, state_);
777 hardware_class_ = hardware_class; 779 hardware_class_ = hardware_class;
778 780
779 // Start the next part of the init task: loading plugin information. 781 // Start the next part of the init task: loading plugin information.
780 PluginService::GetInstance()->GetPlugins( 782 PluginService::GetInstance()->GetPlugins(
781 base::Bind(&MetricsService::OnInitTaskGotPluginInfo, 783 base::Bind(&MetricsService::OnInitTaskGotPluginInfo,
782 self_ptr_factory_.GetWeakPtr())); 784 self_ptr_factory_.GetWeakPtr()));
783 } 785 }
784 786
785 void MetricsService::OnInitTaskGotPluginInfo( 787 void MetricsService::OnInitTaskGotPluginInfo(
786 const std::vector<webkit::WebPluginInfo>& plugins) { 788 const std::vector<webkit::WebPluginInfo>& plugins) {
787 DCHECK_EQ(state_, INIT_TASK_SCHEDULED); 789 DCHECK_EQ(INIT_TASK_SCHEDULED, state_);
788 plugins_ = plugins; 790 plugins_ = plugins;
789 791
792 // Start the next part of the init task: fetching performance data. This will
793 // call into |FinishedReceivingProfilerData()| when the task completes.
794 chrome_browser_metrics::TrackingSynchronizer::FetchProfilerDataAsynchronously(
795 self_ptr_factory_.GetWeakPtr());
796 }
797
798 void MetricsService::ReceivedProfilerData(
799 const tracked_objects::ProcessDataSnapshot& process_data,
800 content::ProcessType process_type) {
801 DCHECK_EQ(INIT_TASK_SCHEDULED, state_);
802
803 // Upon the first callback, create the initial log so that we can immediately
804 // save the profiler data.
805 if (!initial_log_.get())
806 initial_log_.reset(new MetricsLog(client_id_, session_id_));
807
808 initial_log_->RecordProfilerData(process_data, process_type);
809 }
810
811 void MetricsService::FinishedReceivingProfilerData() {
812 DCHECK_EQ(INIT_TASK_SCHEDULED, state_);
813
790 io_thread_ = g_browser_process->io_thread(); 814 io_thread_ = g_browser_process->io_thread();
791 if (state_ == INIT_TASK_SCHEDULED) 815 state_ = INIT_TASK_DONE;
792 state_ = INIT_TASK_DONE;
793 } 816 }
794 817
795 std::string MetricsService::GenerateClientID() { 818 std::string MetricsService::GenerateClientID() {
796 return guid::GenerateGUID(); 819 return guid::GenerateGUID();
797 } 820 }
798 821
799 //------------------------------------------------------------------------------ 822 //------------------------------------------------------------------------------
800 // State save methods 823 // State save methods
801 824
802 void MetricsService::ScheduleNextStateSave() { 825 void MetricsService::ScheduleNextStateSave() {
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 case INITIALIZED: 1031 case INITIALIZED:
1009 case INIT_TASK_SCHEDULED: // We should be further along by now. 1032 case INIT_TASK_SCHEDULED: // We should be further along by now.
1010 DCHECK(false); 1033 DCHECK(false);
1011 return; 1034 return;
1012 1035
1013 case INIT_TASK_DONE: 1036 case INIT_TASK_DONE:
1014 // We need to wait for the initial log to be ready before sending 1037 // We need to wait for the initial log to be ready before sending
1015 // anything, because the server will tell us whether it wants to hear 1038 // anything, because the server will tell us whether it wants to hear
1016 // from us. 1039 // from us.
1017 PrepareInitialLog(); 1040 PrepareInitialLog();
1018 DCHECK(state_ == INIT_TASK_DONE); 1041 DCHECK_EQ(INIT_TASK_DONE, state_);
1019 log_manager_.LoadPersistedUnsentLogs(); 1042 log_manager_.LoadPersistedUnsentLogs();
1020 state_ = INITIAL_LOG_READY; 1043 state_ = INITIAL_LOG_READY;
1021 break; 1044 break;
1022 1045
1023 case SENDING_OLD_LOGS: 1046 case SENDING_OLD_LOGS:
1024 if (log_manager_.has_unsent_logs()) { 1047 if (log_manager_.has_unsent_logs()) {
1025 log_manager_.StageNextLogForUpload(); 1048 log_manager_.StageNextLogForUpload();
1026 break; 1049 break;
1027 } 1050 }
1028 state_ = SENDING_CURRENT_LOGS; 1051 state_ = SENDING_CURRENT_LOGS;
1029 // Fall through. 1052 // Fall through.
1030 1053
1031 case SENDING_CURRENT_LOGS: 1054 case SENDING_CURRENT_LOGS:
1032 StopRecording(); 1055 StopRecording();
1033 StartRecording(); 1056 StartRecording();
1034 log_manager_.StageNextLogForUpload(); 1057 log_manager_.StageNextLogForUpload();
1035 break; 1058 break;
1036 1059
1037 default: 1060 default:
1038 NOTREACHED(); 1061 NOTREACHED();
1039 return; 1062 return;
1040 } 1063 }
1041 1064
1042 DCHECK(log_manager_.has_staged_log()); 1065 DCHECK(log_manager_.has_staged_log());
1043 } 1066 }
1044 1067
1045 void MetricsService::PrepareInitialLog() { 1068 void MetricsService::PrepareInitialLog() {
1046 DCHECK(state_ == INIT_TASK_DONE); 1069 DCHECK_EQ(INIT_TASK_DONE, state_);
1047 1070
1048 MetricsLog* log = new MetricsLog(client_id_, session_id_); 1071 DCHECK(initial_log_.get());
1049 log->set_hardware_class(hardware_class_); // Adds to initial log. 1072 initial_log_->set_hardware_class(hardware_class_);
1050 log->RecordEnvironment(plugins_, profile_dictionary_.get()); 1073 initial_log_->RecordEnvironment(plugins_, profile_dictionary_.get());
1051 1074
1052 // Histograms only get written to the current log, so make the new log current 1075 // Histograms only get written to the current log, so make the new log current
1053 // before writing them. 1076 // before writing them.
1054 log_manager_.PauseCurrentLog(); 1077 log_manager_.PauseCurrentLog();
1055 log_manager_.BeginLoggingWithLog(log, MetricsLogManager::INITIAL_LOG); 1078 log_manager_.BeginLoggingWithLog(initial_log_.release(),
1079 MetricsLogManager::INITIAL_LOG);
1056 RecordCurrentHistograms(); 1080 RecordCurrentHistograms();
1057 log_manager_.FinishCurrentLog(); 1081 log_manager_.FinishCurrentLog();
1058 log_manager_.ResumePausedLog(); 1082 log_manager_.ResumePausedLog();
1059 1083
1060 DCHECK(!log_manager_.has_staged_log()); 1084 DCHECK(!log_manager_.has_staged_log());
1061 log_manager_.StageNextLogForUpload(); 1085 log_manager_.StageNextLogForUpload();
1062 } 1086 }
1063 1087
1064 void MetricsService::StoreUnsentLogs() { 1088 void MetricsService::StoreUnsentLogs() {
1065 if (state_ < INITIAL_LOG_READY) 1089 if (state_ < INITIAL_LOG_READY)
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1250 break; 1274 break;
1251 1275
1252 default: 1276 default:
1253 NOTREACHED(); 1277 NOTREACHED();
1254 break; 1278 break;
1255 } 1279 }
1256 1280
1257 log_manager_.DiscardStagedLog(); 1281 log_manager_.DiscardStagedLog();
1258 1282
1259 if (log_manager_.has_unsent_logs()) 1283 if (log_manager_.has_unsent_logs())
1260 DCHECK(state_ < SENDING_CURRENT_LOGS); 1284 DCHECK_LT(state_, SENDING_CURRENT_LOGS);
1261 } 1285 }
1262 1286
1263 // Error 400 indicates a problem with the log, not with the server, so 1287 // Error 400 indicates a problem with the log, not with the server, so
1264 // don't consider that a sign that the server is in trouble. 1288 // don't consider that a sign that the server is in trouble.
1265 bool server_is_healthy = upload_succeeded || response_code_ == 400; 1289 bool server_is_healthy = upload_succeeded || response_code_ == 400;
1266 1290
1267 scheduler_->UploadFinished(server_is_healthy, 1291 scheduler_->UploadFinished(server_is_healthy,
1268 log_manager_.has_unsent_logs()); 1292 log_manager_.has_unsent_logs());
1269 1293
1270 // Collect network stats if UMA upload succeeded. 1294 // Collect network stats if UMA upload succeeded.
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
1670 if (local_state) { 1694 if (local_state) {
1671 const PrefService::Preference* uma_pref = 1695 const PrefService::Preference* uma_pref =
1672 local_state->FindPreference(prefs::kMetricsReportingEnabled); 1696 local_state->FindPreference(prefs::kMetricsReportingEnabled);
1673 if (uma_pref) { 1697 if (uma_pref) {
1674 bool success = uma_pref->GetValue()->GetAsBoolean(&result); 1698 bool success = uma_pref->GetValue()->GetAsBoolean(&result);
1675 DCHECK(success); 1699 DCHECK(success);
1676 } 1700 }
1677 } 1701 }
1678 return result; 1702 return result;
1679 } 1703 }
OLDNEW
« chrome/browser/metrics/metrics_log.cc ('K') | « chrome/browser/metrics/metrics_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698