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

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: Add struct constructor/destructor. Created 6 years, 8 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:
25 // Contains data that are common to all activity kinds below. 28 // Contains data that are common to all activity kinds below.
26 struct GCM_EXPORT Activity { 29 struct GCM_EXPORT Activity {
27 Activity(); 30 Activity();
28 virtual ~Activity(); 31 virtual ~Activity();
29 32
30 base::Time time; 33 base::Time time;
31 std::string event; // A short description of the event. 34 std::string event; // A short description of the event.
32 std::string details; // Any additional detail about the event. 35 std::string details; // Any additional detail about the event.
33 }; 36 };
34 37
38 // Contains relevant data of a connection activity.
39 struct GCM_EXPORT ConnectionActivity : Activity {
40 ConnectionActivity();
41 virtual ~ConnectionActivity();
42 };
43
44 // Contains relevant data of a registration/unregistration step.
45 struct GCM_EXPORT RegistrationActivity : Activity {
46 RegistrationActivity();
47 virtual ~RegistrationActivity();
48
49 std::string app_id;
50 std::string sender_ids; // Comma separated sender ids.
51 };
52
53 // Contains relevant data of a message receiving event.
54 struct GCM_EXPORT ReceivingActivity : Activity {
55 ReceivingActivity();
56 virtual ~ReceivingActivity();
57
58 std::string app_id;
59 std::string from;
60 int message_byte_size;
61 };
62
35 // Contains relevant data of a send-message step. 63 // Contains relevant data of a send-message step.
36 struct GCM_EXPORT SendingActivity : Activity { 64 struct GCM_EXPORT SendingActivity : Activity {
37 SendingActivity(); 65 SendingActivity();
38 virtual ~SendingActivity(); 66 virtual ~SendingActivity();
39 67
40 std::string app_id; 68 std::string app_id;
41 std::string receiver_id; 69 std::string receiver_id;
42 std::string message_id; 70 std::string message_id;
43 }; 71 };
44 72
73 struct GCM_EXPORT RecordedActivities {
74 RecordedActivities();
75 virtual ~RecordedActivities();
76
77 std::vector<GCMStatsRecorder::ConnectionActivity> connection_activities;
78 std::vector<GCMStatsRecorder::RegistrationActivity> registration_activities;
79 std::vector<GCMStatsRecorder::ReceivingActivity> receiving_activities;
80 std::vector<GCMStatsRecorder::SendingActivity> sending_activities;
81 };
82
45 GCMStatsRecorder(); 83 GCMStatsRecorder();
46 virtual ~GCMStatsRecorder(); 84 virtual ~GCMStatsRecorder();
47 85
48 // Indicates whether the recorder is currently recording activities or not. 86 // Indicates whether the recorder is currently recording activities or not.
49 bool is_recording() const { 87 bool is_recording() const {
50 return is_recording_; 88 return is_recording_;
51 } 89 }
52 90
53 // Turns recording on/off. 91 // Turns recording on/off.
54 void SetRecording(bool recording); 92 void SetRecording(bool recording);
55 93
56 // Clear all recorded activities. 94 // Clear all recorded activities.
57 void Clear(); 95 void Clear();
58 96
97 // All RecordXXXX methods below will record one activity. It will be inserted
98 // to the front of a queue so that entries in the queue had reverse
99 // chronological order.
100
101 // Records that a connection to MCS has been initiated.
102 void RecordConnectionInitiated(const std::string& host);
103
104 // Records that a connection has been delayed due to backoff.
105 void RecordConnectionDelayedDueToBackoff(int64 delay_msec);
106
107 // Records that connection has been successfully established.
108 void RecordConnectionSuccess();
109
110 // Records that connection has failed with a network error code.
111 void RecordConnectionFailure(int network_error);
112
113 // Records that connection reset has been signaled.
114 void RecordConnectionResetSignaled(
115 ConnectionFactory::ConnectionResetReason reason);
116
117 // Records that a registration request has been sent. This could be initiated
118 // directly from API, or from retry logic.
119 void RecordRegistrationSent(const std::string& app_id,
120 const std::string& sender_ids);
121
122 // Records that a registration response has been received from server.
123 void RecordRegistrationResponse(const std::string& app_id,
124 const std::vector<std::string>& sender_ids,
125 RegistrationRequest::Status status);
126
127 // Records that a registration retry has been requested. The actual retry
128 // action may not occur until some time later according to backoff logic.
129 void RecordRegistrationRetryRequested(
130 const std::string& app_id,
131 const std::vector<std::string>& sender_ids,
132 int retries_left);
133
134 // Records that an unregistration request has been sent. This could be
135 // initiated directly from API, or from retry logic.
136 void RecordUnregistrationSent(const std::string& app_id);
137
138 // Records that an unregistration response has been received from server.
139 void RecordUnregistrationResponse(const std::string& app_id,
140 UnregistrationRequest::Status status);
141
142 // Records that an unregistration retry has been requested and delayed due to
143 // backoff logic.
144 void RecordUnregistrationRetryDelayed(const std::string& app_id,
145 int64 delay_msec);
146
147 // Records that a data message has been received. If this message is not
148 // sent to a registered app, to_registered_app shoudl be false. If it
149 // indicates that a message has been dropped on the server, is_message_dropped
150 // should be true.
151 void RecordDataMessageRecieved(const std::string& app_id,
152 const std::string& from,
153 int message_byte_size,
154 bool to_registered_app,
Nicolas Zea 2014/04/24 21:37:43 nit: style guide prefers using an enum rather than
juyik 2014/04/25 20:37:39 Done. Added enum of received message type.
155 bool is_message_dropped);
156
59 // Records that an outgoing data message was sent over the wire. 157 // Records that an outgoing data message was sent over the wire.
60 void RecordDataSentToWire(const std::string& app_id, 158 void RecordDataSentToWire(const std::string& app_id,
61 const std::string& receiver_id, 159 const std::string& receiver_id,
62 const std::string& message_id, 160 const std::string& message_id,
63 int queued); 161 int queued);
64 // Records that the MCS client sent a 'send status' notification to callback. 162 // Records that the MCS client sent a 'send status' notification to callback.
65 void RecordNotifySendStatus(const std::string& app_id, 163 void RecordNotifySendStatus(const std::string& app_id,
66 const std::string& receiver_id, 164 const std::string& receiver_id,
67 const std::string& message_id, 165 const std::string& message_id,
68 MCSClient::MessageSendStatus status, 166 MCSClient::MessageSendStatus status,
69 int byte_size, 167 int byte_size,
70 int ttl); 168 int ttl);
71 // Records that a 'send error' message was received. 169 // Records that a 'send error' message was received.
72 void RecordIncomingSendError(const std::string& app_id, 170 void RecordIncomingSendError(const std::string& app_id,
73 const std::string& receiver_id, 171 const std::string& receiver_id,
74 const std::string& message_id); 172 const std::string& message_id);
75 173
76 // Records that a sending activity has occurred. It will be inserted to the 174 // Collect all recorded activities into the struct.
77 // front of a queue ao that entries in the queue had reverse chronological 175 void CollectActivities(RecordedActivities* recorder_activities) const;
78 // order.
79 void CollectSendingActivities(std::vector<SendingActivity>* activities) const;
80 176
177 const std::deque<ConnectionActivity>& connection_activities() const {
178 return connection_activities_;
179 }
180 const std::deque<RegistrationActivity>& registration_activities() const {
181 return registration_activities_;
182 }
183 const std::deque<ReceivingActivity>& receiving_activities() const {
184 return receiving_activities_;
185 }
81 const std::deque<SendingActivity>& sending_activities() const { 186 const std::deque<SendingActivity>& sending_activities() const {
82 return sending_activities_; 187 return sending_activities_;
83 } 188 }
84 189
85 protected: 190 protected:
191 void RecordConnection(const std::string& event,
192 const std::string& details);
193 void RecordRegistration(const std::string& app_id,
194 const std::string& sender_id,
195 const std::string& event,
196 const std::string& details);
197 void RecordReceiving(const std::string& app_id,
198 const std::string& from,
199 int message_byte_size,
200 const std::string& event,
201 const std::string& details);
86 void RecordSending(const std::string& app_id, 202 void RecordSending(const std::string& app_id,
87 const std::string& receiver_id, 203 const std::string& receiver_id,
88 const std::string& message_id, 204 const std::string& message_id,
89 const std::string& event, 205 const std::string& event,
90 const std::string& details); 206 const std::string& details);
91 207
92 bool is_recording_; 208 bool is_recording_;
93 209
210 std::deque<ConnectionActivity> connection_activities_;
211 std::deque<RegistrationActivity> registration_activities_;
212 std::deque<ReceivingActivity> receiving_activities_;
94 std::deque<SendingActivity> sending_activities_; 213 std::deque<SendingActivity> sending_activities_;
95 214
96 DISALLOW_COPY_AND_ASSIGN(GCMStatsRecorder); 215 DISALLOW_COPY_AND_ASSIGN(GCMStatsRecorder);
97 }; 216 };
98 217
99 } // namespace gcm 218 } // namespace gcm
100 219
101 #endif // GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_ 220 #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