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.
5 #ifndef NET_BASE_LOAD_TIMING_INFO_H_
6 #define NET_BASE_LOAD_TIMING_INFO_H_
8 #include "base/basictypes.h"
9 #include "base/time/time.h"
10 #include "net/base/net_export.h"
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/.
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.
23 // Requests with connection errors generally only have request start times as
24 // well, since they never received an established socket.
26 // The general order for events is:
38 // receive_headers_end
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 and HTTP pipelining, PAC scripts are only run once for
44 // each shared session, so no time may be spent blocking on them.
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?
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.
57 struct 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
{
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
;
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
;
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
;
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.
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.
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.
114 // 0 when there is no socket associated with the request, or it's not an HTTP
116 uint32 socket_log_id
;
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
121 base::Time request_start_time
;
123 base::TimeTicks request_start
;
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
;
129 ConnectTiming connect_timing
;
131 // The time that sending HTTP request started / ended.
132 base::TimeTicks send_start
;
133 base::TimeTicks send_end
;
135 // The time at which the end of the HTTP headers were received.
136 base::TimeTicks receive_headers_end
;
141 #endif // NET_BASE_LOAD_TIMING_INFO_H_