Compute if a layer is clipped outside CalcDrawProps
[chromium-blink-merge.git] / net / quic / quic_connection_logger.h
blob6e81e217c9ead78174ff9ce506070c988410fbdd
1 // Copyright (c) 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.
5 #ifndef NET_QUIC_QUIC_CONNECTION_LOGGER_H_
6 #define NET_QUIC_QUIC_CONNECTION_LOGGER_H_
8 #include <bitset>
10 #include "net/base/ip_endpoint.h"
11 #include "net/base/network_change_notifier.h"
12 #include "net/log/net_log.h"
13 #include "net/quic/quic_connection.h"
14 #include "net/quic/quic_protocol.h"
15 #include "net/quic/quic_spdy_session.h"
17 namespace net {
18 namespace test {
19 class QuicConnectionLoggerPeer;
20 } // namespace test
22 class CryptoHandshakeMessage;
23 class CertVerifyResult;
25 // This class is a debug visitor of a QuicConnection which logs
26 // events to |net_log|.
27 class NET_EXPORT_PRIVATE QuicConnectionLogger
28 : public QuicConnectionDebugVisitor {
29 public:
30 QuicConnectionLogger(QuicSpdySession* session,
31 const char* const connection_description,
32 const BoundNetLog& net_log);
34 ~QuicConnectionLogger() override;
36 // QuicPacketGenerator::DebugDelegateInterface
37 void OnFrameAddedToPacket(const QuicFrame& frame) override;
39 // QuicConnectionDebugVisitorInterface
40 void OnPacketSent(const SerializedPacket& serialized_packet,
41 QuicPacketSequenceNumber original_sequence_number,
42 EncryptionLevel level,
43 TransmissionType transmission_type,
44 const QuicEncryptedPacket& packet,
45 QuicTime sent_time) override;
46 void OnPacketReceived(const IPEndPoint& self_address,
47 const IPEndPoint& peer_address,
48 const QuicEncryptedPacket& packet) override;
49 void OnIncorrectConnectionId(QuicConnectionId connection_id) override;
50 void OnUndecryptablePacket() override;
51 void OnDuplicatePacket(QuicPacketSequenceNumber sequence_number) override;
52 void OnProtocolVersionMismatch(QuicVersion version) override;
53 void OnPacketHeader(const QuicPacketHeader& header) override;
54 void OnStreamFrame(const QuicStreamFrame& frame) override;
55 void OnAckFrame(const QuicAckFrame& frame) override;
56 void OnStopWaitingFrame(const QuicStopWaitingFrame& frame) override;
57 void OnRstStreamFrame(const QuicRstStreamFrame& frame) override;
58 void OnConnectionCloseFrame(const QuicConnectionCloseFrame& frame) override;
59 void OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) override;
60 void OnBlockedFrame(const QuicBlockedFrame& frame) override;
61 void OnGoAwayFrame(const QuicGoAwayFrame& frame) override;
62 void OnPingFrame(const QuicPingFrame& frame) override;
63 void OnPublicResetPacket(const QuicPublicResetPacket& packet) override;
64 void OnVersionNegotiationPacket(
65 const QuicVersionNegotiationPacket& packet) override;
66 void OnRevivedPacket(const QuicPacketHeader& revived_header,
67 base::StringPiece payload) override;
68 void OnConnectionClosed(QuicErrorCode error, bool from_peer) override;
69 void OnSuccessfulVersionNegotiation(const QuicVersion& version) override;
71 void OnCryptoHandshakeMessageReceived(
72 const CryptoHandshakeMessage& message);
73 void OnCryptoHandshakeMessageSent(
74 const CryptoHandshakeMessage& message);
75 void UpdateReceivedFrameCounts(QuicStreamId stream_id,
76 int num_frames_received,
77 int num_duplicate_frames_received);
78 void OnCertificateVerified(const CertVerifyResult& result);
80 // Returns connection's overall packet loss rate in fraction.
81 float ReceivedPacketLossRate() const;
83 private:
84 friend class test::QuicConnectionLoggerPeer;
86 // Do a factory get for a histogram for recording data, about individual
87 // packet sequence numbers, that was gathered in the vectors
88 // received_packets_ and received_acks_. |statistic_name| identifies which
89 // element of data is recorded, and is used to form the histogram name.
90 base::HistogramBase* GetPacketSequenceNumberHistogram(
91 const char* statistic_name) const;
92 // Do a factory get for a histogram to record a 6-packet loss-sequence as a
93 // sample. The histogram will record the 64 distinct possible combinations.
94 // |which_6| is used to adjust the name of the histogram to distinguish the
95 // first 6 packets in a connection, vs. some later 6 packets.
96 base::HistogramBase* Get6PacketHistogram(const char* which_6) const;
97 // Do a factory get for a histogram to record cumulative stats across a 21
98 // packet sequence. |which_21| is used to adjust the name of the histogram
99 // to distinguish the first 21 packets' loss data, vs. some later 21 packet
100 // sequences' loss data.
101 base::HistogramBase* Get21CumulativeHistogram(const char* which_21) const;
102 // Add samples associated with a |bit_mask_of_packets| to the given histogram
103 // that was provided by Get21CumulativeHistogram(). The LSB of that mask
104 // corresponds to the oldest packet sequence number in the series of packets,
105 // and the bit in the 2^20 position corresponds to the most recently received
106 // packet. Of the maximum of 21 bits that are valid (correspond to packets),
107 // only the most significant |valid_bits_in_mask| are processed.
108 // A bit value of 0 indicates that a packet was never received, and a 1
109 // indicates the packet was received.
110 static void AddTo21CumulativeHistogram(base::HistogramBase* histogram,
111 int bit_mask_of_packets,
112 int valid_bits_in_mask);
113 // For connections longer than 21 received packets, this call will calculate
114 // the overall packet loss rate, and record it into a histogram.
115 void RecordAggregatePacketLossRate() const;
116 // At destruction time, this records results of |pacaket_received_| into
117 // histograms for specific connection types.
118 void RecordLossHistograms() const;
120 BoundNetLog net_log_;
121 QuicSpdySession* session_; // Unowned.
122 // The last packet sequence number received.
123 QuicPacketSequenceNumber last_received_packet_sequence_number_;
124 // The size of the most recently received packet.
125 size_t last_received_packet_size_;
126 // The size of the previously received packet.
127 size_t previous_received_packet_size_;
128 // The largest packet sequence number received. In the case where a packet is
129 // received late (out of order), this value will not be updated.
130 QuicPacketSequenceNumber largest_received_packet_sequence_number_;
131 // The largest packet sequence number which the peer has failed to
132 // receive, according to the missing packet set in their ack frames.
133 QuicPacketSequenceNumber largest_received_missing_packet_sequence_number_;
134 // Number of times that the current received packet sequence number is
135 // smaller than the last received packet sequence number.
136 size_t num_out_of_order_received_packets_;
137 // Number of times that the current received packet sequence number is
138 // smaller than the last received packet sequence number and where the
139 // size of the current packet is larger than the size of the previous
140 // packet.
141 size_t num_out_of_order_large_received_packets_;
142 // The number of times that OnPacketHeader was called.
143 // If the network replicates packets, then this number may be slightly
144 // different from the real number of distinct packets received.
145 QuicPacketCount num_packets_received_;
146 // Number of times a truncated ACK frame was sent.
147 size_t num_truncated_acks_sent_;
148 // Number of times a truncated ACK frame was received.
149 size_t num_truncated_acks_received_;
150 // The kCADR value provided by the server in ServerHello.
151 IPEndPoint local_address_from_shlo_;
152 // The first local address from which a packet was received.
153 IPEndPoint local_address_from_self_;
154 // Count of the number of frames received.
155 int num_frames_received_;
156 // Count of the number of duplicate frames received.
157 int num_duplicate_frames_received_;
158 // Count of the number of packets received with incorrect connection IDs.
159 int num_incorrect_connection_ids_;
160 // Count of the number of undecryptable packets received.
161 int num_undecryptable_packets_;
162 // Count of the number of duplicate packets received.
163 int num_duplicate_packets_;
164 // Count of the number of BLOCKED frames received.
165 int num_blocked_frames_received_;
166 // Count of the number of BLOCKED frames sent.
167 int num_blocked_frames_sent_;
168 // Vector of inital packets status' indexed by packet sequence numbers, where
169 // false means never received. Zero is not a valid packet sequence number, so
170 // that offset is never used, and we'll track 150 packets.
171 std::bitset<151> received_packets_;
172 // Vector to indicate which of the initial 150 received packets turned out to
173 // contain solo ACK frames. An element is true iff an ACK frame was in the
174 // corresponding packet, and there was very little else.
175 std::bitset<151> received_acks_;
176 // The available type of connection (WiFi, 3G, etc.) when connection was first
177 // used.
178 const char* const connection_description_;
180 DISALLOW_COPY_AND_ASSIGN(QuicConnectionLogger);
183 } // namespace net
185 #endif // NET_QUIC_QUIC_CONNECTION_LOGGER_H_