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 * which holds the information for {@link http://w3c.github.io/navigation-ti ming/} and | |
56 * {@link https://www.w3.org/TR/resource-timing/}. | |
57 * | |
58 * Events happen in this order: | |
59 * request start | |
60 * proxy start | |
61 * proxy end | |
62 * dns start | |
63 * dns end | |
64 * connect start | |
65 * ssl start | |
66 * ssl end | |
67 * connect end | |
68 * send start | |
69 * send end | |
70 * response start | |
71 * response end | |
72 * | |
73 * Start times are reported as the time when a request started blocking on e vent, not when the | |
74 * event actually occurred, with the exception of push start and end. If a m etric is not | |
75 * meaningful or not available, including cases when a request finished befo re reaching that | |
76 * stage, start and end times will be null. If no time was spent blocking on an event, start | |
77 * and end will be the same time. | |
78 * | |
52 * {@hide} as it's a prototype. | 79 * {@hide} as it's a prototype. |
53 */ | 80 */ |
54 public static class Metrics { | 81 public abstract static class Metrics { |
82 /** | |
83 * @return {@link java.util.Date} representing when proxy resolution sta rted. Null if there | |
84 * is no PAC. | |
85 */ | |
55 @Nullable | 86 @Nullable |
56 private final Long mTtfbMs; | 87 public abstract Date getProxyStart(); |
88 | |
89 /** | |
90 * @return {@link java.util.Date} representing when proxy resolution fin ished. Null if there | |
91 * is no PAC. | |
xunjieli
2016/09/01 22:17:42
As far as I know, Cronet doesn't do PAC resolution
mgersh
2016/09/02 19:32:08
Ah, didn't know that, thanks. Done.
| |
92 */ | |
57 @Nullable | 93 @Nullable |
58 private final Long mTotalTimeMs; | 94 public abstract Date getProxyEnd(); |
95 | |
96 /** | |
97 * @return {@link java.util.Date} representing when DNS lookup started. Null if a proxy is | |
98 * used to determine the DNS address. | |
99 */ | |
59 @Nullable | 100 @Nullable |
60 private final Long mSentBytesCount; | 101 public abstract Date getDnsStart(); |
102 | |
103 /** | |
104 * @return {@link java.util.Date} representing when DNS lookup finished. Null if a proxy is | |
105 * used to determine the DNS address. | |
106 */ | |
61 @Nullable | 107 @Nullable |
62 private final Long mReceivedBytesCount; | 108 public abstract Date getDnsEnd(); |
63 | 109 |
64 public Metrics(@Nullable Long ttfbMs, @Nullable Long totalTimeMs, | 110 /** |
65 @Nullable Long sentBytesCount, @Nullable Long receivedBytesCount ) { | 111 * @return {@link java.util.Date} representing when connection establish ment started, |
66 mTtfbMs = ttfbMs; | 112 * typically when DNS resolution finishes if no proxy is used. |
67 mTotalTimeMs = totalTimeMs; | 113 */ |
68 mSentBytesCount = sentBytesCount; | 114 @Nullable |
69 mReceivedBytesCount = receivedBytesCount; | 115 public abstract Date getConnectStart(); |
70 } | 116 |
117 /** | |
118 * @return {@link java.util.Date} representing when connection establish ment finished, | |
119 * after TCP connection is established and, if using HTTPS, SSL handshak e is completed. | |
120 */ | |
121 @Nullable | |
122 public abstract Date getConnectEnd(); | |
123 | |
124 /** | |
125 * @return {@link java.util.Date} representing when SSL handshake starte d. Null if SSL is | |
126 * not used. | |
127 */ | |
128 @Nullable | |
129 public abstract Date getSslStart(); | |
130 | |
131 /** | |
132 * @return {@link java.util.Date} representing when SSL handshake finish ed. Null if SSL is | |
133 * not used. | |
134 */ | |
135 @Nullable | |
136 public abstract Date getSslEnd(); | |
137 | |
138 /** | |
139 * @return {@link java.util.Date} representing when sending HTTP request headers started. | |
140 */ | |
141 @Nullable | |
142 public abstract Date getSendingStart(); | |
143 | |
144 /** | |
145 * @return {@link java.util.Date} representing when sending HTTP request body finished. | |
146 */ | |
147 @Nullable | |
148 public abstract Date getSendingEnd(); | |
149 | |
150 /** | |
151 * @return {@link java.util.Date} representing when the first byte of an HTTP2 server push | |
152 * was received. Null if server push is not used. | |
153 */ | |
154 @Nullable | |
155 public abstract Date getPushStart(); | |
156 | |
157 /** | |
158 * @return {@link java.util.Date} representing when the last byte of an HTTP2 server push | |
159 * was received. Null if server push is not used. | |
160 */ | |
161 @Nullable | |
162 public abstract Date getPushEnd(); | |
163 | |
164 /** | |
165 * @return {@link java.util.Date} representing when the first byte of th e response was | |
166 * received. | |
167 */ | |
168 @Nullable | |
169 public abstract Date getResponseStart(); | |
170 | |
171 /** | |
172 * @return {@link java.util.Date} representing when the last byte of the response was | |
173 * received. | |
174 */ | |
175 @Nullable | |
176 public abstract Date getResponseEnd(); | |
177 | |
178 /** | |
179 * @return whether this request reused a socket from a previous request. When true, DNS, | |
180 * connection, and SSL times will be null. | |
181 */ | |
182 @Nullable | |
183 public abstract boolean getSocketReused(); | |
71 | 184 |
72 /** | 185 /** |
73 * Returns milliseconds between request initiation and first byte of res ponse headers, | 186 * Returns milliseconds between request initiation and first byte of res ponse headers, |
74 * or null if not collected. | 187 * or null if not collected. |
75 */ | 188 */ |
76 @Nullable | 189 @Nullable |
77 public Long getTtfbMs() { | 190 public abstract Long getTtfbMs(); |
xunjieli
2016/09/01 22:17:42
I am inclining to suggest to spell out Tfbs since
mgersh
2016/09/02 19:32:08
This is part of the old API which will go away soo
| |
78 return mTtfbMs; | |
79 } | |
80 | 191 |
81 /** | 192 /** |
82 * Returns milliseconds between request initiation and finish, | 193 * Returns milliseconds between request initiation and finish, |
83 * including a failure or cancellation, or null if not collected. | 194 * including a failure or cancellation, or null if not collected. |
84 */ | 195 */ |
85 @Nullable | 196 @Nullable |
86 public Long getTotalTimeMs() { | 197 public abstract Long getTotalTimeMs(); |
87 return mTotalTimeMs; | |
88 } | |
89 | 198 |
90 /** | 199 /** |
91 * Returns total bytes sent over the network transport layer, or null if not collected. | 200 * Returns total bytes sent over the network transport layer, or null if not collected. |
92 */ | 201 */ |
93 @Nullable | 202 @Nullable |
94 public Long getSentBytesCount() { | 203 public abstract Long getSentBytesCount(); |
95 return mSentBytesCount; | |
96 } | |
97 | 204 |
98 /** | 205 /** |
99 * Returns total bytes received over the network transport layer, or nul l if not collected. | 206 * Returns total bytes received over the network transport layer, or nul l if not collected. |
100 */ | 207 */ |
101 @Nullable | 208 @Nullable |
102 public Long getReceivedBytesCount() { | 209 public abstract Long getReceivedBytesCount(); |
103 return mReceivedBytesCount; | |
104 } | |
105 } | 210 } |
106 | 211 |
212 public static final int SUCCEEDED = 0; | |
213 public static final int FAILED = 1; | |
214 public static final int CANCELED = 2; | |
xunjieli
2016/09/01 22:17:42
Maybe use intDef and add a documentation on what t
mgersh
2016/09/02 19:32:08
Huh, IntDef is cool. Done.
| |
215 | |
107 private final String mUrl; | 216 private final String mUrl; |
108 private final Collection<Object> mAnnotations; | 217 private final Collection<Object> mAnnotations; |
109 private final Metrics mMetrics; | 218 private final Metrics mMetrics; |
219 // One of SUCCEEDED, FAILED, or CANCELED | |
220 private final int mFinishedReason; | |
110 @Nullable | 221 @Nullable |
111 private final UrlResponseInfo mResponseInfo; | 222 private final UrlResponseInfo mResponseInfo; |
223 @Nullable | |
224 private final UrlRequestException mException; | |
112 | 225 |
113 /** | 226 /** |
114 * @hide only used by internal implementation. | 227 * @hide only used by internal implementation. |
115 */ | 228 */ |
116 public RequestFinishedInfo(String url, Collection<Object> annotations, Metri cs metrics, | 229 public RequestFinishedInfo(String url, Collection<Object> annotations, Metri cs metrics, |
117 @Nullable UrlResponseInfo responseInfo) { | 230 int finishedReason, @Nullable UrlResponseInfo responseInfo, |
231 @Nullable UrlRequestException exception) { | |
118 mUrl = url; | 232 mUrl = url; |
119 mAnnotations = annotations; | 233 mAnnotations = annotations; |
120 mMetrics = metrics; | 234 mMetrics = metrics; |
235 mFinishedReason = finishedReason; | |
121 mResponseInfo = responseInfo; | 236 mResponseInfo = responseInfo; |
237 mException = exception; | |
122 } | 238 } |
123 | 239 |
124 /** Returns the request's original URL. */ | 240 /** Returns the request's original URL. */ |
125 public String getUrl() { | 241 public String getUrl() { |
126 return mUrl; | 242 return mUrl; |
127 } | 243 } |
128 | 244 |
129 /** Returns the objects that the caller has supplied when initiating the req uest. */ | 245 /** Returns the objects that the caller has supplied when initiating the req uest. */ |
130 public Collection<Object> getAnnotations() { | 246 public Collection<Object> getAnnotations() { |
131 return mAnnotations; | 247 return mAnnotations; |
132 } | 248 } |
133 | 249 |
134 // TODO(klm): Collect and return a chain of Metrics objects for redirect res ponses. | 250 // TODO(klm): Collect and return a chain of Metrics objects for redirect res ponses. |
251 // TODO(mgersh): Update this javadoc when new metrics are fully implemented | |
135 /** | 252 /** |
136 * Returns metrics collected for this request. | 253 * Returns metrics collected for this request. |
137 * | 254 * |
138 * <p>The reported times and bytes account for all redirects, i.e. | 255 * <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, | 256 * 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, | 257 * 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. | 258 * 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 | 259 * These cumulative metric definitions are debatable, but are chosen to make sense |
143 * for user-facing latency analysis. | 260 * for user-facing latency analysis. |
144 * | 261 * |
145 * @return metrics collected for this request. | 262 * @return metrics collected for this request. |
146 */ | 263 */ |
147 public Metrics getMetrics() { | 264 public Metrics getMetrics() { |
148 return mMetrics; | 265 return mMetrics; |
149 } | 266 } |
150 | 267 |
151 /** | 268 /** |
269 * Returns the reason why the request finished. | |
270 * @return one of {@link #SUCCEEDED}, {@link #FAILED}, or {@link #CANCELED} | |
271 */ | |
272 public int getFinishedReason() { | |
273 return mFinishedReason; | |
274 } | |
275 | |
276 /** | |
152 * Returns a {@link UrlResponseInfo} for the request, if its response had st arted. | 277 * 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. | 278 * @return {@link UrlResponseInfo} for the request, if its response had star ted. |
154 */ | 279 */ |
155 @Nullable | 280 @Nullable |
156 public UrlResponseInfo getResponseInfo() { | 281 public UrlResponseInfo getResponseInfo() { |
157 return mResponseInfo; | 282 return mResponseInfo; |
158 } | 283 } |
284 | |
285 /** | |
286 * If the request failed, returns the same {@link UrlRequestException} provi ded to | |
287 * {@link UrlRequest.Callback#onFailed}. | |
288 * | |
289 * @return the request's {@link UrlRequestException}, if the request failed | |
290 */ | |
291 @Nullable | |
292 public UrlRequestException getException() { | |
293 return mException; | |
294 } | |
159 } | 295 } |
OLD | NEW |