xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/quic/core/quic_connection_stats.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2013 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 QUICHE_QUIC_CORE_QUIC_CONNECTION_STATS_H_
6 #define QUICHE_QUIC_CORE_QUIC_CONNECTION_STATS_H_
7 
8 #include <cstdint>
9 #include <ostream>
10 
11 #include "quiche/quic/core/quic_bandwidth.h"
12 #include "quiche/quic/core/quic_packets.h"
13 #include "quiche/quic/core/quic_time.h"
14 #include "quiche/quic/core/quic_time_accumulator.h"
15 #include "quiche/quic/platform/api/quic_export.h"
16 
17 namespace quic {
18 
19 // Structure to hold stats for a QuicConnection.
20 struct QUICHE_EXPORT QuicConnectionStats {
21   QUICHE_EXPORT friend std::ostream& operator<<(std::ostream& os,
22                                                 const QuicConnectionStats& s);
23 
24   QuicByteCount bytes_sent = 0;  // Includes retransmissions.
25   QuicPacketCount packets_sent = 0;
26   // Non-retransmitted bytes sent in a stream frame.
27   QuicByteCount stream_bytes_sent = 0;
28   // Packets serialized and discarded before sending.
29   QuicPacketCount packets_discarded = 0;
30 
31   // These include version negotiation and public reset packets, which do not
32   // have packet numbers or frame data.
33   QuicByteCount bytes_received = 0;  // Includes duplicate data for a stream.
34   // Includes packets which were not processable.
35   QuicPacketCount packets_received = 0;
36   // Excludes packets which were not processable.
37   QuicPacketCount packets_processed = 0;
38   QuicByteCount stream_bytes_received = 0;  // Bytes received in a stream frame.
39 
40   QuicByteCount bytes_retransmitted = 0;
41   QuicPacketCount packets_retransmitted = 0;
42 
43   QuicByteCount bytes_spuriously_retransmitted = 0;
44   QuicPacketCount packets_spuriously_retransmitted = 0;
45   // Number of packets abandoned as lost by the loss detection algorithm.
46   QuicPacketCount packets_lost = 0;
47   QuicPacketCount packet_spuriously_detected_lost = 0;
48 
49   // The sum of loss detection response times of all lost packets, in number of
50   // round trips.
51   // Given a packet detected as lost:
52   //   T(S)                            T(1Rtt)    T(D)
53   //     |_________________________________|_______|
54   // Where
55   //   T(S) is the time when the packet is sent.
56   //   T(1Rtt) is one rtt after T(S), using the rtt at the time of detection.
57   //   T(D) is the time of detection, i.e. when the packet is declared as lost.
58   // The loss detection response time is defined as
59   //     (T(D) - T(S)) / (T(1Rtt) - T(S))
60   //
61   // The average loss detection response time is this number divided by
62   // |packets_lost|. Smaller result means detection is faster.
63   float total_loss_detection_response_time = 0.0;
64 
65   // Number of times this connection went through the slow start phase.
66   uint32_t slowstart_count = 0;
67   // Number of round trips spent in slow start.
68   uint32_t slowstart_num_rtts = 0;
69   // Number of packets sent in slow start.
70   QuicPacketCount slowstart_packets_sent = 0;
71   // Number of bytes sent in slow start.
72   QuicByteCount slowstart_bytes_sent = 0;
73   // Number of packets lost exiting slow start.
74   QuicPacketCount slowstart_packets_lost = 0;
75   // Number of bytes lost exiting slow start.
76   QuicByteCount slowstart_bytes_lost = 0;
77   // Time spent in slow start. Populated for BBRv1 and BBRv2.
78   QuicTimeAccumulator slowstart_duration;
79 
80   // Number of PROBE_BW cycles. Populated for BBRv1 and BBRv2.
81   uint32_t bbr_num_cycles = 0;
82   // Number of PROBE_BW cycles shortened for reno coexistence. BBRv2 only.
83   uint32_t bbr_num_short_cycles_for_reno_coexistence = 0;
84   // Whether BBR exited STARTUP due to excessive loss. Populated for BBRv1 and
85   // BBRv2.
86   bool bbr_exit_startup_due_to_loss = false;
87 
88   QuicPacketCount packets_dropped = 0;  // Duplicate or less than least unacked.
89 
90   // Packets that failed to decrypt when they were first received,
91   // before the handshake was complete.
92   QuicPacketCount undecryptable_packets_received_before_handshake_complete = 0;
93 
94   size_t crypto_retransmit_count = 0;
95   // Count of times the loss detection alarm fired.  At least one packet should
96   // be lost when the alarm fires.
97   size_t loss_timeout_count = 0;
98   size_t tlp_count = 0;
99   size_t rto_count = 0;  // Count of times the rto timer fired.
100   size_t pto_count = 0;
101 
102   int64_t min_rtt_us = 0;                 // Minimum RTT in microseconds.
103   int64_t srtt_us = 0;                    // Smoothed RTT in microseconds.
104   int64_t cwnd_bootstrapping_rtt_us = 0;  // RTT used in cwnd_bootstrapping.
105   // The connection's |long_term_mtu_| used for sending packets, populated by
106   // QuicConnection::GetStats().
107   QuicByteCount egress_mtu = 0;
108   // The maximum |long_term_mtu_| the connection ever used.
109   QuicByteCount max_egress_mtu = 0;
110   // Size of the largest packet received from the peer, populated by
111   // QuicConnection::GetStats().
112   QuicByteCount ingress_mtu = 0;
113   QuicBandwidth estimated_bandwidth = QuicBandwidth::Zero();
114 
115   // Reordering stats for received packets.
116   // Number of packets received out of packet number order.
117   QuicPacketCount packets_reordered = 0;
118   // Maximum reordering observed in packet number space.
119   QuicPacketCount max_sequence_reordering = 0;
120   // Maximum reordering observed in microseconds
121   int64_t max_time_reordering_us = 0;
122 
123   // Maximum sequence reordering observed from acked packets.
124   QuicPacketCount sent_packets_max_sequence_reordering = 0;
125   // Number of times that a packet is not detected as lost per reordering_shift,
126   // but would have been if the reordering_shift increases by one.
127   QuicPacketCount sent_packets_num_borderline_time_reorderings = 0;
128 
129   // The following stats are used only in TcpCubicSender.
130   // The number of loss events from TCP's perspective.  Each loss event includes
131   // one or more lost packets.
132   uint32_t tcp_loss_events = 0;
133 
134   // Creation time, as reported by the QuicClock.
135   QuicTime connection_creation_time = QuicTime::Zero();
136 
137   // Handshake completion time.
138   QuicTime handshake_completion_time = QuicTime::Zero();
139 
140   uint64_t blocked_frames_received = 0;
141   uint64_t blocked_frames_sent = 0;
142 
143   // Number of connectivity probing packets received by this connection.
144   uint64_t num_connectivity_probing_received = 0;
145 
146   // Number of PATH_RESPONSE frame received by this connection.
147   uint64_t num_path_response_received = 0;
148 
149   // Whether a RETRY packet was successfully processed.
150   bool retry_packet_processed = false;
151 
152   // Number of received coalesced packets.
153   uint64_t num_coalesced_packets_received = 0;
154   // Number of successfully processed coalesced packets.
155   uint64_t num_coalesced_packets_processed = 0;
156   // Number of ack aggregation epochs. For the same number of bytes acked, the
157   // smaller this value, the more ack aggregation is going on.
158   uint64_t num_ack_aggregation_epochs = 0;
159 
160   // Whether overshooting is detected (and pacing rate decreases) during start
161   // up with network parameters adjusted.
162   bool overshooting_detected_with_network_parameters_adjusted = false;
163 
164   // Whether there is any non app-limited bandwidth sample.
165   bool has_non_app_limited_sample = false;
166 
167   // Packet number of first decrypted packet.
168   QuicPacketNumber first_decrypted_packet;
169 
170   // Max consecutive retransmission timeout before making forward progress.
171   size_t max_consecutive_rto_with_forward_progress = 0;
172 
173   // Number of times when the connection tries to send data but gets throttled
174   // by amplification factor.
175   size_t num_amplification_throttling = 0;
176 
177   // Number of key phase updates that have occurred. In the case of a locally
178   // initiated key update, this is incremented when the keys are updated, before
179   // the peer has acknowledged the key update.
180   uint32_t key_update_count = 0;
181 
182   // Counts the number of undecryptable packets received across all keys. Does
183   // not include packets where a decryption key for that level was absent.
184   QuicPacketCount num_failed_authentication_packets_received = 0;
185 
186   // Counts the number of QUIC+TLS 0-RTT packets received after 0-RTT decrypter
187   // was discarded, only on server connections.
188   QuicPacketCount
189       num_tls_server_zero_rtt_packets_received_after_discarding_decrypter = 0;
190 
191   // Counts the number of packets received with each Explicit Congestion
192   // Notification (ECN) codepoint, except Not-ECT. There is one counter across
193   // all packet number spaces.
194   QuicEcnCounts num_ecn_marks_received;
195 
196   // Counts the number of ACK frames sent with ECN counts.
197   QuicPacketCount num_ack_frames_sent_with_ecn = 0;
198 
199   // True if address is validated via decrypting HANDSHAKE or 1-RTT packet.
200   bool address_validated_via_decrypting_packet = false;
201 
202   // True if address is validated via validating token received in INITIAL
203   // packet.
204   bool address_validated_via_token = false;
205 
206   size_t ping_frames_sent = 0;
207 
208   // Number of detected peer address changes which changes to a peer address
209   // validated by earlier path validation.
210   size_t num_peer_migration_to_proactively_validated_address = 0;
211   // Number of detected peer address changes which triggers reverse path
212   // validation.
213   size_t num_reverse_path_validtion_upon_migration = 0;
214   // Number of detected peer migrations which either succeed reverse path
215   // validation or no need to be validated.
216   size_t num_validated_peer_migration = 0;
217   // Number of detected peer migrations which triggered reverse path validation
218   // and failed and fell back to the old path.
219   size_t num_invalid_peer_migration = 0;
220   // Number of detected peer migrations which triggered reverse path validation
221   // which was canceled because the peer migrated again. Such migration is also
222   // counted as invalid peer migration.
223   size_t num_peer_migration_while_validating_default_path = 0;
224   // Number of NEW_CONNECTION_ID frames sent.
225   size_t num_new_connection_id_sent = 0;
226   // Number of RETIRE_CONNECTION_ID frames sent.
227   size_t num_retire_connection_id_sent = 0;
228   // Number of path degrading.
229   size_t num_path_degrading = 0;
230   // Number of forward progress made after path degrading.
231   size_t num_forward_progress_after_path_degrading = 0;
232 
233   bool server_preferred_address_validated = false;
234   bool failed_to_validate_server_preferred_address = false;
235   // Number of duplicated packets that have been sent to server preferred
236   // address while the validation is pending.
237   size_t num_duplicated_packets_sent_to_server_preferred_address = 0;
238 
239   struct QUICHE_EXPORT TlsServerOperationStats {
240     bool success = false;
241     // If the operation is performed asynchronously, how long did it take.
242     // Zero() for synchronous operations.
243     QuicTime::Delta async_latency = QuicTime::Delta::Zero();
244   };
245 
246   // The TLS server op stats only have values when the corresponding operation
247   // is performed by TlsServerHandshaker. If an operation is done within
248   // BoringSSL, e.g. ticket decrypted without using
249   // TlsServerHandshaker::SessionTicketOpen, it will not be recorded here.
250   std::optional<TlsServerOperationStats> tls_server_select_cert_stats;
251   std::optional<TlsServerOperationStats> tls_server_compute_signature_stats;
252   std::optional<TlsServerOperationStats> tls_server_decrypt_ticket_stats;
253 
254   // The total number of streams which were pending from some time.
255   size_t num_total_pending_streams = 0;
256 };
257 
258 }  // namespace quic
259 
260 #endif  // QUICHE_QUIC_CORE_QUIC_CONNECTION_STATS_H_
261