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

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 arv'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 template <typename T>
21 T* InsertCircularBuffer(std::deque<T>* q, const T& item) {
Nicolas Zea 2014/03/27 18:55:42 Comment for this method
juyik 2014/03/27 20:05:11 Done.
22 DCHECK(q);
23 q->push_front(item);
24 if (q->size() > MAX_LOGGED_ACTIVITY_COUNT) {
25 q->pop_back();
26 }
27 return &q->front();
28 }
29
30 // Helper for getting string representation of the MessageSendStatus enum.
31 std::string GetMessageSendStatusString(
32 gcm::MCSClient::MessageSendStatus status) {
33 switch (status) {
34 case gcm::MCSClient::QUEUED:
35 return "QUEUED";
36 case gcm::MCSClient::SENT:
37 return "SENT";
38 case gcm::MCSClient::QUEUE_SIZE_LIMIT_REACHED:
39 return "QUEUE_SIZE_LIMIT_REACHED";
40 case gcm::MCSClient::APP_QUEUE_SIZE_LIMIT_REACHED:
41 return "APP_QUEUE_SIZE_LIMIT_REACHED";
42 case gcm::MCSClient::MESSAGE_TOO_LARGE:
43 return "MESSAGE_TOO_LARGE";
44 case gcm::MCSClient::NO_CONNECTION_ON_ZERO_TTL:
45 return "NO_CONNECTION_ON_ZERO_TTL";
46 case gcm::MCSClient::TTL_EXCEEDED:
47 return "TTL_EXCEEDED";
48 default:
49 NOTREACHED();
50 return "UNKNOWN";
51 }
52 }
53
54 } // namespace
55
56 GCMStatsRecorder::Activity::Activity()
57 : time(base::Time::Now()) {
58 }
59
60 GCMStatsRecorder::Activity::~Activity() {
61 }
62
63 GCMStatsRecorder::SendingActivity::SendingActivity() {
64 }
65
66 GCMStatsRecorder::SendingActivity::~SendingActivity() {
67 }
68
69 GCMStatsRecorder::GCMStatsRecorder() : is_recording_(false) {
70 }
71
72 GCMStatsRecorder::~GCMStatsRecorder() {
73 }
74
75 void GCMStatsRecorder::SetRecording(bool recording) {
76 is_recording_ = recording;
77 }
78
79 void GCMStatsRecorder::Clear() {
80 sending_activities_.clear();
81 }
82
83 void GCMStatsRecorder::RecordSending(const std::string& app_id,
84 const std::string& receiver_id,
85 const std::string& message_id,
86 const std::string& event,
87 const std::string& details) {
88 SendingActivity data;
89 SendingActivity* inserted_data = InsertCircularBuffer(
90 &sending_activities_, data);
91 inserted_data->app_id = app_id;
92 inserted_data->receiver_id = receiver_id;
93 inserted_data->message_id = message_id;
94 inserted_data->event = event;
95 inserted_data->details = details;
96 }
97
98 void GCMStatsRecorder::RecordSentToWire(
99 const std::string& app_id,
100 const std::string& receiver_id,
101 const std::string& message_id,
102 int queued) {
103 if (is_recording_) {
104 RecordSending(app_id, receiver_id, message_id, "Sent to wire",
105 base::StringPrintf("Msg queued for %d seconds", queued));
106 }
107 }
108
109 void GCMStatsRecorder::RecordNotifySendStatus(
110 const std::string& app_id,
111 const std::string& receiver_id,
112 const std::string& message_id,
113 gcm::MCSClient::MessageSendStatus status,
114 int byte_size,
115 int ttl) {
116 UMA_HISTOGRAM_ENUMERATION("GCM.SendMessageStatus", status,
117 gcm::MCSClient::SEND_STATUS_COUNT);
118 if (is_recording_) {
119 RecordSending(
120 app_id,
121 receiver_id,
122 message_id,
123 base::StringPrintf("SEND status: %s",
124 GetMessageSendStatusString(status).c_str()),
125 base::StringPrintf("Msg size: %d bytes, TTL: %d", byte_size, ttl));
126 }
127 }
128
129 void GCMStatsRecorder::RecordIncomingSendError(
130 const std::string& app_id,
131 const std::string& receiver_id,
132 const std::string& message_id,
133 int byte_size,
134 int ttl) {
135 UMA_HISTOGRAM_COUNTS("GCM.IncomingSendErrors", 1);
136 if (is_recording_) {
137 RecordSending(app_id, receiver_id, message_id, "Received 'send error' msg",
138 base::StringPrintf("Msg size: %d bytes, TTL: %d",
139 byte_size, ttl));
140 }
141 }
142
143 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698