From d49a6264617043a450e776984a76468b542ba411 Mon Sep 17 00:00:00 2001 From: "erikkay@google.com" Date: Tue, 2 Sep 2008 16:42:15 +0000 Subject: Initial pass at simple event tracing. I added a few traces to tcp_socket and test_shell to get an idea of what a simple trace might look like. Here's a sample output line: 11:24:19.660604 0x1e278:0x1e24c BEGIN url.load [0x5 http://mail.google.com/mail/] format is:hh:mm:ss.us pid:tid TYPE NAME [id, extra] git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1641 0039d316-1c4b-4281-b951-d872f2087c98 --- net/base/tcp_client_socket.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'net') diff --git a/net/base/tcp_client_socket.cc b/net/base/tcp_client_socket.cc index 9b6959e..fc65995 100644 --- a/net/base/tcp_client_socket.cc +++ b/net/base/tcp_client_socket.cc @@ -4,6 +4,8 @@ #include "net/base/tcp_client_socket.h" +#include "base/string_util.h" +#include "base/trace_event.h" #include "net/base/net_errors.h" #include "net/base/winsock_init.h" @@ -67,6 +69,7 @@ int TCPClientSocket::Connect(CompletionCallback* callback) { if (socket_ != INVALID_SOCKET) return OK; + TRACE_EVENT_BEGIN("socket.connect", this, ""); const struct addrinfo* ai = current_ai_; DCHECK(ai); @@ -80,6 +83,7 @@ int TCPClientSocket::Connect(CompletionCallback* callback) { WSAEventSelect(socket_, overlapped_.hEvent, FD_CONNECT); if (!connect(socket_, ai->ai_addr, static_cast(ai->ai_addrlen))) { + TRACE_EVENT_END("socket.connect", this, ""); // Connected without waiting! return OK; } @@ -105,6 +109,8 @@ void TCPClientSocket::Disconnect() { if (socket_ == INVALID_SOCKET) return; + TRACE_EVENT_INSTANT("socket.disconnect", this, ""); + // Make sure the message loop is not watching this object anymore. watcher_.StopWatching(); @@ -224,6 +230,7 @@ void TCPClientSocket::DoCallback(int rv) { void TCPClientSocket::DidCompleteConnect() { int result; + TRACE_EVENT_END("socket.connect", this, ""); wait_state_ = NOT_WAITING; WSANETWORKEVENTS events; @@ -263,6 +270,13 @@ void TCPClientSocket::DidCompleteIO() { BOOL ok = WSAGetOverlappedResult( socket_, &overlapped_, &num_bytes, FALSE, &flags); WSAResetEvent(overlapped_.hEvent); + if (wait_state_ == WAITING_READ) { + TRACE_EVENT_INSTANT("socket.read", this, + StringPrintf("%d bytes", num_bytes)); + } else { + TRACE_EVENT_INSTANT("socket.write", this, + StringPrintf("%d bytes", num_bytes)); + } wait_state_ = NOT_WAITING; DoCallback(ok ? num_bytes : MapWinsockError(WSAGetLastError())); } -- cgit v1.1