| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/net/network_stats.h" | 5 #include "chrome/browser/net/network_stats.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 static const uint32 kPacketNumberLength = 10; | 77 static const uint32 kPacketNumberLength = 10; |
| 78 | 78 |
| 79 // This specifies the starting position of the <encoded_payload> in | 79 // This specifies the starting position of the <encoded_payload> in |
| 80 // "echo response". | 80 // "echo response". |
| 81 static const uint32 kEncodedPayloadStart = kKeyEnd; | 81 static const uint32 kEncodedPayloadStart = kKeyEnd; |
| 82 | 82 |
| 83 // HistogramPortSelector and kPorts should be kept in sync. Port 999999 is | 83 // HistogramPortSelector and kPorts should be kept in sync. Port 999999 is |
| 84 // used by the unit tests. | 84 // used by the unit tests. |
| 85 static const int32 kPorts[] = {6121, 999999}; | 85 static const int32 kPorts[] = {6121, 999999}; |
| 86 | 86 |
| 87 // Maximum number of packets that can be sent to the server for packet loss | 87 // Number of packets that are recorded in a packet-correlation histogram, which |
| 88 // correlation test. | 88 // shows exactly what sequence of packets were responded to. We use this to |
| 89 static const uint32 kMaximumCorrelationPackets = 6; | 89 // deduce specific packet loss correlation. |
| 90 static const uint32 kCorrelatedLossPacketCount = 6; |
| 90 | 91 |
| 91 // Maximum number of packets that can be sent to the server. | 92 // Maximum number of packets that can be sent to the server. |
| 92 static const uint32 kMaximumSequentialPackets = 21; | 93 static const uint32 kMaximumSequentialPackets = 21; |
| 93 | 94 |
| 94 // This specifies the maximum message (payload) size. | 95 // This specifies the maximum message (payload) size. |
| 95 static const uint32 kMaxMessage = kMaximumSequentialPackets * 2048; | 96 static const uint32 kMaxMessage = kMaximumSequentialPackets * 2048; |
| 96 | 97 |
| 97 // NetworkStats methods and members. | 98 // NetworkStats methods and members. |
| 98 NetworkStats::NetworkStats() | 99 NetworkStats::NetworkStats() |
| 99 : read_buffer_(NULL), | 100 : read_buffer_(NULL), |
| (...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 if (!finished_callback_.is_null()) { | 676 if (!finished_callback_.is_null()) { |
| 676 net::CompletionCallback callback = finished_callback_; | 677 net::CompletionCallback callback = finished_callback_; |
| 677 finished_callback_.Reset(); | 678 finished_callback_.Reset(); |
| 678 callback.Run(result); | 679 callback.Run(result); |
| 679 } | 680 } |
| 680 } | 681 } |
| 681 | 682 |
| 682 void NetworkStats::RecordHistograms(const ProtocolValue& protocol, | 683 void NetworkStats::RecordHistograms(const ProtocolValue& protocol, |
| 683 const Status& status, | 684 const Status& status, |
| 684 int result) { | 685 int result) { |
| 685 if (packets_to_send_ != kMaximumSequentialPackets && | 686 if (packets_to_send_ != kMaximumSequentialPackets) |
| 686 packets_to_send_ != kMaximumCorrelationPackets) { | |
| 687 return; | 687 return; |
| 688 } | |
| 689 | 688 |
| 690 std::string load_size_string = base::StringPrintf("%dB", load_size_); | 689 std::string load_size_string = base::StringPrintf("%dB", load_size_); |
| 691 | 690 |
| 692 if (packets_to_send_ == kMaximumCorrelationPackets) { | 691 RecordPacketLossSeriesHistograms(protocol, load_size_string, status, result); |
| 693 RecordPacketLossSeriesHistograms( | |
| 694 protocol, load_size_string, status, result); | |
| 695 return; | |
| 696 } | |
| 697 | 692 |
| 698 for (uint32 i = 0; i < 3; i++) | 693 for (uint32 i = 0; i < 3; i++) |
| 699 RecordRTTHistograms(protocol, load_size_string, i); | 694 RecordRTTHistograms(protocol, load_size_string, i); |
| 700 | 695 |
| 701 RecordRTTHistograms(protocol, load_size_string, 9); | 696 RecordRTTHistograms(protocol, load_size_string, 9); |
| 702 RecordRTTHistograms(protocol, load_size_string, 19); | 697 RecordRTTHistograms(protocol, load_size_string, 19); |
| 703 | 698 |
| 704 RecordAcksReceivedHistograms(load_size_string); | 699 RecordAcksReceivedHistograms(load_size_string); |
| 705 } | 700 } |
| 706 | 701 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 771 base::Histogram::kUmaTargetedHistogramFlag); | 766 base::Histogram::kUmaTargetedHistogramFlag); |
| 772 acks_received_count_histogram->Add(count); | 767 acks_received_count_histogram->Add(count); |
| 773 } | 768 } |
| 774 } | 769 } |
| 775 | 770 |
| 776 void NetworkStats::RecordPacketLossSeriesHistograms( | 771 void NetworkStats::RecordPacketLossSeriesHistograms( |
| 777 const ProtocolValue& protocol, | 772 const ProtocolValue& protocol, |
| 778 const std::string& load_size_string, | 773 const std::string& load_size_string, |
| 779 const Status& status, | 774 const Status& status, |
| 780 int result) { | 775 int result) { |
| 781 DCHECK_EQ(packets_to_send_, kMaximumCorrelationPackets); | 776 DCHECK_GT(packets_to_send_, kCorrelatedLossPacketCount); |
| 782 | |
| 783 const char* test_name = TestName(); | 777 const char* test_name = TestName(); |
| 784 | 778 |
| 785 // Build "NetConnectivity3.Send6.SeriesAcked.<port>.<load_size>" histogram | 779 // Build "NetConnectivity3.Send6.SeriesAcked.<port>.<load_size>" histogram |
| 786 // name. Total number of histograms are 5*2. | 780 // name. Total number of histograms are 5*2. |
| 787 std::string series_acked_histogram_name = base::StringPrintf( | 781 std::string series_acked_histogram_name = base::StringPrintf( |
| 788 "NetConnectivity3.%s.Send6.SeriesAcked.%d.%s", | 782 "NetConnectivity3.%s.Send6.SeriesAcked.%d.%s", |
| 789 test_name, | 783 test_name, |
| 790 kPorts[histogram_port_], | 784 kPorts[histogram_port_], |
| 791 load_size_string.c_str()); | 785 load_size_string.c_str()); |
| 792 // Build "NetConnectivity3.Send6.PacketsSent.<port>.<load_size>" histogram | |
| 793 // name. Total number of histograms are 5*2. | |
| 794 std::string packets_sent_histogram_name = base::StringPrintf( | |
| 795 "NetConnectivity3.%s.Send6.PacketsSent.%d.%s", | |
| 796 test_name, | |
| 797 kPorts[histogram_port_], | |
| 798 load_size_string.c_str()); | |
| 799 | 786 |
| 787 uint32 correlated_packet_mask = |
| 788 ((1 << kCorrelatedLossPacketCount) - 1) & packets_received_mask_; |
| 789 |
| 800 // If we are running without a proxy, we'll generate 2 distinct histograms in | 790 // If we are running without a proxy, we'll generate 2 distinct histograms in |
| 801 // each case, one will have the ".NoProxy" suffix. | 791 // each case, one will have the ".NoProxy" suffix. |
| 802 size_t histogram_count = has_proxy_server_ ? 1 : 2; | 792 size_t histogram_count = has_proxy_server_ ? 1 : 2; |
| 803 for (size_t i = 0; i < histogram_count; i++) { | 793 for (size_t i = 0; i < histogram_count; i++) { |
| 804 // For packet loss test, just record packet loss data. | 794 // For packet loss test, just record packet loss data. |
| 805 base::Histogram* series_acked_histogram = base::LinearHistogram::FactoryGet( | 795 base::Histogram* series_acked_histogram = base::LinearHistogram::FactoryGet( |
| 806 series_acked_histogram_name, | 796 series_acked_histogram_name, |
| 807 1, | 797 1, |
| 808 2 << kMaximumCorrelationPackets, | 798 1 << kCorrelatedLossPacketCount, |
| 809 (2 << kMaximumCorrelationPackets) + 1, | 799 (1 << kCorrelatedLossPacketCount) + 1, |
| 810 base::Histogram::kUmaTargetedHistogramFlag); | 800 base::Histogram::kUmaTargetedHistogramFlag); |
| 811 series_acked_histogram->Add(packets_received_mask_); | 801 series_acked_histogram->Add(correlated_packet_mask); |
| 812 series_acked_histogram_name.append(".NoProxy"); | 802 series_acked_histogram_name.append(".NoProxy"); |
| 813 | |
| 814 base::Histogram* packets_sent_histogram = | |
| 815 base::Histogram::FactoryGet( | |
| 816 packets_sent_histogram_name, | |
| 817 1, kMaximumCorrelationPackets, kMaximumCorrelationPackets + 1, | |
| 818 base::Histogram::kUmaTargetedHistogramFlag); | |
| 819 packets_sent_histogram->Add(packets_sent_); | |
| 820 packets_sent_histogram_name.append(".NoProxy"); | |
| 821 } | 803 } |
| 822 } | 804 } |
| 823 | 805 |
| 824 void NetworkStats::RecordRTTHistograms(const ProtocolValue& protocol, | 806 void NetworkStats::RecordRTTHistograms(const ProtocolValue& protocol, |
| 825 const std::string& load_size_string, | 807 const std::string& load_size_string, |
| 826 uint32 index) { | 808 uint32 index) { |
| 827 DCHECK_GE(index, 0u); | 809 DCHECK_GE(index, 0u); |
| 828 DCHECK_LT(index, packet_status_.size()); | 810 DCHECK_LT(index, packet_status_.size()); |
| 829 | 811 |
| 830 const char* test_name = TestName(); | 812 const char* test_name = TestName(); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1000 ProxyDetector* proxy_client = new ProxyDetector( | 982 ProxyDetector* proxy_client = new ProxyDetector( |
| 1001 proxy_service, server_address, callback); | 983 proxy_service, server_address, callback); |
| 1002 proxy_client->StartResolveProxy(); | 984 proxy_client->StartResolveProxy(); |
| 1003 } | 985 } |
| 1004 | 986 |
| 1005 // static | 987 // static |
| 1006 void StartNetworkStatsTest(net::HostResolver* host_resolver, | 988 void StartNetworkStatsTest(net::HostResolver* host_resolver, |
| 1007 const net::HostPortPair& server_address, | 989 const net::HostPortPair& server_address, |
| 1008 NetworkStats::HistogramPortSelector histogram_port, | 990 NetworkStats::HistogramPortSelector histogram_port, |
| 1009 bool has_proxy_server) { | 991 bool has_proxy_server) { |
| 1010 int experiment_to_run = base::RandInt(1, 4); | 992 int experiment_to_run = base::RandInt(1, 3); |
| 1011 switch (experiment_to_run) { | 993 switch (experiment_to_run) { |
| 1012 case 1: | 994 case 1: |
| 1013 { | 995 { |
| 1014 NetworkStats* udp_stats_client = new NetworkStats(); | 996 NetworkStats* udp_stats_client = new NetworkStats(); |
| 1015 udp_stats_client->Start( | 997 udp_stats_client->Start( |
| 1016 host_resolver, server_address, histogram_port, has_proxy_server, | 998 host_resolver, server_address, histogram_port, has_proxy_server, |
| 1017 kLargeTestBytesToSend, kMaximumCorrelationPackets, | 999 kSmallTestBytesToSend, kMaximumSequentialPackets, |
| 1018 net::CompletionCallback()); | 1000 net::CompletionCallback()); |
| 1019 } | 1001 } |
| 1020 break; | 1002 break; |
| 1021 case 2: | 1003 case 2: |
| 1022 { | 1004 { |
| 1023 NetworkStats* udp_stats_client = new NetworkStats(); | 1005 NetworkStats* udp_stats_client = new NetworkStats(); |
| 1024 udp_stats_client->Start( | 1006 udp_stats_client->Start( |
| 1025 host_resolver, server_address, histogram_port, has_proxy_server, | 1007 host_resolver, server_address, histogram_port, has_proxy_server, |
| 1026 kSmallTestBytesToSend, kMaximumSequentialPackets, | 1008 kMediumTestBytesToSend, kMaximumSequentialPackets, |
| 1027 net::CompletionCallback()); | 1009 net::CompletionCallback()); |
| 1028 } | 1010 } |
| 1029 break; | 1011 break; |
| 1030 case 3: | 1012 case 3: |
| 1031 { | 1013 { |
| 1032 NetworkStats* udp_stats_client = new NetworkStats(); | 1014 NetworkStats* udp_stats_client = new NetworkStats(); |
| 1033 udp_stats_client->Start( | 1015 udp_stats_client->Start( |
| 1034 host_resolver, server_address, histogram_port, has_proxy_server, | 1016 host_resolver, server_address, histogram_port, has_proxy_server, |
| 1035 kMediumTestBytesToSend, kMaximumSequentialPackets, | |
| 1036 net::CompletionCallback()); | |
| 1037 } | |
| 1038 break; | |
| 1039 case 4: | |
| 1040 { | |
| 1041 NetworkStats* udp_stats_client = new NetworkStats(); | |
| 1042 udp_stats_client->Start( | |
| 1043 host_resolver, server_address, histogram_port, has_proxy_server, | |
| 1044 kLargeTestBytesToSend, kMaximumSequentialPackets, | 1017 kLargeTestBytesToSend, kMaximumSequentialPackets, |
| 1045 net::CompletionCallback()); | 1018 net::CompletionCallback()); |
| 1046 } | 1019 } |
| 1047 break; | 1020 break; |
| 1048 } | 1021 } |
| 1049 } | 1022 } |
| 1050 | 1023 |
| 1051 } // namespace chrome_browser_net | 1024 } // namespace chrome_browser_net |
| OLD | NEW |