load_timing_info.h 8.8 KB

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