OLD | NEW |
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/checkin_request.h" |
14 #include "google_apis/gcm/engine/connection_factory.h" | 15 #include "google_apis/gcm/engine/connection_factory.h" |
15 #include "google_apis/gcm/engine/mcs_client.h" | 16 #include "google_apis/gcm/engine/mcs_client.h" |
16 #include "google_apis/gcm/engine/registration_request.h" | 17 #include "google_apis/gcm/engine/registration_request.h" |
17 #include "google_apis/gcm/engine/unregistration_request.h" | 18 #include "google_apis/gcm/engine/unregistration_request.h" |
18 | 19 |
19 namespace gcm { | 20 namespace gcm { |
20 | 21 |
21 // Records GCM internal stats and activities for debugging purpose. Recording | 22 // Records GCM internal stats and activities for debugging purpose. Recording |
22 // can be turned on/off by calling SetRecording(...) function. It is turned off | 23 // can be turned on/off by calling SetRecording(...) function. It is turned off |
23 // by default. | 24 // by default. |
(...skipping 18 matching lines...) Expand all Loading... |
42 std::string event; // A short description of the event. | 43 std::string event; // A short description of the event. |
43 std::string details; // Any additional detail about the event. | 44 std::string details; // Any additional detail about the event. |
44 }; | 45 }; |
45 | 46 |
46 // Contains relevant data of a connection activity. | 47 // Contains relevant data of a connection activity. |
47 struct GCM_EXPORT ConnectionActivity : Activity { | 48 struct GCM_EXPORT ConnectionActivity : Activity { |
48 ConnectionActivity(); | 49 ConnectionActivity(); |
49 virtual ~ConnectionActivity(); | 50 virtual ~ConnectionActivity(); |
50 }; | 51 }; |
51 | 52 |
| 53 // Contains relevant data of a check-in activity. |
| 54 struct GCM_EXPORT CheckinActivity : Activity { |
| 55 CheckinActivity(); |
| 56 virtual ~CheckinActivity(); |
| 57 }; |
| 58 |
52 // Contains relevant data of a registration/unregistration step. | 59 // Contains relevant data of a registration/unregistration step. |
53 struct GCM_EXPORT RegistrationActivity : Activity { | 60 struct GCM_EXPORT RegistrationActivity : Activity { |
54 RegistrationActivity(); | 61 RegistrationActivity(); |
55 virtual ~RegistrationActivity(); | 62 virtual ~RegistrationActivity(); |
56 | 63 |
57 std::string app_id; | 64 std::string app_id; |
58 std::string sender_ids; // Comma separated sender ids. | 65 std::string sender_ids; // Comma separated sender ids. |
59 }; | 66 }; |
60 | 67 |
61 // Contains relevant data of a message receiving event. | 68 // Contains relevant data of a message receiving event. |
(...skipping 13 matching lines...) Expand all Loading... |
75 | 82 |
76 std::string app_id; | 83 std::string app_id; |
77 std::string receiver_id; | 84 std::string receiver_id; |
78 std::string message_id; | 85 std::string message_id; |
79 }; | 86 }; |
80 | 87 |
81 struct GCM_EXPORT RecordedActivities { | 88 struct GCM_EXPORT RecordedActivities { |
82 RecordedActivities(); | 89 RecordedActivities(); |
83 virtual ~RecordedActivities(); | 90 virtual ~RecordedActivities(); |
84 | 91 |
| 92 std::vector<GCMStatsRecorder::CheckinActivity> checkin_activities; |
85 std::vector<GCMStatsRecorder::ConnectionActivity> connection_activities; | 93 std::vector<GCMStatsRecorder::ConnectionActivity> connection_activities; |
86 std::vector<GCMStatsRecorder::RegistrationActivity> registration_activities; | 94 std::vector<GCMStatsRecorder::RegistrationActivity> registration_activities; |
87 std::vector<GCMStatsRecorder::ReceivingActivity> receiving_activities; | 95 std::vector<GCMStatsRecorder::ReceivingActivity> receiving_activities; |
88 std::vector<GCMStatsRecorder::SendingActivity> sending_activities; | 96 std::vector<GCMStatsRecorder::SendingActivity> sending_activities; |
89 }; | 97 }; |
90 | 98 |
91 GCMStatsRecorder(); | 99 GCMStatsRecorder(); |
92 virtual ~GCMStatsRecorder(); | 100 virtual ~GCMStatsRecorder(); |
93 | 101 |
94 // Indicates whether the recorder is currently recording activities or not. | 102 // Indicates whether the recorder is currently recording activities or not. |
95 bool is_recording() const { | 103 bool is_recording() const { |
96 return is_recording_; | 104 return is_recording_; |
97 } | 105 } |
98 | 106 |
99 // Turns recording on/off. | 107 // Turns recording on/off. |
100 void SetRecording(bool recording); | 108 void SetRecording(bool recording); |
101 | 109 |
102 // Clear all recorded activities. | 110 // Clear all recorded activities. |
103 void Clear(); | 111 void Clear(); |
104 | 112 |
105 // All RecordXXXX methods below will record one activity. It will be inserted | 113 // 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 | 114 // to the front of a queue so that entries in the queue had reverse |
107 // chronological order. | 115 // chronological order. |
108 | 116 |
| 117 // Records that a check-in has been initiated. |
| 118 void RecordCheckinInitiated(uint64 android_id); |
| 119 |
| 120 // Records that a check-in has been delayed due to backoff. |
| 121 void RecordCheckinDelayedDueToBackoff(int64 delay_msec); |
| 122 |
| 123 // Records that a check-in request has succeeded. |
| 124 void RecordCheckinSuccess(); |
| 125 |
| 126 // Records that a check-in request has failed. If a retry will be tempted then |
| 127 // will_retry should be true. |
| 128 void RecordCheckinFailure(std::string status, bool will_retry); |
| 129 |
109 // Records that a connection to MCS has been initiated. | 130 // Records that a connection to MCS has been initiated. |
110 void RecordConnectionInitiated(const std::string& host); | 131 void RecordConnectionInitiated(const std::string& host); |
111 | 132 |
112 // Records that a connection has been delayed due to backoff. | 133 // Records that a connection has been delayed due to backoff. |
113 void RecordConnectionDelayedDueToBackoff(int64 delay_msec); | 134 void RecordConnectionDelayedDueToBackoff(int64 delay_msec); |
114 | 135 |
115 // Records that connection has been successfully established. | 136 // Records that connection has been successfully established. |
116 void RecordConnectionSuccess(); | 137 void RecordConnectionSuccess(); |
117 | 138 |
118 // Records that connection has failed with a network error code. | 139 // Records that connection has failed with a network error code. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 int byte_size, | 196 int byte_size, |
176 int ttl); | 197 int ttl); |
177 // Records that a 'send error' message was received. | 198 // Records that a 'send error' message was received. |
178 void RecordIncomingSendError(const std::string& app_id, | 199 void RecordIncomingSendError(const std::string& app_id, |
179 const std::string& receiver_id, | 200 const std::string& receiver_id, |
180 const std::string& message_id); | 201 const std::string& message_id); |
181 | 202 |
182 // Collect all recorded activities into the struct. | 203 // Collect all recorded activities into the struct. |
183 void CollectActivities(RecordedActivities* recorder_activities) const; | 204 void CollectActivities(RecordedActivities* recorder_activities) const; |
184 | 205 |
| 206 const std::deque<CheckinActivity>& checkin_activities() const { |
| 207 return checkin_activities_; |
| 208 } |
185 const std::deque<ConnectionActivity>& connection_activities() const { | 209 const std::deque<ConnectionActivity>& connection_activities() const { |
186 return connection_activities_; | 210 return connection_activities_; |
187 } | 211 } |
188 const std::deque<RegistrationActivity>& registration_activities() const { | 212 const std::deque<RegistrationActivity>& registration_activities() const { |
189 return registration_activities_; | 213 return registration_activities_; |
190 } | 214 } |
191 const std::deque<ReceivingActivity>& receiving_activities() const { | 215 const std::deque<ReceivingActivity>& receiving_activities() const { |
192 return receiving_activities_; | 216 return receiving_activities_; |
193 } | 217 } |
194 const std::deque<SendingActivity>& sending_activities() const { | 218 const std::deque<SendingActivity>& sending_activities() const { |
195 return sending_activities_; | 219 return sending_activities_; |
196 } | 220 } |
197 | 221 |
198 protected: | 222 protected: |
| 223 void RecordCheckin(const std::string& event, |
| 224 const std::string& details); |
199 void RecordConnection(const std::string& event, | 225 void RecordConnection(const std::string& event, |
200 const std::string& details); | 226 const std::string& details); |
201 void RecordRegistration(const std::string& app_id, | 227 void RecordRegistration(const std::string& app_id, |
202 const std::string& sender_id, | 228 const std::string& sender_id, |
203 const std::string& event, | 229 const std::string& event, |
204 const std::string& details); | 230 const std::string& details); |
205 void RecordReceiving(const std::string& app_id, | 231 void RecordReceiving(const std::string& app_id, |
206 const std::string& from, | 232 const std::string& from, |
207 int message_byte_size, | 233 int message_byte_size, |
208 const std::string& event, | 234 const std::string& event, |
209 const std::string& details); | 235 const std::string& details); |
210 void RecordSending(const std::string& app_id, | 236 void RecordSending(const std::string& app_id, |
211 const std::string& receiver_id, | 237 const std::string& receiver_id, |
212 const std::string& message_id, | 238 const std::string& message_id, |
213 const std::string& event, | 239 const std::string& event, |
214 const std::string& details); | 240 const std::string& details); |
215 | 241 |
216 bool is_recording_; | 242 bool is_recording_; |
217 | 243 |
| 244 std::deque<CheckinActivity> checkin_activities_; |
218 std::deque<ConnectionActivity> connection_activities_; | 245 std::deque<ConnectionActivity> connection_activities_; |
219 std::deque<RegistrationActivity> registration_activities_; | 246 std::deque<RegistrationActivity> registration_activities_; |
220 std::deque<ReceivingActivity> receiving_activities_; | 247 std::deque<ReceivingActivity> receiving_activities_; |
221 std::deque<SendingActivity> sending_activities_; | 248 std::deque<SendingActivity> sending_activities_; |
222 | 249 |
223 DISALLOW_COPY_AND_ASSIGN(GCMStatsRecorder); | 250 DISALLOW_COPY_AND_ASSIGN(GCMStatsRecorder); |
224 }; | 251 }; |
225 | 252 |
226 } // namespace gcm | 253 } // namespace gcm |
227 | 254 |
228 #endif // GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_ | 255 #endif // GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_ |
OLD | NEW |