OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 package org.chromium.net; | 5 package org.chromium.net; |
6 | 6 |
7 import android.support.annotation.Nullable; | 7 import android.support.annotation.Nullable; |
8 | 8 |
9 import java.util.Collection; | 9 import java.util.Collection; |
10 import java.util.Date; | |
10 import java.util.concurrent.Executor; | 11 import java.util.concurrent.Executor; |
11 | 12 |
12 /** | 13 /** |
13 * Information about a finished request. Passed to {@link RequestFinishedInfo.Li stener}. | 14 * Information about a finished request. Passed to {@link RequestFinishedInfo.Li stener}. |
14 * | 15 * |
15 * {@hide} as it's a prototype. | 16 * {@hide} as it's a prototype. |
16 */ | 17 */ |
17 public final class RequestFinishedInfo { | 18 public final class RequestFinishedInfo { |
18 /** | 19 /** |
19 * Listens for finished requests for the purpose of collecting metrics. | 20 * Listens for finished requests for the purpose of collecting metrics. |
(...skipping 22 matching lines...) Expand all Loading... | |
42 * @return this listener's {@link java.util.concurrent.Executor} | 43 * @return this listener's {@link java.util.concurrent.Executor} |
43 */ | 44 */ |
44 public Executor getExecutor() { | 45 public Executor getExecutor() { |
45 return mExecutor; | 46 return mExecutor; |
46 } | 47 } |
47 } | 48 } |
48 | 49 |
49 /** | 50 /** |
50 * Metrics collected for a single request. | 51 * Metrics collected for a single request. |
51 * | 52 * |
53 * Most timing metrics are taken from | |
54 * {@link https://cs.chromium.org/chromium/src/net/base/load_timing_info.h L oadTimingInfo}. | |
55 * See that file for more information about how to interpret them. | |
56 * | |
57 * Start times are reported as the time when a request started blocking on e vent, not when the | |
58 * event actually occurred, with the exception of push start. If a metric is not meaningful or | |
59 * not available, start and end times will be null. If no time was spent blo cking on an event, | |
60 * start and end will be the same time. | |
61 * | |
52 * {@hide} as it's a prototype. | 62 * {@hide} as it's a prototype. |
53 */ | 63 */ |
54 public static class Metrics { | 64 public static class Metrics { |
55 @Nullable | 65 @Nullable |
66 private final long mProxyStartMs; | |
67 @Nullable | |
68 private final long mProxyEndMs; | |
69 @Nullable | |
70 private final long mDnsStartMs; | |
71 @Nullable | |
72 private final long mDnsEndMs; | |
73 @Nullable | |
74 private final long mConnectStartMs; | |
75 @Nullable | |
76 private final long mConnectEndMs; | |
77 @Nullable | |
78 private final long mSslStartMs; | |
79 @Nullable | |
mef
2016/08/10 03:03:37
Is simple long nullable or do you need to use Long
mgersh
2016/08/29 18:05:44
I didn't actually want to make these nullable, the
| |
80 private final long mSslEndMs; | |
81 @Nullable | |
82 private final long mSendingStartMs; | |
83 @Nullable | |
84 private final long mSendingEndMs; | |
85 @Nullable | |
86 private final long mPushStartMs; | |
87 @Nullable | |
88 private final long mPushEndMs; | |
89 @Nullable | |
90 private final long mResponseStartMs; | |
91 @Nullable | |
92 private final long mResponseEndMs; | |
93 private final boolean mSocketReused; | |
94 | |
95 @Nullable | |
56 private final Long mTtfbMs; | 96 private final Long mTtfbMs; |
57 @Nullable | 97 @Nullable |
58 private final Long mTotalTimeMs; | 98 private final Long mTotalTimeMs; |
59 @Nullable | 99 @Nullable |
60 private final Long mSentBytesCount; | 100 private final Long mSentBytesCount; |
61 @Nullable | 101 @Nullable |
62 private final Long mReceivedBytesCount; | 102 private final Long mReceivedBytesCount; |
63 | 103 |
104 /** | |
105 * Old-style constructor | |
106 */ | |
64 public Metrics(@Nullable Long ttfbMs, @Nullable Long totalTimeMs, | 107 public Metrics(@Nullable Long ttfbMs, @Nullable Long totalTimeMs, |
65 @Nullable Long sentBytesCount, @Nullable Long receivedBytesCount ) { | 108 @Nullable Long sentBytesCount, @Nullable Long receivedBytesCount ) { |
66 mTtfbMs = ttfbMs; | 109 mTtfbMs = ttfbMs; |
67 mTotalTimeMs = totalTimeMs; | 110 mTotalTimeMs = totalTimeMs; |
68 mSentBytesCount = sentBytesCount; | 111 mSentBytesCount = sentBytesCount; |
69 mReceivedBytesCount = receivedBytesCount; | 112 mReceivedBytesCount = receivedBytesCount; |
113 | |
114 // Everything else is 0 for now | |
115 mProxyStartMs = 0; | |
116 mProxyEndMs = 0; | |
117 mDnsStartMs = 0; | |
118 mDnsEndMs = 0; | |
119 mConnectStartMs = 0; | |
120 mConnectEndMs = 0; | |
121 mSslStartMs = 0; | |
122 mSslEndMs = 0; | |
123 mSendingStartMs = 0; | |
124 mSendingEndMs = 0; | |
125 mPushStartMs = 0; | |
126 mPushEndMs = 0; | |
127 mResponseStartMs = 0; | |
128 mResponseEndMs = 0; | |
129 mSocketReused = false; | |
70 } | 130 } |
71 | 131 |
72 /** | 132 /** |
133 * New-style constructor | |
134 */ | |
135 public Metrics(long proxyStartMs, long proxyEndMs, long dnsStartMs, long dnsEndMs, | |
136 long connectStartMs, long connectEndMs, long sslStartMs, long ss lEndMs, | |
137 long sendingStartMs, long sendingEndMs, long pushStartMs, long p ushEndMs, | |
138 long responseStartMs, long responseEndMs, boolean socketReused, long sentBytesCount, | |
139 long receivedBytesCount) { | |
140 mProxyStartMs = proxyStartMs; | |
141 mProxyEndMs = proxyEndMs; | |
mef
2016/08/10 03:03:37
shouldall these constructors and member variables
mgersh
2016/08/29 18:05:44
Done.
| |
142 mDnsStartMs = dnsStartMs; | |
143 mDnsEndMs = dnsEndMs; | |
144 mConnectStartMs = connectStartMs; | |
145 mConnectEndMs = connectEndMs; | |
146 mSslStartMs = sslStartMs; | |
147 mSslEndMs = sslEndMs; | |
148 mSendingStartMs = sendingStartMs; | |
149 mSendingEndMs = sendingEndMs; | |
150 mPushStartMs = pushStartMs; | |
151 mPushEndMs = pushEndMs; | |
152 mResponseStartMs = responseStartMs; | |
153 mResponseEndMs = responseEndMs; | |
154 mSocketReused = socketReused; | |
155 mSentBytesCount = sentBytesCount; | |
156 mReceivedBytesCount = receivedBytesCount; | |
157 | |
158 // Don't care about these anymore | |
159 mTtfbMs = null; | |
160 mTotalTimeMs = null; | |
161 } | |
162 | |
163 @Nullable | |
164 private static Date toDate(long timestamp) { | |
165 if (timestamp != 0) { | |
166 return new Date(timestamp); | |
167 } | |
168 return null; | |
169 } | |
170 | |
171 /** | |
172 * @return {@link java.util.Date} representing when proxy resolution sta rted. Null if there | |
173 * is no PAC. | |
174 */ | |
175 @Nullable | |
176 public Date getProxyStart() { | |
177 return toDate(mProxyStartMs); | |
178 } | |
179 | |
180 /** | |
181 * @return {@link java.util.Date} representing when proxy resolution fin ished. Null if there | |
182 * is no PAC. | |
183 */ | |
184 @Nullable | |
185 public Date getProxyEnd() { | |
186 return toDate(mProxyEndMs); | |
187 } | |
188 | |
189 /** | |
190 * @return {@link java.util.Date} representing when DNS lookup started. | |
191 */ | |
192 @Nullable | |
193 public Date getDnsStart() { | |
194 return toDate(mDnsStartMs); | |
195 } | |
196 | |
197 /** | |
198 * @return {@link java.util.Date} representing when DNS lookup finished. | |
199 */ | |
200 @Nullable | |
201 public Date getDnsEnd() { | |
202 return toDate(mDnsEndMs); | |
203 } | |
204 | |
205 /** | |
206 * @return {@link java.util.Date} representing when connection establish ment started. | |
207 */ | |
208 @Nullable | |
209 public Date getConnectStart() { | |
210 return toDate(mConnectStartMs); | |
211 } | |
212 | |
213 /** | |
214 * @return {@link java.util.Date} representing when connection establish ment finished. | |
215 */ | |
216 @Nullable | |
217 public Date getConnectEnd() { | |
218 return toDate(mConnectEndMs); | |
219 } | |
220 | |
221 /** | |
222 * @return {@link java.util.Date} representing when SSL handshake starte d. | |
223 */ | |
224 @Nullable | |
225 public Date getSslStart() { | |
226 return toDate(mSslStartMs); | |
227 } | |
228 | |
229 /** | |
230 * @return {@link java.util.Date} representing when SSL handshake finish ed. | |
231 */ | |
232 @Nullable | |
233 public Date getSslEnd() { | |
234 return toDate(mSslEndMs); | |
235 } | |
236 | |
237 /** | |
238 * @return {@link java.util.Date} representing when sending HTTP request headers started. | |
239 */ | |
240 @Nullable | |
241 public Date getSendingStart() { | |
242 return toDate(mSendingStartMs); | |
243 } | |
244 | |
245 /** | |
246 * @return {@link java.util.Date} representing when sending HTTP request body finished. | |
247 */ | |
248 @Nullable | |
249 public Date getSendingEnd() { | |
250 return toDate(mSendingEndMs); | |
251 } | |
252 | |
253 /** | |
254 * @return {@link java.util.Date} representing when the first byte of an HTTP2 server push | |
255 * was received. | |
256 */ | |
257 @Nullable | |
258 public Date getPushStart() { | |
259 return toDate(mPushStartMs); | |
260 } | |
261 | |
262 /** | |
263 * @return {@link java.util.Date} representing when the last byte of an HTTP2 server push | |
264 * was received. | |
mef
2016/08/10 03:03:37
For all @Nullable results we need to explain the s
| |
265 */ | |
266 @Nullable | |
267 public Date getPushEnd() { | |
268 return toDate(mPushEndMs); | |
269 } | |
270 | |
271 /** | |
272 * @return {@link java.util.Date} representing when the first byte of th e response was | |
273 * received. | |
274 */ | |
275 @Nullable | |
276 public Date getResponseStart() { | |
277 return toDate(mResponseStartMs); | |
278 } | |
279 | |
280 /** | |
281 * @return {@link java.util.Date} representing when the last byte of the response was | |
282 * received. | |
283 */ | |
284 @Nullable | |
285 public Date getResponseEnd() { | |
286 return toDate(mResponseEndMs); | |
287 } | |
288 | |
289 /** | |
290 * @return whether the socket was reused. When true, DNS, connection, an d SSL times will be | |
291 * null. | |
292 */ | |
293 @Nullable | |
294 public boolean getSocketReused() { | |
295 return mSocketReused; | |
296 } | |
297 | |
298 /** | |
73 * Returns milliseconds between request initiation and first byte of res ponse headers, | 299 * Returns milliseconds between request initiation and first byte of res ponse headers, |
74 * or null if not collected. | 300 * or null if not collected. |
75 */ | 301 */ |
76 @Nullable | 302 @Nullable |
77 public Long getTtfbMs() { | 303 public Long getTtfbMs() { |
78 return mTtfbMs; | 304 return mTtfbMs; |
79 } | 305 } |
80 | 306 |
81 /** | 307 /** |
82 * Returns milliseconds between request initiation and finish, | 308 * Returns milliseconds between request initiation and finish, |
(...skipping 14 matching lines...) Expand all Loading... | |
97 | 323 |
98 /** | 324 /** |
99 * Returns total bytes received over the network transport layer, or nul l if not collected. | 325 * Returns total bytes received over the network transport layer, or nul l if not collected. |
100 */ | 326 */ |
101 @Nullable | 327 @Nullable |
102 public Long getReceivedBytesCount() { | 328 public Long getReceivedBytesCount() { |
103 return mReceivedBytesCount; | 329 return mReceivedBytesCount; |
104 } | 330 } |
105 } | 331 } |
106 | 332 |
333 public static final int SUCCEEDED = 0; | |
334 public static final int FAILED = 1; | |
335 public static final int CANCELED = 2; | |
336 | |
107 private final String mUrl; | 337 private final String mUrl; |
108 private final Collection<Object> mAnnotations; | 338 private final Collection<Object> mAnnotations; |
109 private final Metrics mMetrics; | 339 private final Metrics mMetrics; |
340 // One of SUCCEEDED, FAILED, or CANCELED | |
341 private final int mFinishedReason; | |
110 @Nullable | 342 @Nullable |
111 private final UrlResponseInfo mResponseInfo; | 343 private final UrlResponseInfo mResponseInfo; |
344 @Nullable | |
345 private final UrlRequestException mException; | |
112 | 346 |
113 /** | 347 /** |
114 * @hide only used by internal implementation. | 348 * @hide only used by internal implementation. |
115 */ | 349 */ |
116 public RequestFinishedInfo(String url, Collection<Object> annotations, Metri cs metrics, | 350 public RequestFinishedInfo(String url, Collection<Object> annotations, Metri cs metrics, |
117 @Nullable UrlResponseInfo responseInfo) { | 351 int finishedReason, @Nullable UrlResponseInfo responseInfo, |
352 @Nullable UrlRequestException exception) { | |
118 mUrl = url; | 353 mUrl = url; |
119 mAnnotations = annotations; | 354 mAnnotations = annotations; |
120 mMetrics = metrics; | 355 mMetrics = metrics; |
356 mFinishedReason = finishedReason; | |
121 mResponseInfo = responseInfo; | 357 mResponseInfo = responseInfo; |
358 mException = exception; | |
122 } | 359 } |
123 | 360 |
124 /** Returns the request's original URL. */ | 361 /** Returns the request's original URL. */ |
125 public String getUrl() { | 362 public String getUrl() { |
126 return mUrl; | 363 return mUrl; |
127 } | 364 } |
128 | 365 |
129 /** Returns the objects that the caller has supplied when initiating the req uest. */ | 366 /** Returns the objects that the caller has supplied when initiating the req uest. */ |
130 public Collection<Object> getAnnotations() { | 367 public Collection<Object> getAnnotations() { |
131 return mAnnotations; | 368 return mAnnotations; |
132 } | 369 } |
133 | 370 |
134 // TODO(klm): Collect and return a chain of Metrics objects for redirect res ponses. | 371 // TODO(klm): Collect and return a chain of Metrics objects for redirect res ponses. |
372 // TODO(mgersh): Update this javadoc when new metrics are fully implemented | |
135 /** | 373 /** |
136 * Returns metrics collected for this request. | 374 * Returns metrics collected for this request. |
137 * | 375 * |
138 * <p>The reported times and bytes account for all redirects, i.e. | 376 * <p>The reported times and bytes account for all redirects, i.e. |
139 * the TTFB is from the start of the original request to the ultimate respon se headers, | 377 * the TTFB is from the start of the original request to the ultimate respon se headers, |
140 * the TTLB is from the start of the original request to the end of the ulti mate response, | 378 * the TTLB is from the start of the original request to the end of the ulti mate response, |
141 * the received byte count is for all redirects and the ultimate response co mbined. | 379 * the received byte count is for all redirects and the ultimate response co mbined. |
142 * These cumulative metric definitions are debatable, but are chosen to make sense | 380 * These cumulative metric definitions are debatable, but are chosen to make sense |
143 * for user-facing latency analysis. | 381 * for user-facing latency analysis. |
144 * | 382 * |
145 * @return metrics collected for this request. | 383 * @return metrics collected for this request. |
146 */ | 384 */ |
147 public Metrics getMetrics() { | 385 public Metrics getMetrics() { |
148 return mMetrics; | 386 return mMetrics; |
149 } | 387 } |
150 | 388 |
151 /** | 389 /** |
390 * Returns the reason why the request finished. | |
391 * @return one of {@link #SUCCEEDED}, {@link #FAILED}, or {@link #CANCELED} | |
392 */ | |
393 public int getFinishedReason() { | |
394 return mFinishedReason; | |
395 } | |
396 | |
397 /** | |
152 * Returns a {@link UrlResponseInfo} for the request, if its response had st arted. | 398 * Returns a {@link UrlResponseInfo} for the request, if its response had st arted. |
153 * @return {@link UrlResponseInfo} for the request, if its response had star ted. | 399 * @return {@link UrlResponseInfo} for the request, if its response had star ted. |
154 */ | 400 */ |
155 @Nullable | 401 @Nullable |
156 public UrlResponseInfo getResponseInfo() { | 402 public UrlResponseInfo getResponseInfo() { |
157 return mResponseInfo; | 403 return mResponseInfo; |
158 } | 404 } |
405 | |
406 /** | |
407 * If the request failed, returns the same {@link UrlRequestException} provi ded to | |
408 * {@link UrlRequest.Callback#onFailed}. | |
409 * | |
410 * @return the request's {@link UrlRequestException}, if the request failed | |
411 */ | |
412 @Nullable | |
413 public UrlRequestException getException() { | |
414 return mException; | |
415 } | |
159 } | 416 } |
OLD | NEW |