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" |
| 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 |
45 GCMStatsRecorder(); | 73 GCMStatsRecorder(); |
46 virtual ~GCMStatsRecorder(); | 74 virtual ~GCMStatsRecorder(); |
47 | 75 |
48 // Indicates whether the recorder is currently recording activities or not. | 76 // Indicates whether the recorder is currently recording activities or not. |
49 bool is_recording() const { | 77 bool is_recording() const { |
50 return is_recording_; | 78 return is_recording_; |
51 } | 79 } |
52 | 80 |
53 // Turns recording on/off. | 81 // Turns recording on/off. |
54 void SetRecording(bool recording); | 82 void SetRecording(bool recording); |
55 | 83 |
56 // Clear all recorded activities. | 84 // Clear all recorded activities. |
57 void Clear(); | 85 void Clear(); |
58 | 86 |
| 87 // Records that a connection to MCS has been initiated. |
| 88 void RecordConnectionInitiated(const std::string& host); |
| 89 |
| 90 // Records that a connection has been delayed due to backoff. |
| 91 void RecordConnectionDelayedDueToBackoff(int64 delay_msec); |
| 92 |
| 93 // Records that connection has been successfully established. |
| 94 void RecordConnectionSuccess(); |
| 95 |
| 96 // Records that connection reset has been signaled. |
| 97 void RecordConnectionResetSignaled( |
| 98 ConnectionFactory::ConnectionResetReason reason); |
| 99 |
| 100 // Records that a registration request has been sent. This could be initiated |
| 101 // directly from API, or from retry logic. |
| 102 void RecordRegistrationSent(const std::string& app_id, |
| 103 const std::string& sender_ids); |
| 104 |
| 105 // Records that a registration response has been received from server. |
| 106 void RecordRegistrationResponse(const std::string& app_id, |
| 107 const std::vector<std::string>& sender_ids, |
| 108 RegistrationRequest::Status status); |
| 109 |
| 110 // Records that a registration retry has been requested. The actual retry |
| 111 // action may not occur until some time later according to backoff logic. |
| 112 void RecordRegistrationRetryRequested( |
| 113 const std::string& app_id, |
| 114 const std::vector<std::string>& sender_ids, |
| 115 int retries_left); |
| 116 |
| 117 // Records that an unregistration request has been sent. This could be |
| 118 // initiated directly from API, or from retry logic. |
| 119 void RecordUnregistrationSent(const std::string& app_id); |
| 120 |
| 121 // Records that an unregistration response has been received from server. |
| 122 void RecordUnregistrationResponse(const std::string& app_id, |
| 123 UnregistrationRequest::Status status); |
| 124 |
| 125 // Records that an unregistration retry has been requested and delayed due to |
| 126 // backoff logic. |
| 127 void RecordUnregistrationRetryDelayed(const std::string& app_id, |
| 128 int64 delay_msec); |
| 129 |
| 130 // Records that a data message has been received. If this message is not |
| 131 // sent to a registered app, to_registered_app shoudl be false. If it |
| 132 // indicates that a message has been dropped on the server, is_message_dropped |
| 133 // should be true. |
| 134 void RecordDataMessageRecieved(const std::string& app_id, |
| 135 const std::string& from, |
| 136 int message_byte_size, |
| 137 bool to_registered_app, |
| 138 bool is_message_dropped); |
| 139 |
59 // Records that an outgoing data message was sent over the wire. | 140 // Records that an outgoing data message was sent over the wire. |
60 void RecordDataSentToWire(const std::string& app_id, | 141 void RecordDataSentToWire(const std::string& app_id, |
61 const std::string& receiver_id, | 142 const std::string& receiver_id, |
62 const std::string& message_id, | 143 const std::string& message_id, |
63 int queued); | 144 int queued); |
64 // Records that the MCS client sent a 'send status' notification to callback. | 145 // Records that the MCS client sent a 'send status' notification to callback. |
65 void RecordNotifySendStatus(const std::string& app_id, | 146 void RecordNotifySendStatus(const std::string& app_id, |
66 const std::string& receiver_id, | 147 const std::string& receiver_id, |
67 const std::string& message_id, | 148 const std::string& message_id, |
68 MCSClient::MessageSendStatus status, | 149 MCSClient::MessageSendStatus status, |
69 int byte_size, | 150 int byte_size, |
70 int ttl); | 151 int ttl); |
71 // Records that a 'send error' message was received. | 152 // Records that a 'send error' message was received. |
72 void RecordIncomingSendError(const std::string& app_id, | 153 void RecordIncomingSendError(const std::string& app_id, |
73 const std::string& receiver_id, | 154 const std::string& receiver_id, |
74 const std::string& message_id); | 155 const std::string& message_id); |
75 | 156 |
76 // Records that a sending activity has occurred. It will be inserted to the | 157 // 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 | 158 // front of a queue so that entries in the queue had reverse chronological |
78 // order. | 159 // order. |
79 void CollectSendingActivities(std::vector<SendingActivity>* activities) const; | 160 void CollectActivities( |
| 161 std::vector<ConnectionActivity>* connection_activities, |
| 162 std::vector<RegistrationActivity>* registration_activities, |
| 163 std::vector<ReceivingActivity>* receiving_activities, |
| 164 std::vector<SendingActivity>* sending_activities) const; |
80 | 165 |
| 166 const std::deque<ConnectionActivity>& connection_activities() const { |
| 167 return connection_activities_; |
| 168 } |
| 169 const std::deque<RegistrationActivity>& registration_activities() const { |
| 170 return registration_activities_; |
| 171 } |
| 172 const std::deque<ReceivingActivity>& receiving_activities() const { |
| 173 return receiving_activities_; |
| 174 } |
81 const std::deque<SendingActivity>& sending_activities() const { | 175 const std::deque<SendingActivity>& sending_activities() const { |
82 return sending_activities_; | 176 return sending_activities_; |
83 } | 177 } |
84 | 178 |
85 protected: | 179 protected: |
| 180 void RecordConnection(const std::string& event, |
| 181 const std::string& details); |
| 182 void RecordRegistration(const std::string& app_id, |
| 183 const std::string& sender_id, |
| 184 const std::string& event, |
| 185 const std::string& details); |
| 186 void RecordReceiving(const std::string& app_id, |
| 187 const std::string& from, |
| 188 int message_byte_size, |
| 189 const std::string& event, |
| 190 const std::string& details); |
86 void RecordSending(const std::string& app_id, | 191 void RecordSending(const std::string& app_id, |
87 const std::string& receiver_id, | 192 const std::string& receiver_id, |
88 const std::string& message_id, | 193 const std::string& message_id, |
89 const std::string& event, | 194 const std::string& event, |
90 const std::string& details); | 195 const std::string& details); |
91 | 196 |
92 bool is_recording_; | 197 bool is_recording_; |
93 | 198 |
| 199 std::deque<ConnectionActivity> connection_activities_; |
| 200 std::deque<RegistrationActivity> registration_activities_; |
| 201 std::deque<ReceivingActivity> receiving_activities_; |
94 std::deque<SendingActivity> sending_activities_; | 202 std::deque<SendingActivity> sending_activities_; |
95 | 203 |
96 DISALLOW_COPY_AND_ASSIGN(GCMStatsRecorder); | 204 DISALLOW_COPY_AND_ASSIGN(GCMStatsRecorder); |
97 }; | 205 }; |
98 | 206 |
99 } // namespace gcm | 207 } // namespace gcm |
100 | 208 |
101 #endif // GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_ | 209 #endif // GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_ |
OLD | NEW |