From 704bce5baf2b27331bac2363075398c8961a3196 Mon Sep 17 00:00:00 2001 From: Daniel Collins Date: Wed, 20 Jan 2021 20:51:16 +0000 Subject: [PATCH] Add profiling for some ipxwrapper.dll functions. --- src/ipxwrapper.c | 14 ++++++++++++++ src/ipxwrapper.h | 9 +++++++++ src/ipxwrapper_prof_defs.h | 3 +++ src/router.c | 5 +++++ 4 files changed, 31 insertions(+) create mode 100644 src/ipxwrapper_prof_defs.h diff --git a/src/ipxwrapper.c b/src/ipxwrapper.c index db62f42..a300e35 100644 --- a/src/ipxwrapper.c +++ b/src/ipxwrapper.c @@ -30,6 +30,7 @@ #include "ipxwrapper.h" #include "common.h" +#include "funcprof.h" #include "interface.h" #include "router.h" #include "addrcache.h" @@ -50,6 +51,14 @@ static CRITICAL_SECTION sockets_cs; typedef ULONGLONG WINAPI (*GetTickCount64_t)(void); static HMODULE kernel32 = NULL; +struct FuncStats ipxwrapper_fstats[] = { + #define FPROF_DECL(func) { #func }, + #include "ipxwrapper_prof_defs.h" + #undef FPROF_DECL +}; + +const unsigned int ipxwrapper_fstats_size = sizeof(ipxwrapper_fstats) / sizeof(*ipxwrapper_fstats); + static void init_cs(CRITICAL_SECTION *cs) { if(!InitializeCriticalSectionAndSpinCount(cs, 0x80000000)) @@ -69,6 +78,7 @@ static DWORD WINAPI prof_thread_main(LPVOID lpParameter) while(WaitForSingleObject(prof_thread_exit, PROF_INTERVAL_MS) == WAIT_TIMEOUT) { fprof_report(STUBS_DLL_NAME, stub_fstats, NUM_STUBS); + fprof_report("ipxwrapper.dll", ipxwrapper_fstats, ipxwrapper_fstats_size); } return 0; @@ -79,6 +89,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) if(fdwReason == DLL_PROCESS_ATTACH) { fprof_init(stub_fstats, NUM_STUBS); + fprof_init(ipxwrapper_fstats, ipxwrapper_fstats_size); log_open("ipxwrapper.log"); @@ -187,6 +198,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) unload_dlls(); fprof_report(STUBS_DLL_NAME, stub_fstats, NUM_STUBS); + fprof_report("ipxwrapper.dll", ipxwrapper_fstats, ipxwrapper_fstats_size); log_close(); @@ -196,6 +208,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) kernel32 = NULL; } + fprof_cleanup(ipxwrapper_fstats, ipxwrapper_fstats_size); fprof_cleanup(stub_fstats, NUM_STUBS); } @@ -225,6 +238,7 @@ ipx_socket *get_socket(SOCKET sockfd) /* Lock the mutex */ void lock_sockets(void) { + FPROF_RECORD_SCOPE(&(ipxwrapper_fstats[IPXWRAPPER_FSTATS_lock_sockets])); EnterCriticalSection(&sockets_cs); } diff --git a/src/ipxwrapper.h b/src/ipxwrapper.h index ea34dec..f6cfed1 100644 --- a/src/ipxwrapper.h +++ b/src/ipxwrapper.h @@ -27,6 +27,7 @@ #include #include "config.h" +#include "funcprof.h" #include "router.h" /* The standard Windows driver (in XP) only allows 1467 bytes anyway */ @@ -130,6 +131,14 @@ struct spxinit extern ipx_socket *sockets; extern main_config_t main_config; +extern struct FuncStats ipxwrapper_fstats[]; + +enum { + #define FPROF_DECL(func) IPXWRAPPER_FSTATS_ ## func, + #include "ipxwrapper_prof_defs.h" + #undef FPROF_DECL +}; + ipx_socket *get_socket(SOCKET sockfd); void lock_sockets(void); void unlock_sockets(void); diff --git a/src/ipxwrapper_prof_defs.h b/src/ipxwrapper_prof_defs.h new file mode 100644 index 0000000..147e89d --- /dev/null +++ b/src/ipxwrapper_prof_defs.h @@ -0,0 +1,3 @@ +FPROF_DECL(_deliver_packet) +FPROF_DECL(_handle_udp_recv) +FPROF_DECL(lock_sockets) diff --git a/src/router.c b/src/router.c index d3f8955..817974c 100644 --- a/src/router.c +++ b/src/router.c @@ -26,6 +26,7 @@ #include "router.h" #include "common.h" +#include "funcprof.h" #include "ipxwrapper.h" #include "interface.h" #include "addrcache.h" @@ -197,6 +198,8 @@ static void _deliver_packet( const void *data, size_t data_size) { + FPROF_RECORD_SCOPE(&(ipxwrapper_fstats[IPXWRAPPER_FSTATS__deliver_packet])); + { IPX_STRING_ADDR(src_addr, src_net, src_node, src_socket); IPX_STRING_ADDR(dest_addr, dest_net, dest_node, dest_socket); @@ -320,6 +323,8 @@ static void _deliver_packet( static void _handle_udp_recv(ipx_packet *packet, size_t packet_size, struct sockaddr_in src_ip) { + FPROF_RECORD_SCOPE(&(ipxwrapper_fstats[IPXWRAPPER_FSTATS__handle_udp_recv])); + size_t data_size = ntohs(packet->size); if(packet_size < sizeof(ipx_packet) - 1 || data_size > MAX_DATA_SIZE || data_size + sizeof(ipx_packet) - 1 != packet_size)