summaryrefslogtreecommitdiffstats
path: root/net
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
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')
-rw-r--r--net/base/capturing_net_log.h2
-rw-r--r--net/base/forwarding_net_log.cc2
-rw-r--r--net/base/net_log.cc6
-rw-r--r--net/base/net_log.h10
-rw-r--r--net/base/net_log_event_type_list.h8
-rw-r--r--net/http/http_network_transaction.cc6
-rw-r--r--net/http/http_proxy_client_socket.cc4
-rw-r--r--net/proxy/proxy_service.cc4
-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
-rw-r--r--net/spdy/spdy_proxy_client_socket.cc4
-rw-r--r--net/spdy/spdy_session.cc10
-rw-r--r--net/url_request/url_request.cc2
16 files changed, 113 insertions, 40 deletions
diff --git a/net/base/capturing_net_log.h b/net/base/capturing_net_log.h
index 6e0f620..ff7cf16 100644
--- a/net/base/capturing_net_log.h
+++ b/net/base/capturing_net_log.h
@@ -52,7 +52,7 @@ class CapturingNetLog : public NetLog {
EventPhase phase,
EventParameters* extra_parameters);
virtual uint32 NextID();
- virtual LogLevel GetLogLevel() const { return LOG_ALL; }
+ virtual LogLevel GetLogLevel() const { return LOG_ALL_BUT_BYTES; }
// Returns the list of all entries in the log.
const EntryList& entries() const { return entries_; }
diff --git a/net/base/forwarding_net_log.cc b/net/base/forwarding_net_log.cc
index efe6eff..7cfd6a9 100644
--- a/net/base/forwarding_net_log.cc
+++ b/net/base/forwarding_net_log.cc
@@ -89,7 +89,7 @@ uint32 ForwardingNetLog::NextID() {
NetLog::LogLevel ForwardingNetLog::GetLogLevel() const {
// Can't forward a synchronous API.
CHECK(false) << "Not supported";
- return LOG_ALL;
+ return LOG_ALL_BUT_BYTES;
}
} // namespace net
diff --git a/net/base/net_log.cc b/net/base/net_log.cc
index f9f31c7..1499d72 100644
--- a/net/base/net_log.cc
+++ b/net/base/net_log.cc
@@ -131,10 +131,14 @@ NetLog::LogLevel BoundNetLog::GetLogLevel() const {
return NetLog::LOG_BASIC;
}
-bool BoundNetLog::IsLoggingAll() const {
+bool BoundNetLog::IsLoggingBytes() const {
return GetLogLevel() == NetLog::LOG_ALL;
}
+bool BoundNetLog::IsLoggingAllEvents() const {
+ return GetLogLevel() <= NetLog::LOG_ALL_BUT_BYTES;
+}
+
void BoundNetLog::AddEvent(
NetLog::EventType event_type,
const scoped_refptr<NetLog::EventParameters>& params) const {
diff --git a/net/base/net_log.h b/net/base/net_log.h
index f240105..aa0b70e5 100644
--- a/net/base/net_log.h
+++ b/net/base/net_log.h
@@ -98,8 +98,13 @@ class NetLog {
// Specifies the granularity of events that should be emitted to the log.
enum LogLevel {
// Log everything possible, even if it is slow and memory expensive.
+ // Includes logging of transferred bytes.
LOG_ALL,
+ // Log all events, but do not include the actual transferred bytes as
+ // parameters for bytes sent/received events.
+ LOG_ALL_BUT_BYTES,
+
// Only log events which are cheap, and don't consume much memory.
LOG_BASIC,
};
@@ -194,7 +199,10 @@ class BoundNetLog {
NetLog::LogLevel GetLogLevel() const;
// Returns true if the log level is LOG_ALL.
- bool IsLoggingAll() const;
+ bool IsLoggingBytes() const;
+
+ // Returns true if the log level is LOG_ALL or LOG_ALL_BUT_BYTES.
+ bool IsLoggingAllEvents() const;
// Helper to create a BoundNetLog given a NetLog and a SourceType. Takes care
// of creating a unique source ID, and handles the case of NULL net_log.
diff --git a/net/base/net_log_event_type_list.h b/net/base/net_log_event_type_list.h
index b0b4d4b..398f7c1 100644
--- a/net/base/net_log_event_type_list.h
+++ b/net/base/net_log_event_type_list.h
@@ -347,14 +347,18 @@ EVENT_TYPE(SSL_NSS_ERROR)
// The specified number of bytes were sent on the socket.
// The following parameters are attached:
// {
-// "num_bytes": <Number of bytes that were just sent>
+// "byte_count": <Number of bytes that were just sent>,
+// "hex_encoded_bytes": <The exact bytes sent, as a hexadecimal string.
+// Only present when byte logging is enabled>
// }
EVENT_TYPE(SOCKET_BYTES_SENT)
// The specified number of bytes were received on the socket.
// The following parameters are attached:
// {
-// "num_bytes": <Number of bytes that were just sent>
+// "byte_count": <Number of bytes that were just received>,
+// "hex_encoded_bytes": <The exact bytes received, as a hexadecimal string.
+// Only present when byte logging is enabled>
// }
EVENT_TYPE(SOCKET_BYTES_RECEIVED)
diff --git a/net/http/http_network_transaction.cc b/net/http/http_network_transaction.cc
index f4c12d0..7d43117 100644
--- a/net/http/http_network_transaction.cc
+++ b/net/http/http_network_transaction.cc
@@ -723,7 +723,7 @@ int HttpNetworkTransaction::DoSendRequest() {
if (session_->network_delegate())
session_->network_delegate()->OnSendHttpRequest(&request_headers);
- if (net_log_.IsLoggingAll()) {
+ if (net_log_.IsLoggingAllEvents()) {
net_log_.AddEvent(
NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS,
new NetLogHttpRequestParameter(request_line, request_headers));
@@ -731,7 +731,7 @@ int HttpNetworkTransaction::DoSendRequest() {
request_headers_ = request_line + request_headers.ToString();
} else {
- if (net_log_.IsLoggingAll()) {
+ if (net_log_.IsLoggingAllEvents()) {
net_log_.AddEvent(
NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS,
new NetLogHttpRequestParameter(request_->url.spec(),
@@ -826,7 +826,7 @@ int HttpNetworkTransaction::DoReadHeadersComplete(int result) {
return rv;
}
- if (net_log_.IsLoggingAll()) {
+ if (net_log_.IsLoggingAllEvents()) {
net_log_.AddEvent(
NetLog::TYPE_HTTP_TRANSACTION_READ_RESPONSE_HEADERS,
new NetLogHttpResponseParameter(response_.headers));
diff --git a/net/http/http_proxy_client_socket.cc b/net/http/http_proxy_client_socket.cc
index ddefe8e..2da59b7 100644
--- a/net/http/http_proxy_client_socket.cc
+++ b/net/http/http_proxy_client_socket.cc
@@ -331,7 +331,7 @@ int HttpProxyClientSocket::DoSendRequest() {
HttpRequestHeaders request_headers;
BuildTunnelRequest(request_, authorization_headers, endpoint_,
&request_line, &request_headers);
- if (net_log_.IsLoggingAll()) {
+ if (net_log_.IsLoggingAllEvents()) {
net_log_.AddEvent(
NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
new NetLogHttpRequestParameter(
@@ -369,7 +369,7 @@ int HttpProxyClientSocket::DoReadHeadersComplete(int result) {
if (response_.headers->GetParsedHttpVersion() < HttpVersion(1, 0))
return ERR_TUNNEL_CONNECTION_FAILED;
- if (net_log_.IsLoggingAll()) {
+ if (net_log_.IsLoggingAllEvents()) {
net_log_.AddEvent(
NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
new NetLogHttpResponseParameter(response_.headers));
diff --git a/net/proxy/proxy_service.cc b/net/proxy/proxy_service.cc
index 632e63b..644daad 100644
--- a/net/proxy/proxy_service.cc
+++ b/net/proxy/proxy_service.cc
@@ -692,8 +692,8 @@ int ProxyService::DidFinishResolvingProxy(ProxyInfo* result,
const BoundNetLog& net_log) {
// Log the result of the proxy resolution.
if (result_code == OK) {
- // When full logging is enabled, dump the proxy list.
- if (net_log.IsLoggingAll()) {
+ // When logging all events is enabled, dump the proxy list.
+ if (net_log.IsLoggingAllEvents()) {
net_log.AddEvent(
NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST,
new NetLogStringParameter("pac_string", result->ToPacString()));
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;
diff --git a/net/spdy/spdy_proxy_client_socket.cc b/net/spdy/spdy_proxy_client_socket.cc
index d36b6306..9973f86 100644
--- a/net/spdy/spdy_proxy_client_socket.cc
+++ b/net/spdy/spdy_proxy_client_socket.cc
@@ -302,7 +302,7 @@ int SpdyProxyClientSocket::DoSendRequest() {
HttpRequestHeaders request_headers;
BuildTunnelRequest(request_, authorization_headers, endpoint_, &request_line,
&request_headers);
- if (net_log_.IsLoggingAll()) {
+ if (net_log_.IsLoggingAllEvents()) {
net_log_.AddEvent(
NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
new NetLogHttpRequestParameter(
@@ -341,7 +341,7 @@ int SpdyProxyClientSocket::DoReadReplyComplete(int result) {
return ERR_TUNNEL_CONNECTION_FAILED;
next_state_ = STATE_OPEN;
- if (net_log_.IsLoggingAll()) {
+ if (net_log_.IsLoggingAllEvents()) {
net_log_.AddEvent(
NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
new NetLogHttpResponseParameter(response_.headers));
diff --git a/net/spdy/spdy_session.cc b/net/spdy/spdy_session.cc
index 3967a81..b6e1529 100644
--- a/net/spdy/spdy_session.cc
+++ b/net/spdy/spdy_session.cc
@@ -456,7 +456,7 @@ int SpdySession::WriteSynStream(
spdy_requests.Increment();
streams_initiated_count_++;
- if (net_log().IsLoggingAll()) {
+ if (net_log().IsLoggingAllEvents()) {
net_log().AddEvent(
NetLog::TYPE_SPDY_SESSION_SYN_STREAM,
new NetLogSpdySynParameter(headers, flags, stream_id));
@@ -502,7 +502,7 @@ int SpdySession::WriteStreamData(spdy::SpdyStreamId stream_id,
stream->DecreaseSendWindowSize(len);
}
- if (net_log().IsLoggingAll())
+ if (net_log().IsLoggingAllEvents())
net_log().AddEvent(NetLog::TYPE_SPDY_SESSION_SEND_DATA,
new NetLogSpdyDataParameter(stream_id, len, flags));
@@ -959,7 +959,7 @@ void SpdySession::OnError(spdy::SpdyFramer* framer) {
void SpdySession::OnStreamFrameData(spdy::SpdyStreamId stream_id,
const char* data,
size_t len) {
- if (net_log().IsLoggingAll())
+ if (net_log().IsLoggingAllEvents())
net_log().AddEvent(NetLog::TYPE_SPDY_SESSION_RECV_DATA,
new NetLogSpdyDataParameter(stream_id, len, spdy::SpdyDataFlags()));
@@ -992,7 +992,7 @@ void SpdySession::OnSyn(const spdy::SpdySynStreamControlFrame& frame,
spdy::SpdyStreamId stream_id = frame.stream_id();
spdy::SpdyStreamId associated_stream_id = frame.associated_stream_id();
- if (net_log_.IsLoggingAll()) {
+ if (net_log_.IsLoggingAllEvents()) {
net_log_.AddEvent(
NetLog::TYPE_SPDY_SESSION_PUSHED_SYN_STREAM,
new NetLogSpdySynParameter(
@@ -1090,7 +1090,7 @@ void SpdySession::OnSynReply(const spdy::SpdySynReplyControlFrame& frame,
}
stream->set_response_received();
- if (net_log().IsLoggingAll()) {
+ if (net_log().IsLoggingAllEvents()) {
net_log().AddEvent(
NetLog::TYPE_SPDY_SESSION_SYN_REPLY,
new NetLogSpdySynParameter(
diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc
index ee52e0a..c3ce979 100644
--- a/net/url_request/url_request.cc
+++ b/net/url_request/url_request.cc
@@ -490,7 +490,7 @@ void URLRequest::OrphanJob() {
}
int URLRequest::Redirect(const GURL& location, int http_status_code) {
- if (net_log_.IsLoggingAll()) {
+ if (net_log_.IsLoggingAllEvents()) {
net_log_.AddEvent(
net::NetLog::TYPE_URL_REQUEST_REDIRECTED,
new net::NetLogStringParameter(