summaryrefslogtreecommitdiffstats
path: root/net/socket
diff options
context:
space:
mode:
authormmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-14 19:58:14 +0000
committermmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-14 19:58:14 +0000
commit465aeb94531f3d73959412b2c8033005fb7c44d7 (patch)
tree39d71fab356d8816ac83b5bb819ce455027c3906 /net/socket
parent26783d056f3639d6310c41d1f499d5a9b13bbf90 (diff)
downloadchromium_src-465aeb94531f3d73959412b2c8033005fb7c44d7.zip
chromium_src-465aeb94531f3d73959412b2c8033005fb7c44d7.tar.gz
chromium_src-465aeb94531f3d73959412b2c8033005fb7c44d7.tar.bz2
Add actual bytes sent/received to net-internals.
BUG=54745 TEST=manual Review URL: http://codereview.chromium.org/3582007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62627 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/socket')
-rw-r--r--net/socket/client_socket.cc51
-rw-r--r--net/socket/client_socket.h8
-rw-r--r--net/socket/tcp_client_socket_libevent.cc16
-rw-r--r--net/socket/tcp_client_socket_pool.cc4
-rw-r--r--net/socket/tcp_client_socket_win.cc16
5 files changed, 76 insertions, 19 deletions
diff --git a/net/socket/client_socket.cc b/net/socket/client_socket.cc
index 8be3ae1..6f38eae 100644
--- a/net/socket/client_socket.cc
+++ b/net/socket/client_socket.cc
@@ -6,9 +6,47 @@
#include "base/metrics/field_trial.h"
#include "base/metrics/histogram.h"
+#include "base/string_number_conversions.h"
+#include "base/values.h"
namespace net {
+namespace {
+
+// Parameters for SOCKET_BYTES_RECEIVED and SOCKET_BYTES_SENT events.
+// Includes bytes transferred and, if |bytes| is not NULL, the bytes themselves.
+class NetLogBytesTransferredParameter : public NetLog::EventParameters {
+ public:
+ NetLogBytesTransferredParameter(int byte_count, const char* bytes);
+
+ virtual Value* ToValue() const;
+
+ private:
+ const int byte_count_;
+ std::string hex_encoded_bytes_;
+ bool has_bytes_;
+};
+
+NetLogBytesTransferredParameter::NetLogBytesTransferredParameter(
+ int byte_count, const char* transferred_bytes)
+ : byte_count_(byte_count),
+ has_bytes_(false) {
+ if (transferred_bytes) {
+ hex_encoded_bytes_ = base::HexEncode(transferred_bytes, byte_count);
+ has_bytes_ = true;
+ }
+}
+
+Value* NetLogBytesTransferredParameter::ToValue() const {
+ DictionaryValue* dict = new DictionaryValue();
+ dict->SetInteger("byte_count", byte_count_);
+ if (has_bytes_)
+ dict->SetString("hex_encoded_bytes", hex_encoded_bytes_);
+ return dict;
+}
+
+} // namespace
+
ClientSocket::UseHistory::UseHistory()
: was_ever_connected_(false),
was_used_to_convey_data_(false),
@@ -98,4 +136,17 @@ bool ClientSocket::UseHistory::was_used_to_convey_data() const {
return was_used_to_convey_data_;
}
+void ClientSocket::LogByteTransfer(const BoundNetLog& net_log,
+ NetLog::EventType event_type,
+ int byte_count,
+ char* bytes) const {
+ scoped_refptr<NetLog::EventParameters> params;
+ if (net_log.IsLoggingBytes()) {
+ params = new NetLogBytesTransferredParameter(byte_count, bytes);
+ } else {
+ params = new NetLogBytesTransferredParameter(byte_count, NULL);
+ }
+ net_log.AddEvent(event_type, params);
+}
+
} // namespace net
diff --git a/net/socket/client_socket.h b/net/socket/client_socket.h
index f44f1f1..b4173c0 100644
--- a/net/socket/client_socket.h
+++ b/net/socket/client_socket.h
@@ -6,12 +6,12 @@
#define NET_SOCKET_CLIENT_SOCKET_H_
#pragma once
+#include "net/base/net_log.h"
#include "net/socket/socket.h"
namespace net {
class AddressList;
-class BoundNetLog;
class ClientSocket : public Socket {
public:
@@ -106,6 +106,12 @@ class ClientSocket : public Socket {
bool subresource_speculation_;
DISALLOW_COPY_AND_ASSIGN(UseHistory);
};
+
+ // Logs a SOCKET_BYTES_RECEIVED or SOCKET_BYTES_SENT event to the NetLog.
+ // Determines whether to log the received bytes or not, based on the current
+ // logging level.
+ void LogByteTransfer(const BoundNetLog& net_log, NetLog::EventType event_type,
+ int byte_count, char* bytes) const;
};
} // namespace net
diff --git a/net/socket/tcp_client_socket_libevent.cc b/net/socket/tcp_client_socket_libevent.cc
index 86d6afe9..f896ac6 100644
--- a/net/socket/tcp_client_socket_libevent.cc
+++ b/net/socket/tcp_client_socket_libevent.cc
@@ -332,8 +332,8 @@ int TCPClientSocketLibevent::Read(IOBuffer* buf,
read_bytes.Add(nread);
if (nread > 0)
use_history_.set_was_used_to_convey_data();
- net_log_.AddEvent(NetLog::TYPE_SOCKET_BYTES_RECEIVED,
- new NetLogIntegerParameter("num_bytes", nread));
+ LogByteTransfer(
+ net_log_, NetLog::TYPE_SOCKET_BYTES_RECEIVED, nread, buf->data());
return nread;
}
if (errno != EAGAIN && errno != EWOULDBLOCK) {
@@ -371,8 +371,8 @@ int TCPClientSocketLibevent::Write(IOBuffer* buf,
write_bytes.Add(nwrite);
if (nwrite > 0)
use_history_.set_was_used_to_convey_data();
- net_log_.AddEvent(NetLog::TYPE_SOCKET_BYTES_SENT,
- new NetLogIntegerParameter("num_bytes", nwrite));
+ LogByteTransfer(
+ net_log_, NetLog::TYPE_SOCKET_BYTES_SENT, nwrite, buf->data());
return nwrite;
}
if (errno != EAGAIN && errno != EWOULDBLOCK)
@@ -491,8 +491,8 @@ void TCPClientSocketLibevent::DidCompleteRead() {
read_bytes.Add(bytes_transferred);
if (bytes_transferred > 0)
use_history_.set_was_used_to_convey_data();
- net_log_.AddEvent(NetLog::TYPE_SOCKET_BYTES_RECEIVED,
- new NetLogIntegerParameter("num_bytes", result));
+ LogByteTransfer(net_log_, NetLog::TYPE_SOCKET_BYTES_RECEIVED, result,
+ read_buf_->data());
} else {
result = MapPosixError(errno);
}
@@ -518,8 +518,8 @@ void TCPClientSocketLibevent::DidCompleteWrite() {
write_bytes.Add(bytes_transferred);
if (bytes_transferred > 0)
use_history_.set_was_used_to_convey_data();
- net_log_.AddEvent(NetLog::TYPE_SOCKET_BYTES_SENT,
- new NetLogIntegerParameter("num_bytes", result));
+ LogByteTransfer(net_log_, NetLog::TYPE_SOCKET_BYTES_SENT, result,
+ write_buf_->data());
} else {
result = MapPosixError(errno);
}
diff --git a/net/socket/tcp_client_socket_pool.cc b/net/socket/tcp_client_socket_pool.cc
index 820f58e..5f1f43f 100644
--- a/net/socket/tcp_client_socket_pool.cc
+++ b/net/socket/tcp_client_socket_pool.cc
@@ -218,7 +218,7 @@ int TCPClientSocketPool::RequestSocket(
const scoped_refptr<TCPSocketParams>* casted_params =
static_cast<const scoped_refptr<TCPSocketParams>*>(params);
- if (net_log.IsLoggingAll()) {
+ if (net_log.IsLoggingAllEvents()) {
// TODO(eroman): Split out the host and port parameters.
net_log.AddEvent(
NetLog::TYPE_TCP_CLIENT_SOCKET_POOL_REQUESTED_SOCKET,
@@ -239,7 +239,7 @@ void TCPClientSocketPool::RequestSockets(
const scoped_refptr<TCPSocketParams>* casted_params =
static_cast<const scoped_refptr<TCPSocketParams>*>(params);
- if (net_log.IsLoggingAll()) {
+ if (net_log.IsLoggingAllEvents()) {
// TODO(eroman): Split out the host and port parameters.
net_log.AddEvent(
NetLog::TYPE_TCP_CLIENT_SOCKET_POOL_REQUESTED_SOCKETS,
diff --git a/net/socket/tcp_client_socket_win.cc b/net/socket/tcp_client_socket_win.cc
index 9bbb034..fc6ca27 100644
--- a/net/socket/tcp_client_socket_win.cc
+++ b/net/socket/tcp_client_socket_win.cc
@@ -568,8 +568,8 @@ int TCPClientSocketWin::Read(IOBuffer* buf,
read_bytes.Add(num);
if (num > 0)
use_history_.set_was_used_to_convey_data();
- net_log_.AddEvent(NetLog::TYPE_SOCKET_BYTES_RECEIVED,
- new NetLogIntegerParameter("num_bytes", num));
+ LogByteTransfer(net_log_, NetLog::TYPE_SOCKET_BYTES_RECEIVED, num,
+ core_->read_buffer_.buf);
return static_cast<int>(num);
}
} else {
@@ -620,8 +620,8 @@ int TCPClientSocketWin::Write(IOBuffer* buf,
write_bytes.Add(rv);
if (rv > 0)
use_history_.set_was_used_to_convey_data();
- net_log_.AddEvent(NetLog::TYPE_SOCKET_BYTES_SENT,
- new NetLogIntegerParameter("num_bytes", rv));
+ LogByteTransfer(net_log_, NetLog::TYPE_SOCKET_BYTES_SENT, rv,
+ core_->write_buffer_.buf);
return rv;
}
} else {
@@ -781,8 +781,8 @@ void TCPClientSocketWin::DidCompleteRead() {
read_bytes.Add(num_bytes);
if (num_bytes > 0)
use_history_.set_was_used_to_convey_data();
- net_log_.AddEvent(NetLog::TYPE_SOCKET_BYTES_RECEIVED,
- new NetLogIntegerParameter("num_bytes", num_bytes));
+ LogByteTransfer(net_log_, NetLog::TYPE_SOCKET_BYTES_RECEIVED, num_bytes,
+ core_->read_buffer_.buf);
}
DoReadCallback(ok ? num_bytes : MapWinsockError(WSAGetLastError()));
}
@@ -812,8 +812,8 @@ void TCPClientSocketWin::DidCompleteWrite() {
write_bytes.Add(num_bytes);
if (num_bytes > 0)
use_history_.set_was_used_to_convey_data();
- net_log_.AddEvent(NetLog::TYPE_SOCKET_BYTES_SENT,
- new NetLogIntegerParameter("num_bytes", rv));
+ LogByteTransfer(net_log_, NetLog::TYPE_SOCKET_BYTES_SENT, num_bytes,
+ core_->write_buffer_.buf);
}
}
core_->write_iobuffer_ = NULL;