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

Side by Side Diff: components/metrics/metrics_service.cc

Issue 799613002: Fix a bug that causes the metrics loop to be broken. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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())
(...skipping 10 matching lines...) Expand all
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 sent
1117 // the initial stability log, but not yet the initial metrics log (treat the 1120 // the initial stability log, but not yet the initial metrics log (treat the
1118 // two as a single unit of work as far as the scheduler is concerned). 1121 // two as a single unit of work as far as the scheduler is concerned).
jwd 2014/12/11 20:39:54 Please update this comment.
Steven Holte 2014/12/11 20:46:54 Slightly tweaked the comment, but it's basically c
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
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
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698