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 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1045 | 1045 |
1046 void MetricsService::OnLogUploadComplete(int response_code) { | 1046 void MetricsService::OnLogUploadComplete(int response_code) { |
1047 DCHECK(log_upload_in_progress_); | 1047 DCHECK(log_upload_in_progress_); |
1048 log_upload_in_progress_ = false; | 1048 log_upload_in_progress_ = false; |
1049 | 1049 |
1050 // Log a histogram to track response success vs. failure rates. | 1050 // Log a histogram to track response success vs. failure rates. |
1051 UMA_HISTOGRAM_ENUMERATION("UMA.UploadResponseStatus.Protobuf", | 1051 UMA_HISTOGRAM_ENUMERATION("UMA.UploadResponseStatus.Protobuf", |
1052 ResponseCodeToStatus(response_code), | 1052 ResponseCodeToStatus(response_code), |
1053 NUM_RESPONSE_STATUSES); | 1053 NUM_RESPONSE_STATUSES); |
1054 | 1054 |
| 1055 bool suppress_reschedule = false; |
| 1056 |
1055 bool upload_succeeded = response_code == 200; | 1057 bool upload_succeeded = response_code == 200; |
1056 | 1058 |
1057 // Provide boolean for error recovery (allow us to ignore response_code). | 1059 // Provide boolean for error recovery (allow us to ignore response_code). |
1058 bool discard_log = false; | 1060 bool discard_log = false; |
1059 const size_t log_size = log_manager_.staged_log().length(); | 1061 const size_t log_size = log_manager_.staged_log().length(); |
1060 if (upload_succeeded) { | 1062 if (upload_succeeded) { |
1061 UMA_HISTOGRAM_COUNTS_10000("UMA.LogSize.OnSuccess", log_size / 1024); | 1063 UMA_HISTOGRAM_COUNTS_10000("UMA.LogSize.OnSuccess", log_size / 1024); |
1062 } else if (log_size > kUploadLogAvoidRetransmitSize) { | 1064 } else if (log_size > kUploadLogAvoidRetransmitSize) { |
1063 UMA_HISTOGRAM_COUNTS("UMA.Large Rejected Log was Discarded", | 1065 UMA_HISTOGRAM_COUNTS("UMA.Large Rejected Log was Discarded", |
1064 static_cast<int>(log_size)); | 1066 static_cast<int>(log_size)); |
(...skipping 13 matching lines...) Expand all Loading... |
1078 switch (state_) { | 1080 switch (state_) { |
1079 case SENDING_INITIAL_STABILITY_LOG: | 1081 case SENDING_INITIAL_STABILITY_LOG: |
1080 if (NewInitialMetricsTimingEnabled()) { | 1082 if (NewInitialMetricsTimingEnabled()) { |
1081 // The initial metrics log is already in the queue of unsent logs. | 1083 // The initial metrics log is already in the queue of unsent logs. |
1082 state_ = SENDING_OLD_LOGS; | 1084 state_ = SENDING_OLD_LOGS; |
1083 } else { | 1085 } else { |
1084 PrepareInitialMetricsLog(); | 1086 PrepareInitialMetricsLog(); |
1085 log_manager_.StageNextLogForUpload(); | 1087 log_manager_.StageNextLogForUpload(); |
1086 SendStagedLog(); | 1088 SendStagedLog(); |
1087 state_ = SENDING_INITIAL_METRICS_LOG; | 1089 state_ = SENDING_INITIAL_METRICS_LOG; |
| 1090 suppress_reschedule = true; |
1088 } | 1091 } |
1089 break; | 1092 break; |
1090 | 1093 |
1091 case SENDING_INITIAL_METRICS_LOG: | 1094 case SENDING_INITIAL_METRICS_LOG: |
1092 state_ = log_manager_.has_unsent_logs() ? SENDING_OLD_LOGS | 1095 state_ = log_manager_.has_unsent_logs() ? SENDING_OLD_LOGS |
1093 : SENDING_CURRENT_LOGS; | 1096 : SENDING_CURRENT_LOGS; |
1094 break; | 1097 break; |
1095 | 1098 |
1096 case SENDING_OLD_LOGS: | 1099 case SENDING_OLD_LOGS: |
1097 if (!log_manager_.has_unsent_logs()) | 1100 if (!log_manager_.has_unsent_logs()) |
1098 state_ = SENDING_CURRENT_LOGS; | 1101 state_ = SENDING_CURRENT_LOGS; |
1099 break; | 1102 break; |
1100 | 1103 |
1101 case SENDING_CURRENT_LOGS: | 1104 case SENDING_CURRENT_LOGS: |
1102 break; | 1105 break; |
1103 | 1106 |
1104 default: | 1107 default: |
1105 NOTREACHED(); | 1108 NOTREACHED(); |
1106 break; | 1109 break; |
1107 } | 1110 } |
1108 | 1111 |
1109 if (log_manager_.has_unsent_logs()) | 1112 if (log_manager_.has_unsent_logs()) |
1110 DCHECK_LT(state_, SENDING_CURRENT_LOGS); | 1113 DCHECK_LT(state_, SENDING_CURRENT_LOGS); |
1111 } | 1114 } |
1112 | 1115 |
1113 // Error 400 indicates a problem with the log, not with the server, so | 1116 // Error 400 indicates a problem with the log, not with the server, so |
1114 // don't consider that a sign that the server is in trouble. | 1117 // don't consider that a sign that the server is in trouble. |
1115 bool server_is_healthy = upload_succeeded || response_code == 400; | 1118 bool server_is_healthy = upload_succeeded || response_code == 400; |
1116 // Don't notify the scheduler that the upload is finished if we've only sent | 1119 // Don't notify the scheduler that the upload is finished if we've only just |
1117 // the initial stability log, but not yet the initial metrics log (treat the | 1120 // sent the initial stability log, but not yet the initial metrics log (treat |
1118 // two as a single unit of work as far as the scheduler is concerned). | 1121 // the two as a single unit of work as far as the scheduler is concerned). |
1119 if (state_ != SENDING_INITIAL_METRICS_LOG) { | 1122 if (!suppress_reschedule) { |
1120 scheduler_->UploadFinished(server_is_healthy, | 1123 scheduler_->UploadFinished(server_is_healthy, |
1121 log_manager_.has_unsent_logs()); | 1124 log_manager_.has_unsent_logs()); |
1122 } | 1125 } |
1123 | 1126 |
1124 if (server_is_healthy) | 1127 if (server_is_healthy) |
1125 client_->OnLogUploadComplete(); | 1128 client_->OnLogUploadComplete(); |
1126 } | 1129 } |
1127 | 1130 |
1128 void MetricsService::IncrementPrefValue(const char* path) { | 1131 void MetricsService::IncrementPrefValue(const char* path) { |
1129 int value = local_state_->GetInteger(path); | 1132 int value = local_state_->GetInteger(path); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1254 local_state_->SetBoolean(path, value); | 1257 local_state_->SetBoolean(path, value); |
1255 RecordCurrentState(local_state_); | 1258 RecordCurrentState(local_state_); |
1256 } | 1259 } |
1257 | 1260 |
1258 void MetricsService::RecordCurrentState(PrefService* pref) { | 1261 void MetricsService::RecordCurrentState(PrefService* pref) { |
1259 pref->SetInt64(prefs::kStabilityLastTimestampSec, | 1262 pref->SetInt64(prefs::kStabilityLastTimestampSec, |
1260 base::Time::Now().ToTimeT()); | 1263 base::Time::Now().ToTimeT()); |
1261 } | 1264 } |
1262 | 1265 |
1263 } // namespace metrics | 1266 } // namespace metrics |
OLD | NEW |