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