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

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: Add tests 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
814 // TODO(isherman): I'm not following why the IO thread needs to be stored to a
815 // member variable at the end of the init task. Reviewers, do you know?
Ilya Sherman 2012/04/18 01:18:44 (?)
jar (doing other things) 2012/04/18 03:18:45 This seems a bit wrongish. I think we generally t
Ilya Sherman 2012/04/18 21:46:15 Ok, split this off to https://chromiumcodereview.a
790 io_thread_ = g_browser_process->io_thread(); 816 io_thread_ = g_browser_process->io_thread();
791 if (state_ == INIT_TASK_SCHEDULED) 817 state_ = INIT_TASK_DONE;
792 state_ = INIT_TASK_DONE;
793 } 818 }
794 819
795 std::string MetricsService::GenerateClientID() { 820 std::string MetricsService::GenerateClientID() {
796 return guid::GenerateGUID(); 821 return guid::GenerateGUID();
797 } 822 }
798 823
799 //------------------------------------------------------------------------------ 824 //------------------------------------------------------------------------------
800 // State save methods 825 // State save methods
801 826
802 void MetricsService::ScheduleNextStateSave() { 827 void MetricsService::ScheduleNextStateSave() {
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 case INITIALIZED: 1033 case INITIALIZED:
1009 case INIT_TASK_SCHEDULED: // We should be further along by now. 1034 case INIT_TASK_SCHEDULED: // We should be further along by now.
1010 DCHECK(false); 1035 DCHECK(false);
1011 return; 1036 return;
1012 1037
1013 case INIT_TASK_DONE: 1038 case INIT_TASK_DONE:
1014 // We need to wait for the initial log to be ready before sending 1039 // 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 1040 // anything, because the server will tell us whether it wants to hear
1016 // from us. 1041 // from us.
1017 PrepareInitialLog(); 1042 PrepareInitialLog();
1018 DCHECK(state_ == INIT_TASK_DONE); 1043 DCHECK_EQ(INIT_TASK_DONE, state_);
1019 log_manager_.LoadPersistedUnsentLogs(); 1044 log_manager_.LoadPersistedUnsentLogs();
1020 state_ = INITIAL_LOG_READY; 1045 state_ = INITIAL_LOG_READY;
1021 break; 1046 break;
1022 1047
1023 case SENDING_OLD_LOGS: 1048 case SENDING_OLD_LOGS:
1024 if (log_manager_.has_unsent_logs()) { 1049 if (log_manager_.has_unsent_logs()) {
1025 log_manager_.StageNextLogForUpload(); 1050 log_manager_.StageNextLogForUpload();
1026 break; 1051 break;
1027 } 1052 }
1028 state_ = SENDING_CURRENT_LOGS; 1053 state_ = SENDING_CURRENT_LOGS;
1029 // Fall through. 1054 // Fall through.
1030 1055
1031 case SENDING_CURRENT_LOGS: 1056 case SENDING_CURRENT_LOGS:
1032 StopRecording(); 1057 StopRecording();
1033 StartRecording(); 1058 StartRecording();
1034 log_manager_.StageNextLogForUpload(); 1059 log_manager_.StageNextLogForUpload();
1035 break; 1060 break;
1036 1061
1037 default: 1062 default:
1038 NOTREACHED(); 1063 NOTREACHED();
1039 return; 1064 return;
1040 } 1065 }
1041 1066
1042 DCHECK(log_manager_.has_staged_log()); 1067 DCHECK(log_manager_.has_staged_log());
1043 } 1068 }
1044 1069
1045 void MetricsService::PrepareInitialLog() { 1070 void MetricsService::PrepareInitialLog() {
1046 DCHECK(state_ == INIT_TASK_DONE); 1071 DCHECK_EQ(INIT_TASK_DONE, state_);
1047 1072
1048 MetricsLog* log = new MetricsLog(client_id_, session_id_); 1073 DCHECK(initial_log_.get());
1049 log->set_hardware_class(hardware_class_); // Adds to initial log. 1074 initial_log_->set_hardware_class(hardware_class_);
1050 log->RecordEnvironment(plugins_, profile_dictionary_.get()); 1075 initial_log_->RecordEnvironment(plugins_, profile_dictionary_.get());
1051 1076
1052 // Histograms only get written to the current log, so make the new log current 1077 // Histograms only get written to the current log, so make the new log current
1053 // before writing them. 1078 // before writing them.
1054 log_manager_.PauseCurrentLog(); 1079 log_manager_.PauseCurrentLog();
1055 log_manager_.BeginLoggingWithLog(log, MetricsLogManager::INITIAL_LOG); 1080 log_manager_.BeginLoggingWithLog(initial_log_.release(),
1081 MetricsLogManager::INITIAL_LOG);
1056 RecordCurrentHistograms(); 1082 RecordCurrentHistograms();
1057 log_manager_.FinishCurrentLog(); 1083 log_manager_.FinishCurrentLog();
1058 log_manager_.ResumePausedLog(); 1084 log_manager_.ResumePausedLog();
1059 1085
1060 DCHECK(!log_manager_.has_staged_log()); 1086 DCHECK(!log_manager_.has_staged_log());
1061 log_manager_.StageNextLogForUpload(); 1087 log_manager_.StageNextLogForUpload();
1062 } 1088 }
1063 1089
1064 void MetricsService::StoreUnsentLogs() { 1090 void MetricsService::StoreUnsentLogs() {
1065 if (state_ < INITIAL_LOG_READY) 1091 if (state_ < INITIAL_LOG_READY)
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1250 break; 1276 break;
1251 1277
1252 default: 1278 default:
1253 NOTREACHED(); 1279 NOTREACHED();
1254 break; 1280 break;
1255 } 1281 }
1256 1282
1257 log_manager_.DiscardStagedLog(); 1283 log_manager_.DiscardStagedLog();
1258 1284
1259 if (log_manager_.has_unsent_logs()) 1285 if (log_manager_.has_unsent_logs())
1260 DCHECK(state_ < SENDING_CURRENT_LOGS); 1286 DCHECK_LT(state_, SENDING_CURRENT_LOGS);
1261 } 1287 }
1262 1288
1263 // Error 400 indicates a problem with the log, not with the server, so 1289 // 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. 1290 // don't consider that a sign that the server is in trouble.
1265 bool server_is_healthy = upload_succeeded || response_code_ == 400; 1291 bool server_is_healthy = upload_succeeded || response_code_ == 400;
1266 1292
1267 scheduler_->UploadFinished(server_is_healthy, 1293 scheduler_->UploadFinished(server_is_healthy,
1268 log_manager_.has_unsent_logs()); 1294 log_manager_.has_unsent_logs());
1269 1295
1270 // Collect network stats if UMA upload succeeded. 1296 // Collect network stats if UMA upload succeeded.
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
1670 if (local_state) { 1696 if (local_state) {
1671 const PrefService::Preference* uma_pref = 1697 const PrefService::Preference* uma_pref =
1672 local_state->FindPreference(prefs::kMetricsReportingEnabled); 1698 local_state->FindPreference(prefs::kMetricsReportingEnabled);
1673 if (uma_pref) { 1699 if (uma_pref) {
1674 bool success = uma_pref->GetValue()->GetAsBoolean(&result); 1700 bool success = uma_pref->GetValue()->GetAsBoolean(&result);
1675 DCHECK(success); 1701 DCHECK(success);
1676 } 1702 }
1677 } 1703 }
1678 return result; 1704 return result;
1679 } 1705 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/metrics_service.h ('k') | chrome/browser/metrics/metrics_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698