OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/quic/quic_connection_logger.h" | 5 #include "net/quic/quic_connection_logger.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 int range_start = 0; | 762 int range_start = 0; |
763 for (int i = 1; i <= valid_bits_in_mask; ++i) { | 763 for (int i = 1; i <= valid_bits_in_mask; ++i) { |
764 bits_so_far += bit_mask_of_packets & 1; | 764 bits_so_far += bit_mask_of_packets & 1; |
765 bit_mask_of_packets >>= 1; | 765 bit_mask_of_packets >>= 1; |
766 DCHECK_LT(range_start + bits_so_far, kBoundingSampleInCumulativeHistogram); | 766 DCHECK_LT(range_start + bits_so_far, kBoundingSampleInCumulativeHistogram); |
767 histogram->Add(range_start + bits_so_far); | 767 histogram->Add(range_start + bits_so_far); |
768 range_start += i + 1; | 768 range_start += i + 1; |
769 } | 769 } |
770 } | 770 } |
771 | 771 |
| 772 float QuicConnectionLogger::ReceivedPacketLossRate() const { |
| 773 if (largest_received_packet_sequence_number_ <= num_packets_received_) |
| 774 return 0.0f; |
| 775 return (largest_received_packet_sequence_number_ - num_packets_received_) / |
| 776 largest_received_packet_sequence_number_; |
| 777 } |
| 778 |
772 void QuicConnectionLogger::RecordAggregatePacketLossRate() const { | 779 void QuicConnectionLogger::RecordAggregatePacketLossRate() const { |
773 // For short connections under 22 packets in length, we'll rely on the | 780 // For short connections under 22 packets in length, we'll rely on the |
774 // Net.QuicSession.21CumulativePacketsReceived_* histogram to indicate packet | 781 // Net.QuicSession.21CumulativePacketsReceived_* histogram to indicate packet |
775 // loss rates. This way we avoid tremendously anomalous contributions to our | 782 // loss rates. This way we avoid tremendously anomalous contributions to our |
776 // histogram. (e.g., if we only got 5 packets, but lost 1, we'd otherwise | 783 // histogram. (e.g., if we only got 5 packets, but lost 1, we'd otherwise |
777 // record a 20% loss in this histogram!). We may still get some strange data | 784 // record a 20% loss in this histogram!). We may still get some strange data |
778 // (1 loss in 22 is still high :-/). | 785 // (1 loss in 22 is still high :-/). |
779 if (largest_received_packet_sequence_number_ <= 21) | 786 if (largest_received_packet_sequence_number_ <= 21) |
780 return; | 787 return; |
781 | 788 |
782 QuicPacketSequenceNumber divisor = largest_received_packet_sequence_number_; | |
783 QuicPacketSequenceNumber numerator = divisor - num_packets_received_; | |
784 if (divisor < 100000) | |
785 numerator *= 1000; | |
786 else | |
787 divisor /= 1000; | |
788 string prefix("Net.QuicSession.PacketLossRate_"); | 789 string prefix("Net.QuicSession.PacketLossRate_"); |
789 base::HistogramBase* histogram = base::Histogram::FactoryGet( | 790 base::HistogramBase* histogram = base::Histogram::FactoryGet( |
790 prefix + connection_description_, 1, 1000, 75, | 791 prefix + connection_description_, 1, 1000, 75, |
791 base::HistogramBase::kUmaTargetedHistogramFlag); | 792 base::HistogramBase::kUmaTargetedHistogramFlag); |
792 histogram->Add(static_cast<base::HistogramBase::Sample>(numerator / divisor)); | 793 histogram->Add(static_cast<base::HistogramBase::Sample>( |
| 794 ReceivedPacketLossRate() * 1000)); |
793 } | 795 } |
794 | 796 |
795 void QuicConnectionLogger::RecordLossHistograms() const { | 797 void QuicConnectionLogger::RecordLossHistograms() const { |
796 if (largest_received_packet_sequence_number_ == 0) | 798 if (largest_received_packet_sequence_number_ == 0) |
797 return; // Connection was never used. | 799 return; // Connection was never used. |
798 RecordAggregatePacketLossRate(); | 800 RecordAggregatePacketLossRate(); |
799 | 801 |
800 base::HistogramBase* is_not_ack_histogram = | 802 base::HistogramBase* is_not_ack_histogram = |
801 GetPacketSequenceNumberHistogram("IsNotAck_"); | 803 GetPacketSequenceNumberHistogram("IsNotAck_"); |
802 base::HistogramBase* is_an_ack_histogram = | 804 base::HistogramBase* is_an_ack_histogram = |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 continue; | 860 continue; |
859 } | 861 } |
860 // Record some overlapping patterns, to get a better picture, since this is | 862 // Record some overlapping patterns, to get a better picture, since this is |
861 // not very expensive. | 863 // not very expensive. |
862 if (i % 3 == 0) | 864 if (i % 3 == 0) |
863 six_packet_histogram->Add(recent_6_mask); | 865 six_packet_histogram->Add(recent_6_mask); |
864 } | 866 } |
865 } | 867 } |
866 | 868 |
867 } // namespace net | 869 } // namespace net |
OLD | NEW |