From: notaz Date: Fri, 19 Nov 2010 17:22:13 +0000 (+0200) Subject: basic profiling X-Git-Tag: r1~71 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=pcsx_rearmed.git;a=commitdiff_plain;h=14dffdb7a0457fc647103deafa5f1cac12e888fb;hp=b60f2812208aa36dc8b9e8e90f02b608dafd0c00 basic profiling --- diff --git a/frontend/main.c b/frontend/main.c index e36ad481..884b6176 100644 --- a/frontend/main.c +++ b/frontend/main.c @@ -14,6 +14,7 @@ #include #include "plugin.h" +#include "pcnt.h" #include "../gui/Linux.h" #include "../libpcsxcore/misc.h" @@ -192,6 +193,7 @@ int main(int argc, char *argv[]) SysMessage("Failed loading plugins!"); return 1; } + pcnt_hook_plugins(); if (OpenPlugins() == -1) { return 1; diff --git a/frontend/pcnt.h b/frontend/pcnt.h new file mode 100644 index 00000000..57bc88ad --- /dev/null +++ b/frontend/pcnt.h @@ -0,0 +1,52 @@ + +enum pcounters { + PCNT_ALL, + PCNT_GPU, + PCNT_SPU, + PCNT_CNT +}; + +extern unsigned int pcounters[PCNT_CNT]; +extern unsigned int pcounter_starts[PCNT_CNT]; + +#define pcnt_start(id) \ + pcounter_starts[id] = pcnt_get() + +#define pcnt_end(id) \ + pcounters[id] += pcnt_get() - pcounter_starts[id] + +void pcnt_hook_plugins(void); + +static inline void pcnt_print(float fps) +{ + unsigned int total, gpu, spu, rem; + int i; + + for (i = 0; i < PCNT_CNT; i++) + pcounters[i] >>= 10; + + total = pcounters[PCNT_ALL]; + gpu = pcounters[PCNT_GPU]; + spu = pcounters[PCNT_SPU]; + rem = total - gpu - spu; + if (!total) + total++; + + printf("%2.1f %6u %6u %6u (%2d %2d %2d)\n", fps, gpu, spu, rem, + gpu * 100 / total, spu * 100 / total, rem * 100 / total); + + memset(pcounters, 0, sizeof(pcounters)); +} + +static inline unsigned int pcnt_get(void) +{ + unsigned int val; +#ifdef __ARM_ARCH_7A__ + __asm__ volatile("mrc p15, 0, %0, c9, c13, 0" + : "=r"(val)); +#else + val = 0; +#endif + return val; +} + diff --git a/frontend/plugin.c b/frontend/plugin.c index bea6eb5d..d6aca8a5 100644 --- a/frontend/plugin.c +++ b/frontend/plugin.c @@ -199,3 +199,76 @@ void *plugin_link(enum builtint_plugins_e id, const char *sym) return NULL; } +/* basic profile stuff */ +#include "pcnt.h" + +unsigned int pcounters[PCNT_CNT]; +unsigned int pcounter_starts[PCNT_CNT]; + +#define pc_hook_func(name, args, pargs, cnt) \ +extern void (*name) args; \ +static void (*o_##name) args; \ +static void w_##name args \ +{ \ + unsigned int pc_start = pcnt_get(); \ + o_##name pargs; \ + pcounters[cnt] += pcnt_get() - pc_start; \ +} + +#define pc_hook_func_ret(retn, name, args, pargs, cnt) \ +extern retn (*name) args; \ +static retn (*o_##name) args; \ +static retn w_##name args \ +{ \ + retn ret; \ + unsigned int pc_start = pcnt_get(); \ + ret = o_##name pargs; \ + pcounters[cnt] += pcnt_get() - pc_start; \ + return ret; \ +} + +pc_hook_func (GPU_writeStatus, (uint32_t a0), (a0), PCNT_GPU) +pc_hook_func (GPU_writeData, (uint32_t a0), (a0), PCNT_GPU) +pc_hook_func (GPU_writeDataMem, (uint32_t *a0, int a1), (a0, a1), PCNT_GPU) +pc_hook_func_ret(uint32_t, GPU_readStatus, (void), (), PCNT_GPU) +pc_hook_func_ret(uint32_t, GPU_readData, (void), (), PCNT_GPU) +pc_hook_func (GPU_readDataMem, (uint32_t *a0, int a1), (a0, a1), PCNT_GPU) +pc_hook_func_ret(long, GPU_dmaChain, (uint32_t *a0, int32_t a1), (a0, a1), PCNT_GPU) +pc_hook_func (GPU_updateLace, (void), (), PCNT_GPU) + +pc_hook_func (SPU_writeRegister, (unsigned long a0, unsigned short a1), (a0, a1), PCNT_SPU) +pc_hook_func_ret(unsigned short,SPU_readRegister, (unsigned long a0), (a0), PCNT_SPU) +pc_hook_func (SPU_writeDMA, (unsigned short a0), (a0), PCNT_SPU) +pc_hook_func_ret(unsigned short,SPU_readDMA, (void), (), PCNT_SPU) +pc_hook_func (SPU_writeDMAMem, (unsigned short *a0, int a1), (a0, a1), PCNT_SPU) +pc_hook_func (SPU_readDMAMem, (unsigned short *a0, int a1), (a0, a1), PCNT_SPU) +pc_hook_func (SPU_playADPCMchannel, (void *a0), (a0), PCNT_SPU) +pc_hook_func (SPU_async, (unsigned int a0), (a0), PCNT_SPU) +pc_hook_func (SPU_playCDDAchannel, (short *a0, int a1), (a0, a1), PCNT_SPU) + +#define hook_it(name) { \ + o_##name = name; \ + name = w_##name; \ +} + +void pcnt_hook_plugins(void) +{ + hook_it(GPU_writeStatus); + hook_it(GPU_writeData); + hook_it(GPU_writeDataMem); + hook_it(GPU_readStatus); + hook_it(GPU_readData); + hook_it(GPU_readDataMem); + hook_it(GPU_dmaChain); + hook_it(GPU_updateLace); + hook_it(SPU_writeRegister); + hook_it(SPU_readRegister); + hook_it(SPU_writeDMA); + hook_it(SPU_readDMA); + hook_it(SPU_writeDMAMem); + hook_it(SPU_readDMAMem); + hook_it(SPU_playADPCMchannel); + hook_it(SPU_async); + hook_it(SPU_playCDDAchannel); +} + diff --git a/plugins/dfxvideo/draw_fb.c b/plugins/dfxvideo/draw_fb.c index 39be291c..ce3f5154 100644 --- a/plugins/dfxvideo/draw_fb.c +++ b/plugins/dfxvideo/draw_fb.c @@ -64,9 +64,11 @@ static void blit(void) static int fbw, fbh, fb24bpp; +#include "pcnt.h" + void DoBufferSwap(void) { - static float fps_old; + static int fps_counter; if (PSXDisplay.DisplayMode.x == 0 || PSXDisplay.DisplayMode.y == 0) return; @@ -78,13 +80,18 @@ void DoBufferSwap(void) pl_fbdev_set_mode(fbw, fbh, fb24bpp ? 24 : 16); } - if (fps_cur != fps_old) { - printf("%2.1f\n", fps_cur); - fps_old = fps_cur; - } - blit(); pl_fbdev_flip(); + + pcnt_end(PCNT_ALL); + + if (++fps_counter == 60/6) { + //printf("%2.1f\n", fps_cur); + pcnt_print(fps_cur); + fps_counter = 0; + } + + pcnt_start(PCNT_ALL); } void DoClearScreenBuffer(void) // CLEAR DX BUFFER @@ -128,6 +135,7 @@ void CloseDisplay(void) { CloseMenu(); pl_fbdev_finish(); + //WriteConfig(); } void CreatePic(unsigned char * pMem)