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 #include "google_apis/gcm/monitoring/gcm_stats_recorder.h" | 5 #include "google_apis/gcm/monitoring/gcm_stats_recorder.h" |
| 6 | 6 |
| 7 #include <deque> | 7 #include <deque> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/format_macros.h" | |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 12 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 13 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 14 | 15 |
| 15 namespace gcm { | 16 namespace gcm { |
| 16 | 17 |
| 17 const uint32 MAX_LOGGED_ACTIVITY_COUNT = 100; | 18 const uint32 MAX_LOGGED_ACTIVITY_COUNT = 100; |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 47 case gcm::MCSClient::NO_CONNECTION_ON_ZERO_TTL: | 48 case gcm::MCSClient::NO_CONNECTION_ON_ZERO_TTL: |
| 48 return "NO_CONNECTION_ON_ZERO_TTL"; | 49 return "NO_CONNECTION_ON_ZERO_TTL"; |
| 49 case gcm::MCSClient::TTL_EXCEEDED: | 50 case gcm::MCSClient::TTL_EXCEEDED: |
| 50 return "TTL_EXCEEDED"; | 51 return "TTL_EXCEEDED"; |
| 51 default: | 52 default: |
| 52 NOTREACHED(); | 53 NOTREACHED(); |
| 53 return "UNKNOWN"; | 54 return "UNKNOWN"; |
| 54 } | 55 } |
| 55 } | 56 } |
| 56 | 57 |
| 58 // Helper for getting string representation of the | |
| 59 // ConnectionFactory::ConnectionResetReason enum. | |
| 60 std::string GetConnectionResetReasonString( | |
| 61 gcm::ConnectionFactory::ConnectionResetReason reason) { | |
| 62 switch (reason) { | |
| 63 case gcm::ConnectionFactory::LOGIN_FAILURE: | |
| 64 return "LOGIN_FAILURE"; | |
| 65 case gcm::ConnectionFactory::CLOSE_COMMAND: | |
| 66 return "CLOSE_COMMAND"; | |
| 67 case gcm::ConnectionFactory::HEARTBEAT_FAILURE: | |
| 68 return "HEARTBEAT_FAILURE"; | |
| 69 case gcm::ConnectionFactory::SOCKET_FAILURE: | |
| 70 return "SOCKET_FAILURE"; | |
| 71 case gcm::ConnectionFactory::NETWORK_CHANGE: | |
| 72 return "NETWORK_CHANGE"; | |
| 73 default: | |
| 74 NOTREACHED(); | |
| 75 return "UNKNOWN_REASON"; | |
| 76 } | |
| 77 } | |
| 78 | |
| 79 // Helper for getting string representation of the RegistrationRequest::Status | |
| 80 // enum. | |
| 81 std::string GetRegistrationStatusString( | |
| 82 gcm::RegistrationRequest::Status status) { | |
| 83 switch (status) { | |
| 84 case gcm::RegistrationRequest::SUCCESS: | |
| 85 return "SUCCESS"; | |
| 86 case gcm::RegistrationRequest::INVALID_PARAMETERS: | |
| 87 return "INVALID_PARAMETERS"; | |
| 88 case gcm::RegistrationRequest::INVALID_SENDER: | |
| 89 return "INVALID_SENDER"; | |
| 90 case gcm::RegistrationRequest::AUTHENTICATION_FAILED: | |
| 91 return "AUTHENTICATION_FAILED"; | |
| 92 case gcm::RegistrationRequest::DEVICE_REGISTRATION_ERROR: | |
| 93 return "DEVICE_REGISTRATION_ERROR"; | |
| 94 case gcm::RegistrationRequest::UNKNOWN_ERROR: | |
| 95 return "UNKNOWN_ERROR"; | |
| 96 case gcm::RegistrationRequest::URL_FETCHING_FAILED: | |
| 97 return "URL_FETCHING_FAILED"; | |
| 98 case gcm::RegistrationRequest::HTTP_NOT_OK: | |
| 99 return "HTTP_NOT_OK"; | |
| 100 case gcm::RegistrationRequest::RESPONSE_PARSING_FAILED: | |
| 101 return "RESPONSE_PARSING_FAILED"; | |
| 102 case gcm::RegistrationRequest::REACHED_MAX_RETRIES: | |
| 103 return "REACHED_MAX_RETRIES"; | |
| 104 default: | |
| 105 NOTREACHED(); | |
| 106 return "UNKNOWN_STATUS"; | |
| 107 } | |
| 108 } | |
| 109 | |
| 57 } // namespace | 110 } // namespace |
| 58 | 111 |
| 59 GCMStatsRecorder::Activity::Activity() | 112 GCMStatsRecorder::Activity::Activity() |
| 60 : time(base::Time::Now()) { | 113 : time(base::Time::Now()) { |
| 61 } | 114 } |
| 62 | 115 |
| 63 GCMStatsRecorder::Activity::~Activity() { | 116 GCMStatsRecorder::Activity::~Activity() { |
| 64 } | 117 } |
| 65 | 118 |
| 119 GCMStatsRecorder::ConnectionActivity::ConnectionActivity() { | |
| 120 } | |
| 121 | |
| 122 GCMStatsRecorder::ConnectionActivity::~ConnectionActivity() { | |
| 123 } | |
| 124 | |
| 125 GCMStatsRecorder::RegistrationActivity::RegistrationActivity() { | |
| 126 } | |
| 127 | |
| 128 GCMStatsRecorder::RegistrationActivity::~RegistrationActivity() { | |
| 129 } | |
| 130 | |
| 131 GCMStatsRecorder::ReceivingActivity::ReceivingActivity() : | |
|
jianli
2014/04/23 17:22:35
nit: ":" should be placed at the next line.
juyik
2014/04/23 21:36:56
Done.
| |
| 132 message_byte_size(0) { | |
| 133 } | |
| 134 | |
| 135 GCMStatsRecorder::ReceivingActivity::~ReceivingActivity() { | |
| 136 } | |
| 137 | |
| 66 GCMStatsRecorder::SendingActivity::SendingActivity() { | 138 GCMStatsRecorder::SendingActivity::SendingActivity() { |
| 67 } | 139 } |
| 68 | 140 |
| 69 GCMStatsRecorder::SendingActivity::~SendingActivity() { | 141 GCMStatsRecorder::SendingActivity::~SendingActivity() { |
| 70 } | 142 } |
| 71 | 143 |
| 72 GCMStatsRecorder::GCMStatsRecorder() : is_recording_(false) { | 144 GCMStatsRecorder::GCMStatsRecorder() : is_recording_(false) { |
| 73 } | 145 } |
| 74 | 146 |
| 75 GCMStatsRecorder::~GCMStatsRecorder() { | 147 GCMStatsRecorder::~GCMStatsRecorder() { |
| 76 } | 148 } |
| 77 | 149 |
| 78 void GCMStatsRecorder::SetRecording(bool recording) { | 150 void GCMStatsRecorder::SetRecording(bool recording) { |
| 79 is_recording_ = recording; | 151 is_recording_ = recording; |
| 80 } | 152 } |
| 81 | 153 |
| 82 void GCMStatsRecorder::Clear() { | 154 void GCMStatsRecorder::Clear() { |
| 83 sending_activities_.clear(); | 155 sending_activities_.clear(); |
| 84 } | 156 } |
| 85 | 157 |
| 86 void GCMStatsRecorder::CollectSendingActivities( | 158 void GCMStatsRecorder::RecordConnection( |
| 87 std::vector<SendingActivity>* activities) const { | 159 const std::string& event, |
| 88 activities->insert(activities->begin(), | 160 const std::string& details) { |
| 89 sending_activities_.begin(), | 161 ConnectionActivity data; |
| 90 sending_activities_.end()); | 162 ConnectionActivity* inserted_data = InsertCircularBuffer( |
| 163 &connection_activities_, data); | |
| 164 inserted_data->event = event; | |
| 165 inserted_data->details = details; | |
| 166 } | |
| 167 | |
| 168 void GCMStatsRecorder::RecordConnectionInitiated(const std::string& host) { | |
| 169 if (is_recording_) { | |
|
jianli
2014/04/23 17:22:35
nit: brackets not needed
juyik
2014/04/23 21:36:56
Done.
| |
| 170 RecordConnection("Connection initiated", host); | |
| 171 } | |
| 172 } | |
| 173 | |
| 174 void GCMStatsRecorder::RecordConnectionDelayedDueToBackoff(int64 delay_msec) { | |
| 175 if (is_recording_) { | |
| 176 RecordConnection("Connection backoff", | |
| 177 base::StringPrintf("Delayed for %" PRId64 " msec", | |
| 178 delay_msec)); | |
| 179 } | |
| 180 } | |
| 181 | |
| 182 void GCMStatsRecorder::RecordConnectionSuccess() { | |
| 183 if (is_recording_) { | |
| 184 RecordConnection("Connection succeeded", std::string()); | |
| 185 } | |
| 186 } | |
| 187 | |
| 188 void GCMStatsRecorder::RecordConnectionResetSignaled( | |
| 189 ConnectionFactory::ConnectionResetReason reason) { | |
| 190 if (is_recording_) { | |
| 191 RecordConnection("Connection reset", | |
| 192 GetConnectionResetReasonString(reason)); | |
| 193 } | |
| 194 } | |
| 195 | |
| 196 void GCMStatsRecorder::RecordRegistration( | |
| 197 const std::string& android_id, | |
| 198 const std::string& app_id, | |
| 199 const std::string& sender_ids, | |
| 200 const std::string& event, | |
| 201 const std::string& details) { | |
| 202 RegistrationActivity data; | |
| 203 RegistrationActivity* inserted_data = InsertCircularBuffer( | |
| 204 ®istration_activities_, data); | |
| 205 inserted_data->android_id = android_id; | |
| 206 inserted_data->app_id = app_id; | |
| 207 inserted_data->sender_ids = sender_ids; | |
| 208 inserted_data->event = event; | |
| 209 inserted_data->details = details; | |
| 210 } | |
| 211 | |
| 212 void GCMStatsRecorder::RecordRegistrationSent( | |
| 213 const std::string& android_id, | |
| 214 const std::string& app_id, | |
| 215 const std::string& sender_ids) { | |
| 216 UMA_HISTOGRAM_COUNTS("GCM.RegistrationRequest", 1); | |
| 217 if (is_recording_) { | |
| 218 RecordRegistration(android_id, app_id, sender_ids, | |
| 219 "Registration request sent", std::string()); | |
| 220 } | |
| 221 } | |
| 222 | |
| 223 void GCMStatsRecorder::RecordRegistrationResponse( | |
| 224 const std::string& android_id, | |
| 225 const std::string& app_id, | |
| 226 const std::vector<std::string>& sender_ids, | |
| 227 RegistrationRequest::Status status) { | |
| 228 if (is_recording_) { | |
| 229 RecordRegistration(android_id, app_id, JoinString(sender_ids, ","), | |
| 230 "Registration response received", | |
| 231 GetRegistrationStatusString(status)); | |
| 232 } | |
| 233 } | |
| 234 | |
| 235 void GCMStatsRecorder::RecordRegistrationRetryRequested( | |
| 236 const std::string& android_id, | |
| 237 const std::string& app_id, | |
| 238 const std::vector<std::string>& sender_ids, | |
| 239 int retries_left) { | |
| 240 if (is_recording_) { | |
| 241 RecordRegistration(android_id, app_id, JoinString(sender_ids, ","), | |
| 242 "Registration retry requested", | |
| 243 base::StringPrintf("Retries left: %d", retries_left)); | |
| 244 } | |
| 245 } | |
| 246 | |
| 247 void GCMStatsRecorder::RecordReceiving( | |
| 248 const std::string& app_id, | |
| 249 const std::string& from, | |
| 250 int message_byte_size, | |
| 251 const std::string& event, | |
| 252 const std::string& details) { | |
| 253 ReceivingActivity data; | |
| 254 ReceivingActivity* inserted_data = InsertCircularBuffer( | |
| 255 &receiving_activities_, data); | |
| 256 inserted_data->app_id = app_id; | |
| 257 inserted_data->from = from; | |
| 258 inserted_data->message_byte_size = message_byte_size; | |
| 259 inserted_data->event = event; | |
| 260 inserted_data->details = details; | |
| 261 } | |
| 262 | |
| 263 void GCMStatsRecorder::RecordDataRecieved( | |
| 264 const std::string& app_id, | |
| 265 const std::string& from, | |
| 266 int message_byte_size, | |
| 267 bool to_registered_app) { | |
| 268 if (to_registered_app) | |
| 269 UMA_HISTOGRAM_COUNTS("GCM.DataMessageReceived", 1); | |
| 270 if (is_recording_) { | |
| 271 RecordReceiving(app_id, from, message_byte_size, "Data msg received", | |
| 272 to_registered_app ? std::string() : | |
| 273 "No such registered app found"); | |
| 274 } | |
| 275 } | |
| 276 | |
| 277 void GCMStatsRecorder::RecordDataDeletedMessage( | |
| 278 const std::string& app_id, | |
| 279 const std::string& from, | |
| 280 int message_byte_size) { | |
| 281 UMA_HISTOGRAM_COUNTS("GCM.DataMessageDeletedOnServer", 1); | |
| 282 if (is_recording_) { | |
| 283 RecordReceiving(app_id, from, message_byte_size, "Data msg received", | |
| 284 "Message has been deleted on server"); | |
| 285 } | |
| 286 } | |
| 287 | |
| 288 void GCMStatsRecorder::CollectActivities( | |
| 289 std::vector<ConnectionActivity>* connection_activities, | |
| 290 std::vector<RegistrationActivity>* registration_activities, | |
| 291 std::vector<ReceivingActivity>* receiving_activities, | |
| 292 std::vector<SendingActivity>* sending_activities) const { | |
| 293 connection_activities->insert(connection_activities->begin(), | |
| 294 connection_activities_.begin(), | |
| 295 connection_activities_.end()); | |
| 296 registration_activities->insert(registration_activities->begin(), | |
| 297 registration_activities_.begin(), | |
| 298 registration_activities_.end()); | |
| 299 receiving_activities->insert(receiving_activities->begin(), | |
| 300 receiving_activities_.begin(), | |
| 301 receiving_activities_.end()); | |
| 302 sending_activities->insert(sending_activities->begin(), | |
| 303 sending_activities_.begin(), | |
| 304 sending_activities_.end()); | |
| 91 } | 305 } |
| 92 | 306 |
| 93 void GCMStatsRecorder::RecordSending(const std::string& app_id, | 307 void GCMStatsRecorder::RecordSending(const std::string& app_id, |
| 94 const std::string& receiver_id, | 308 const std::string& receiver_id, |
| 95 const std::string& message_id, | 309 const std::string& message_id, |
| 96 const std::string& event, | 310 const std::string& event, |
| 97 const std::string& details) { | 311 const std::string& details) { |
| 98 SendingActivity data; | 312 SendingActivity data; |
| 99 SendingActivity* inserted_data = InsertCircularBuffer( | 313 SendingActivity* inserted_data = InsertCircularBuffer( |
| 100 &sending_activities_, data); | 314 &sending_activities_, data); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 const std::string& receiver_id, | 355 const std::string& receiver_id, |
| 142 const std::string& message_id) { | 356 const std::string& message_id) { |
| 143 UMA_HISTOGRAM_COUNTS("GCM.IncomingSendErrors", 1); | 357 UMA_HISTOGRAM_COUNTS("GCM.IncomingSendErrors", 1); |
| 144 if (is_recording_) { | 358 if (is_recording_) { |
| 145 RecordSending(app_id, receiver_id, message_id, "Received 'send error' msg", | 359 RecordSending(app_id, receiver_id, message_id, "Received 'send error' msg", |
| 146 std::string()); | 360 std::string()); |
| 147 } | 361 } |
| 148 } | 362 } |
| 149 | 363 |
| 150 } // namespace gcm | 364 } // namespace gcm |
| OLD | NEW |