1
0
mirror of https://github.com/solemnwarning/ipxwrapper synced 2024-12-30 16:45:37 +01:00

Add profiling for some ipxwrapper.dll functions.

This commit is contained in:
Daniel Collins 2021-01-20 20:51:16 +00:00
parent e686e8dbe2
commit 704bce5baf
4 changed files with 31 additions and 0 deletions

View File

@ -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);
}

View File

@ -27,6 +27,7 @@
#include <uthash.h>
#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);

View File

@ -0,0 +1,3 @@
FPROF_DECL(_deliver_packet)
FPROF_DECL(_handle_udp_recv)
FPROF_DECL(lock_sockets)

View File

@ -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)