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

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: . 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 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 const tracked_objects::ProcessDataSnapshot& process_data, 1036 const tracked_objects::ProcessDataSnapshot& process_data,
1037 int process_type) { 1037 int process_type) {
1038 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); 1038 DCHECK_EQ(INIT_TASK_SCHEDULED, state_);
1039 1039
1040 // Upon the first callback, create the initial log so that we can immediately 1040 // Upon the first callback, create the initial log so that we can immediately
1041 // save the profiler data. 1041 // save the profiler data.
1042 if (!initial_metrics_log_.get()) { 1042 if (!initial_metrics_log_.get()) {
1043 initial_metrics_log_.reset( 1043 initial_metrics_log_.reset(
1044 new MetricsLog(state_manager_->client_id(), session_id_, 1044 new MetricsLog(state_manager_->client_id(), session_id_,
1045 MetricsLog::ONGOING_LOG)); 1045 MetricsLog::ONGOING_LOG));
1046 NotifyOnDidCreateMetricsLog();
1046 } 1047 }
1047 1048
1048 initial_metrics_log_->RecordProfilerData(process_data, process_type); 1049 initial_metrics_log_->RecordProfilerData(process_data, process_type);
1049 } 1050 }
1050 1051
1051 void MetricsService::FinishedReceivingProfilerData() { 1052 void MetricsService::FinishedReceivingProfilerData() {
1052 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); 1053 DCHECK_EQ(INIT_TASK_SCHEDULED, state_);
1053 state_ = INIT_TASK_DONE; 1054 state_ = INIT_TASK_DONE;
1054 scheduler_->InitTaskComplete(); 1055 scheduler_->InitTaskComplete();
1055 } 1056 }
(...skipping 13 matching lines...) Expand all
1069 last_updated_time_ = now; 1070 last_updated_time_ = now;
1070 1071
1071 const int64 incremental_time_secs = incremental_uptime->InSeconds(); 1072 const int64 incremental_time_secs = incremental_uptime->InSeconds();
1072 if (incremental_time_secs > 0) { 1073 if (incremental_time_secs > 0) {
1073 int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec); 1074 int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec);
1074 metrics_uptime += incremental_time_secs; 1075 metrics_uptime += incremental_time_secs;
1075 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime); 1076 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime);
1076 } 1077 }
1077 } 1078 }
1078 1079
1080 void MetricsService::AddObserver(MetricsServiceObserver* observer) {
1081 DCHECK(thread_checker_.CalledOnValidThread());
1082 observers_.AddObserver(observer);
1083 }
1084
1085 void MetricsService::RemoveObserver(MetricsServiceObserver* observer) {
1086 DCHECK(thread_checker_.CalledOnValidThread());
1087 observers_.RemoveObserver(observer);
1088 }
1089
1090 void MetricsService::NotifyOnDidCreateMetricsLog() {
1091 DCHECK(thread_checker_.CalledOnValidThread());
1092 FOR_EACH_OBSERVER(
1093 MetricsServiceObserver, observers_, OnDidCreateMetricsLog());
1094 }
1095
1079 //------------------------------------------------------------------------------ 1096 //------------------------------------------------------------------------------
1080 // State save methods 1097 // State save methods
1081 1098
1082 void MetricsService::ScheduleNextStateSave() { 1099 void MetricsService::ScheduleNextStateSave() {
1083 state_saver_factory_.InvalidateWeakPtrs(); 1100 state_saver_factory_.InvalidateWeakPtrs();
1084 1101
1085 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, 1102 base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
1086 base::Bind(&MetricsService::SaveLocalState, 1103 base::Bind(&MetricsService::SaveLocalState,
1087 state_saver_factory_.GetWeakPtr()), 1104 state_saver_factory_.GetWeakPtr()),
1088 base::TimeDelta::FromMinutes(kSaveStateIntervalMinutes)); 1105 base::TimeDelta::FromMinutes(kSaveStateIntervalMinutes));
(...skipping 15 matching lines...) Expand all
1104 1121
1105 //------------------------------------------------------------------------------ 1122 //------------------------------------------------------------------------------
1106 // Recording control methods 1123 // Recording control methods
1107 1124
1108 void MetricsService::OpenNewLog() { 1125 void MetricsService::OpenNewLog() {
1109 DCHECK(!log_manager_.current_log()); 1126 DCHECK(!log_manager_.current_log());
1110 1127
1111 log_manager_.BeginLoggingWithLog( 1128 log_manager_.BeginLoggingWithLog(
1112 new MetricsLog(state_manager_->client_id(), session_id_, 1129 new MetricsLog(state_manager_->client_id(), session_id_,
1113 MetricsLog::ONGOING_LOG)); 1130 MetricsLog::ONGOING_LOG));
1131 NotifyOnDidCreateMetricsLog();
1114 if (state_ == INITIALIZED) { 1132 if (state_ == INITIALIZED) {
1115 // We only need to schedule that run once. 1133 // We only need to schedule that run once.
1116 state_ = INIT_TASK_SCHEDULED; 1134 state_ = INIT_TASK_SCHEDULED;
1117 1135
1118 // Schedules a task on the file thread for execution of slower 1136 // Schedules a task on the file thread for execution of slower
1119 // initialization steps (such as plugin list generation) necessary 1137 // initialization steps (such as plugin list generation) necessary
1120 // for sending the initial log. This avoids blocking the main UI 1138 // for sending the initial log. This avoids blocking the main UI
1121 // thread. 1139 // thread.
1122 BrowserThread::PostDelayedTask( 1140 BrowserThread::PostDelayedTask(
1123 BrowserThread::FILE, 1141 BrowserThread::FILE,
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
1401 } 1419 }
1402 1420
1403 void MetricsService::PrepareInitialStabilityLog() { 1421 void MetricsService::PrepareInitialStabilityLog() {
1404 DCHECK_EQ(INITIALIZED, state_); 1422 DCHECK_EQ(INITIALIZED, state_);
1405 PrefService* pref = g_browser_process->local_state(); 1423 PrefService* pref = g_browser_process->local_state();
1406 DCHECK_NE(0, pref->GetInteger(prefs::kStabilityCrashCount)); 1424 DCHECK_NE(0, pref->GetInteger(prefs::kStabilityCrashCount));
1407 1425
1408 scoped_ptr<MetricsLog> initial_stability_log( 1426 scoped_ptr<MetricsLog> initial_stability_log(
1409 new MetricsLog(state_manager_->client_id(), session_id_, 1427 new MetricsLog(state_manager_->client_id(), session_id_,
1410 MetricsLog::INITIAL_STABILITY_LOG)); 1428 MetricsLog::INITIAL_STABILITY_LOG));
1429
1430 // Do not call NotifyOnDidCreateMetricsLog here because the stability
1431 // log describes stats from the _previous_ session.
1432
1411 if (!initial_stability_log->LoadSavedEnvironmentFromPrefs()) 1433 if (!initial_stability_log->LoadSavedEnvironmentFromPrefs())
1412 return; 1434 return;
1413 initial_stability_log->RecordStabilityMetrics(base::TimeDelta(), 1435 initial_stability_log->RecordStabilityMetrics(base::TimeDelta(),
1414 base::TimeDelta()); 1436 base::TimeDelta());
1415 log_manager_.LoadPersistedUnsentLogs(); 1437 log_manager_.LoadPersistedUnsentLogs();
1416 1438
1417 log_manager_.PauseCurrentLog(); 1439 log_manager_.PauseCurrentLog();
1418 log_manager_.BeginLoggingWithLog(initial_stability_log.release()); 1440 log_manager_.BeginLoggingWithLog(initial_stability_log.release());
1419 #if defined(OS_ANDROID) 1441 #if defined(OS_ANDROID)
1420 ConvertAndroidStabilityPrefsToHistograms(pref); 1442 ConvertAndroidStabilityPrefsToHistograms(pref);
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
1930 // Android has its own settings for metrics / crash uploading. 1952 // Android has its own settings for metrics / crash uploading.
1931 const PrefService* prefs = g_browser_process->local_state(); 1953 const PrefService* prefs = g_browser_process->local_state();
1932 return prefs->GetBoolean(prefs::kCrashReportingEnabled); 1954 return prefs->GetBoolean(prefs::kCrashReportingEnabled);
1933 #else 1955 #else
1934 return MetricsServiceHelper::IsMetricsReportingEnabled(); 1956 return MetricsServiceHelper::IsMetricsReportingEnabled();
1935 #endif 1957 #endif
1936 #else 1958 #else
1937 return false; 1959 return false;
1938 #endif 1960 #endif
1939 } 1961 }
1962
1963 void MetricsServiceHelper::AddMetricsServiceObserver(
1964 MetricsServiceObserver* observer) {
1965 MetricsService* metrics_service = g_browser_process->metrics_service();
1966 if (metrics_service)
1967 metrics_service->AddObserver(observer);
1968 }
1969
1970 void MetricsServiceHelper::RemoveMetricsServiceObserver(
1971 MetricsServiceObserver* observer) {
1972 MetricsService* metrics_service = g_browser_process->metrics_service();
1973 if (metrics_service)
1974 metrics_service->RemoveObserver(observer);
1975 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/metrics_service.h ('k') | chrome/browser/metrics/metrics_service_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698