| 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 int QuicConnectionLogger::PacketLossRate() const { |
| 773 if (largest_received_packet_sequence_number_ == 0) |
| 774 return 100; // Never received a packet from server, very lossy connection? |
| 775 QuicPacketSequenceNumber divisor = largest_received_packet_sequence_number_; |
| 776 QuicPacketSequenceNumber numerator = divisor - num_packets_received_; |
| 777 if (divisor < 100000) |
| 778 numerator *= 1000; |
| 779 else |
| 780 divisor /= 1000; |
| 781 return numerator / divisor; |
| 782 } |
| 783 |
| 772 void QuicConnectionLogger::RecordAggregatePacketLossRate() const { | 784 void QuicConnectionLogger::RecordAggregatePacketLossRate() const { |
| 773 // For short connections under 22 packets in length, we'll rely on the | 785 // For short connections under 22 packets in length, we'll rely on the |
| 774 // Net.QuicSession.21CumulativePacketsReceived_* histogram to indicate packet | 786 // Net.QuicSession.21CumulativePacketsReceived_* histogram to indicate packet |
| 775 // loss rates. This way we avoid tremendously anomalous contributions to our | 787 // 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 | 788 // 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 | 789 // record a 20% loss in this histogram!). We may still get some strange data |
| 778 // (1 loss in 22 is still high :-/). | 790 // (1 loss in 22 is still high :-/). |
| 779 if (largest_received_packet_sequence_number_ <= 21) | 791 if (largest_received_packet_sequence_number_ <= 21) |
| 780 return; | 792 return; |
| 781 | 793 |
| 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_"); | 794 string prefix("Net.QuicSession.PacketLossRate_"); |
| 789 base::HistogramBase* histogram = base::Histogram::FactoryGet( | 795 base::HistogramBase* histogram = base::Histogram::FactoryGet( |
| 790 prefix + connection_description_, 1, 1000, 75, | 796 prefix + connection_description_, 1, 1000, 75, |
| 791 base::HistogramBase::kUmaTargetedHistogramFlag); | 797 base::HistogramBase::kUmaTargetedHistogramFlag); |
| 792 histogram->Add(static_cast<base::HistogramBase::Sample>(numerator / divisor)); | 798 histogram->Add(static_cast<base::HistogramBase::Sample>(PacketLossRate())); |
| 793 } | 799 } |
| 794 | 800 |
| 795 void QuicConnectionLogger::RecordLossHistograms() const { | 801 void QuicConnectionLogger::RecordLossHistograms() const { |
| 796 if (largest_received_packet_sequence_number_ == 0) | 802 if (largest_received_packet_sequence_number_ == 0) |
| 797 return; // Connection was never used. | 803 return; // Connection was never used. |
| 798 RecordAggregatePacketLossRate(); | 804 RecordAggregatePacketLossRate(); |
| 799 | 805 |
| 800 base::HistogramBase* is_not_ack_histogram = | 806 base::HistogramBase* is_not_ack_histogram = |
| 801 GetPacketSequenceNumberHistogram("IsNotAck_"); | 807 GetPacketSequenceNumberHistogram("IsNotAck_"); |
| 802 base::HistogramBase* is_an_ack_histogram = | 808 base::HistogramBase* is_an_ack_histogram = |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 858 continue; | 864 continue; |
| 859 } | 865 } |
| 860 // Record some overlapping patterns, to get a better picture, since this is | 866 // Record some overlapping patterns, to get a better picture, since this is |
| 861 // not very expensive. | 867 // not very expensive. |
| 862 if (i % 3 == 0) | 868 if (i % 3 == 0) |
| 863 six_packet_histogram->Add(recent_6_mask); | 869 six_packet_histogram->Add(recent_6_mask); |
| 864 } | 870 } |
| 865 } | 871 } |
| 866 | 872 |
| 867 } // namespace net | 873 } // namespace net |
| OLD | NEW |