Bind profiling in X11 to F10

This commit is contained in:
Gabriel Corona 2015-08-25 00:54:23 +02:00
parent 4ad6db345b
commit ad068dcff2
5 changed files with 48 additions and 6 deletions

View File

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

View File

@ -41,6 +41,9 @@
#include <sys/soundcard.h>
#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);

View File

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

View File

@ -34,6 +34,7 @@
#include "hw/sh4/dyna/blockmanager.h"
#include <set>
#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()

View File

@ -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);
bool sample_Switch(int freq);
void sample_Syms(u8* data,u32 len);