Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 544 | 544 |
| 545 //------------------------------------------------------------------------------ | 545 //------------------------------------------------------------------------------ |
| 546 // Initialization methods | 546 // Initialization methods |
| 547 | 547 |
| 548 void MetricsService::InitializeMetricsState() { | 548 void MetricsService::InitializeMetricsState() { |
| 549 local_state_->SetString(metrics::prefs::kStabilityStatsVersion, | 549 local_state_->SetString(metrics::prefs::kStabilityStatsVersion, |
| 550 client_->GetVersionString()); | 550 client_->GetVersionString()); |
| 551 local_state_->SetInt64(metrics::prefs::kStabilityStatsBuildTime, | 551 local_state_->SetInt64(metrics::prefs::kStabilityStatsBuildTime, |
| 552 MetricsLog::GetBuildTime()); | 552 MetricsLog::GetBuildTime()); |
| 553 | 553 |
| 554 log_manager_.LoadPersistedUnsentLogs(); | |
| 555 | |
| 554 session_id_ = local_state_->GetInteger(metrics::prefs::kMetricsSessionID); | 556 session_id_ = local_state_->GetInteger(metrics::prefs::kMetricsSessionID); |
| 555 | 557 |
| 556 if (!local_state_->GetBoolean(metrics::prefs::kStabilityExitedCleanly)) { | 558 if (!local_state_->GetBoolean(metrics::prefs::kStabilityExitedCleanly)) { |
| 557 IncrementPrefValue(metrics::prefs::kStabilityCrashCount); | 559 IncrementPrefValue(metrics::prefs::kStabilityCrashCount); |
| 558 // Reset flag, and wait until we call LogNeedForCleanShutdown() before | 560 // Reset flag, and wait until we call LogNeedForCleanShutdown() before |
| 559 // monitoring. | 561 // monitoring. |
| 560 local_state_->SetBoolean(metrics::prefs::kStabilityExitedCleanly, true); | 562 local_state_->SetBoolean(metrics::prefs::kStabilityExitedCleanly, true); |
| 561 | 563 |
| 562 // TODO(rtenneti): On windows, consider saving/getting execution_phase from | 564 // TODO(rtenneti): On windows, consider saving/getting execution_phase from |
| 563 // the registry. | 565 // the registry. |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 874 case INITIALIZED: | 876 case INITIALIZED: |
| 875 case INIT_TASK_SCHEDULED: // We should be further along by now. | 877 case INIT_TASK_SCHEDULED: // We should be further along by now. |
| 876 NOTREACHED(); | 878 NOTREACHED(); |
| 877 return; | 879 return; |
| 878 | 880 |
| 879 case INIT_TASK_DONE: | 881 case INIT_TASK_DONE: |
| 880 if (has_initial_stability_log_) { | 882 if (has_initial_stability_log_) { |
| 881 // There's an initial stability log, ready to send. | 883 // There's an initial stability log, ready to send. |
| 882 log_manager_.StageNextLogForUpload(); | 884 log_manager_.StageNextLogForUpload(); |
| 883 has_initial_stability_log_ = false; | 885 has_initial_stability_log_ = false; |
| 884 // Note: No need to call LoadPersistedUnsentLogs() here because unsent | |
| 885 // logs have already been loaded by PrepareInitialStabilityLog(). | |
| 886 state_ = SENDING_INITIAL_STABILITY_LOG; | 886 state_ = SENDING_INITIAL_STABILITY_LOG; |
| 887 } else { | 887 } else { |
| 888 PrepareInitialMetricsLog(); | 888 PrepareInitialMetricsLog(); |
| 889 // Load unsent logs (if any) from local state. | |
| 890 log_manager_.LoadPersistedUnsentLogs(); | |
| 891 state_ = SENDING_INITIAL_METRICS_LOG; | 889 state_ = SENDING_INITIAL_METRICS_LOG; |
| 892 } | 890 } |
| 893 break; | 891 break; |
| 894 | 892 |
| 895 case SENDING_OLD_LOGS: | 893 case SENDING_OLD_LOGS: |
| 896 NOTREACHED(); // Shouldn't be staging a new log during old log sending. | 894 NOTREACHED(); // Shouldn't be staging a new log during old log sending. |
| 897 return; | 895 return; |
| 898 | 896 |
| 899 case SENDING_CURRENT_LOGS: | 897 case SENDING_CURRENT_LOGS: |
| 900 CloseCurrentLog(); | 898 CloseCurrentLog(); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 916 | 914 |
| 917 scoped_ptr<MetricsLog> initial_stability_log( | 915 scoped_ptr<MetricsLog> initial_stability_log( |
| 918 CreateLog(MetricsLog::INITIAL_STABILITY_LOG)); | 916 CreateLog(MetricsLog::INITIAL_STABILITY_LOG)); |
| 919 | 917 |
| 920 // Do not call NotifyOnDidCreateMetricsLog here because the stability | 918 // Do not call NotifyOnDidCreateMetricsLog here because the stability |
| 921 // log describes stats from the _previous_ session. | 919 // log describes stats from the _previous_ session. |
| 922 | 920 |
| 923 if (!initial_stability_log->LoadSavedEnvironmentFromPrefs()) | 921 if (!initial_stability_log->LoadSavedEnvironmentFromPrefs()) |
| 924 return; | 922 return; |
| 925 | 923 |
| 926 log_manager_.LoadPersistedUnsentLogs(); | |
| 927 | |
| 928 log_manager_.PauseCurrentLog(); | 924 log_manager_.PauseCurrentLog(); |
| 929 log_manager_.BeginLoggingWithLog(initial_stability_log.Pass()); | 925 log_manager_.BeginLoggingWithLog(initial_stability_log.Pass()); |
| 930 | 926 |
| 931 // Note: Some stability providers may record stability stats via histograms, | 927 // Note: Some stability providers may record stability stats via histograms, |
| 932 // so this call has to be after BeginLoggingWithLog(). | 928 // so this call has to be after BeginLoggingWithLog(). |
| 933 log_manager_.current_log()->RecordStabilityMetrics( | 929 log_manager_.current_log()->RecordStabilityMetrics( |
| 934 metrics_providers_.get(), base::TimeDelta(), base::TimeDelta()); | 930 metrics_providers_.get(), base::TimeDelta(), base::TimeDelta()); |
| 935 RecordCurrentStabilityHistograms(); | 931 RecordCurrentStabilityHistograms(); |
| 936 | 932 |
| 937 // Note: RecordGeneralMetrics() intentionally not called since this log is for | 933 // Note: RecordGeneralMetrics() intentionally not called since this log is for |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 959 GetUptimes(local_state_, &incremental_uptime, &uptime); | 955 GetUptimes(local_state_, &incremental_uptime, &uptime); |
| 960 | 956 |
| 961 // Histograms only get written to the current log, so make the new log current | 957 // Histograms only get written to the current log, so make the new log current |
| 962 // before writing them. | 958 // before writing them. |
| 963 log_manager_.PauseCurrentLog(); | 959 log_manager_.PauseCurrentLog(); |
| 964 log_manager_.BeginLoggingWithLog(initial_metrics_log_.Pass()); | 960 log_manager_.BeginLoggingWithLog(initial_metrics_log_.Pass()); |
| 965 | 961 |
| 966 // Note: Some stability providers may record stability stats via histograms, | 962 // Note: Some stability providers may record stability stats via histograms, |
| 967 // so this call has to be after BeginLoggingWithLog(). | 963 // so this call has to be after BeginLoggingWithLog(). |
| 968 MetricsLog* current_log = | 964 MetricsLog* current_log = |
| 969 static_cast<MetricsLog*>(log_manager_.current_log()); | 965 static_cast<MetricsLog*>(log_manager_.current_log()); |
|
Alexei Svitkine (slow)
2014/07/14 18:46:54
Nit: While you're here, you may as well remove thi
Steven Holte
2014/07/15 01:22:01
Done. x3
| |
| 970 current_log->RecordStabilityMetrics(metrics_providers_.get(), | 966 current_log->RecordStabilityMetrics(metrics_providers_.get(), |
| 971 base::TimeDelta(), base::TimeDelta()); | 967 base::TimeDelta(), base::TimeDelta()); |
| 972 RecordCurrentHistograms(); | 968 RecordCurrentHistograms(); |
| 973 | 969 |
| 974 current_log->RecordGeneralMetrics(metrics_providers_.get()); | 970 current_log->RecordGeneralMetrics(metrics_providers_.get()); |
| 975 | 971 |
| 976 log_manager_.FinishCurrentLog(); | 972 log_manager_.FinishCurrentLog(); |
| 977 log_manager_.ResumePausedLog(); | 973 log_manager_.ResumePausedLog(); |
| 978 | 974 |
| 975 // Store unsent logs, including the initial log that was just saved, so | |
| 976 // that they're not lost in case of a crash before upload time. | |
| 977 log_manager_.PersistUnsentLogs(); | |
| 978 | |
| 979 DCHECK(!log_manager_.has_staged_log()); | 979 DCHECK(!log_manager_.has_staged_log()); |
| 980 log_manager_.StageNextLogForUpload(); | 980 log_manager_.StageNextLogForUpload(); |
| 981 } | 981 } |
| 982 | 982 |
| 983 void MetricsService::SendStagedLog() { | 983 void MetricsService::SendStagedLog() { |
| 984 DCHECK(log_manager_.has_staged_log()); | 984 DCHECK(log_manager_.has_staged_log()); |
| 985 if (!log_manager_.has_staged_log()) | 985 if (!log_manager_.has_staged_log()) |
| 986 return; | 986 return; |
| 987 | 987 |
| 988 DCHECK(!log_upload_in_progress_); | 988 DCHECK(!log_upload_in_progress_); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1032 const size_t log_size = log_manager_.staged_log().length(); | 1032 const size_t log_size = log_manager_.staged_log().length(); |
| 1033 if (!upload_succeeded && log_size > kUploadLogAvoidRetransmitSize) { | 1033 if (!upload_succeeded && log_size > kUploadLogAvoidRetransmitSize) { |
| 1034 UMA_HISTOGRAM_COUNTS("UMA.Large Rejected Log was Discarded", | 1034 UMA_HISTOGRAM_COUNTS("UMA.Large Rejected Log was Discarded", |
| 1035 static_cast<int>(log_size)); | 1035 static_cast<int>(log_size)); |
| 1036 discard_log = true; | 1036 discard_log = true; |
| 1037 } else if (response_code == 400) { | 1037 } else if (response_code == 400) { |
| 1038 // Bad syntax. Retransmission won't work. | 1038 // Bad syntax. Retransmission won't work. |
| 1039 discard_log = true; | 1039 discard_log = true; |
| 1040 } | 1040 } |
| 1041 | 1041 |
| 1042 if (upload_succeeded || discard_log) | 1042 if (upload_succeeded || discard_log) { |
| 1043 log_manager_.DiscardStagedLog(); | 1043 log_manager_.DiscardStagedLog(); |
| 1044 // Store the updated list to disk now that the removed log is uploaded. | |
| 1045 log_manager_.PersistUnsentLogs(); | |
| 1046 } | |
| 1044 | 1047 |
| 1045 if (!log_manager_.has_staged_log()) { | 1048 if (!log_manager_.has_staged_log()) { |
| 1046 switch (state_) { | 1049 switch (state_) { |
| 1047 case SENDING_INITIAL_STABILITY_LOG: | 1050 case SENDING_INITIAL_STABILITY_LOG: |
| 1048 // Store the updated list to disk now that the removed log is uploaded. | |
| 1049 log_manager_.PersistUnsentLogs(); | |
| 1050 PrepareInitialMetricsLog(); | 1051 PrepareInitialMetricsLog(); |
| 1051 SendStagedLog(); | 1052 SendStagedLog(); |
| 1052 state_ = SENDING_INITIAL_METRICS_LOG; | 1053 state_ = SENDING_INITIAL_METRICS_LOG; |
| 1053 break; | 1054 break; |
| 1054 | 1055 |
| 1055 case SENDING_INITIAL_METRICS_LOG: | 1056 case SENDING_INITIAL_METRICS_LOG: |
| 1056 // The initial metrics log never gets persisted to local state, so it's | |
| 1057 // not necessary to call log_manager_.PersistUnsentLogs() here. | |
| 1058 // TODO(asvitkine): It should be persisted like the initial stability | |
| 1059 // log and old unsent logs. http://crbug.com/328417 | |
| 1060 state_ = log_manager_.has_unsent_logs() ? SENDING_OLD_LOGS | 1057 state_ = log_manager_.has_unsent_logs() ? SENDING_OLD_LOGS |
| 1061 : SENDING_CURRENT_LOGS; | 1058 : SENDING_CURRENT_LOGS; |
| 1062 break; | 1059 break; |
| 1063 | 1060 |
| 1064 case SENDING_OLD_LOGS: | 1061 case SENDING_OLD_LOGS: |
| 1065 // Store the updated list to disk now that the removed log is uploaded. | |
| 1066 log_manager_.PersistUnsentLogs(); | |
| 1067 if (!log_manager_.has_unsent_logs()) | 1062 if (!log_manager_.has_unsent_logs()) |
| 1068 state_ = SENDING_CURRENT_LOGS; | 1063 state_ = SENDING_CURRENT_LOGS; |
| 1069 break; | 1064 break; |
| 1070 | 1065 |
| 1071 case SENDING_CURRENT_LOGS: | 1066 case SENDING_CURRENT_LOGS: |
| 1072 break; | 1067 break; |
| 1073 | 1068 |
| 1074 default: | 1069 default: |
| 1075 NOTREACHED(); | 1070 NOTREACHED(); |
| 1076 break; | 1071 break; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1197 RecordCurrentState(local_state_); | 1192 RecordCurrentState(local_state_); |
| 1198 } | 1193 } |
| 1199 | 1194 |
| 1200 void MetricsService::RecordCurrentState(PrefService* pref) { | 1195 void MetricsService::RecordCurrentState(PrefService* pref) { |
| 1201 pref->SetInt64(metrics::prefs::kStabilityLastTimestampSec, | 1196 pref->SetInt64(metrics::prefs::kStabilityLastTimestampSec, |
| 1202 Time::Now().ToTimeT()); | 1197 Time::Now().ToTimeT()); |
| 1203 | 1198 |
| 1204 for (size_t i = 0; i < metrics_providers_.size(); ++i) | 1199 for (size_t i = 0; i < metrics_providers_.size(); ++i) |
| 1205 metrics_providers_[i]->RecordCurrentState(); | 1200 metrics_providers_[i]->RecordCurrentState(); |
| 1206 } | 1201 } |
| OLD | NEW |