Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(579)

Side by Side Diff: net/socket/tcp_socket_libevent.cc

Issue 1215543003: Add UMA for the kernel's TCP RTT estimate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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/socket/tcp_socket.h" 5 #include "net/socket/tcp_socket.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <netinet/tcp.h> 8 #include <netinet/tcp.h>
9 #include <sys/socket.h> 9 #include <sys/socket.h>
10 10
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 return true; 107 return true;
108 } 108 }
109 109
110 void RegisterTCPFastOpenIntentAndSupport(bool user_enabled, 110 void RegisterTCPFastOpenIntentAndSupport(bool user_enabled,
111 bool system_supported) { 111 bool system_supported) {
112 g_tcp_fastopen_supported = system_supported; 112 g_tcp_fastopen_supported = system_supported;
113 g_tcp_fastopen_user_enabled = user_enabled; 113 g_tcp_fastopen_user_enabled = user_enabled;
114 } 114 }
115 #endif 115 #endif
116 116
117 #if defined(TCP_INFO)
118 bool GetTcpInfo(SocketDescriptor fd, tcp_info* info) {
119 socklen_t info_len = sizeof(tcp_info);
120 return getsockopt(fd, IPPROTO_TCP, TCP_INFO, info, &info_len) == 0 &&
121 info_len == sizeof(tcp_info);
122 }
123 #endif // defined(TCP_INFO)
124
117 } // namespace 125 } // namespace
118 126
119 //----------------------------------------------------------------------------- 127 //-----------------------------------------------------------------------------
120 128
121 bool IsTCPFastOpenSupported() { 129 bool IsTCPFastOpenSupported() {
122 return g_tcp_fastopen_supported; 130 return g_tcp_fastopen_supported;
123 } 131 }
124 132
125 bool IsTCPFastOpenUserEnabled() { 133 bool IsTCPFastOpenUserEnabled() {
126 return g_tcp_fastopen_user_enabled; 134 return g_tcp_fastopen_user_enabled;
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 TCP_FASTOPEN_FAST_CONNECT_READ_FAILED : 721 TCP_FASTOPEN_FAST_CONNECT_READ_FAILED :
714 TCP_FASTOPEN_SLOW_CONNECT_READ_FAILED); 722 TCP_FASTOPEN_SLOW_CONNECT_READ_FAILED);
715 return; 723 return;
716 } 724 }
717 725
718 bool getsockopt_success = false; 726 bool getsockopt_success = false;
719 bool server_acked_data = false; 727 bool server_acked_data = false;
720 #if defined(TCP_INFO) 728 #if defined(TCP_INFO)
721 // Probe to see the if the socket used TCP FastOpen. 729 // Probe to see the if the socket used TCP FastOpen.
722 tcp_info info; 730 tcp_info info;
723 socklen_t info_len = sizeof(tcp_info); 731 getsockopt_success = GetTcpInfo(socket_->socket_fd(), &info);
724 getsockopt_success = getsockopt(socket_->socket_fd(), IPPROTO_TCP, TCP_INFO, 732 server_acked_data =
725 &info, &info_len) == 0 && 733 getsockopt_success && (info.tcpi_options & TCPI_OPT_SYN_DATA);
726 info_len == sizeof(tcp_info); 734 #endif // defined(TCP_INFO)
727 server_acked_data = getsockopt_success &&
728 (info.tcpi_options & TCPI_OPT_SYN_DATA);
729 #endif
730 735
731 if (getsockopt_success) { 736 if (getsockopt_success) {
732 if (tcp_fastopen_status_ == TCP_FASTOPEN_FAST_CONNECT_RETURN) { 737 if (tcp_fastopen_status_ == TCP_FASTOPEN_FAST_CONNECT_RETURN) {
733 tcp_fastopen_status_ = (server_acked_data ? 738 tcp_fastopen_status_ = (server_acked_data ?
734 TCP_FASTOPEN_SYN_DATA_ACK : 739 TCP_FASTOPEN_SYN_DATA_ACK :
735 TCP_FASTOPEN_SYN_DATA_NACK); 740 TCP_FASTOPEN_SYN_DATA_NACK);
736 } else { 741 } else {
737 tcp_fastopen_status_ = (server_acked_data ? 742 tcp_fastopen_status_ = (server_acked_data ?
738 TCP_FASTOPEN_NO_SYN_DATA_ACK : 743 TCP_FASTOPEN_NO_SYN_DATA_ACK :
739 TCP_FASTOPEN_NO_SYN_DATA_NACK); 744 TCP_FASTOPEN_NO_SYN_DATA_NACK);
740 } 745 }
741 } else { 746 } else {
742 tcp_fastopen_status_ = 747 tcp_fastopen_status_ =
743 (tcp_fastopen_status_ == TCP_FASTOPEN_FAST_CONNECT_RETURN ? 748 (tcp_fastopen_status_ == TCP_FASTOPEN_FAST_CONNECT_RETURN ?
744 TCP_FASTOPEN_SYN_DATA_GETSOCKOPT_FAILED : 749 TCP_FASTOPEN_SYN_DATA_GETSOCKOPT_FAILED :
745 TCP_FASTOPEN_NO_SYN_DATA_GETSOCKOPT_FAILED); 750 TCP_FASTOPEN_NO_SYN_DATA_GETSOCKOPT_FAILED);
746 } 751 }
747 } 752 }
748 753
754 bool TCPSocketLibevent::GetEstimatedRoundTripTime(
755 base::TimeDelta* out_rtt) const {
756 DCHECK(out_rtt);
757 if (!socket_)
758 return false;
759
760 #if defined(TCP_INFO)
761 tcp_info info;
762 if (GetTcpInfo(socket_->socket_fd(), &info)) {
763 // tcpi_rtt is zero when the kernel doesn't have an RTT estimate,
764 // and possibly in other cases such as connections to localhost.
765 if (info.tcpi_rtt > 0) {
766 *out_rtt = base::TimeDelta::FromMicroseconds(info.tcpi_rtt);
767 return true;
768 }
769 }
770 #endif // defined(TCP_INFO)
771 return false;
772 }
773
749 } // namespace net 774 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698