tcp: Add APICall trace entry and move TRACEs into locked parts.

The APICall trace entry just records the function name but this is
enough to deduce where some of the state changes come from.

Also move the TRACE macros past the MutexLockers to ensure that their
output happens at the time when the methods actually run.
This commit is contained in:
Michael Lotz
2015-08-02 23:21:11 +02:00
parent 05220224ff
commit bc49140bab
@@ -274,6 +274,29 @@ protected:
tcp_state fState; tcp_state fState;
}; };
class APICall : public AbstractTraceEntry {
public:
APICall(TCPEndpoint* endpoint, const char* which)
:
fEndpoint(endpoint),
fWhich(which),
fState(endpoint->State())
{
Initialized();
}
virtual void AddDump(TraceOutput& out)
{
out.Print("tcp:%p (%12s) api call: %s", fEndpoint,
name_for_state(fState), fWhich);
}
protected:
TCPEndpoint* fEndpoint;
const char* fWhich;
tcp_state fState;
};
} // namespace TCPTracing } // namespace TCPTracing
# define T(x) new(std::nothrow) TCPTracing::x # define T(x) new(std::nothrow) TCPTracing::x
@@ -434,6 +457,8 @@ TCPEndpoint::TCPEndpoint(net_socket* socket)
TCPEndpoint::_DelayedAcknowledgeTimer, this); TCPEndpoint::_DelayedAcknowledgeTimer, this);
gStackModule->init_timer(&fTimeWaitTimer, TCPEndpoint::_TimeWaitTimer, gStackModule->init_timer(&fTimeWaitTimer, TCPEndpoint::_TimeWaitTimer,
this); this);
T(APICall(this, "constructor"));
} }
@@ -441,6 +466,8 @@ TCPEndpoint::~TCPEndpoint()
{ {
mutex_lock(&fLock); mutex_lock(&fLock);
T(APICall(this, "destructor"));
_CancelConnectionTimers(); _CancelConnectionTimers();
gStackModule->cancel_timer(&fTimeWaitTimer); gStackModule->cancel_timer(&fTimeWaitTimer);
T(TimerSet(this, "time-wait", -1)); T(TimerSet(this, "time-wait", -1));
@@ -476,6 +503,7 @@ status_t
TCPEndpoint::Open() TCPEndpoint::Open()
{ {
TRACE("Open()"); TRACE("Open()");
T(APICall(this, "open"));
status_t status = ProtocolSocket::Open(); status_t status = ProtocolSocket::Open();
if (status < B_OK) if (status < B_OK)
@@ -492,10 +520,11 @@ TCPEndpoint::Open()
status_t status_t
TCPEndpoint::Close() TCPEndpoint::Close()
{ {
TRACE("Close()");
MutexLocker locker(fLock); MutexLocker locker(fLock);
TRACE("Close()");
T(APICall(this, "close"));
if (fState == LISTEN) if (fState == LISTEN)
delete_sem(fAcceptSemaphore); delete_sem(fAcceptSemaphore);
@@ -533,10 +562,11 @@ TCPEndpoint::Close()
void void
TCPEndpoint::Free() TCPEndpoint::Free()
{ {
TRACE("Free()");
MutexLocker _(fLock); MutexLocker _(fLock);
TRACE("Free()");
T(APICall(this, "free"));
if (fState <= SYNCHRONIZE_SENT) if (fState <= SYNCHRONIZE_SENT)
return; return;
@@ -557,13 +587,14 @@ TCPEndpoint::Free()
status_t status_t
TCPEndpoint::Connect(const sockaddr* address) TCPEndpoint::Connect(const sockaddr* address)
{ {
TRACE("Connect() on address %s", PrintAddress(address));
if (!AddressModule()->is_same_family(address)) if (!AddressModule()->is_same_family(address))
return EAFNOSUPPORT; return EAFNOSUPPORT;
MutexLocker locker(fLock); MutexLocker locker(fLock);
TRACE("Connect() on address %s", PrintAddress(address));
T(APICall(this, "connect"));
if (gStackModule->is_restarted_syscall()) { if (gStackModule->is_restarted_syscall()) {
bigtime_t timeout = gStackModule->restore_syscall_restart_timeout(); bigtime_t timeout = gStackModule->restore_syscall_restart_timeout();
status_t status = _WaitForEstablished(locker, timeout); status_t status = _WaitForEstablished(locker, timeout);
@@ -635,10 +666,11 @@ TCPEndpoint::Connect(const sockaddr* address)
status_t status_t
TCPEndpoint::Accept(struct net_socket** _acceptedSocket) TCPEndpoint::Accept(struct net_socket** _acceptedSocket)
{ {
TRACE("Accept()");
MutexLocker locker(fLock); MutexLocker locker(fLock);
TRACE("Accept()");
T(APICall(this, "accept"));
status_t status; status_t status;
bigtime_t timeout = absolute_timeout(socket->receive.timeout); bigtime_t timeout = absolute_timeout(socket->receive.timeout);
if (gStackModule->is_restarted_syscall()) if (gStackModule->is_restarted_syscall())
@@ -679,6 +711,7 @@ TCPEndpoint::Bind(const sockaddr *address)
MutexLocker lock(fLock); MutexLocker lock(fLock);
TRACE("Bind() on address %s", PrintAddress(address)); TRACE("Bind() on address %s", PrintAddress(address));
T(APICall(this, "bind"));
if (fState != CLOSED) if (fState != CLOSED)
return EISCONN; return EISCONN;
@@ -690,9 +723,11 @@ TCPEndpoint::Bind(const sockaddr *address)
status_t status_t
TCPEndpoint::Unbind(struct sockaddr *address) TCPEndpoint::Unbind(struct sockaddr *address)
{ {
TRACE("Unbind()");
MutexLocker _(fLock); MutexLocker _(fLock);
TRACE("Unbind()");
T(APICall(this, "unbind"));
return fManager->Unbind(this); return fManager->Unbind(this);
} }
@@ -700,10 +735,11 @@ TCPEndpoint::Unbind(struct sockaddr *address)
status_t status_t
TCPEndpoint::Listen(int count) TCPEndpoint::Listen(int count)
{ {
TRACE("Listen()");
MutexLocker _(fLock); MutexLocker _(fLock);
TRACE("Listen()");
T(APICall(this, "listen"));
if (fState != CLOSED && fState != LISTEN) if (fState != CLOSED && fState != LISTEN)
return B_BAD_VALUE; return B_BAD_VALUE;
@@ -731,10 +767,11 @@ TCPEndpoint::Listen(int count)
status_t status_t
TCPEndpoint::Shutdown(int direction) TCPEndpoint::Shutdown(int direction)
{ {
TRACE("Shutdown(%i)", direction);
MutexLocker lock(fLock); MutexLocker lock(fLock);
TRACE("Shutdown(%i)", direction);
T(APICall(this, "shutdown"));
if (direction == SHUT_RD || direction == SHUT_RDWR) if (direction == SHUT_RD || direction == SHUT_RDWR)
fFlags |= FLAG_NO_RECEIVE; fFlags |= FLAG_NO_RECEIVE;
@@ -757,6 +794,7 @@ TCPEndpoint::SendData(net_buffer *buffer)
TRACE("SendData(buffer %p, size %" B_PRIu32 ", flags %#" B_PRIx32 TRACE("SendData(buffer %p, size %" B_PRIu32 ", flags %#" B_PRIx32
") [total %" B_PRIuSIZE " bytes, has %" B_PRIuSIZE "]", buffer, ") [total %" B_PRIuSIZE " bytes, has %" B_PRIuSIZE "]", buffer,
buffer->size, buffer->flags, fSendQueue.Size(), fSendQueue.Free()); buffer->size, buffer->flags, fSendQueue.Size(), fSendQueue.Free());
T(APICall(this, "senddata"));
uint32 flags = buffer->flags; uint32 flags = buffer->flags;
@@ -856,6 +894,7 @@ TCPEndpoint::SendAvailable()
available = EPIPE; available = EPIPE;
TRACE("SendAvailable(): %" B_PRIdSSIZE, available); TRACE("SendAvailable(): %" B_PRIdSSIZE, available);
T(APICall(this, "sendavailable"));
return available; return available;
} }
@@ -876,10 +915,11 @@ TCPEndpoint::FillStat(net_stat *stat)
status_t status_t
TCPEndpoint::ReadData(size_t numBytes, uint32 flags, net_buffer** _buffer) TCPEndpoint::ReadData(size_t numBytes, uint32 flags, net_buffer** _buffer)
{ {
MutexLocker locker(fLock);
TRACE("ReadData(%" B_PRIuSIZE " bytes, flags %#" B_PRIx32 ")", numBytes, TRACE("ReadData(%" B_PRIuSIZE " bytes, flags %#" B_PRIx32 ")", numBytes,
flags); flags);
T(APICall(this, "readdata"));
MutexLocker locker(fLock);
*_buffer = NULL; *_buffer = NULL;
@@ -975,6 +1015,7 @@ TCPEndpoint::ReadAvailable()
MutexLocker locker(fLock); MutexLocker locker(fLock);
TRACE("ReadAvailable(): %" B_PRIdSSIZE, _AvailableData()); TRACE("ReadAvailable(): %" B_PRIdSSIZE, _AvailableData());
T(APICall(this, "readavailable"));
return _AvailableData(); return _AvailableData();
} }