1 // Copyright 2012 The Chromium Authors 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 NET_BASE_LOAD_TIMING_INFO_H_ 6 #define NET_BASE_LOAD_TIMING_INFO_H_ 7 8 #include <stdint.h> 9 10 #include "base/time/time.h" 11 #include "net/base/net_export.h" 12 13 namespace net { 14 15 // Structure containing timing information for a request. 16 // It addresses the needs of 17 // http://groups.google.com/group/http-archive-specification/web/har-1-1-spec, 18 // http://dev.w3.org/2006/webapi/WebTiming/, and 19 // http://www.w3.org/TR/resource-timing/. 20 // 21 // All events that do not apply to a request have null times. For non-HTTP 22 // requests, all times other than the request_start times are null. 23 // 24 // Requests with connection errors generally only have request start times as 25 // well, since they never received an established socket. 26 // 27 // The general order for events is: 28 // request_start 29 // service_worker_router_evaluation_start 30 // service_worker_cache_lookup_start 31 // service_worker_start_time 32 // proxy_start 33 // proxy_end 34 // domain_lookup_start 35 // domain_lookup_end 36 // connect_start 37 // ssl_start 38 // ssl_end 39 // connect_end 40 // send_start 41 // send_end 42 // service_worker_ready_time 43 // service_worker_fetch_start 44 // service_worker_respond_with_settled 45 // first_early_hints_time 46 // receive_headers_start 47 // receive_non_informational_headers_start 48 // receive_headers_end 49 // 50 // Times represent when a request starts/stops blocking on an event(*), not the 51 // time the events actually occurred. In particular, in the case of preconnects 52 // and socket reuse, no time may be spent blocking on establishing a connection. 53 // In the case of SPDY, PAC scripts are only run once for each shared session, 54 // so no time may be spent blocking on them. 55 // 56 // (*) Note 1: push_start and push_end are the exception to this, as they 57 // represent the operation which is asynchronous to normal request flow and 58 // hence are provided as absolute values and not converted to "blocking" time. 59 // 60 // (*) Note 2: Internally to the network stack, times are those of actual event 61 // occurrence. URLRequest converts them to time which the network stack was 62 // blocked on each state, as per resource timing specs. 63 // 64 // DNS and SSL times are both times for the host, not the proxy, so DNS times 65 // when using proxies are null, and only requests to HTTPS hosts (Not proxies) 66 // have SSL times. 67 struct NET_EXPORT LoadTimingInfo { 68 // Contains the LoadTimingInfo events related to establishing a connection. 69 // These are all set by ConnectJobs. 70 struct NET_EXPORT_PRIVATE ConnectTiming { 71 ConnectTiming(); 72 ~ConnectTiming(); 73 74 // The time spent looking up the host's DNS address. Null for requests that 75 // used proxies to look up the DNS address. Also null for SOCKS4 proxies, 76 // since the DNS address is only looked up after the connection is 77 // established, which results in unexpected event ordering. 78 // TODO(mmenke): The SOCKS4 event ordering could be refactored to allow 79 // these times to be non-null. 80 // Corresponds to |domainLookupStart| and |domainLookupEnd| in 81 // ResourceTiming (http://www.w3.org/TR/resource-timing/) for Web-surfacing 82 // requests. 83 base::TimeTicks domain_lookup_start; 84 base::TimeTicks domain_lookup_end; 85 86 // The time spent establishing the connection. Connect time includes proxy 87 // connect times (though not proxy_resolve or DNS lookup times), time spent 88 // waiting in certain queues, TCP, and SSL time. 89 // TODO(mmenke): For proxies, this includes time spent blocking on higher 90 // level socket pools. Fix this. 91 // TODO(mmenke): Retried connections to the same server should apparently 92 // be included in this time. Consider supporting that. 93 // Since the network stack has multiple notions of a "retry", 94 // handled at different levels, this may not be worth 95 // worrying about - backup jobs, reused socket failure, 96 // multiple round authentication. 97 // Corresponds to |connectStart| and |connectEnd| in ResourceTiming 98 // (http://www.w3.org/TR/resource-timing/) for Web-surfacing requests. 99 base::TimeTicks connect_start; 100 base::TimeTicks connect_end; 101 102 // The time when the SSL handshake started / completed. For non-HTTPS 103 // requests these are null. These times are only for the SSL connection to 104 // the final destination server, not an SSL/SPDY proxy. 105 // |ssl_start| corresponds to |secureConnectionStart| in ResourceTiming 106 // (http://www.w3.org/TR/resource-timing/) for Web-surfacing requests. 107 base::TimeTicks ssl_start; 108 base::TimeTicks ssl_end; 109 }; 110 111 LoadTimingInfo(); 112 LoadTimingInfo(const LoadTimingInfo& other); 113 ~LoadTimingInfo(); 114 115 // True if the socket was reused. When true, DNS, connect, and SSL times 116 // will all be null. When false, those times may be null, too, for non-HTTP 117 // requests, or when they don't apply to a request. 118 // 119 // For requests that are sent again after an AUTH challenge, this will be true 120 // if the original socket is reused, and false if a new socket is used. 121 // Responding to a proxy AUTH challenge is never considered to be reusing a 122 // socket, since a connection to the host wasn't established when the 123 // challenge was received. 124 bool socket_reused = false; 125 126 // Unique socket ID, can be used to identify requests served by the same 127 // socket. For connections tunnelled over SPDY proxies, this is the ID of 128 // the virtual connection (The SpdyProxyClientSocket), not the ID of the 129 // actual socket. HTTP requests handled by the SPDY proxy itself all use the 130 // actual socket's ID. 131 // 132 // 0 when there is no socket associated with the request, or it's not an HTTP 133 // request. 134 uint32_t socket_log_id; 135 136 // Start time as a base::Time, so times can be coverted into actual times. 137 // Other times are recorded as TimeTicks so they are not affected by clock 138 // changes. 139 base::Time request_start_time; 140 141 // Corresponds to |fetchStart| in ResourceTiming 142 // (http://www.w3.org/TR/resource-timing/) for Web-surfacing requests. 143 // Note that this field is not used in ResourceTiming as |requestStart|, which 144 // has the same name but exposes a different field. 145 base::TimeTicks request_start; 146 147 // The time immediately before ServiceWorker static routing API starts 148 // matching a request with the registered router rules. 149 base::TimeTicks service_worker_router_evaluation_start; 150 151 // The time immediately before ServiceWorker static routing API starts 152 // looking up the cache storage when "cache" is specified as its source. 153 base::TimeTicks service_worker_cache_lookup_start; 154 155 // The time immediately before starting ServiceWorker. If the response is not 156 // provided by the ServiceWorker, kept empty. 157 // Corresponds to |workerStart| in 158 // ResourceTiming (http://www.w3.org/TR/resource-timing/) for Web-surfacing 159 base::TimeTicks service_worker_start_time; 160 161 // The time immediately before dispatching fetch event in ServiceWorker. 162 // If the response is not provided by the ServiceWorker, kept empty. 163 // This value will be used for |fetchStart| (or |redirectStart|) in 164 // ResourceTiming (http://www.w3.org/TR/resource-timing/) for Web-surfacing 165 // if this is greater than |request_start|. 166 base::TimeTicks service_worker_ready_time; 167 168 // The time when serviceworker fetch event was popped off the event queue 169 // and fetch event handler started running. 170 // If the response is not provided by the ServiceWorker, kept empty. 171 base::TimeTicks service_worker_fetch_start; 172 173 // The time when serviceworker's fetch event's respondWith promise was 174 // settled. If the response is not provided by the ServiceWorker, kept empty. 175 base::TimeTicks service_worker_respond_with_settled; 176 177 // The time spent determining which proxy to use. Null when there is no PAC. 178 base::TimeTicks proxy_resolve_start; 179 base::TimeTicks proxy_resolve_end; 180 181 ConnectTiming connect_timing; 182 183 // The time that sending HTTP request started / ended. 184 // |send_start| corresponds to |requestStart| in ResourceTiming 185 // (http://www.w3.org/TR/resource-timing/) for Web-surfacing requests. 186 base::TimeTicks send_start; 187 base::TimeTicks send_end; 188 189 // The time at which the first / last byte of the HTTP headers were received. 190 // 191 // |receive_headers_start| corresponds to |responseStart| in ResourceTiming 192 // (http://www.w3.org/TR/resource-timing/) for Web-surfacing requests. This 193 // can be the time at which the first byte of the HTTP headers for 194 // informational responses (1xx) as per the ResourceTiming spec (see note at 195 // https://www.w3.org/TR/resource-timing-2/#dom-performanceresourcetiming-responsestart). 196 base::TimeTicks receive_headers_start; 197 base::TimeTicks receive_headers_end; 198 199 // The time at which the first byte of the HTTP headers for the 200 // non-informational response (non-1xx). See also comments on 201 // |receive_headers_start|. 202 base::TimeTicks receive_non_informational_headers_start; 203 204 // The time that the first 103 Early Hints response is received. 205 base::TimeTicks first_early_hints_time; 206 207 // In case the resource was proactively pushed by the server, these are 208 // the times that push started and ended. Note that push_end will be null 209 // if the request is still being transmitted, i.e. the underlying h2 stream 210 // is not closed by the server. 211 base::TimeTicks push_start; 212 base::TimeTicks push_end; 213 }; 214 215 } // namespace net 216 217 #endif // NET_BASE_LOAD_TIMING_INFO_H_ 218