From e43a2cac32cb773994b11a3d964ec4acc372d273 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 26 Jul 2023 21:33:36 -0700 Subject: Added a profiler and investageted Server. --- src/stable/server.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/stable/server.cpp') diff --git a/src/stable/server.cpp b/src/stable/server.cpp index 3c42bf4..0552510 100644 --- a/src/stable/server.cpp +++ b/src/stable/server.cpp @@ -13,17 +13,27 @@ #include "bu/tcpsocket.h" #include "bu/config.h" +#ifdef PROFILE_BU_SERVER +#define BU_PROFILE_START( x ) Bu::Profiler::getInstance().startEvent( x ) +#define BU_PROFILE_END( x ) Bu::Profiler::getInstance().endEvent( x ) +#else +#define BU_PROFILE_START( x ) (void)0 +#define BU_PROFILE_END( x ) (void)0 +#endif + Bu::Server::Server() : nTimeoutSec( 0 ), nTimeoutUSec( 0 ), bAutoTick( false ) { + BU_PROFILE_START("server"); FD_ZERO( &fdActive ); } Bu::Server::~Server() { shutdown(); + BU_PROFILE_START("server"); } void Bu::Server::addPort( int nPort, int nPoolSize ) @@ -50,6 +60,7 @@ void Bu::Server::setTimeout( int nTimeoutSec, int nTimeoutUSec ) void Bu::Server::scan() { + BU_PROFILE_START("scan"); struct timeval xTimeout = { nTimeoutSec, nTimeoutUSec }; fd_set fdRead = fdActive; @@ -68,6 +79,7 @@ void Bu::Server::scan() { char buf[1024]; strerror_r( errno, buf, 1024 ); + BU_PROFILE_END("scan"); throw ExceptionBase( Bu::String("Error attempting to scan open connections: %1: %2").arg( errno ).arg( buf ).end().getStr() ); @@ -85,7 +97,9 @@ void Bu::Server::scan() else { Client *pClient = hClients.get( j ); + BU_PROFILE_START("processInput"); pClient->processInput(); + BU_PROFILE_END("processInput"); if( !pClient->isOpen() ) { closeClient( j ); @@ -99,7 +113,9 @@ void Bu::Server::scan() Client *pClient = hClients.get( j ); try { + BU_PROFILE_START("processOutput"); pClient->processOutput(); + BU_PROFILE_END("processOutput"); } catch( Bu::TcpSocketException &e ) { @@ -133,10 +149,13 @@ void Bu::Server::scan() if( bAutoTick ) tick(); + + BU_PROFILE_END("scan"); } void Bu::Server::addClient( socket_t nSocket, int nPort ) { + BU_PROFILE_START("addClient"); FD_SET( nSocket, &fdActive ); Client *c = new Client( @@ -146,6 +165,7 @@ void Bu::Server::addClient( socket_t nSocket, int nPort ) hClients.insert( nSocket, c ); onNewConnection( c, nPort ); + BU_PROFILE_END("addClient"); } Bu::Server::SrvClientLink::SrvClientLink( Bu::Client *pClient ) : @@ -208,11 +228,13 @@ void Bu::Server::shutdown() void Bu::Server::closeClient( socket_t iSocket ) { + BU_PROFILE_START("closeClient"); Bu::Client *pClient = hClients.get( iSocket ); onClosedConnection( pClient ); pClient->close(); hClients.erase( iSocket ); FD_CLR( iSocket, &fdActive ); delete pClient; + BU_PROFILE_END("closeClient"); } -- cgit v1.2.3