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

Side by Side Diff: chrome/browser/net/passive_log_collector.h

Issue 1696005: Add net log entries that summarize transmit and receive byte counts. (Closed)
Patch Set: More tests and address comments Created 10 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
« no previous file with comments | « chrome/browser/net/chrome_net_log.cc ('k') | chrome/browser/net/passive_log_collector.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 CHROME_BROWSER_NET_PASSIVE_LOG_COLLECTOR_H_ 5 #ifndef CHROME_BROWSER_NET_PASSIVE_LOG_COLLECTOR_H_
6 #define CHROME_BROWSER_NET_PASSIVE_LOG_COLLECTOR_H_ 6 #define CHROME_BROWSER_NET_PASSIVE_LOG_COLLECTOR_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/hash_tables.h" 10 #include "base/hash_tables.h"
11 #include "base/ref_counted.h" 11 #include "base/ref_counted.h"
12 #include "base/time.h" 12 #include "base/time.h"
13 #include "chrome/browser/net/chrome_net_log.h" 13 #include "chrome/browser/net/chrome_net_log.h"
14 #include "net/base/net_log.h" 14 #include "net/base/net_log.h"
15 #include "testing/gtest/include/gtest/gtest_prod.h"
15 16
16 class PassiveLogCollector : public ChromeNetLog::Observer { 17 class PassiveLogCollector : public ChromeNetLog::Observer {
17 public: 18 public:
18 // This structure encapsulates all of the parameters of a captured event, 19 // This structure encapsulates all of the parameters of a captured event,
19 // including an "order" field that identifies when it was captured relative 20 // including an "order" field that identifies when it was captured relative
20 // to other events. 21 // to other events.
21 struct Entry { 22 struct Entry {
22 Entry(int order, 23 Entry(uint32 order,
23 net::NetLog::EventType type, 24 net::NetLog::EventType type,
24 const base::TimeTicks& time, 25 const base::TimeTicks& time,
25 net::NetLog::Source source, 26 net::NetLog::Source source,
26 net::NetLog::EventPhase phase, 27 net::NetLog::EventPhase phase,
27 net::NetLog::EventParameters* extra_parameters) 28 net::NetLog::EventParameters* extra_parameters)
28 : order(order), type(type), time(time), source(source), phase(phase), 29 : order(order), type(type), time(time), source(source), phase(phase),
29 extra_parameters(extra_parameters) { 30 extra_parameters(extra_parameters) {
30 } 31 }
31 32
32 int order; 33 uint32 order;
33 net::NetLog::EventType type; 34 net::NetLog::EventType type;
34 base::TimeTicks time; 35 base::TimeTicks time;
35 net::NetLog::Source source; 36 net::NetLog::Source source;
36 net::NetLog::EventPhase phase; 37 net::NetLog::EventPhase phase;
37 scoped_refptr<net::NetLog::EventParameters> extra_parameters; 38 scoped_refptr<net::NetLog::EventParameters> extra_parameters;
38 }; 39 };
39 40
40 typedef std::vector<Entry> EntryList; 41 typedef std::vector<Entry> EntryList;
41 42
42 struct RequestInfo { 43 struct RequestInfo {
43 RequestInfo() : num_entries_truncated(0) {} 44 RequestInfo()
44 std::string url; 45 : source_id(net::NetLog::Source::kInvalidId),
46 num_entries_truncated(0),
47 total_bytes_transmitted(0),
48 total_bytes_received(0),
49 bytes_transmitted(0),
50 bytes_received(0),
51 last_tx_rx_position(0) {}
52 uint32 source_id;
45 EntryList entries; 53 EntryList entries;
46 size_t num_entries_truncated; 54 size_t num_entries_truncated;
55 net::NetLog::Source subordinate_source;
56
57 // Only used in RequestTracker.
58 std::string url;
59
60 // Only used in SocketTracker.
61 uint64 total_bytes_transmitted;
62 uint64 total_bytes_received;
63 uint64 bytes_transmitted;
64 uint64 bytes_received;
65 uint32 last_tx_rx_position; // The |order| of the last Tx or Rx entry.
66 base::TimeTicks last_tx_rx_time; // The |time| of the last Tx or Rx entry.
47 }; 67 };
48 68
49 typedef std::vector<RequestInfo> RequestInfoList; 69 typedef std::vector<RequestInfo> RequestInfoList;
50 70
51 // This class stores and manages the passively logged information for 71 // This class stores and manages the passively logged information for
52 // URLRequests/SocketStreams/ConnectJobs. 72 // URLRequests/SocketStreams/ConnectJobs.
53 class RequestTrackerBase { 73 class RequestTrackerBase {
54 public: 74 public:
55 explicit RequestTrackerBase(size_t max_graveyard_size); 75 explicit RequestTrackerBase(size_t max_graveyard_size);
56 76
57 void OnAddEntry(const Entry& entry); 77 void OnAddEntry(const Entry& entry);
58 78
59 RequestInfoList GetLiveRequests() const; 79 RequestInfoList GetLiveRequests() const;
60 void ClearRecentlyDeceased(); 80 void ClearRecentlyDeceased();
61 RequestInfoList GetRecentlyDeceased() const; 81 RequestInfoList GetRecentlyDeceased() const;
62 void SetUnbounded(bool unbounded); 82 void SetUnbounded(bool unbounded);
63 83
64 bool IsUnbounded() const { return is_unbounded_; } 84 bool is_unbounded() const { return is_unbounded_; }
65 85
66 void Clear(); 86 void Clear();
67 87
68 // Appends all the captured entries to |out|. The ordering is undefined. 88 // Appends all the captured entries to |out|. The ordering is undefined.
69 void AppendAllEntries(EntryList* out) const; 89 void AppendAllEntries(EntryList* out) const;
70 90
71 const RequestInfo* GetRequestInfoFromGraveyard(int id) const;
72
73 protected: 91 protected:
74 enum Action { 92 enum Action {
75 ACTION_NONE, 93 ACTION_NONE,
76 ACTION_DELETE, 94 ACTION_DELETE,
77 ACTION_MOVE_TO_GRAVEYARD, 95 ACTION_MOVE_TO_GRAVEYARD,
78 }; 96 };
79 97
80 // Updates |out_info| with the information from |entry|. Returns an action 98 // Updates |out_info| with the information from |entry|. Returns an action
81 // to perform for this map entry on completion. 99 // to perform for this map entry on completion.
82 virtual Action DoAddEntry(const Entry& entry, RequestInfo* out_info) = 0; 100 virtual Action DoAddEntry(const Entry& entry, RequestInfo* out_info) = 0;
83 101
84 bool is_unbounded() const { return is_unbounded_; } 102 // Finds a request, either in the live entries or the graveyard and returns
103 // it.
104 RequestInfo* GetRequestInfo(uint32 id);
105
106 // When GetLiveRequests() is called, RequestTrackerBase calls this method
107 // for each entry after adding it to the list which will be returned
108 // to the caller.
109 virtual void OnLiveRequest(RequestInfo* info) const {}
85 110
86 private: 111 private:
87 typedef base::hash_map<int, RequestInfo> SourceIDToInfoMap; 112 typedef base::hash_map<uint32, RequestInfo> SourceIDToInfoMap;
88 113
89 void RemoveFromLiveRequests(int source_id); 114 void RemoveFromLiveRequests(uint32 source_id);
90 void InsertIntoGraveyard(const RequestInfo& info); 115 void InsertIntoGraveyard(const RequestInfo& info);
91 116
92 SourceIDToInfoMap live_requests_; 117 SourceIDToInfoMap live_requests_;
93 size_t max_graveyard_size_; 118 size_t max_graveyard_size_;
94 size_t next_graveyard_index_; 119 size_t next_graveyard_index_;
95 RequestInfoList graveyard_; 120 RequestInfoList graveyard_;
96 bool is_unbounded_; 121 bool is_unbounded_;
97 122
98 DISALLOW_COPY_AND_ASSIGN(RequestTrackerBase); 123 DISALLOW_COPY_AND_ASSIGN(RequestTrackerBase);
99 }; 124 };
100 125
101 // Specialization of RequestTrackerBase for handling ConnectJobs. 126 // Specialization of RequestTrackerBase for handling ConnectJobs.
102 class ConnectJobTracker : public RequestTrackerBase { 127 class ConnectJobTracker : public RequestTrackerBase {
103 public: 128 public:
104 static const size_t kMaxGraveyardSize; 129 static const size_t kMaxGraveyardSize;
105 130
106 ConnectJobTracker(); 131 ConnectJobTracker();
107 132
133 void AppendLogEntries(RequestInfo* out_info, bool unbounded,
134 uint32 connect_id);
135
108 protected: 136 protected:
109 virtual Action DoAddEntry(const Entry& entry, RequestInfo* out_info); 137 virtual Action DoAddEntry(const Entry& entry, RequestInfo* out_info);
110 private: 138 private:
111 DISALLOW_COPY_AND_ASSIGN(ConnectJobTracker); 139 DISALLOW_COPY_AND_ASSIGN(ConnectJobTracker);
112 }; 140 };
113 141
142 // Specialization of RequestTrackerBase for handling Sockets.
143 class SocketTracker : public RequestTrackerBase {
144 public:
145 static const size_t kMaxGraveyardSize;
146
147 SocketTracker();
148
149 void AppendLogEntries(RequestInfo* out_info, bool unbounded,
150 uint32 socket_id, bool clear);
151
152 protected:
153 virtual Action DoAddEntry(const Entry& entry, RequestInfo* out_info);
154
155 private:
156 void ClearInfo(RequestInfo* info);
157
158 DISALLOW_COPY_AND_ASSIGN(SocketTracker);
159 };
160
114 // Specialization of RequestTrackerBase for handling URLRequest/SocketStream. 161 // Specialization of RequestTrackerBase for handling URLRequest/SocketStream.
115 class RequestTracker : public RequestTrackerBase { 162 class RequestTracker : public RequestTrackerBase {
116 public: 163 public:
117 static const size_t kMaxGraveyardSize; 164 static const size_t kMaxGraveyardSize;
118 static const size_t kMaxGraveyardURLSize; 165 static const size_t kMaxGraveyardURLSize;
119 166
120 explicit RequestTracker(ConnectJobTracker* connect_job_tracker); 167 RequestTracker(ConnectJobTracker* connect_job_tracker,
168 SocketTracker* socket_tracker);
169
170 void IntegrateSubordinateSource(RequestInfo* info,
171 bool clear_entries) const;
121 172
122 protected: 173 protected:
123 virtual Action DoAddEntry(const Entry& entry, RequestInfo* out_info); 174 virtual Action DoAddEntry(const Entry& entry, RequestInfo* out_info);
124 175
176 virtual void OnLiveRequest(RequestInfo* info) const {
177 IntegrateSubordinateSource(info, false);
178 }
179
125 private: 180 private:
126 // Searches through |connect_job_tracker_| for information on the
127 // ConnectJob specified in |entry|, and appends it to |live_entry|.
128 void AddConnectJobInfo(const Entry& entry, RequestInfo* live_entry);
129
130 ConnectJobTracker* connect_job_tracker_; 181 ConnectJobTracker* connect_job_tracker_;
182 SocketTracker* socket_tracker_;
131 183
132 DISALLOW_COPY_AND_ASSIGN(RequestTracker); 184 DISALLOW_COPY_AND_ASSIGN(RequestTracker);
133 }; 185 };
134 186
135 // Tracks the log entries for the last seen SOURCE_INIT_PROXY_RESOLVER. 187 // Tracks the log entries for the last seen SOURCE_INIT_PROXY_RESOLVER.
136 class InitProxyResolverTracker { 188 class InitProxyResolverTracker {
137 public: 189 public:
138 InitProxyResolverTracker(); 190 InitProxyResolverTracker();
139 191
140 void OnAddEntry(const Entry& entry); 192 void OnAddEntry(const Entry& entry);
(...skipping 30 matching lines...) Expand all
171 223
172 InitProxyResolverTracker* init_proxy_resolver_tracker() { 224 InitProxyResolverTracker* init_proxy_resolver_tracker() {
173 return &init_proxy_resolver_tracker_; 225 return &init_proxy_resolver_tracker_;
174 } 226 }
175 227
176 // Fills |out| with the full list of events that have been passively 228 // Fills |out| with the full list of events that have been passively
177 // captured. The list is ordered by capture time. 229 // captured. The list is ordered by capture time.
178 void GetAllCapturedEvents(EntryList* out) const; 230 void GetAllCapturedEvents(EntryList* out) const;
179 231
180 private: 232 private:
233 FRIEND_TEST(PassiveLogCollectorTest, LostConnectJob);
234 FRIEND_TEST(PassiveLogCollectorTest, LostSocket);
235
181 ConnectJobTracker connect_job_tracker_; 236 ConnectJobTracker connect_job_tracker_;
237 SocketTracker socket_tracker_;
182 RequestTracker url_request_tracker_; 238 RequestTracker url_request_tracker_;
183 RequestTracker socket_stream_tracker_; 239 RequestTracker socket_stream_tracker_;
184 InitProxyResolverTracker init_proxy_resolver_tracker_; 240 InitProxyResolverTracker init_proxy_resolver_tracker_;
185 241
186 // The count of how many events have flowed through this log. Used to set the 242 // The count of how many events have flowed through this log. Used to set the
187 // "order" field on captured events. 243 // "order" field on captured events.
188 int num_events_seen_; 244 uint32 num_events_seen_;
189 245
190 DISALLOW_COPY_AND_ASSIGN(PassiveLogCollector); 246 DISALLOW_COPY_AND_ASSIGN(PassiveLogCollector);
191 }; 247 };
192 248
193 #endif // CHROME_BROWSER_NET_PASSIVE_LOG_COLLECTOR_H_ 249 #endif // CHROME_BROWSER_NET_PASSIVE_LOG_COLLECTOR_H_
OLDNEW
« no previous file with comments | « chrome/browser/net/chrome_net_log.cc ('k') | chrome/browser/net/passive_log_collector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698