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

Side by Side Diff: components/gcm_driver/gcm_stats_recorder_impl.cc

Issue 344613003: Record GCM received data message intervals in UMA (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Jian's and Filip's comments Created 6 years, 5 months 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
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 #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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 15
16 namespace gcm { 16 namespace gcm {
17 17
18 const uint32 MAX_LOGGED_ACTIVITY_COUNT = 100; 18 const uint32 MAX_LOGGED_ACTIVITY_COUNT = 100;
19 const int64 RECEIVED_DATA_MESSAGE_BUSRT_SECONDS = 2;
fgorski 2014/07/16 04:11:11 s/BUSRT/BURST/ s/BURST/BURST_LENGTH/
juyik 2014/07/16 17:49:23 Done.
19 20
20 namespace { 21 namespace {
21 22
22 // Insert an item to the front of deque while maintaining the size of the deque. 23 // Insert an item to the front of deque while maintaining the size of the deque.
23 // Overflow item is discarded. 24 // Overflow item is discarded.
24 template <typename T> 25 template <typename T>
25 T* InsertCircularBuffer(std::deque<T>* q, const T& item) { 26 T* InsertCircularBuffer(std::deque<T>* q, const T& item) {
26 DCHECK(q); 27 DCHECK(q);
27 q->push_front(item); 28 q->push_front(item);
28 if (q->size() > MAX_LOGGED_ACTIVITY_COUNT) { 29 if (q->size() > MAX_LOGGED_ACTIVITY_COUNT) {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 default: 136 default:
136 NOTREACHED(); 137 NOTREACHED();
137 return "UNKNOWN_STATUS"; 138 return "UNKNOWN_STATUS";
138 } 139 }
139 } 140 }
140 141
141 } // namespace 142 } // namespace
142 143
143 GCMStatsRecorderImpl::GCMStatsRecorderImpl() 144 GCMStatsRecorderImpl::GCMStatsRecorderImpl()
144 : is_recording_(false), 145 : is_recording_(false),
145 delegate_(NULL) { 146 delegate_(NULL),
147 last_data_message_received_timestamp_(0) {
146 } 148 }
147 149
148 GCMStatsRecorderImpl::~GCMStatsRecorderImpl() { 150 GCMStatsRecorderImpl::~GCMStatsRecorderImpl() {
149 } 151 }
150 152
151 void GCMStatsRecorderImpl::SetRecording(bool recording) { 153 void GCMStatsRecorderImpl::SetRecording(bool recording) {
152 is_recording_ = recording; 154 is_recording_ = recording;
153 } 155 }
154 156
155 void GCMStatsRecorderImpl::SetDelegate(Delegate* delegate) { 157 void GCMStatsRecorderImpl::SetDelegate(Delegate* delegate) {
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 } 357 }
356 358
357 void GCMStatsRecorderImpl::RecordDataMessageReceived( 359 void GCMStatsRecorderImpl::RecordDataMessageReceived(
358 const std::string& app_id, 360 const std::string& app_id,
359 const std::string& from, 361 const std::string& from,
360 int message_byte_size, 362 int message_byte_size,
361 bool to_registered_app, 363 bool to_registered_app,
362 ReceivedMessageType message_type) { 364 ReceivedMessageType message_type) {
363 if (to_registered_app) 365 if (to_registered_app)
364 UMA_HISTOGRAM_COUNTS("GCM.DataMessageReceived", 1); 366 UMA_HISTOGRAM_COUNTS("GCM.DataMessageReceived", 1);
367
368 int64 new_timestamp = base::Time::Now().ToTimeT();
fgorski 2014/07/16 04:11:11 use base::Time
juyik 2014/07/16 17:49:23 Done.
369 if (last_data_message_received_timestamp_ == 0) {
370 last_data_message_received_timestamp_ = new_timestamp;
371 } else if ((new_timestamp - last_data_message_received_timestamp_) >=
fgorski 2014/07/16 04:11:11 new_timestamp - last_data_message_received_timesta
juyik 2014/07/16 17:49:23 Done.
372 RECEIVED_DATA_MESSAGE_BUSRT_SECONDS) {
373 UMA_HISTOGRAM_COUNTS("GCM.DataMessageBurstReceivedIntervalSeconds",
374 new_timestamp - last_data_message_received_timestamp_);
fgorski 2014/07/16 04:11:11 (new_timestamp - last_data_message_received_timest
fgorski 2014/07/16 04:32:24 One more thing, Remember to set last_data_message_
juyik 2014/07/16 17:49:23 Done.
juyik 2014/07/16 17:49:24 Done.
375 }
376
365 if (!is_recording_) 377 if (!is_recording_)
366 return; 378 return;
367 if (!to_registered_app) { 379 if (!to_registered_app) {
368 RecordReceiving(app_id, from, message_byte_size, "Data msg received", 380 RecordReceiving(app_id, from, message_byte_size, "Data msg received",
369 to_registered_app ? std::string() : 381 to_registered_app ? std::string() :
370 "No such registered app found"); 382 "No such registered app found");
371 } else { 383 } else {
372 switch(message_type) { 384 switch(message_type) {
373 case GCMStatsRecorderImpl::DATA_MESSAGE: 385 case GCMStatsRecorderImpl::DATA_MESSAGE:
374 RecordReceiving(app_id, from, message_byte_size, "Data msg received", 386 RecordReceiving(app_id, from, message_byte_size, "Data msg received",
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 const std::string& receiver_id, 472 const std::string& receiver_id,
461 const std::string& message_id) { 473 const std::string& message_id) {
462 UMA_HISTOGRAM_COUNTS("GCM.IncomingSendErrors", 1); 474 UMA_HISTOGRAM_COUNTS("GCM.IncomingSendErrors", 1);
463 if (!is_recording_) 475 if (!is_recording_)
464 return; 476 return;
465 RecordSending(app_id, receiver_id, message_id, "Received 'send error' msg", 477 RecordSending(app_id, receiver_id, message_id, "Received 'send error' msg",
466 std::string()); 478 std::string());
467 } 479 }
468 480
469 } // namespace gcm 481 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698