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 "components/gcm_driver/gcm_stats_recorder_impl.h" | 5 #include "components/gcm_driver/gcm_stats_recorder_impl.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/format_macros.h" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 default: | 136 default: |
| 137 NOTREACHED(); | 137 NOTREACHED(); |
| 138 return "UNKNOWN_STATUS"; | 138 return "UNKNOWN_STATUS"; |
| 139 } | 139 } |
| 140 } | 140 } |
| 141 | 141 |
| 142 } // namespace | 142 } // namespace |
| 143 | 143 |
| 144 GCMStatsRecorderImpl::GCMStatsRecorderImpl() | 144 GCMStatsRecorderImpl::GCMStatsRecorderImpl() |
| 145 : is_recording_(false), | 145 : is_recording_(false), |
| 146 delegate_(NULL) { | 146 delegate_(NULL), |
| 147 data_message_received_since_connected_(false) { | |
| 147 } | 148 } |
| 148 | 149 |
| 149 GCMStatsRecorderImpl::~GCMStatsRecorderImpl() { | 150 GCMStatsRecorderImpl::~GCMStatsRecorderImpl() { |
| 150 } | 151 } |
| 151 | 152 |
| 152 void GCMStatsRecorderImpl::SetRecording(bool recording) { | 153 void GCMStatsRecorderImpl::SetRecording(bool recording) { |
| 153 is_recording_ = recording; | 154 is_recording_ = recording; |
| 154 } | 155 } |
| 155 | 156 |
| 156 void GCMStatsRecorderImpl::SetDelegate(Delegate* delegate) { | 157 void GCMStatsRecorderImpl::SetDelegate(Delegate* delegate) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 const std::string& details) { | 218 const std::string& details) { |
| 218 ConnectionActivity data; | 219 ConnectionActivity data; |
| 219 ConnectionActivity* inserted_data = InsertCircularBuffer( | 220 ConnectionActivity* inserted_data = InsertCircularBuffer( |
| 220 &connection_activities_, data); | 221 &connection_activities_, data); |
| 221 inserted_data->event = event; | 222 inserted_data->event = event; |
| 222 inserted_data->details = details; | 223 inserted_data->details = details; |
| 223 NotifyActivityRecorded(); | 224 NotifyActivityRecorded(); |
| 224 } | 225 } |
| 225 | 226 |
| 226 void GCMStatsRecorderImpl::RecordConnectionInitiated(const std::string& host) { | 227 void GCMStatsRecorderImpl::RecordConnectionInitiated(const std::string& host) { |
| 228 last_connection_initiation_time_ = base::Time::Now(); | |
|
jar (doing other things)
2014/07/30 21:25:06
I'd strongly suggest using TimeTicks rather than T
juyik
2014/07/31 20:55:34
Done.
| |
| 229 last_connection_success_time_ = base::Time(); | |
| 230 data_message_received_since_connected_ = false; | |
| 227 if (!is_recording_) | 231 if (!is_recording_) |
| 228 return; | 232 return; |
| 229 RecordConnection("Connection initiated", host); | 233 RecordConnection("Connection initiated", host); |
| 230 } | 234 } |
| 231 | 235 |
| 232 void GCMStatsRecorderImpl::RecordConnectionDelayedDueToBackoff( | 236 void GCMStatsRecorderImpl::RecordConnectionDelayedDueToBackoff( |
| 233 int64 delay_msec) { | 237 int64 delay_msec) { |
| 234 if (!is_recording_) | 238 if (!is_recording_) |
| 235 return; | 239 return; |
| 236 RecordConnection("Connection backoff", | 240 RecordConnection("Connection backoff", |
| 237 base::StringPrintf("Delayed for %" PRId64 " msec", | 241 base::StringPrintf("Delayed for %" PRId64 " msec", |
| 238 delay_msec)); | 242 delay_msec)); |
| 239 } | 243 } |
| 240 | 244 |
| 241 void GCMStatsRecorderImpl::RecordConnectionSuccess() { | 245 void GCMStatsRecorderImpl::RecordConnectionSuccess() { |
| 246 DCHECK(!last_connection_initiation_time_.is_null()); | |
| 247 UMA_HISTOGRAM_COUNTS( | |
|
jar (doing other things)
2014/07/30 21:25:06
nit: use UMA_HISTOGRAM_TIMES() and it will take ca
juyik
2014/07/31 20:55:34
Done.
| |
| 248 "GCM.ConnectionLatency", | |
| 249 (base::Time::Now() - last_connection_initiation_time_).InMilliseconds()); | |
| 250 last_connection_success_time_ = base::Time::Now(); | |
| 251 last_connection_initiation_time_ = base::Time(); | |
| 242 if (!is_recording_) | 252 if (!is_recording_) |
| 243 return; | 253 return; |
| 244 RecordConnection("Connection succeeded", std::string()); | 254 RecordConnection("Connection succeeded", std::string()); |
| 245 } | 255 } |
| 246 | 256 |
| 247 void GCMStatsRecorderImpl::RecordConnectionFailure(int network_error) { | 257 void GCMStatsRecorderImpl::RecordConnectionFailure(int network_error) { |
| 248 if (!is_recording_) | 258 if (!is_recording_) |
| 249 return; | 259 return; |
| 250 RecordConnection("Connection failed", | 260 RecordConnection("Connection failed", |
| 251 base::StringPrintf("With network error %d", network_error)); | 261 base::StringPrintf("With network error %d", network_error)); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 369 last_received_data_message_burst_start_time_ = new_timestamp; | 379 last_received_data_message_burst_start_time_ = new_timestamp; |
| 370 } else if ((new_timestamp - last_received_data_message_burst_start_time_) >= | 380 } else if ((new_timestamp - last_received_data_message_burst_start_time_) >= |
| 371 base::TimeDelta::FromSeconds( | 381 base::TimeDelta::FromSeconds( |
| 372 RECEIVED_DATA_MESSAGE_BURST_LENGTH_SECONDS)) { | 382 RECEIVED_DATA_MESSAGE_BURST_LENGTH_SECONDS)) { |
| 373 UMA_HISTOGRAM_COUNTS( | 383 UMA_HISTOGRAM_COUNTS( |
| 374 "GCM.DataMessageBurstReceivedIntervalSeconds", | 384 "GCM.DataMessageBurstReceivedIntervalSeconds", |
| 375 (new_timestamp - last_received_data_message_burst_start_time_) | 385 (new_timestamp - last_received_data_message_burst_start_time_) |
| 376 .InSeconds()); | 386 .InSeconds()); |
| 377 last_received_data_message_burst_start_time_ = new_timestamp; | 387 last_received_data_message_burst_start_time_ = new_timestamp; |
| 378 } | 388 } |
| 389 if (!data_message_received_since_connected_) { | |
| 390 DCHECK(!last_connection_success_time_.is_null()); | |
| 391 UMA_HISTOGRAM_COUNTS( | |
| 392 "GCM.FirstReceivedDataMessageLatencyAfterConnection", | |
| 393 (new_timestamp - last_connection_success_time_).InMilliseconds()); | |
| 394 data_message_received_since_connected_ = true; | |
| 395 } | |
| 379 | 396 |
| 380 if (!is_recording_) | 397 if (!is_recording_) |
| 381 return; | 398 return; |
| 382 if (!to_registered_app) { | 399 if (!to_registered_app) { |
| 383 RecordReceiving(app_id, from, message_byte_size, "Data msg received", | 400 RecordReceiving(app_id, from, message_byte_size, "Data msg received", |
| 384 to_registered_app ? std::string() : | 401 to_registered_app ? std::string() : |
| 385 "No such registered app found"); | 402 "No such registered app found"); |
| 386 } else { | 403 } else { |
| 387 switch(message_type) { | 404 switch(message_type) { |
| 388 case GCMStatsRecorderImpl::DATA_MESSAGE: | 405 case GCMStatsRecorderImpl::DATA_MESSAGE: |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 475 const std::string& receiver_id, | 492 const std::string& receiver_id, |
| 476 const std::string& message_id) { | 493 const std::string& message_id) { |
| 477 UMA_HISTOGRAM_COUNTS("GCM.IncomingSendErrors", 1); | 494 UMA_HISTOGRAM_COUNTS("GCM.IncomingSendErrors", 1); |
| 478 if (!is_recording_) | 495 if (!is_recording_) |
| 479 return; | 496 return; |
| 480 RecordSending(app_id, receiver_id, message_id, "Received 'send error' msg", | 497 RecordSending(app_id, receiver_id, message_id, "Received 'send error' msg", |
| 481 std::string()); | 498 std::string()); |
| 482 } | 499 } |
| 483 | 500 |
| 484 } // namespace gcm | 501 } // namespace gcm |
| OLD | NEW |