OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_ | |
6 #define GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_ | |
7 | |
8 #include <deque> | |
9 #include <map> | |
jianli
2014/03/18 23:53:23
not used
juyik
2014/03/20 01:09:53
Done.
| |
10 #include <string> | |
11 #include <vector> | |
12 | |
13 #include "base/compiler_specific.h" | |
14 #include "base/memory/ref_counted.h" | |
15 #include "base/memory/weak_ptr.h" | |
16 #include "base/stl_util.h" | |
jianli
2014/03/18 23:53:23
not used?
juyik
2014/03/20 01:09:53
Done.
| |
17 #include "base/time/time.h" | |
18 #include "google_apis/gcm/base/gcm_export.h" | |
19 | |
20 namespace gcm { | |
21 | |
22 // Records GCM internal stats and activities for debugging purpose. Recording | |
23 // can be turned on/off by calling SetRecording(...) function. It is turned off | |
24 // by default. | |
25 // This class is not thread safe. It is meant to be owned by a gcm client | |
26 // instance. | |
27 class GCM_EXPORT GCMStatsRecorder { | |
fgorski
2014/03/18 21:28:37
Tests for recorder?
juyik
2014/03/20 01:09:53
Done.
| |
28 public: | |
29 // Type of the activity. Each activity is one step in a larger operation ( | |
30 // register, send, receive, etc). | |
31 // Any change made to this enum must propagate to GetTypeString() function. | |
32 enum ActivityType { | |
33 Initiated, // First attempt of an operation. | |
34 RetryRequested, // A retry of the operation is requested. | |
35 Retry, // The retry of the operation is actually starting. | |
36 Success, // The operation has completed successfully. | |
37 Intermediate, // The activity is an intermediate step of an operation. | |
38 Failure, // The operation has failed; no more retries. | |
39 Error, // The operation encountered an error. | |
40 }; | |
41 | |
42 // Contains data that are common to all activity kinds below. | |
43 struct GCM_EXPORT Activity { | |
44 Activity(); | |
45 virtual ~Activity(); | |
46 std::string GetTypeString() const; | |
47 | |
48 base::Time time; | |
49 ActivityType type; | |
50 std::string details; // Any additional detail about this activity. | |
51 }; | |
52 | |
53 // Contains relevant data of a check-in step. | |
54 struct GCM_EXPORT CheckinActivity : Activity { | |
55 CheckinActivity(); | |
56 virtual ~CheckinActivity() OVERRIDE; | |
57 | |
58 uint64 android_id; | |
59 }; | |
60 | |
61 // Contains relevant data of a register step. | |
62 struct GCM_EXPORT RegisterActivity : Activity { | |
63 RegisterActivity(); | |
64 virtual ~RegisterActivity() OVERRIDE; | |
65 | |
66 std::string app_id; | |
67 std::string sender_id; | |
68 }; | |
69 | |
70 // Contains relevant data of a send-message step. | |
71 struct GCM_EXPORT SendMessageActivity : Activity { | |
72 SendMessageActivity(); | |
73 virtual ~SendMessageActivity() OVERRIDE; | |
74 | |
75 std::string app_id; | |
76 std::string receiver_id; | |
77 std::string message_id; | |
78 uint64 message_len; // Sent message's length in bytes. | |
79 }; | |
80 | |
81 // Contains relevant data of a receive-message step. | |
82 struct GCM_EXPORT ReceiveMessageActivity : Activity { | |
83 ReceiveMessageActivity(); | |
84 virtual ~ReceiveMessageActivity() OVERRIDE; | |
85 | |
86 std::string sender_id; | |
87 std::string app_id; | |
88 int message_size; // The number of key-value pairs in received message. | |
89 }; | |
90 | |
91 GCMStatsRecorder(); | |
92 virtual ~GCMStatsRecorder(); | |
93 | |
94 // Indicates whether the recorder is currently recording activities or not. | |
95 bool IsRecording() const { | |
jianli
2014/03/18 23:53:23
nit: this can be exposed as getter: bool is_record
juyik
2014/03/20 01:09:53
Done.
| |
96 return is_recording_; | |
97 } | |
98 | |
99 // Turns recording on/off. | |
100 void SetRecording(bool recording); | |
101 | |
102 // Clear all recorded activities. | |
103 void Clear(); | |
104 | |
105 // Record a checkin activity. | |
106 void RecordCheckin(uint64 android_id, ActivityType type); | |
107 | |
108 // Record a register activity. | |
109 void RecordRegister(const std::string& app_id, | |
jianli
2014/03/18 23:53:23
RecordRegistration?
juyik
2014/03/20 01:09:53
Will do in my future patch. Splitting this part of
| |
110 ActivityType type, | |
111 const std::vector<std::string>& sender_id); | |
112 void RecordRegisterWithStatus(const std::string& app_id, | |
fgorski
2014/03/18 21:28:37
For this and most of the other methods. Consider p
juyik
2014/03/20 01:09:53
I thought about it a little and I felt that the So
| |
113 ActivityType type, | |
114 const std::vector<std::string>& sender_id, | |
115 std::string status); | |
jianli
2014/03/18 23:53:23
It would be better to combine both RecordRegister*
juyik
2014/03/20 01:09:53
Will do in my future patch. Splitting this part of
| |
116 | |
117 // Record a send activity. | |
118 void RecordSend(const std::string& app_id, | |
jianli
2014/03/18 23:53:23
RecordSending?
juyik
2014/03/20 01:09:53
Done.
| |
119 ActivityType type, | |
120 const std::string& receiver_id, | |
121 const std::string& message_id, | |
122 uint64 msg_len); | |
123 void RecordSendWithDetails(const std::string& app_id, | |
124 ActivityType type, | |
125 const std::string& receiver_id, | |
126 const std::string& message_id, | |
127 uint64 msg_len, | |
128 const std::string& details); | |
129 | |
130 // Record a receive activity. | |
131 void RecordReceiveDataMessage(const std::string& sender_id, | |
132 const std::string& app_id, | |
133 int message_size); | |
134 void RecordReceiveWithDetails(ActivityType type, | |
135 const std::string& sender_id, | |
136 const std::string& app_id, | |
137 const std::string& details); | |
138 | |
139 const std::deque<CheckinActivity>& CheckinActivities() const { | |
jianli
2014/03/18 23:53:23
ditto for all these 4 methods
juyik
2014/03/20 01:09:53
Done for sending. Will do the rest in my future pa
| |
140 return checkin_activities_; | |
141 } | |
142 const std::deque<RegisterActivity>& RegisterActivities() const { | |
143 return register_activities_; | |
144 } | |
145 const std::deque<SendMessageActivity>& SendMessageActivities() const { | |
146 return send_activities_; | |
147 } | |
148 const std::deque<ReceiveMessageActivity>& ReceiveMessageActivities() const { | |
149 return receive_activities_; | |
150 } | |
151 | |
152 private: | |
153 bool is_recording_; | |
154 | |
155 std::deque<CheckinActivity> checkin_activities_; | |
156 std::deque<RegisterActivity> register_activities_; | |
157 std::deque<SendMessageActivity> send_activities_; | |
158 std::deque<ReceiveMessageActivity> receive_activities_; | |
159 | |
160 DISALLOW_COPY_AND_ASSIGN(GCMStatsRecorder); | |
161 }; | |
162 | |
163 } // namespace gcm | |
164 | |
165 #endif // GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_ | |
OLD | NEW |