1// Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 "base/basictypes.h" 9#include "base/time/time.h" 10#include "net/base/net_export.h" 11 12namespace net { 13 14// Structure containing timing information for a request. 15// It addresses the needs of 16// http://groups.google.com/group/http-archive-specification/web/har-1-1-spec, 17// http://dev.w3.org/2006/webapi/WebTiming/, and 18// http://www.w3.org/TR/resource-timing/. 19// 20// All events that do not apply to a request have null times. For non-HTTP 21// requests, all times other than the request_start times are null. 22// 23// Requests with connection errors generally only have request start times as 24// well, since they never received an established socket. 25// 26// The general order for events is: 27// request_start 28// proxy_start 29// proxy_end 30// dns_start 31// dns_end 32// connect_start 33// ssl_start 34// ssl_end 35// connect_end 36// send_start 37// send_end 38// receive_headers_end 39// 40// Times represent when a request starts/stops blocking on an event, not the 41// time the events actually occurred. In particular, in the case of preconnects 42// and socket reuse, no time may be spent blocking on establishing a connection. 43// In the case of SPDY, PAC scripts are only run once for each shared session, 44// so no time may be spent blocking on them. 45// 46// DNS and SSL times are both times for the host, not the proxy, so DNS times 47// when using proxies are null, and only requests to HTTPS hosts (Not proxies) 48// have SSL times. One exception to this is when a proxy server itself returns 49// a redirect response. In this case, the connect times treat the proxy as the 50// host. The send and receive times will all be null, however. 51// See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. 52// TODO(mmenke): Is this worth fixing? 53// 54// Note that internal to the network stack, times are when events actually 55// occurred. URLRequest converts them to time which the network stack was 56// blocked on each state. 57struct NET_EXPORT LoadTimingInfo { 58 // Contains the LoadTimingInfo events related to establishing a connection. 59 // These are all set by ConnectJobs. 60 struct NET_EXPORT_PRIVATE ConnectTiming { 61 ConnectTiming(); 62 ~ConnectTiming(); 63 64 // The time spent looking up the host's DNS address. Null for requests that 65 // used proxies to look up the DNS address. Also null for SOCKS4 proxies, 66 // since the DNS address is only looked up after the connection is 67 // established, which results in unexpected event ordering. 68 // TODO(mmenke): The SOCKS4 event ordering could be refactored to allow 69 // these times to be non-null. 70 base::TimeTicks dns_start; 71 base::TimeTicks dns_end; 72 73 // The time spent establishing the connection. Connect time includes proxy 74 // connect times (Though not proxy_resolve times), DNS lookup times, time 75 // spent waiting in certain queues, TCP, and SSL time. 76 // TODO(mmenke): For proxies, this includes time spent blocking on higher 77 // level socket pools. Fix this. 78 // TODO(mmenke): Retried connections to the same server should apparently 79 // be included in this time. Consider supporting that. 80 // Since the network stack has multiple notions of a "retry", 81 // handled at different levels, this may not be worth 82 // worrying about - backup jobs, reused socket failure, 83 // multiple round authentication. 84 base::TimeTicks connect_start; 85 base::TimeTicks connect_end; 86 87 // The time when the SSL handshake started / completed. For non-HTTPS 88 // requests these are null. These times are only for the SSL connection to 89 // the final destination server, not an SSL/SPDY proxy. 90 base::TimeTicks ssl_start; 91 base::TimeTicks ssl_end; 92 }; 93 94 LoadTimingInfo(); 95 ~LoadTimingInfo(); 96 97 // True if the socket was reused. When true, DNS, connect, and SSL times 98 // will all be null. When false, those times may be null, too, for non-HTTP 99 // requests, or when they don't apply to a request. 100 // 101 // For requests that are sent again after an AUTH challenge, this will be true 102 // if the original socket is reused, and false if a new socket is used. 103 // Responding to a proxy AUTH challenge is never considered to be reusing a 104 // socket, since a connection to the host wasn't established when the 105 // challenge was received. 106 bool socket_reused; 107 108 // Unique socket ID, can be used to identify requests served by the same 109 // socket. For connections tunnelled over SPDY proxies, this is the ID of 110 // the virtual connection (The SpdyProxyClientSocket), not the ID of the 111 // actual socket. HTTP requests handled by the SPDY proxy itself all use the 112 // actual socket's ID. 113 // 114 // 0 when there is no socket associated with the request, or it's not an HTTP 115 // request. 116 uint32 socket_log_id; 117 118 // Start time as a base::Time, so times can be coverted into actual times. 119 // Other times are recorded as TimeTicks so they are not affected by clock 120 // changes. 121 base::Time request_start_time; 122 123 base::TimeTicks request_start; 124 125 // The time spent determing which proxy to use. Null when there is no PAC. 126 base::TimeTicks proxy_resolve_start; 127 base::TimeTicks proxy_resolve_end; 128 129 ConnectTiming connect_timing; 130 131 // The time that sending HTTP request started / ended. 132 base::TimeTicks send_start; 133 base::TimeTicks send_end; 134 135 // The time at which the end of the HTTP headers were received. 136 base::TimeTicks receive_headers_end; 137}; 138 139} // namespace net 140 141#endif // NET_BASE_LOAD_TIMING_INFO_H_ 142