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.IntDef; | |
7 import android.support.annotation.Nullable; | 8 import android.support.annotation.Nullable; |
8 | 9 |
10 import java.lang.annotation.Retention; | |
11 import java.lang.annotation.RetentionPolicy; | |
9 import java.util.Collection; | 12 import java.util.Collection; |
13 import java.util.Date; | |
10 import java.util.concurrent.Executor; | 14 import java.util.concurrent.Executor; |
11 | 15 |
12 /** | 16 /** |
13 * Information about a finished request. Passed to {@link RequestFinishedInfo.Li stener}. | 17 * Information about a finished request. Passed to {@link RequestFinishedInfo.Li stener}. |
14 * | 18 * |
15 * {@hide} as it's a prototype. | 19 * {@hide} as it's a prototype. |
16 */ | 20 */ |
17 public final class RequestFinishedInfo { | 21 public final class RequestFinishedInfo { |
18 /** | 22 /** |
19 * Listens for finished requests for the purpose of collecting metrics. | 23 * Listens for finished requests for the purpose of collecting metrics. |
(...skipping 20 matching lines...) Expand all Loading... | |
40 /** | 44 /** |
41 * Returns this listener's executor. Can be called on any thread. | 45 * Returns this listener's executor. Can be called on any thread. |
42 * @return this listener's {@link java.util.concurrent.Executor} | 46 * @return this listener's {@link java.util.concurrent.Executor} |
43 */ | 47 */ |
44 public Executor getExecutor() { | 48 public Executor getExecutor() { |
45 return mExecutor; | 49 return mExecutor; |
46 } | 50 } |
47 } | 51 } |
48 | 52 |
49 /** | 53 /** |
50 * Metrics collected for a single request. | 54 * Metrics collected for a single request. |
pauljensen
2016/09/06 17:22:23
Can we elaborate a bit more here? Like by adding
mgersh
2016/09/07 22:09:58
Done.
| |
51 * | 55 * |
56 * Most timing metrics are taken from | |
57 * {@link https://cs.chromium.org/chromium/src/net/base/load_timing_info.h L oadTimingInfo}, | |
58 * which holds the information for {@link http://w3c.github.io/navigation-ti ming/} and | |
59 * {@link https://www.w3.org/TR/resource-timing/}. | |
pauljensen
2016/09/06 17:22:23
This is kind of an implementation detail. Perhaps
mgersh
2016/09/07 22:09:57
Done.
| |
60 * | |
61 * Events happen in this order: | |
62 * request start | |
pauljensen
2016/09/06 17:22:23
Use <ol> and <li>'s
pauljensen
2016/09/06 17:22:23
I feel like we should include links from these lis
mgersh
2016/09/07 22:09:58
Done.
mgersh
2016/09/07 22:09:58
Done.
| |
63 * dns start | |
pauljensen
2016/09/06 17:22:23
dns->DNS
here and below
mgersh
2016/09/07 22:09:57
Done.
| |
64 * dns end | |
65 * connect start | |
66 * ssl start | |
pauljensen
2016/09/06 17:22:23
ssl->SSL
here and below
mgersh
2016/09/07 22:09:58
Done.
| |
67 * ssl end | |
68 * connect end | |
69 * send start | |
70 * send end | |
71 * response start | |
72 * response end | |
73 * | |
74 * Start times are reported as the time when a request started blocking on e vent, not when the | |
75 * event actually occurred, with the exception of push start and end. If a m etric is not | |
76 * meaningful or not available, including cases when a request finished befo re reaching that | |
77 * stage, start and end times will be null. If no time was spent blocking on an event, start | |
pauljensen
2016/09/06 17:22:23
null->{@code null}
mgersh
2016/09/07 22:09:58
Done.
| |
78 * and end will be the same time. | |
79 * | |
80 * Timestamps are recorded using a clock that is guaranteed not to run backw ards. All timestamps | |
81 * are correct relative to the system clock at the time of request start, an d taking the | |
82 * difference between two timestamps will give the correct difference betwee n the events. In | |
83 * order to preserve this property, timestamps for events other than request start are not | |
84 * guaranteed to match the system clock at the times they represent. | |
pauljensen
2016/09/06 17:22:23
Could we simplify this paragraph or preface it wit
mgersh
2016/09/07 22:09:58
Done.
| |
85 * | |
52 * {@hide} as it's a prototype. | 86 * {@hide} as it's a prototype. |
53 */ | 87 */ |
54 public static class Metrics { | 88 public abstract static class Metrics { |
55 @Nullable | 89 /** |
56 private final Long mTtfbMs; | 90 * @return {@link java.util.Date} representing when the request started from the perspective |
pauljensen
2016/09/06 17:22:23
All of these methods need a method description in
mgersh
2016/09/07 22:09:58
Done.
| |
57 @Nullable | 91 * of the native URLRequest layer. This timestamp will match the system clock at the time it |
xunjieli
2016/09/05 23:24:17
nit: Avoid implementation details in the Javadoc.
mgersh
2016/09/07 22:09:57
Done.
| |
58 private final Long mTotalTimeMs; | 92 * represents. |
59 @Nullable | 93 */ |
60 private final Long mSentBytesCount; | 94 @Nullable |
61 @Nullable | 95 public abstract Date getRequestStart(); |
62 private final Long mReceivedBytesCount; | 96 |
63 | 97 /** |
64 public Metrics(@Nullable Long ttfbMs, @Nullable Long totalTimeMs, | 98 * @return {@link java.util.Date} representing when DNS lookup started. Null if a proxy is |
pauljensen
2016/09/06 17:22:23
What do you mean by "a proxy" here?
pauljensen
2016/09/06 17:22:23
Null->{@code null}
here and below
mgersh
2016/09/07 22:09:57
I think I mean the thing that Helen said doesn't a
mgersh
2016/09/07 22:09:58
Done.
| |
65 @Nullable Long sentBytesCount, @Nullable Long receivedBytesCount ) { | 99 * used to determine the DNS address. |
pauljensen
2016/09/06 17:22:23
doesn't this and some of the other methods return
mgersh
2016/09/07 22:09:58
Done.
| |
66 mTtfbMs = ttfbMs; | 100 */ |
67 mTotalTimeMs = totalTimeMs; | 101 @Nullable |
68 mSentBytesCount = sentBytesCount; | 102 public abstract Date getDnsStart(); |
69 mReceivedBytesCount = receivedBytesCount; | 103 |
70 } | 104 /** |
105 * @return {@link java.util.Date} representing when DNS lookup finished. Null if a proxy is | |
106 * used to determine the DNS address. | |
107 */ | |
108 @Nullable | |
109 public abstract Date getDnsEnd(); | |
110 | |
111 /** | |
112 * @return {@link java.util.Date} representing when connection establish ment started, | |
113 * typically when DNS resolution finishes if no proxy is used. | |
114 */ | |
115 @Nullable | |
116 public abstract Date getConnectStart(); | |
117 | |
118 /** | |
119 * @return {@link java.util.Date} representing when connection establish ment finished, | |
120 * after TCP connection is established and, if using HTTPS, SSL handshak e is completed. | |
121 */ | |
122 @Nullable | |
123 public abstract Date getConnectEnd(); | |
124 | |
125 /** | |
126 * @return {@link java.util.Date} representing when SSL handshake starte d. Null if SSL is | |
127 * not used. | |
128 */ | |
129 @Nullable | |
130 public abstract Date getSslStart(); | |
131 | |
132 /** | |
133 * @return {@link java.util.Date} representing when SSL handshake finish ed. Null if SSL is | |
134 * not used. | |
135 */ | |
136 @Nullable | |
137 public abstract Date getSslEnd(); | |
138 | |
139 /** | |
140 * @return {@link java.util.Date} representing when sending HTTP request headers started. | |
141 */ | |
142 @Nullable | |
143 public abstract Date getSendingStart(); | |
144 | |
145 /** | |
146 * @return {@link java.util.Date} representing when sending HTTP request body finished. | |
pauljensen
2016/09/06 17:22:23
It's a little odd that getSendingStart() is docume
mgersh
2016/09/07 22:09:58
Done.
| |
147 */ | |
148 @Nullable | |
149 public abstract Date getSendingEnd(); | |
150 | |
151 /** | |
152 * @return {@link java.util.Date} representing when the first byte of an HTTP2 server push | |
pauljensen
2016/09/06 17:22:23
HTTP2->HTTP/2
here and below
so as to match things
mgersh
2016/09/07 22:09:58
Done.
| |
153 * was received. Null if server push is not used. | |
154 */ | |
155 @Nullable | |
156 public abstract Date getPushStart(); | |
157 | |
158 /** | |
159 * @return {@link java.util.Date} representing when the last byte of an HTTP2 server push | |
160 * was received. Null if server push is not used. | |
161 */ | |
162 @Nullable | |
163 public abstract Date getPushEnd(); | |
164 | |
165 /** | |
166 * @return {@link java.util.Date} representing when the first byte of th e response was | |
167 * received. | |
168 */ | |
169 @Nullable | |
170 public abstract Date getResponseStart(); | |
171 | |
172 /** | |
173 * @return {@link java.util.Date} representing when the last byte of the response was | |
174 * received. | |
175 */ | |
176 @Nullable | |
177 public abstract Date getResponseEnd(); | |
178 | |
179 /** | |
180 * @return whether this request reused a socket from a previous request. When true, DNS, | |
pauljensen
2016/09/06 17:22:23
true->{@code true}
mgersh
2016/09/07 22:09:58
Done.
| |
181 * connection, and SSL times will be null. | |
182 */ | |
183 @Nullable | |
184 public abstract boolean getSocketReused(); | |
71 | 185 |
72 /** | 186 /** |
73 * Returns milliseconds between request initiation and first byte of res ponse headers, | 187 * Returns milliseconds between request initiation and first byte of res ponse headers, |
74 * or null if not collected. | 188 * or null if not collected. |
75 */ | 189 * TODO(mgersh): Remove once new API works http://crbug.com/629194 |
76 @Nullable | 190 */ |
77 public Long getTtfbMs() { | 191 @Nullable |
78 return mTtfbMs; | 192 public abstract Long getTtfbMs(); |
79 } | |
80 | 193 |
81 /** | 194 /** |
82 * Returns milliseconds between request initiation and finish, | 195 * Returns milliseconds between request initiation and finish, |
83 * including a failure or cancellation, or null if not collected. | 196 * including a failure or cancellation, or null if not collected. |
84 */ | 197 * TODO(mgersh): Remove once new API works http://crbug.com/629194 |
85 @Nullable | 198 */ |
86 public Long getTotalTimeMs() { | 199 @Nullable |
87 return mTotalTimeMs; | 200 public abstract Long getTotalTimeMs(); |
88 } | |
89 | 201 |
90 /** | 202 /** |
91 * Returns total bytes sent over the network transport layer, or null if not collected. | 203 * Returns total bytes sent over the network transport layer, or null if not collected. |
92 */ | 204 */ |
93 @Nullable | 205 @Nullable |
94 public Long getSentBytesCount() { | 206 public abstract Long getSentBytesCount(); |
95 return mSentBytesCount; | |
96 } | |
97 | 207 |
98 /** | 208 /** |
99 * Returns total bytes received over the network transport layer, or nul l if not collected. | 209 * Returns total bytes received over the network transport layer, or nul l if not collected. |
100 */ | 210 */ |
101 @Nullable | 211 @Nullable |
102 public Long getReceivedBytesCount() { | 212 public abstract Long getReceivedBytesCount(); |
103 return mReceivedBytesCount; | |
104 } | |
105 } | 213 } |
106 | 214 |
107 private final String mUrl; | 215 private final String mUrl; |
108 private final Collection<Object> mAnnotations; | 216 private final Collection<Object> mAnnotations; |
109 private final Metrics mMetrics; | 217 private final Metrics mMetrics; |
218 | |
219 /** @hide */ | |
220 @IntDef({SUCCEEDED, FAILED, CANCELED}) | |
221 @Retention(RetentionPolicy.SOURCE) | |
222 public @interface FinishedReason {} | |
223 | |
224 /** | |
225 * The request succeeded. Returned from {@link #getFinishedReason}. | |
pauljensen
2016/09/06 17:22:23
do you need to qualify the class, so Metrics#getFi
pauljensen
2016/09/06 17:22:23
should we prefix this description with "Reason val
mgersh
2016/09/07 22:09:58
Done.
mgersh
2016/09/07 22:09:58
No, both this and getFinishedReason() are in Reque
| |
226 */ | |
227 public static final int SUCCEEDED = 0; | |
228 /** | |
229 * The request failed or errored. Returned from {@link #getFinishedReason}. | |
230 */ | |
231 public static final int FAILED = 1; | |
232 /** | |
233 * The request was canceled. Returned from {@link #getFinishedReason}. | |
234 */ | |
235 public static final int CANCELED = 2; | |
236 | |
237 @FinishedReason | |
238 private final int mFinishedReason; | |
239 | |
110 @Nullable | 240 @Nullable |
111 private final UrlResponseInfo mResponseInfo; | 241 private final UrlResponseInfo mResponseInfo; |
242 @Nullable | |
243 private final UrlRequestException mException; | |
112 | 244 |
113 /** | 245 /** |
114 * @hide only used by internal implementation. | 246 * @hide only used by internal implementation. |
115 */ | 247 */ |
116 public RequestFinishedInfo(String url, Collection<Object> annotations, Metri cs metrics, | 248 public RequestFinishedInfo(String url, Collection<Object> annotations, Metri cs metrics, |
117 @Nullable UrlResponseInfo responseInfo) { | 249 @FinishedReason int finishedReason, @Nullable UrlResponseInfo respon seInfo, |
250 @Nullable UrlRequestException exception) { | |
118 mUrl = url; | 251 mUrl = url; |
119 mAnnotations = annotations; | 252 mAnnotations = annotations; |
120 mMetrics = metrics; | 253 mMetrics = metrics; |
254 mFinishedReason = finishedReason; | |
121 mResponseInfo = responseInfo; | 255 mResponseInfo = responseInfo; |
256 mException = exception; | |
122 } | 257 } |
123 | 258 |
124 /** Returns the request's original URL. */ | 259 /** Returns the request's original URL. */ |
125 public String getUrl() { | 260 public String getUrl() { |
126 return mUrl; | 261 return mUrl; |
127 } | 262 } |
128 | 263 |
129 /** Returns the objects that the caller has supplied when initiating the req uest. */ | 264 /** Returns the objects that the caller has supplied when initiating the req uest. */ |
130 public Collection<Object> getAnnotations() { | 265 public Collection<Object> getAnnotations() { |
131 return mAnnotations; | 266 return mAnnotations; |
132 } | 267 } |
133 | 268 |
134 // TODO(klm): Collect and return a chain of Metrics objects for redirect res ponses. | 269 // TODO(klm): Collect and return a chain of Metrics objects for redirect res ponses. |
270 // TODO(mgersh): Update this javadoc when new metrics are fully implemented | |
135 /** | 271 /** |
136 * Returns metrics collected for this request. | 272 * Returns metrics collected for this request. |
137 * | 273 * |
138 * <p>The reported times and bytes account for all redirects, i.e. | 274 * <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, | 275 * 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, | 276 * 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. | 277 * 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 | 278 * These cumulative metric definitions are debatable, but are chosen to make sense |
143 * for user-facing latency analysis. | 279 * for user-facing latency analysis. |
144 * | 280 * |
145 * @return metrics collected for this request. | 281 * @return metrics collected for this request. |
146 */ | 282 */ |
147 public Metrics getMetrics() { | 283 public Metrics getMetrics() { |
148 return mMetrics; | 284 return mMetrics; |
149 } | 285 } |
150 | 286 |
151 /** | 287 /** |
288 * Returns the reason why the request finished. | |
289 * @return one of {@link #SUCCEEDED}, {@link #FAILED}, or {@link #CANCELED} | |
290 */ | |
291 @FinishedReason | |
292 public int getFinishedReason() { | |
293 return mFinishedReason; | |
294 } | |
295 | |
296 /** | |
152 * Returns a {@link UrlResponseInfo} for the request, if its response had st arted. | 297 * 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. | 298 * @return {@link UrlResponseInfo} for the request, if its response had star ted. |
154 */ | 299 */ |
155 @Nullable | 300 @Nullable |
156 public UrlResponseInfo getResponseInfo() { | 301 public UrlResponseInfo getResponseInfo() { |
157 return mResponseInfo; | 302 return mResponseInfo; |
158 } | 303 } |
304 | |
305 /** | |
306 * If the request failed, returns the same {@link UrlRequestException} provi ded to | |
307 * {@link UrlRequest.Callback#onFailed}. | |
308 * | |
309 * @return the request's {@link UrlRequestException}, if the request failed | |
310 */ | |
311 @Nullable | |
312 public UrlRequestException getException() { | |
313 return mException; | |
314 } | |
159 } | 315 } |
OLD | NEW |