xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/quic/core/quic_trace_visitor.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright (c) 2018 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_TRACE_VISITOR_H_
6 #define QUICHE_QUIC_CORE_QUIC_TRACE_VISITOR_H_
7 
8 #include "quiche/quic/core/quic_connection.h"
9 #include "quiche/quic/core/quic_types.h"
10 #include "quic_trace/quic_trace.pb.h"
11 
12 namespace quic {
13 
14 // Records a QUIC trace protocol buffer for a QuicConnection.  It's the
15 // responsibility of the user of this visitor to process or store the resulting
16 // trace, which can be accessed via trace().
17 class QUICHE_NO_EXPORT QuicTraceVisitor : public QuicConnectionDebugVisitor {
18  public:
19   explicit QuicTraceVisitor(const QuicConnection* connection);
20 
21   void OnPacketSent(QuicPacketNumber packet_number,
22                     QuicPacketLength packet_length, bool has_crypto_handshake,
23                     TransmissionType transmission_type,
24                     EncryptionLevel encryption_level,
25                     const QuicFrames& retransmittable_frames,
26                     const QuicFrames& nonretransmittable_frames,
27                     QuicTime sent_time, uint32_t batch_id) override;
28 
29   void OnIncomingAck(QuicPacketNumber ack_packet_number,
30                      EncryptionLevel ack_decrypted_level,
31                      const QuicAckFrame& ack_frame, QuicTime ack_receive_time,
32                      QuicPacketNumber largest_observed, bool rtt_updated,
33                      QuicPacketNumber least_unacked_sent_packet) override;
34 
35   void OnPacketLoss(QuicPacketNumber lost_packet_number,
36                     EncryptionLevel encryption_level,
37                     TransmissionType transmission_type,
38                     QuicTime detection_time) override;
39 
40   void OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame,
41                            const QuicTime& receive_time) override;
42 
43   void OnSuccessfulVersionNegotiation(
44       const ParsedQuicVersion& version) override;
45 
46   void OnApplicationLimited() override;
47 
48   void OnAdjustNetworkParameters(QuicBandwidth bandwidth, QuicTime::Delta rtt,
49                                  QuicByteCount old_cwnd,
50                                  QuicByteCount new_cwnd) override;
51 
52   // Returns a mutable pointer to the trace.  The trace is owned by the
53   // visitor, but can be moved using Swap() method after the connection is
54   // finished.
trace()55   quic_trace::Trace* trace() { return &trace_; }
56 
57  private:
58   // Converts QuicTime into a microsecond delta w.r.t. the beginning of the
59   // connection.
60   uint64_t ConvertTimestampToRecordedFormat(QuicTime timestamp);
61   // Populates a quic_trace::Frame message from |frame|.
62   void PopulateFrameInfo(const QuicFrame& frame,
63                          quic_trace::Frame* frame_record);
64   // Populates a quic_trace::TransportState message from the associated
65   // connection.
66   void PopulateTransportState(quic_trace::TransportState* state);
67 
68   quic_trace::Trace trace_;
69   const QuicConnection* connection_;
70   const QuicTime start_time_;
71 };
72 
73 }  // namespace quic
74 
75 #endif  // QUICHE_QUIC_CORE_QUIC_TRACE_VISITOR_H_
76