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

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

Issue 253203002: Log operator code histogram on new metric log (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@api_move
Patch Set: create observer in ChromeBrowserMainExtraPartsMetrics::PostBrowserStart() Created 6 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
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 is 10 // A MetricsService instance is typically created at application startup. It is
(...skipping 1026 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 const tracked_objects::ProcessDataSnapshot& process_data, 1037 const tracked_objects::ProcessDataSnapshot& process_data,
1038 int process_type) { 1038 int process_type) {
1039 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); 1039 DCHECK_EQ(INIT_TASK_SCHEDULED, state_);
1040 1040
1041 // Upon the first callback, create the initial log so that we can immediately 1041 // Upon the first callback, create the initial log so that we can immediately
1042 // save the profiler data. 1042 // save the profiler data.
1043 if (!initial_metrics_log_.get()) { 1043 if (!initial_metrics_log_.get()) {
1044 initial_metrics_log_.reset( 1044 initial_metrics_log_.reset(
1045 new MetricsLog(state_manager_->client_id(), session_id_, 1045 new MetricsLog(state_manager_->client_id(), session_id_,
1046 MetricsLog::ONGOING_LOG)); 1046 MetricsLog::ONGOING_LOG));
1047 NotifyOnDidCreateMetricsLog();
1047 } 1048 }
1048 1049
1049 initial_metrics_log_->RecordProfilerData(process_data, process_type); 1050 initial_metrics_log_->RecordProfilerData(process_data, process_type);
1050 } 1051 }
1051 1052
1052 void MetricsService::FinishedReceivingProfilerData() { 1053 void MetricsService::FinishedReceivingProfilerData() {
1053 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); 1054 DCHECK_EQ(INIT_TASK_SCHEDULED, state_);
1054 state_ = INIT_TASK_DONE; 1055 state_ = INIT_TASK_DONE;
1055 scheduler_->InitTaskComplete(); 1056 scheduler_->InitTaskComplete();
1056 } 1057 }
(...skipping 13 matching lines...) Expand all
1070 last_updated_time_ = now; 1071 last_updated_time_ = now;
1071 1072
1072 const int64 incremental_time_secs = incremental_uptime->InSeconds(); 1073 const int64 incremental_time_secs = incremental_uptime->InSeconds();
1073 if (incremental_time_secs > 0) { 1074 if (incremental_time_secs > 0) {
1074 int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec); 1075 int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec);
1075 metrics_uptime += incremental_time_secs; 1076 metrics_uptime += incremental_time_secs;
1076 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime); 1077 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime);
1077 } 1078 }
1078 } 1079 }
1079 1080
1081 void MetricsService::AddObserver(MetricsServiceObserver* observer) {
1082 DCHECK(thread_checker_.CalledOnValidThread());
1083 observers_.AddObserver(observer);
1084 }
1085
1086 void MetricsService::RemoveObserver(MetricsServiceObserver* observer) {
1087 DCHECK(thread_checker_.CalledOnValidThread());
1088 observers_.RemoveObserver(observer);
1089 }
1090
1091 void MetricsService::NotifyOnDidCreateMetricsLog() {
1092 DCHECK(thread_checker_.CalledOnValidThread());
1093 FOR_EACH_OBSERVER(
1094 MetricsServiceObserver, observers_, OnDidCreateMetricsLog());
1095 }
1096
1080 //------------------------------------------------------------------------------ 1097 //------------------------------------------------------------------------------
1081 // State save methods 1098 // State save methods
1082 1099
1083 void MetricsService::ScheduleNextStateSave() { 1100 void MetricsService::ScheduleNextStateSave() {
1084 state_saver_factory_.InvalidateWeakPtrs(); 1101 state_saver_factory_.InvalidateWeakPtrs();
1085 1102
1086 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, 1103 base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
1087 base::Bind(&MetricsService::SaveLocalState, 1104 base::Bind(&MetricsService::SaveLocalState,
1088 state_saver_factory_.GetWeakPtr()), 1105 state_saver_factory_.GetWeakPtr()),
1089 base::TimeDelta::FromMinutes(kSaveStateIntervalMinutes)); 1106 base::TimeDelta::FromMinutes(kSaveStateIntervalMinutes));
(...skipping 15 matching lines...) Expand all
1105 1122
1106 //------------------------------------------------------------------------------ 1123 //------------------------------------------------------------------------------
1107 // Recording control methods 1124 // Recording control methods
1108 1125
1109 void MetricsService::OpenNewLog() { 1126 void MetricsService::OpenNewLog() {
1110 DCHECK(!log_manager_.current_log()); 1127 DCHECK(!log_manager_.current_log());
1111 1128
1112 log_manager_.BeginLoggingWithLog( 1129 log_manager_.BeginLoggingWithLog(
1113 new MetricsLog(state_manager_->client_id(), session_id_, 1130 new MetricsLog(state_manager_->client_id(), session_id_,
1114 MetricsLog::ONGOING_LOG)); 1131 MetricsLog::ONGOING_LOG));
1132 NotifyOnDidCreateMetricsLog();
1115 if (state_ == INITIALIZED) { 1133 if (state_ == INITIALIZED) {
1116 // We only need to schedule that run once. 1134 // We only need to schedule that run once.
1117 state_ = INIT_TASK_SCHEDULED; 1135 state_ = INIT_TASK_SCHEDULED;
1118 1136
1119 // Schedules a task on the file thread for execution of slower 1137 // Schedules a task on the file thread for execution of slower
1120 // initialization steps (such as plugin list generation) necessary 1138 // initialization steps (such as plugin list generation) necessary
1121 // for sending the initial log. This avoids blocking the main UI 1139 // for sending the initial log. This avoids blocking the main UI
1122 // thread. 1140 // thread.
1123 BrowserThread::PostDelayedTask( 1141 BrowserThread::PostDelayedTask(
1124 BrowserThread::FILE, 1142 BrowserThread::FILE,
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
1402 } 1420 }
1403 1421
1404 void MetricsService::PrepareInitialStabilityLog() { 1422 void MetricsService::PrepareInitialStabilityLog() {
1405 DCHECK_EQ(INITIALIZED, state_); 1423 DCHECK_EQ(INITIALIZED, state_);
1406 PrefService* pref = g_browser_process->local_state(); 1424 PrefService* pref = g_browser_process->local_state();
1407 DCHECK_NE(0, pref->GetInteger(prefs::kStabilityCrashCount)); 1425 DCHECK_NE(0, pref->GetInteger(prefs::kStabilityCrashCount));
1408 1426
1409 scoped_ptr<MetricsLog> initial_stability_log( 1427 scoped_ptr<MetricsLog> initial_stability_log(
1410 new MetricsLog(state_manager_->client_id(), session_id_, 1428 new MetricsLog(state_manager_->client_id(), session_id_,
1411 MetricsLog::INITIAL_STABILITY_LOG)); 1429 MetricsLog::INITIAL_STABILITY_LOG));
1430 NotifyOnDidCreateMetricsLog();
Alexei Svitkine (slow) 2014/05/08 21:00:56 Remove this line. Possibly replace with a comment.
bolian 2014/05/08 22:17:57 Done.
1412 if (!initial_stability_log->LoadSavedEnvironmentFromPrefs()) 1431 if (!initial_stability_log->LoadSavedEnvironmentFromPrefs())
1413 return; 1432 return;
1414 initial_stability_log->RecordStabilityMetrics(base::TimeDelta(), 1433 initial_stability_log->RecordStabilityMetrics(base::TimeDelta(),
1415 base::TimeDelta()); 1434 base::TimeDelta());
1416 log_manager_.LoadPersistedUnsentLogs(); 1435 log_manager_.LoadPersistedUnsentLogs();
1417 1436
1418 log_manager_.PauseCurrentLog(); 1437 log_manager_.PauseCurrentLog();
1419 log_manager_.BeginLoggingWithLog(initial_stability_log.release()); 1438 log_manager_.BeginLoggingWithLog(initial_stability_log.release());
1420 #if defined(OS_ANDROID) 1439 #if defined(OS_ANDROID)
1421 ConvertAndroidStabilityPrefsToHistograms(pref); 1440 ConvertAndroidStabilityPrefsToHistograms(pref);
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
1931 // Android has its own settings for metrics / crash uploading. 1950 // Android has its own settings for metrics / crash uploading.
1932 const PrefService* prefs = g_browser_process->local_state(); 1951 const PrefService* prefs = g_browser_process->local_state();
1933 return prefs->GetBoolean(prefs::kCrashReportingEnabled); 1952 return prefs->GetBoolean(prefs::kCrashReportingEnabled);
1934 #else 1953 #else
1935 return MetricsServiceHelper::IsMetricsReportingEnabled(); 1954 return MetricsServiceHelper::IsMetricsReportingEnabled();
1936 #endif 1955 #endif
1937 #else 1956 #else
1938 return false; 1957 return false;
1939 #endif 1958 #endif
1940 } 1959 }
1960
1961 void MetricsServiceHelper::AddMetricsServiceObserver(
1962 MetricsServiceObserver* observer) {
1963 MetricsService* metrics_service = g_browser_process->metrics_service();
1964 if (metrics_service)
1965 metrics_service->AddObserver(observer);
1966 }
1967
1968 void MetricsServiceHelper::RemoveMetricsServiceObserver(
1969 MetricsServiceObserver* observer) {
1970 MetricsService* metrics_service = g_browser_process->metrics_service();
1971 if (metrics_service)
1972 metrics_service->RemoveObserver(observer);
1973 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698