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/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" | |
15 | 17 |
16 namespace gcm { | 18 namespace gcm { |
17 | 19 |
18 // Records GCM internal stats and activities for debugging purpose. Recording | 20 // Records GCM internal stats and activities for debugging purpose. Recording |
19 // can be turned on/off by calling SetRecording(...) function. It is turned off | 21 // can be turned on/off by calling SetRecording(...) function. It is turned off |
20 // by default. | 22 // by default. |
21 // This class is not thread safe. It is meant to be owned by a gcm client | 23 // This class is not thread safe. It is meant to be owned by a gcm client |
22 // instance. | 24 // instance. |
23 class GCM_EXPORT GCMStatsRecorder { | 25 class GCM_EXPORT GCMStatsRecorder { |
24 public: | 26 public: |
25 // Contains data that are common to all activity kinds below. | 27 // Contains data that are common to all activity kinds below. |
26 struct GCM_EXPORT Activity { | 28 struct GCM_EXPORT Activity { |
27 Activity(); | 29 Activity(); |
28 virtual ~Activity(); | 30 virtual ~Activity(); |
29 | 31 |
30 base::Time time; | 32 base::Time time; |
31 std::string event; // A short description of the event. | 33 std::string event; // A short description of the event. |
32 std::string details; // Any additional detail about the event. | 34 std::string details; // Any additional detail about the event. |
33 }; | 35 }; |
34 | 36 |
37 // Contains relevant data of a connection activity. | |
38 struct GCM_EXPORT ConnectionActivity : Activity { | |
39 ConnectionActivity(); | |
40 virtual ~ConnectionActivity(); | |
41 | |
jianli
2014/04/23 17:22:35
nit: remove empty line
juyik
2014/04/23 21:36:56
Done.
| |
42 }; | |
43 | |
44 // Contains relevant data of a registration step. | |
45 struct GCM_EXPORT RegistrationActivity : Activity { | |
46 RegistrationActivity(); | |
47 virtual ~RegistrationActivity(); | |
48 | |
49 std::string android_id; | |
jianli
2014/04/23 17:22:35
Is this needed? Android id is one per profile.
juyik
2014/04/23 21:36:56
Done.
| |
50 std::string app_id; | |
51 std::string sender_ids; // Comma separated sender ids. | |
52 }; | |
53 | |
54 // Contains relevant data of a message receiving event. | |
55 struct GCM_EXPORT ReceivingActivity : Activity { | |
56 ReceivingActivity(); | |
57 virtual ~ReceivingActivity(); | |
58 | |
59 std::string app_id; | |
60 std::string from; | |
61 int message_byte_size; | |
62 }; | |
63 | |
35 // Contains relevant data of a send-message step. | 64 // Contains relevant data of a send-message step. |
36 struct GCM_EXPORT SendingActivity : Activity { | 65 struct GCM_EXPORT SendingActivity : Activity { |
37 SendingActivity(); | 66 SendingActivity(); |
38 virtual ~SendingActivity(); | 67 virtual ~SendingActivity(); |
39 | 68 |
40 std::string app_id; | 69 std::string app_id; |
41 std::string receiver_id; | 70 std::string receiver_id; |
42 std::string message_id; | 71 std::string message_id; |
43 }; | 72 }; |
44 | 73 |
45 GCMStatsRecorder(); | 74 GCMStatsRecorder(); |
46 virtual ~GCMStatsRecorder(); | 75 virtual ~GCMStatsRecorder(); |
47 | 76 |
48 // Indicates whether the recorder is currently recording activities or not. | 77 // Indicates whether the recorder is currently recording activities or not. |
49 bool is_recording() const { | 78 bool is_recording() const { |
50 return is_recording_; | 79 return is_recording_; |
51 } | 80 } |
52 | 81 |
53 // Turns recording on/off. | 82 // Turns recording on/off. |
54 void SetRecording(bool recording); | 83 void SetRecording(bool recording); |
55 | 84 |
56 // Clear all recorded activities. | 85 // Clear all recorded activities. |
57 void Clear(); | 86 void Clear(); |
58 | 87 |
88 // Records that a connection to MCS has been initiated. | |
89 void RecordConnectionInitiated(const std::string& host); | |
90 | |
91 // Records that a connection has been delayed due to backoff. | |
92 void RecordConnectionDelayedDueToBackoff(int64 delay_msec); | |
93 | |
94 // Records that connection has been successfully established. | |
95 void RecordConnectionSuccess(); | |
96 | |
97 // Records that connection reset has been signaled. | |
98 void RecordConnectionResetSignaled( | |
99 ConnectionFactory::ConnectionResetReason reason); | |
100 | |
101 // Records that a registration request has been sent. This could be initiated | |
102 // directly from API, or from retry logic. | |
103 void RecordRegistrationSent(const std::string& android_id, | |
jianli
2014/04/23 17:22:35
No need to record android_id.
juyik
2014/04/23 21:36:56
Done.
| |
104 const std::string& app_id, | |
105 const std::string& sender_ids); | |
106 | |
107 // Records that a registration response has been received from server. | |
108 void RecordRegistrationResponse(const std::string& android_id, | |
jianli
2014/04/23 17:22:35
ditto for android_id.
juyik
2014/04/23 21:36:56
Done.
| |
109 const std::string& app_id, | |
110 const std::vector<std::string>& sender_ids, | |
111 RegistrationRequest::Status status); | |
112 // Records that a registration retry has been requested. The actual retry | |
113 // action may not occur until some time later according to backoff logic. | |
114 void RecordRegistrationRetryRequested( | |
115 const std::string& android_id, | |
jianli
2014/04/23 17:22:35
ditto for android_id.
juyik
2014/04/23 21:36:56
Done.
| |
116 const std::string& app_id, | |
117 const std::vector<std::string>& sender_ids, | |
118 int retries_left); | |
119 | |
120 // Records that a data message has been received. | |
121 void RecordDataRecieved(const std::string& app_id, | |
jianli
2014/04/23 17:22:35
RecordDataMessageReceived
juyik
2014/04/23 21:36:56
Done.
| |
122 const std::string& from, | |
123 int message_byte_size, | |
124 bool to_registered_app); | |
jianli
2014/04/23 17:22:35
dropped?
juyik
2014/04/23 21:36:56
Not really. This means the received message is mea
| |
125 // Records that a received message said data message has been deleted on | |
126 // server. | |
127 void RecordDataDeletedMessage(const std::string& app_id, | |
jianli
2014/04/23 17:22:35
RecordMessagesDeletedReceived
juyik
2014/04/23 21:36:56
N/A anymore because I combined merged the 2 method
| |
128 const std::string& from, | |
129 int message_byte_size); | |
130 | |
59 // Records that an outgoing data message was sent over the wire. | 131 // Records that an outgoing data message was sent over the wire. |
60 void RecordDataSentToWire(const std::string& app_id, | 132 void RecordDataSentToWire(const std::string& app_id, |
61 const std::string& receiver_id, | 133 const std::string& receiver_id, |
62 const std::string& message_id, | 134 const std::string& message_id, |
63 int queued); | 135 int queued); |
64 // Records that the MCS client sent a 'send status' notification to callback. | 136 // Records that the MCS client sent a 'send status' notification to callback. |
65 void RecordNotifySendStatus(const std::string& app_id, | 137 void RecordNotifySendStatus(const std::string& app_id, |
66 const std::string& receiver_id, | 138 const std::string& receiver_id, |
67 const std::string& message_id, | 139 const std::string& message_id, |
68 MCSClient::MessageSendStatus status, | 140 MCSClient::MessageSendStatus status, |
69 int byte_size, | 141 int byte_size, |
70 int ttl); | 142 int ttl); |
71 // Records that a 'send error' message was received. | 143 // Records that a 'send error' message was received. |
72 void RecordIncomingSendError(const std::string& app_id, | 144 void RecordIncomingSendError(const std::string& app_id, |
73 const std::string& receiver_id, | 145 const std::string& receiver_id, |
74 const std::string& message_id); | 146 const std::string& message_id); |
75 | 147 |
76 // Records that a sending activity has occurred. It will be inserted to the | 148 // Records that a sending activity has occurred. It will be inserted to the |
77 // front of a queue ao that entries in the queue had reverse chronological | 149 // front of a queue so that entries in the queue had reverse chronological |
78 // order. | 150 // order. |
79 void CollectSendingActivities(std::vector<SendingActivity>* activities) const; | 151 void CollectActivities( |
152 std::vector<ConnectionActivity>* connection_activities, | |
153 std::vector<RegistrationActivity>* registration_activities, | |
154 std::vector<ReceivingActivity>* receiving_activities, | |
155 std::vector<SendingActivity>* sending_activities) const; | |
80 | 156 |
157 const std::deque<ConnectionActivity>& connection_activities() const { | |
158 return connection_activities_; | |
159 } | |
160 const std::deque<RegistrationActivity>& registration_activities() const { | |
161 return registration_activities_; | |
162 } | |
163 const std::deque<ReceivingActivity>& receiving_activities() const { | |
164 return receiving_activities_; | |
165 } | |
81 const std::deque<SendingActivity>& sending_activities() const { | 166 const std::deque<SendingActivity>& sending_activities() const { |
82 return sending_activities_; | 167 return sending_activities_; |
83 } | 168 } |
84 | 169 |
85 protected: | 170 protected: |
171 void RecordConnection(const std::string& event, | |
172 const std::string& details); | |
173 void RecordRegistration(const std::string& android_id, | |
174 const std::string& app_id, | |
175 const std::string& sender_id, | |
176 const std::string& event, | |
177 const std::string& details); | |
178 void RecordReceiving(const std::string& app_id, | |
179 const std::string& from, | |
180 int message_byte_size, | |
181 const std::string& event, | |
182 const std::string& details); | |
86 void RecordSending(const std::string& app_id, | 183 void RecordSending(const std::string& app_id, |
87 const std::string& receiver_id, | 184 const std::string& receiver_id, |
88 const std::string& message_id, | 185 const std::string& message_id, |
89 const std::string& event, | 186 const std::string& event, |
90 const std::string& details); | 187 const std::string& details); |
91 | 188 |
92 bool is_recording_; | 189 bool is_recording_; |
93 | 190 |
191 std::deque<ConnectionActivity> connection_activities_; | |
192 std::deque<RegistrationActivity> registration_activities_; | |
193 std::deque<ReceivingActivity> receiving_activities_; | |
94 std::deque<SendingActivity> sending_activities_; | 194 std::deque<SendingActivity> sending_activities_; |
95 | 195 |
96 DISALLOW_COPY_AND_ASSIGN(GCMStatsRecorder); | 196 DISALLOW_COPY_AND_ASSIGN(GCMStatsRecorder); |
97 }; | 197 }; |
98 | 198 |
99 } // namespace gcm | 199 } // namespace gcm |
100 | 200 |
101 #endif // GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_ | 201 #endif // GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_ |
OLD | NEW |