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

Side by Side Diff: google_apis/gcm/monitoring/gcm_stats_recorder.h

Issue 248213004: Record connection, registration, and receiving activities. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 6 years, 7 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 #ifndef GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_ 5 #ifndef GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_
6 #define GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_ 6 #define GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_
7 7
8 #include <deque> 8 #include <deque>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "google_apis/gcm/base/gcm_export.h" 13 #include "google_apis/gcm/base/gcm_export.h"
14 #include "google_apis/gcm/engine/connection_factory.h"
14 #include "google_apis/gcm/engine/mcs_client.h" 15 #include "google_apis/gcm/engine/mcs_client.h"
16 #include "google_apis/gcm/engine/registration_request.h"
17 #include "google_apis/gcm/engine/unregistration_request.h"
15 18
16 namespace gcm { 19 namespace gcm {
17 20
18 // Records GCM internal stats and activities for debugging purpose. Recording 21 // Records GCM internal stats and activities for debugging purpose. Recording
19 // can be turned on/off by calling SetRecording(...) function. It is turned off 22 // can be turned on/off by calling SetRecording(...) function. It is turned off
20 // by default. 23 // by default.
21 // This class is not thread safe. It is meant to be owned by a gcm client 24 // This class is not thread safe. It is meant to be owned by a gcm client
22 // instance. 25 // instance.
23 class GCM_EXPORT GCMStatsRecorder { 26 class GCM_EXPORT GCMStatsRecorder {
24 public: 27 public:
28 // Type of a received message
29 enum ReceivedMessageType {
30 // Data message.
31 DATA_MESSAGE,
32 // Message that indicates some messages have been deleted on the server.
33 DELETED_MESSAGES,
34 };
35
25 // Contains data that are common to all activity kinds below. 36 // Contains data that are common to all activity kinds below.
26 struct GCM_EXPORT Activity { 37 struct GCM_EXPORT Activity {
27 Activity(); 38 Activity();
28 virtual ~Activity(); 39 virtual ~Activity();
29 40
30 base::Time time; 41 base::Time time;
31 std::string event; // A short description of the event. 42 std::string event; // A short description of the event.
32 std::string details; // Any additional detail about the event. 43 std::string details; // Any additional detail about the event.
33 }; 44 };
34 45
46 // Contains relevant data of a connection activity.
47 struct GCM_EXPORT ConnectionActivity : Activity {
48 ConnectionActivity();
49 virtual ~ConnectionActivity();
50 };
51
52 // Contains relevant data of a registration/unregistration step.
53 struct GCM_EXPORT RegistrationActivity : Activity {
54 RegistrationActivity();
55 virtual ~RegistrationActivity();
56
57 std::string app_id;
58 std::string sender_ids; // Comma separated sender ids.
59 };
60
61 // Contains relevant data of a message receiving event.
62 struct GCM_EXPORT ReceivingActivity : Activity {
63 ReceivingActivity();
64 virtual ~ReceivingActivity();
65
66 std::string app_id;
67 std::string from;
68 int message_byte_size;
69 };
70
35 // Contains relevant data of a send-message step. 71 // Contains relevant data of a send-message step.
36 struct GCM_EXPORT SendingActivity : Activity { 72 struct GCM_EXPORT SendingActivity : Activity {
37 SendingActivity(); 73 SendingActivity();
38 virtual ~SendingActivity(); 74 virtual ~SendingActivity();
39 75
40 std::string app_id; 76 std::string app_id;
41 std::string receiver_id; 77 std::string receiver_id;
42 std::string message_id; 78 std::string message_id;
43 }; 79 };
44 80
81 struct GCM_EXPORT RecordedActivities {
82 RecordedActivities();
83 virtual ~RecordedActivities();
84
85 std::vector<GCMStatsRecorder::ConnectionActivity> connection_activities;
86 std::vector<GCMStatsRecorder::RegistrationActivity> registration_activities;
87 std::vector<GCMStatsRecorder::ReceivingActivity> receiving_activities;
88 std::vector<GCMStatsRecorder::SendingActivity> sending_activities;
89 };
90
45 GCMStatsRecorder(); 91 GCMStatsRecorder();
46 virtual ~GCMStatsRecorder(); 92 virtual ~GCMStatsRecorder();
47 93
48 // Indicates whether the recorder is currently recording activities or not. 94 // Indicates whether the recorder is currently recording activities or not.
49 bool is_recording() const { 95 bool is_recording() const {
50 return is_recording_; 96 return is_recording_;
51 } 97 }
52 98
53 // Turns recording on/off. 99 // Turns recording on/off.
54 void SetRecording(bool recording); 100 void SetRecording(bool recording);
55 101
56 // Clear all recorded activities. 102 // Clear all recorded activities.
57 void Clear(); 103 void Clear();
58 104
105 // All RecordXXXX methods below will record one activity. It will be inserted
106 // to the front of a queue so that entries in the queue had reverse
107 // chronological order.
108
109 // Records that a connection to MCS has been initiated.
110 void RecordConnectionInitiated(const std::string& host);
111
112 // Records that a connection has been delayed due to backoff.
113 void RecordConnectionDelayedDueToBackoff(int64 delay_msec);
114
115 // Records that connection has been successfully established.
116 void RecordConnectionSuccess();
117
118 // Records that connection has failed with a network error code.
119 void RecordConnectionFailure(int network_error);
120
121 // Records that connection reset has been signaled.
122 void RecordConnectionResetSignaled(
123 ConnectionFactory::ConnectionResetReason reason);
124
125 // Records that a registration request has been sent. This could be initiated
126 // directly from API, or from retry logic.
127 void RecordRegistrationSent(const std::string& app_id,
128 const std::string& sender_ids);
129
130 // Records that a registration response has been received from server.
131 void RecordRegistrationResponse(const std::string& app_id,
132 const std::vector<std::string>& sender_ids,
133 RegistrationRequest::Status status);
134
135 // Records that a registration retry has been requested. The actual retry
136 // action may not occur until some time later according to backoff logic.
137 void RecordRegistrationRetryRequested(
138 const std::string& app_id,
139 const std::vector<std::string>& sender_ids,
140 int retries_left);
141
142 // Records that an unregistration request has been sent. This could be
143 // initiated directly from API, or from retry logic.
144 void RecordUnregistrationSent(const std::string& app_id);
145
146 // Records that an unregistration response has been received from server.
147 void RecordUnregistrationResponse(const std::string& app_id,
148 UnregistrationRequest::Status status);
149
150 // Records that an unregistration retry has been requested and delayed due to
151 // backoff logic.
152 void RecordUnregistrationRetryDelayed(const std::string& app_id,
153 int64 delay_msec);
154
155 // Records that a data message has been received. If this message is not
156 // sent to a registered app, to_registered_app shoudl be false. If it
157 // indicates that a message has been dropped on the server, is_message_dropped
158 // should be true.
159 void RecordDataMessageRecieved(const std::string& app_id,
160 const std::string& from,
161 int message_byte_size,
162 bool to_registered_app,
163 ReceivedMessageType message_type);
164
59 // Records that an outgoing data message was sent over the wire. 165 // Records that an outgoing data message was sent over the wire.
60 void RecordDataSentToWire(const std::string& app_id, 166 void RecordDataSentToWire(const std::string& app_id,
61 const std::string& receiver_id, 167 const std::string& receiver_id,
62 const std::string& message_id, 168 const std::string& message_id,
63 int queued); 169 int queued);
64 // Records that the MCS client sent a 'send status' notification to callback. 170 // Records that the MCS client sent a 'send status' notification to callback.
65 void RecordNotifySendStatus(const std::string& app_id, 171 void RecordNotifySendStatus(const std::string& app_id,
66 const std::string& receiver_id, 172 const std::string& receiver_id,
67 const std::string& message_id, 173 const std::string& message_id,
68 MCSClient::MessageSendStatus status, 174 MCSClient::MessageSendStatus status,
69 int byte_size, 175 int byte_size,
70 int ttl); 176 int ttl);
71 // Records that a 'send error' message was received. 177 // Records that a 'send error' message was received.
72 void RecordIncomingSendError(const std::string& app_id, 178 void RecordIncomingSendError(const std::string& app_id,
73 const std::string& receiver_id, 179 const std::string& receiver_id,
74 const std::string& message_id); 180 const std::string& message_id);
75 181
76 // Records that a sending activity has occurred. It will be inserted to the 182 // Collect all recorded activities into the struct.
77 // front of a queue ao that entries in the queue had reverse chronological 183 void CollectActivities(RecordedActivities* recorder_activities) const;
78 // order.
79 void CollectSendingActivities(std::vector<SendingActivity>* activities) const;
80 184
185 const std::deque<ConnectionActivity>& connection_activities() const {
186 return connection_activities_;
187 }
188 const std::deque<RegistrationActivity>& registration_activities() const {
189 return registration_activities_;
190 }
191 const std::deque<ReceivingActivity>& receiving_activities() const {
192 return receiving_activities_;
193 }
81 const std::deque<SendingActivity>& sending_activities() const { 194 const std::deque<SendingActivity>& sending_activities() const {
82 return sending_activities_; 195 return sending_activities_;
83 } 196 }
84 197
85 protected: 198 protected:
199 void RecordConnection(const std::string& event,
200 const std::string& details);
201 void RecordRegistration(const std::string& app_id,
202 const std::string& sender_id,
203 const std::string& event,
204 const std::string& details);
205 void RecordReceiving(const std::string& app_id,
206 const std::string& from,
207 int message_byte_size,
208 const std::string& event,
209 const std::string& details);
86 void RecordSending(const std::string& app_id, 210 void RecordSending(const std::string& app_id,
87 const std::string& receiver_id, 211 const std::string& receiver_id,
88 const std::string& message_id, 212 const std::string& message_id,
89 const std::string& event, 213 const std::string& event,
90 const std::string& details); 214 const std::string& details);
91 215
92 bool is_recording_; 216 bool is_recording_;
93 217
218 std::deque<ConnectionActivity> connection_activities_;
219 std::deque<RegistrationActivity> registration_activities_;
220 std::deque<ReceivingActivity> receiving_activities_;
94 std::deque<SendingActivity> sending_activities_; 221 std::deque<SendingActivity> sending_activities_;
95 222
96 DISALLOW_COPY_AND_ASSIGN(GCMStatsRecorder); 223 DISALLOW_COPY_AND_ASSIGN(GCMStatsRecorder);
97 }; 224 };
98 225
99 } // namespace gcm 226 } // namespace gcm
100 227
101 #endif // GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_ 228 #endif // GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_
OLDNEW
« no previous file with comments | « google_apis/gcm/gcm_client_impl_unittest.cc ('k') | google_apis/gcm/monitoring/gcm_stats_recorder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698