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

Side by Side Diff: google_apis/gcm/gcm_stats_recorder.cc

Issue 202083005: Add activity recording capability to gcm internals page. User can refresh, start/stop recording, an… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing zea's comments. Created 6 years, 9 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "google_apis/gcm/gcm_stats_recorder.h"
6
7 #include <deque>
8
9 #include "base/logging.h"
10 #include "base/metrics/histogram.h"
11 #include "base/strings/string_util.h"
12 #include "base/strings/stringprintf.h"
13
14 namespace gcm {
15
16 const uint32 MAX_LOGGED_ACTIVITY_COUNT = 100;
17
18 namespace {
19
20 // Insert an itme to the front of deque while maintaining the size of the deque.
21 // Overflow item is discarded.
22 template <typename T>
23 T* InsertCircularBuffer(std::deque<T>* q, const T& item) {
24 DCHECK(q);
25 q->push_front(item);
26 if (q->size() > MAX_LOGGED_ACTIVITY_COUNT) {
27 q->pop_back();
28 }
29 return &q->front();
30 }
31
32 // Helper for getting string representation of the MessageSendStatus enum.
33 std::string GetMessageSendStatusString(
34 gcm::MCSClient::MessageSendStatus status) {
35 switch (status) {
36 case gcm::MCSClient::QUEUED:
37 return "QUEUED";
38 case gcm::MCSClient::SENT:
39 return "SENT";
40 case gcm::MCSClient::QUEUE_SIZE_LIMIT_REACHED:
41 return "QUEUE_SIZE_LIMIT_REACHED";
42 case gcm::MCSClient::APP_QUEUE_SIZE_LIMIT_REACHED:
43 return "APP_QUEUE_SIZE_LIMIT_REACHED";
44 case gcm::MCSClient::MESSAGE_TOO_LARGE:
45 return "MESSAGE_TOO_LARGE";
46 case gcm::MCSClient::NO_CONNECTION_ON_ZERO_TTL:
47 return "NO_CONNECTION_ON_ZERO_TTL";
48 case gcm::MCSClient::TTL_EXCEEDED:
49 return "TTL_EXCEEDED";
50 default:
51 NOTREACHED();
52 return "UNKNOWN";
53 }
54 }
55
56 } // namespace
57
58 GCMStatsRecorder::Activity::Activity()
59 : time(base::Time::Now()) {
60 }
61
62 GCMStatsRecorder::Activity::~Activity() {
63 }
64
65 GCMStatsRecorder::SendingActivity::SendingActivity() {
66 }
67
68 GCMStatsRecorder::SendingActivity::~SendingActivity() {
69 }
70
71 GCMStatsRecorder::GCMStatsRecorder() : is_recording_(false) {
72 }
73
74 GCMStatsRecorder::~GCMStatsRecorder() {
75 }
76
77 void GCMStatsRecorder::SetRecording(bool recording) {
78 is_recording_ = recording;
79 }
80
81 void GCMStatsRecorder::Clear() {
82 sending_activities_.clear();
83 }
84
85 void GCMStatsRecorder::RecordSending(const std::string& app_id,
86 const std::string& receiver_id,
87 const std::string& message_id,
88 const std::string& event,
89 const std::string& details) {
90 SendingActivity data;
91 SendingActivity* inserted_data = InsertCircularBuffer(
92 &sending_activities_, data);
93 inserted_data->app_id = app_id;
94 inserted_data->receiver_id = receiver_id;
95 inserted_data->message_id = message_id;
96 inserted_data->event = event;
97 inserted_data->details = details;
98 }
99
100 void GCMStatsRecorder::RecordDataSentToWire(
101 const std::string& app_id,
102 const std::string& receiver_id,
103 const std::string& message_id,
104 int queued) {
105 if (is_recording_) {
106 RecordSending(app_id, receiver_id, message_id, "Data msg sent to wire",
107 base::StringPrintf("Msg queued for %d seconds", queued));
108 }
109 }
110
111 void GCMStatsRecorder::RecordNotifySendStatus(
112 const std::string& app_id,
113 const std::string& receiver_id,
114 const std::string& message_id,
115 gcm::MCSClient::MessageSendStatus status,
116 int byte_size,
117 int ttl) {
118 UMA_HISTOGRAM_ENUMERATION("GCM.SendMessageStatus", status,
119 gcm::MCSClient::SEND_STATUS_COUNT);
120 if (is_recording_) {
121 RecordSending(
122 app_id,
123 receiver_id,
124 message_id,
125 base::StringPrintf("SEND status: %s",
126 GetMessageSendStatusString(status).c_str()),
127 base::StringPrintf("Msg size: %d bytes, TTL: %d", byte_size, ttl));
128 }
129 }
130
131 void GCMStatsRecorder::RecordIncomingSendError(
132 const std::string& app_id,
133 const std::string& receiver_id,
134 const std::string& message_id,
135 int byte_size,
136 int ttl) {
137 UMA_HISTOGRAM_COUNTS("GCM.IncomingSendErrors", 1);
138 if (is_recording_) {
139 RecordSending(app_id, receiver_id, message_id, "Received 'send error' msg",
140 base::StringPrintf("Msg size: %d bytes, TTL: %d",
141 byte_size, ttl));
142 }
143 }
144
145 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698