From ad068dcff29d3b56e142aa86ae8cf5204ab1a3db Mon Sep 17 00:00:00 2001 From: Gabriel Corona Date: Tue, 25 Aug 2015 00:54:23 +0200 Subject: [PATCH] Bind profiling in X11 to F10 --- core/hw/pvr/Renderer_if.cpp | 8 ++++++++ core/linux-dist/main.cpp | 6 ++++++ core/linux-dist/x11.cpp | 14 ++++++++++++++ core/linux/nixprof/nixprof.cpp | 23 ++++++++++++++++++----- core/profiler/profiler.h | 3 ++- 5 files changed, 48 insertions(+), 6 deletions(-) diff --git a/core/hw/pvr/Renderer_if.cpp b/core/hw/pvr/Renderer_if.cpp index 5dc8183b5..e84ad1103 100644 --- a/core/hw/pvr/Renderer_if.cpp +++ b/core/hw/pvr/Renderer_if.cpp @@ -5,6 +5,10 @@ #include "deps/zlib/zlib.h" +#if FEAT_HAS_NIXPROF +#include "profiler/profiler.h" +#endif + /* rendv3 ideas @@ -221,6 +225,10 @@ bool rend_single_frame() void* rend_thread(void* p) { +#if FEAT_HAS_NIXPROF + install_prof_handler(1); +#endif + #if SET_AFNT cpu_set_t mask; diff --git a/core/linux-dist/main.cpp b/core/linux-dist/main.cpp index 71c197743..21c70e094 100755 --- a/core/linux-dist/main.cpp +++ b/core/linux-dist/main.cpp @@ -41,6 +41,9 @@ #include #endif +#if FEAT_HAS_NIXPROF +#include "profiler/profiler.h" +#endif int msgboxf(const wchar* text, unsigned int type, ...) { @@ -267,6 +270,9 @@ int main(int argc, wchar* argv[]) SetupInput(); #if !defined(TARGET_EMSCRIPTEN) + #if FEAT_HAS_NIXPROF + install_prof_handler(0); + #endif dc_run(); #else emscripten_set_main_loop(&dc_run, 100, false); diff --git a/core/linux-dist/x11.cpp b/core/linux-dist/x11.cpp index 9e629efa8..8981fea59 100644 --- a/core/linux-dist/x11.cpp +++ b/core/linux-dist/x11.cpp @@ -14,6 +14,10 @@ #include "linux-dist/x11.h" #include "linux-dist/main.h" +#if FEAT_HAS_NIXPROF +#include "profiler/profiler.h" +#endif + #if defined(TARGET_PANDORA) #define DEFAULT_FULLSCREEN 1 #define DEFAULT_WINDOW_WIDTH 800 @@ -72,6 +76,16 @@ void input_x11_handle() { die("death by escape key"); } +#if FEAT_HAS_NIXPROF + else if (e.type == KeyRelease && e.xkey.keycode == 76) // F10 button + { + if (sample_Switch(3000)) { + printf("Starting profiling\n"); + } else { + printf("Stopping profiling\n"); + } + } +#endif else if (e.type == KeyRelease && e.xkey.keycode == 95) // F11 button { x11_fullscreen = !x11_fullscreen; diff --git a/core/linux/nixprof/nixprof.cpp b/core/linux/nixprof/nixprof.cpp index 74eb4c283..517013e00 100644 --- a/core/linux/nixprof/nixprof.cpp +++ b/core/linux/nixprof/nixprof.cpp @@ -34,6 +34,7 @@ #include "hw/sh4/dyna/blockmanager.h" #include #include "deps/libelf/elf.h" +#include "profiler/profiler.h" #include "linux/context.h" @@ -202,7 +203,7 @@ static int str_ends_with(const char * str, const char * suffix) void sh4_jitsym(FILE* out); -static void* prof(void *ptr) +static void* profiler_main(void *ptr) { FILE* prof_out; char line[512]; @@ -265,11 +266,11 @@ static void* prof(void *ptr) do { tick_count++; - //printf("Sending SIGPROF %08X %08X\n",thread[0],thread[1]); + // printf("Sending SIGPROF %08X %08X\n",thread[0],thread[1]); for (int i = 0; i < 2; i++) pthread_kill(thread[i], SIGPROF); - //printf("Sent SIGPROF\n"); + // printf("Sent SIGPROF\n"); usleep(prof_wait); - //fwrite(&prof_address[0],1,sizeof(prof_address[0])*2,prof_out); + // fwrite(&prof_address[0],1,sizeof(prof_address[0])*2,prof_out); fprintf(prof_out, "%p %p\n", prof_address[0], prof_address[1]); if (!(tick_count % 10000)) @@ -285,12 +286,24 @@ static void* prof(void *ptr) return 0; } +bool sample_Switch(int freq) +{ + if (prof_run) { + sample_Stop(); + } else { + sample_Start(freq); + } + return prof_run; +} + void sample_Start(int freq) { + if (prof_run) + return; prof_wait = 1000000 / freq; printf("sampling profiler: starting %d hz %d wait\n", freq, prof_wait); prof_run = true; - pthread_create(&proft, NULL, prof, 0); + pthread_create(&proft, NULL, profiler_main, 0); } void sample_Stop() diff --git a/core/profiler/profiler.h b/core/profiler/profiler.h index cf825010b..eb5ead2fe 100644 --- a/core/profiler/profiler.h +++ b/core/profiler/profiler.h @@ -149,4 +149,5 @@ extern profiler_cfg prof; void install_prof_handler(int id); void sample_Start(int freq); void sample_Stop(); -void sample_Syms(u8* data,u32 len); \ No newline at end of file +bool sample_Switch(int freq); +void sample_Syms(u8* data,u32 len);