Chromium Code Reviews| 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" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
| 13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
| 14 #include "base/threading/platform_thread.h" | 14 #include "base/threading/platform_thread.h" |
| 15 #include "base/time.h" | 15 #include "base/time.h" |
| 16 #include "base/tuple.h" | 16 #include "base/tuple.h" |
| 17 #include "chrome/common/chrome_version_info.h" | 17 #include "chrome/common/chrome_version_info.h" |
| 18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 19 #include "googleurl/src/gurl.h" | |
| 19 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
| 20 #include "net/base/net_util.h" | 21 #include "net/base/net_util.h" |
| 21 #include "net/base/network_change_notifier.h" | 22 #include "net/base/network_change_notifier.h" |
| 22 #include "net/base/sys_addrinfo.h" | 23 #include "net/base/sys_addrinfo.h" |
| 23 #include "net/base/test_completion_callback.h" | 24 #include "net/base/test_completion_callback.h" |
| 25 #include "net/proxy/proxy_service.h" | |
| 24 #include "net/socket/tcp_client_socket.h" | 26 #include "net/socket/tcp_client_socket.h" |
| 25 #include "net/udp/udp_client_socket.h" | 27 #include "net/udp/udp_client_socket.h" |
| 26 #include "net/udp/udp_server_socket.h" | 28 #include "net/udp/udp_server_socket.h" |
| 27 | 29 |
| 28 using content::BrowserThread; | 30 using content::BrowserThread; |
| 29 | 31 |
| 30 namespace chrome_browser_net { | 32 namespace chrome_browser_net { |
| 31 | 33 |
| 32 // This specifies the number of bytes to be sent to the TCP/UDP servers as part | 34 // This specifies the number of bytes to be sent to the TCP/UDP servers as part |
| 33 // of small packet size test. | 35 // of small packet size test. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 | 89 |
| 88 // Maximum number of packets that can be sent to the server for packet loss | 90 // Maximum number of packets that can be sent to the server for packet loss |
| 89 // testing. | 91 // testing. |
| 90 static const uint32 kMaximumPackets = 4; | 92 static const uint32 kMaximumPackets = 4; |
| 91 | 93 |
| 92 // NetworkStats methods and members. | 94 // NetworkStats methods and members. |
| 93 NetworkStats::NetworkStats() | 95 NetworkStats::NetworkStats() |
| 94 : load_size_(0), | 96 : load_size_(0), |
| 95 bytes_to_read_(0), | 97 bytes_to_read_(0), |
| 96 bytes_to_send_(0), | 98 bytes_to_send_(0), |
| 99 has_proxy_server_(false), | |
| 97 packets_to_send_(0), | 100 packets_to_send_(0), |
| 98 packets_sent_(0), | 101 packets_sent_(0), |
| 99 base_packet_number_(0), | 102 base_packet_number_(0), |
| 100 packets_received_mask_(0), | 103 packets_received_mask_(0), |
| 101 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 104 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 102 } | 105 } |
| 103 | 106 |
| 104 NetworkStats::~NetworkStats() { | 107 NetworkStats::~NetworkStats() { |
| 105 socket_.reset(); | 108 socket_.reset(); |
| 106 } | 109 } |
| 107 | 110 |
| 108 bool NetworkStats::Start(net::HostResolver* host_resolver, | 111 bool NetworkStats::Start(net::HostResolver* host_resolver, |
| 109 const net::HostPortPair& server_host_port_pair, | 112 const net::HostPortPair& server_host_port_pair, |
| 110 HistogramPortSelector histogram_port, | 113 HistogramPortSelector histogram_port, |
| 114 bool has_proxy_server, | |
| 111 uint32 bytes_to_send, | 115 uint32 bytes_to_send, |
| 112 uint32 packets_to_send, | 116 uint32 packets_to_send, |
| 113 const net::CompletionCallback& finished_callback) { | 117 const net::CompletionCallback& finished_callback) { |
| 114 DCHECK(bytes_to_send); // We should have data to send. | 118 DCHECK(bytes_to_send); // We should have data to send. |
| 115 DCHECK_LE(packets_to_send, kMaximumPackets); | 119 DCHECK_LE(packets_to_send, kMaximumPackets); |
| 116 | 120 |
| 117 Initialize(bytes_to_send, histogram_port, packets_to_send, finished_callback); | 121 Initialize(bytes_to_send, |
| 122 histogram_port, | |
| 123 has_proxy_server, | |
| 124 packets_to_send, | |
| 125 finished_callback); | |
| 118 | 126 |
| 119 net::HostResolver::RequestInfo request(server_host_port_pair); | 127 net::HostResolver::RequestInfo request(server_host_port_pair); |
| 120 int rv = host_resolver->Resolve( | 128 int rv = host_resolver->Resolve( |
| 121 request, &addresses_, | 129 request, &addresses_, |
| 122 base::Bind(&NetworkStats::OnResolveComplete, | 130 base::Bind(&NetworkStats::OnResolveComplete, |
| 123 base::Unretained(this)), | 131 base::Unretained(this)), |
| 124 NULL, net::BoundNetLog()); | 132 NULL, net::BoundNetLog()); |
| 125 if (rv == net::ERR_IO_PENDING) | 133 if (rv == net::ERR_IO_PENDING) |
| 126 return true; | 134 return true; |
| 127 return DoConnect(rv); | 135 return DoConnect(rv); |
| 128 } | 136 } |
| 129 | 137 |
| 130 void NetworkStats::Initialize( | 138 void NetworkStats::Initialize( |
| 131 uint32 bytes_to_send, | 139 uint32 bytes_to_send, |
| 132 HistogramPortSelector histogram_port, | 140 HistogramPortSelector histogram_port, |
| 141 bool has_proxy_server, | |
| 133 uint32 packets_to_send, | 142 uint32 packets_to_send, |
| 134 const net::CompletionCallback& finished_callback) { | 143 const net::CompletionCallback& finished_callback) { |
| 135 DCHECK(bytes_to_send); // We should have data to send. | 144 DCHECK(bytes_to_send); // We should have data to send. |
| 136 DCHECK(packets_to_send); // We should send at least 1 packet. | 145 DCHECK(packets_to_send); // We should send at least 1 packet. |
| 137 DCHECK_LE(bytes_to_send, kLargeTestBytesToSend); | 146 DCHECK_LE(bytes_to_send, kLargeTestBytesToSend); |
| 138 | 147 |
| 139 load_size_ = bytes_to_send; | 148 load_size_ = bytes_to_send; |
| 140 packets_to_send_ = packets_to_send; | 149 packets_to_send_ = packets_to_send; |
| 141 | 150 |
| 142 histogram_port_ = histogram_port; | 151 histogram_port_ = histogram_port; |
| 152 has_proxy_server_ = has_proxy_server; | |
| 143 finished_callback_ = finished_callback; | 153 finished_callback_ = finished_callback; |
| 144 } | 154 } |
| 145 | 155 |
| 146 uint32 SendingPacketSize(uint32 load_size) { | 156 uint32 SendingPacketSize(uint32 load_size) { |
| 147 return kVersionLength + kChecksumLength + kPayloadSizeLength + load_size; | 157 return kVersionLength + kChecksumLength + kPayloadSizeLength + load_size; |
| 148 } | 158 } |
| 149 | 159 |
| 150 uint32 ReceivingPacketSize(uint32 load_size) { | 160 uint32 ReceivingPacketSize(uint32 load_size) { |
| 151 return kVersionLength + kChecksumLength + kPayloadSizeLength + kKeyLength + | 161 return kVersionLength + kChecksumLength + kPayloadSizeLength + kKeyLength + |
| 152 load_size; | 162 load_size; |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 491 if (!stream_.VerifyBytes(&decoded_data[kPacketNumberLength], | 501 if (!stream_.VerifyBytes(&decoded_data[kPacketNumberLength], |
| 492 message_length - kPacketNumberLength)) { | 502 message_length - kPacketNumberLength)) { |
| 493 return PATTERN_CHANGED; | 503 return PATTERN_CHANGED; |
| 494 } | 504 } |
| 495 | 505 |
| 496 packets_received_mask_ |= 1 << (packet_index - 1); | 506 packets_received_mask_ |= 1 << (packet_index - 1); |
| 497 return SUCCESS; | 507 return SUCCESS; |
| 498 } | 508 } |
| 499 | 509 |
| 500 // static | 510 // static |
| 501 void NetworkStats::GetHistogramNames(const ProtocolValue& protocol, | 511 void NetworkStats::GetHistogramNames( |
| 502 HistogramPortSelector port, | 512 const ProtocolValue& protocol, |
| 503 uint32 load_size, | 513 HistogramPortSelector histogram_port, |
| 504 int result, | 514 bool has_proxy_server, |
| 505 std::string* rtt_histogram_name, | 515 uint32 load_size, |
| 506 std::string* status_histogram_name, | 516 int result, |
| 507 std::string* packet_loss_histogram_name) { | 517 std::string* rtt_histogram_name, |
| 508 CHECK_GE(port, PORT_53); | 518 std::string* rtt_no_proxy_histogram_name, |
| 509 CHECK_LE(port, HISTOGRAM_PORT_MAX); | 519 std::string* status_histogram_name, |
| 520 std::string* status_no_proxy_histogram_name, | |
| 521 std::string* packet_loss_histogram_name, | |
| 522 std::string* packet_loss_no_proxy_histogram_name) { | |
|
jar (doing other things)
2012/05/03 16:41:34
If you put ".NoProxy" at the end of the name, cons
ramant (doing other things)
2012/05/04 03:53:11
Done.
| |
| 523 CHECK_GE(histogram_port, PORT_53); | |
| 524 CHECK_LE(histogram_port, HISTOGRAM_PORT_MAX); | |
| 510 | 525 |
| 511 // Build <protocol> string. | 526 // Build <protocol> string. |
| 512 const char* kTcpString = "TCP"; | 527 const char* kTcpString = "TCP"; |
| 513 const char* kUdpString = "UDP"; | 528 const char* kUdpString = "UDP"; |
| 514 const char* protocol_string; | 529 const char* protocol_string; |
| 515 if (protocol == PROTOCOL_TCP) | 530 if (protocol == PROTOCOL_TCP) |
| 516 protocol_string = kTcpString; | 531 protocol_string = kTcpString; |
| 517 else | 532 else |
| 518 protocol_string = kUdpString; | 533 protocol_string = kUdpString; |
| 519 | 534 |
| 535 int32 port = kPorts[histogram_port]; | |
| 536 | |
| 520 // Build <load_size> string. | 537 // Build <load_size> string. |
| 521 const char* kSmallLoadString = "100B"; | 538 const char* kSmallLoadString = "100B"; |
| 522 const char* kLargeLoadString = "1K"; | 539 const char* kLargeLoadString = "1K"; |
| 523 const char* load_size_string; | 540 const char* load_size_string; |
| 524 if (load_size == kSmallTestBytesToSend) | 541 if (load_size == kSmallTestBytesToSend) |
| 525 load_size_string = kSmallLoadString; | 542 load_size_string = kSmallLoadString; |
| 526 else | 543 else |
| 527 load_size_string = kLargeLoadString; | 544 load_size_string = kLargeLoadString; |
| 528 | 545 |
| 529 // Build "NetConnectivity.<protocol>.Success.<port>.<load_size>.RTT" | 546 // Build "NetConnectivity.<protocol>.Success.<port>.<load_size>.RTT" |
| 530 // histogram name. Total number of histograms are 2*5*2. | 547 // and "NetConnectivity.<protocol>.NoProxy.Success.<port>.<load_size>.RTT" |
| 531 if (result == net::OK) { | 548 // histogram names. Total number of histograms are 2*5*2*2. |
| 549 if (result != net::OK) { | |
| 550 rtt_histogram_name->clear(); | |
| 551 } else { | |
| 532 *rtt_histogram_name = base::StringPrintf( | 552 *rtt_histogram_name = base::StringPrintf( |
| 533 "NetConnectivity.%s.Success.%d.%s.RTT", | 553 "NetConnectivity.%s.Success.%d.%s.RTT", |
| 534 protocol_string, | 554 protocol_string, |
| 535 kPorts[port], | 555 port, |
| 556 load_size_string); | |
| 557 if (has_proxy_server) { | |
| 558 rtt_no_proxy_histogram_name->clear(); | |
| 559 } else { | |
| 560 *rtt_no_proxy_histogram_name = base::StringPrintf( | |
| 561 "NetConnectivity.%s.NoProxy.Success.%d.%s.RTT", | |
| 562 protocol_string, | |
| 563 port, | |
| 564 load_size_string); | |
| 565 } | |
| 566 } | |
| 567 | |
| 568 // Build "NetConnectivity.<protocol>.Status.<port>.<load_size>" and | |
| 569 // "NetConnectivity.<protocol>.NoProxy.Status.<port>.<load_size>" histogram | |
| 570 // name. Total number of histograms are 2*2*5*2. | |
| 571 *status_histogram_name = base::StringPrintf( | |
| 572 "NetConnectivity.%s.Status.%d.%s", | |
| 573 protocol_string, | |
| 574 port, | |
| 575 load_size_string); | |
| 576 if (has_proxy_server) { | |
| 577 status_no_proxy_histogram_name->clear(); | |
| 578 } else { | |
| 579 *status_no_proxy_histogram_name = base::StringPrintf( | |
| 580 "NetConnectivity.%s.NoProxy.Status.%d.%s", | |
| 581 protocol_string, | |
| 582 port, | |
| 536 load_size_string); | 583 load_size_string); |
| 537 } | 584 } |
| 538 | 585 |
| 539 // Build "NetConnectivity.<protocol>.Status.<port>.<load_size>" histogram | |
| 540 // name. Total number of histograms are 2*5*2. | |
| 541 *status_histogram_name = base::StringPrintf( | |
| 542 "NetConnectivity.%s.Status.%d.%s", | |
| 543 protocol_string, | |
| 544 kPorts[port], | |
| 545 load_size_string); | |
| 546 | |
| 547 // Build "NetConnectivity.<protocol>.PacketLoss.<port>.<load_size>" histogram | 586 // Build "NetConnectivity.<protocol>.PacketLoss.<port>.<load_size>" histogram |
| 548 // name. Total number of histograms are 5 (because we do this test for UDP | 587 // name. Total number of histograms are 5 (because we do this test for UDP |
| 549 // only). | 588 // only). |
| 550 *packet_loss_histogram_name = base::StringPrintf( | 589 *packet_loss_histogram_name = base::StringPrintf( |
| 551 "NetConnectivity.%s.PacketLoss.%d.%s", | 590 "NetConnectivity.%s.PacketLoss.%d.%s", |
| 552 protocol_string, | 591 protocol_string, |
| 553 kPorts[port], | 592 port, |
| 554 load_size_string); | 593 load_size_string); |
| 594 if (has_proxy_server) { | |
| 595 packet_loss_no_proxy_histogram_name->clear(); | |
| 596 } else { | |
| 597 *packet_loss_no_proxy_histogram_name = base::StringPrintf( | |
| 598 "NetConnectivity.%s.NoProxy.PacketLoss.%d.%s", | |
| 599 protocol_string, | |
| 600 port, | |
| 601 load_size_string); | |
| 602 } | |
| 555 } | 603 } |
| 556 | 604 |
| 557 void NetworkStats::RecordHistograms(const ProtocolValue& protocol, | 605 void NetworkStats::RecordHistograms(const ProtocolValue& protocol, |
| 558 const Status& status, | 606 const Status& status, |
| 559 int result) { | 607 int result) { |
| 560 base::TimeDelta duration = base::TimeTicks::Now() - start_time(); | 608 base::TimeDelta duration = base::TimeTicks::Now() - start_time(); |
| 561 | 609 |
| 562 std::string rtt_histogram_name; | 610 std::string rtt_histogram_name; |
| 611 std::string rtt_no_proxy_histogram_name; | |
| 563 std::string status_histogram_name; | 612 std::string status_histogram_name; |
| 613 std::string status_no_proxy_histogram_name; | |
| 564 std::string packet_loss_histogram_name; | 614 std::string packet_loss_histogram_name; |
| 615 std::string packet_loss_no_proxy_histogram_name; | |
| 565 GetHistogramNames(protocol, | 616 GetHistogramNames(protocol, |
| 566 histogram_port_, | 617 histogram_port_, |
| 618 has_proxy_server_, | |
| 567 load_size_, | 619 load_size_, |
| 568 result, | 620 result, |
| 569 &rtt_histogram_name, | 621 &rtt_histogram_name, |
| 622 &rtt_no_proxy_histogram_name, | |
| 570 &status_histogram_name, | 623 &status_histogram_name, |
| 571 &packet_loss_histogram_name); | 624 &status_no_proxy_histogram_name, |
| 625 &packet_loss_histogram_name, | |
| 626 &packet_loss_no_proxy_histogram_name); | |
| 572 | 627 |
| 573 // For packet loss test, just record packet loss data. | 628 // For packet loss test, just record packet loss data. |
| 574 if (packets_to_send_ > 1) { | 629 if (packets_to_send_ > 1) { |
| 575 base::Histogram* packet_loss_histogram = base::LinearHistogram::FactoryGet( | 630 base::Histogram* packet_loss_histogram = base::LinearHistogram::FactoryGet( |
| 576 packet_loss_histogram_name, | 631 packet_loss_histogram_name, |
| 577 1, | 632 1, |
| 578 2 << kMaximumPackets, | 633 2 << kMaximumPackets, |
| 579 (2 << kMaximumPackets) + 1, | 634 (2 << kMaximumPackets) + 1, |
| 580 base::Histogram::kUmaTargetedHistogramFlag); | 635 base::Histogram::kUmaTargetedHistogramFlag); |
| 581 packet_loss_histogram->Add(packets_received_mask_); | 636 packet_loss_histogram->Add(packets_received_mask_); |
| 582 return; | 637 return; |
| 583 } | 638 } |
| 584 | 639 |
| 585 if (result == net::OK) { | 640 if (result == net::OK) { |
| 586 base::Histogram* rtt_histogram = base::Histogram::FactoryTimeGet( | 641 base::Histogram* rtt_histogram = base::Histogram::FactoryTimeGet( |
| 587 rtt_histogram_name, | 642 rtt_histogram_name, |
| 588 base::TimeDelta::FromMilliseconds(10), | 643 base::TimeDelta::FromMilliseconds(10), |
| 589 base::TimeDelta::FromSeconds(60), 50, | 644 base::TimeDelta::FromSeconds(60), 50, |
| 590 base::Histogram::kUmaTargetedHistogramFlag); | 645 base::Histogram::kUmaTargetedHistogramFlag); |
| 591 rtt_histogram->AddTime(duration); | 646 rtt_histogram->AddTime(duration); |
| 647 | |
| 648 if (!has_proxy_server_) { | |
| 649 base::Histogram* rtt_no_proxy_histogram = base::Histogram::FactoryTimeGet( | |
| 650 rtt_no_proxy_histogram_name, | |
| 651 base::TimeDelta::FromMilliseconds(10), | |
| 652 base::TimeDelta::FromSeconds(60), 50, | |
| 653 base::Histogram::kUmaTargetedHistogramFlag); | |
| 654 rtt_no_proxy_histogram->AddTime(duration); | |
| 655 } | |
| 592 } | 656 } |
| 593 | 657 |
| 594 base::Histogram* status_histogram = base::LinearHistogram::FactoryGet( | 658 base::Histogram* status_histogram = base::LinearHistogram::FactoryGet( |
| 595 status_histogram_name, 1, STATUS_MAX, STATUS_MAX+1, | 659 status_histogram_name, 1, STATUS_MAX, STATUS_MAX+1, |
| 596 base::Histogram::kUmaTargetedHistogramFlag); | 660 base::Histogram::kUmaTargetedHistogramFlag); |
| 597 status_histogram->Add(status); | 661 status_histogram->Add(status); |
| 662 if (!has_proxy_server_) { | |
| 663 base::Histogram* status_no_proxy_histogram = | |
| 664 base::LinearHistogram::FactoryGet( | |
| 665 status_no_proxy_histogram_name, 1, STATUS_MAX, STATUS_MAX+1, | |
| 666 base::Histogram::kUmaTargetedHistogramFlag); | |
| 667 status_no_proxy_histogram->Add(status); | |
| 668 } | |
| 598 } | 669 } |
| 599 | 670 |
| 600 // UDPStatsClient methods and members. | 671 // UDPStatsClient methods and members. |
| 601 UDPStatsClient::UDPStatsClient() | 672 UDPStatsClient::UDPStatsClient() |
| 602 : NetworkStats() { | 673 : NetworkStats() { |
| 603 } | 674 } |
| 604 | 675 |
| 605 UDPStatsClient::~UDPStatsClient() { | 676 UDPStatsClient::~UDPStatsClient() { |
| 606 } | 677 } |
| 607 | 678 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 710 | 781 |
| 711 // Disconnect the socket so that there are no more IO operations. | 782 // Disconnect the socket so that there are no more IO operations. |
| 712 net::TCPClientSocket* tcp_socket = | 783 net::TCPClientSocket* tcp_socket = |
| 713 static_cast<net::TCPClientSocket*>(socket()); | 784 static_cast<net::TCPClientSocket*>(socket()); |
| 714 if (tcp_socket) | 785 if (tcp_socket) |
| 715 tcp_socket->Disconnect(); | 786 tcp_socket->Disconnect(); |
| 716 | 787 |
| 717 delete this; | 788 delete this; |
| 718 } | 789 } |
| 719 | 790 |
| 791 // ProxyClient methods and members. | |
| 792 ProxyClient::ProxyClient(const std::string& network_stats_server, | |
| 793 NetworkStats::HistogramPortSelector histogram_port, | |
| 794 IOThread* io_thread) | |
| 795 : network_stats_server_(network_stats_server), | |
| 796 histogram_port_(histogram_port), | |
| 797 io_thread_(io_thread) { | |
| 798 } | |
| 799 | |
| 800 ProxyClient::~ProxyClient() { | |
| 801 } | |
| 802 | |
| 803 void ProxyClient::ResolveProxy() { | |
| 804 std::string url = base::StringPrintf("https://%s:%d", | |
| 805 network_stats_server_.c_str(), | |
| 806 kPorts[histogram_port_]); | |
| 807 GURL gurl(url); | |
| 808 net::ProxyService* service = | |
| 809 io_thread_->globals()->system_proxy_service.get(); | |
| 810 | |
| 811 int rv = service->ResolveProxy( | |
| 812 gurl, | |
| 813 &proxy_info_, | |
| 814 base::Bind(&ProxyClient::OnResolveProxyComplete, | |
| 815 base::Unretained(this)), | |
| 816 NULL, | |
| 817 net::BoundNetLog()); | |
| 818 if (rv == net::OK) | |
| 819 OnResolveProxyComplete(rv); | |
| 820 } | |
| 821 | |
| 822 void ProxyClient::OnResolveProxyComplete(int result) { | |
| 823 bool has_proxy_server = (proxy_info_.proxy_server().is_valid() && | |
| 824 !proxy_info_.proxy_server().is_direct()); | |
| 825 | |
| 826 net::HostResolver* host_resolver = io_thread_->globals()->host_resolver.get(); | |
| 827 DCHECK(host_resolver); | |
| 828 | |
| 829 DCHECK_GE(histogram_port_, NetworkStats::PORT_53); | |
| 830 DCHECK_LE(histogram_port_, NetworkStats::PORT_8080); | |
| 831 net::HostPortPair server_address(network_stats_server_, | |
| 832 kPorts[histogram_port_]); | |
| 833 | |
| 834 int experiment_to_run = base::RandInt(1, 5); | |
| 835 switch (experiment_to_run) { | |
| 836 case 1: | |
| 837 { | |
| 838 UDPStatsClient* small_udp_stats = new UDPStatsClient(); | |
| 839 small_udp_stats->Start( | |
| 840 host_resolver, server_address, histogram_port_, has_proxy_server, | |
| 841 kSmallTestBytesToSend, 1, net::CompletionCallback()); | |
| 842 } | |
| 843 break; | |
| 844 | |
| 845 case 2: | |
| 846 { | |
| 847 UDPStatsClient* large_udp_stats = new UDPStatsClient(); | |
| 848 large_udp_stats->Start( | |
| 849 host_resolver, server_address, histogram_port_, has_proxy_server, | |
| 850 kLargeTestBytesToSend, 1, net::CompletionCallback()); | |
| 851 } | |
| 852 break; | |
| 853 | |
| 854 case 3: | |
| 855 { | |
| 856 TCPStatsClient* small_tcp_client = new TCPStatsClient(); | |
| 857 small_tcp_client->Start( | |
| 858 host_resolver, server_address, histogram_port_, has_proxy_server, | |
| 859 kSmallTestBytesToSend, 1, net::CompletionCallback()); | |
| 860 } | |
| 861 break; | |
| 862 | |
| 863 case 4: | |
| 864 { | |
| 865 TCPStatsClient* large_tcp_client = new TCPStatsClient(); | |
| 866 large_tcp_client->Start( | |
| 867 host_resolver, server_address, histogram_port_, has_proxy_server, | |
| 868 kLargeTestBytesToSend, 1, net::CompletionCallback()); | |
| 869 } | |
| 870 break; | |
| 871 | |
| 872 case 5: | |
| 873 { | |
| 874 UDPStatsClient* packet_loss_udp_stats = new UDPStatsClient(); | |
| 875 packet_loss_udp_stats->Start( | |
| 876 host_resolver, server_address, histogram_port_, has_proxy_server, | |
| 877 kLargeTestBytesToSend, kMaximumPackets, net::CompletionCallback()); | |
| 878 } | |
| 879 break; | |
| 880 } | |
| 881 } | |
| 882 | |
| 720 // static | 883 // static |
| 721 void CollectNetworkStats(const std::string& network_stats_server, | 884 void CollectNetworkStats(const std::string& network_stats_server, |
| 722 IOThread* io_thread) { | 885 IOThread* io_thread) { |
| 723 if (network_stats_server.empty()) | 886 if (network_stats_server.empty()) |
| 724 return; | 887 return; |
| 725 | 888 |
| 726 // If we are not on IO Thread, then post a task to call CollectNetworkStats on | 889 // If we are not on IO Thread, then post a task to call CollectNetworkStats on |
| 727 // IO Thread. | 890 // IO Thread. |
| 728 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 891 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 729 BrowserThread::PostTask( | 892 BrowserThread::PostTask( |
| 730 BrowserThread::IO, | 893 BrowserThread::IO, |
| 731 FROM_HERE, | 894 FROM_HERE, |
| 732 base::Bind( | 895 base::Bind( |
| 733 &CollectNetworkStats, network_stats_server, io_thread)); | 896 &CollectNetworkStats, network_stats_server, io_thread)); |
| 734 return; | 897 return; |
| 735 } | 898 } |
| 736 | 899 |
| 737 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 900 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 738 | 901 |
| 739 // Check that there is a network connection. We get called only if UMA upload | 902 // Check that there is a network connection. We get called only if UMA upload |
| 740 // to the server has succeeded. | 903 // to the server has succeeded. |
| 741 DCHECK(!net::NetworkChangeNotifier::IsOffline()); | 904 DCHECK(!net::NetworkChangeNotifier::IsOffline()); |
| 742 | 905 |
| 743 CR_DEFINE_STATIC_LOCAL(scoped_refptr<base::FieldTrial>, trial, ()); | 906 CR_DEFINE_STATIC_LOCAL(scoped_refptr<base::FieldTrial>, trial, ()); |
| 744 static bool collect_stats = false; | 907 static bool collect_stats = false; |
| 745 | |
| 746 static uint32 port; | |
| 747 static NetworkStats::HistogramPortSelector histogram_port; | 908 static NetworkStats::HistogramPortSelector histogram_port; |
| 748 | 909 |
| 749 if (!trial.get()) { | 910 if (!trial.get()) { |
| 750 // Set up a field trial to collect network stats for UDP and TCP. | 911 // Set up a field trial to collect network stats for UDP and TCP. |
| 751 const base::FieldTrial::Probability kDivisor = 1000; | 912 const base::FieldTrial::Probability kDivisor = 1000; |
| 752 | 913 |
| 753 // Enable the connectivity testing for 0.5% of the users in stable channel. | 914 // Enable the connectivity testing for 0.5% of the users in stable channel. |
| 754 base::FieldTrial::Probability probability_per_group = 5; | 915 base::FieldTrial::Probability probability_per_group = 5; |
| 755 | 916 |
| 756 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | 917 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 775 if (trial->group() == collect_stats_group) | 936 if (trial->group() == collect_stats_group) |
| 776 collect_stats = true; | 937 collect_stats = true; |
| 777 | 938 |
| 778 if (collect_stats) { | 939 if (collect_stats) { |
| 779 // Pick a port randomly from the set of TCP/UDP echo server ports | 940 // Pick a port randomly from the set of TCP/UDP echo server ports |
| 780 // specified in |kPorts|. | 941 // specified in |kPorts|. |
| 781 histogram_port = static_cast<NetworkStats::HistogramPortSelector>( | 942 histogram_port = static_cast<NetworkStats::HistogramPortSelector>( |
| 782 base::RandInt(NetworkStats::PORT_53, NetworkStats::PORT_8080)); | 943 base::RandInt(NetworkStats::PORT_53, NetworkStats::PORT_8080)); |
| 783 DCHECK_GE(histogram_port, NetworkStats::PORT_53); | 944 DCHECK_GE(histogram_port, NetworkStats::PORT_53); |
| 784 DCHECK_LE(histogram_port, NetworkStats::PORT_8080); | 945 DCHECK_LE(histogram_port, NetworkStats::PORT_8080); |
| 785 port = kPorts[histogram_port]; | |
| 786 } | 946 } |
| 787 } | 947 } |
| 788 | 948 |
| 789 if (!collect_stats) | 949 if (!collect_stats) |
| 790 return; | 950 return; |
| 791 | 951 |
| 792 // Run test kMaxNumberOfTests times. | 952 // Run test kMaxNumberOfTests times. |
| 793 const size_t kMaxNumberOfTests = INT_MAX; | 953 const size_t kMaxNumberOfTests = INT_MAX; |
| 794 static size_t number_of_tests_done = 0; | 954 static size_t number_of_tests_done = 0; |
| 795 if (number_of_tests_done > kMaxNumberOfTests) | 955 if (number_of_tests_done > kMaxNumberOfTests) |
| 796 return; | 956 return; |
| 797 | 957 |
| 798 ++number_of_tests_done; | 958 ++number_of_tests_done; |
| 799 | 959 |
| 800 net::HostResolver* host_resolver = io_thread->globals()->host_resolver.get(); | 960 ProxyClient* proxy_client = new ProxyClient( |
| 801 DCHECK(host_resolver); | 961 network_stats_server, histogram_port, io_thread); |
| 802 | 962 proxy_client->ResolveProxy(); |
| 803 net::HostPortPair server_address(network_stats_server, port); | |
| 804 | |
| 805 int experiment_to_run = base::RandInt(1, 5); | |
| 806 switch (experiment_to_run) { | |
| 807 case 1: | |
| 808 { | |
| 809 UDPStatsClient* small_udp_stats = new UDPStatsClient(); | |
| 810 small_udp_stats->Start( | |
| 811 host_resolver, server_address, histogram_port, | |
| 812 kSmallTestBytesToSend, 1, net::CompletionCallback()); | |
| 813 } | |
| 814 break; | |
| 815 | |
| 816 case 2: | |
| 817 { | |
| 818 UDPStatsClient* large_udp_stats = new UDPStatsClient(); | |
| 819 large_udp_stats->Start( | |
| 820 host_resolver, server_address, histogram_port, | |
| 821 kLargeTestBytesToSend, 1, net::CompletionCallback()); | |
| 822 } | |
| 823 break; | |
| 824 | |
| 825 case 3: | |
| 826 { | |
| 827 TCPStatsClient* small_tcp_client = new TCPStatsClient(); | |
| 828 small_tcp_client->Start( | |
| 829 host_resolver, server_address, histogram_port, | |
| 830 kSmallTestBytesToSend, 1, net::CompletionCallback()); | |
| 831 } | |
| 832 break; | |
| 833 | |
| 834 case 4: | |
| 835 { | |
| 836 TCPStatsClient* large_tcp_client = new TCPStatsClient(); | |
| 837 large_tcp_client->Start( | |
| 838 host_resolver, server_address, histogram_port, | |
| 839 kLargeTestBytesToSend, 1, net::CompletionCallback()); | |
| 840 } | |
| 841 break; | |
| 842 | |
| 843 case 5: | |
| 844 { | |
| 845 UDPStatsClient* packet_loss_udp_stats = new UDPStatsClient(); | |
| 846 packet_loss_udp_stats->Start( | |
| 847 host_resolver, server_address, histogram_port, | |
| 848 kLargeTestBytesToSend, kMaximumPackets, net::CompletionCallback()); | |
| 849 } | |
| 850 break; | |
| 851 } | |
| 852 } | 963 } |
| 853 | 964 |
| 854 } // namespace chrome_browser_net | 965 } // namespace chrome_browser_net |
| OLD | NEW |