added cpu usage to minarch debug hud
This commit is contained in:
parent
d0d87e4a00
commit
bd615423f6
1 changed files with 57 additions and 16 deletions
|
|
@ -589,20 +589,23 @@ static bool environment_callback(unsigned cmd, void *data) { // copied from pico
|
||||||
|
|
||||||
// TODO: tmp? rename this HUD_*? support messages too?
|
// TODO: tmp? rename this HUD_*? support messages too?
|
||||||
SDL_Surface* digits;
|
SDL_Surface* digits;
|
||||||
#define DIGIT_WIDTH 14
|
#define DIGIT_WIDTH 18
|
||||||
#define DIGIT_HEIGHT 16
|
#define DIGIT_HEIGHT 16
|
||||||
|
#define DIGIT_TRACKING -4
|
||||||
enum {
|
enum {
|
||||||
DIGIT_SLASH = 10,
|
DIGIT_SLASH = 10,
|
||||||
DIGIT_DOT,
|
DIGIT_DOT,
|
||||||
|
DIGIT_PERCENT,
|
||||||
DIGIT_COUNT,
|
DIGIT_COUNT,
|
||||||
};
|
};
|
||||||
|
#define DIGIT_SPACE DIGIT_COUNT
|
||||||
static void FPS_init(void) {
|
static void FPS_init(void) {
|
||||||
// TODO: scale
|
// TODO: scale
|
||||||
digits = SDL_CreateRGBSurface(SDL_SWSURFACE,DIGIT_WIDTH*DIGIT_COUNT,DIGIT_HEIGHT,SCREEN_DEPTH, 0,0,0,0);
|
digits = SDL_CreateRGBSurface(SDL_SWSURFACE,DIGIT_WIDTH*DIGIT_COUNT,DIGIT_HEIGHT,SCREEN_DEPTH, 0,0,0,0);
|
||||||
SDL_FillRect(digits, NULL, RGB_BLACK);
|
SDL_FillRect(digits, NULL, RGB_BLACK);
|
||||||
|
|
||||||
SDL_Surface* digit;
|
SDL_Surface* digit;
|
||||||
char* chars[] = { "0","1","2","3","4","5","6","7","8","9","/",".", NULL };
|
char* chars[] = { "0","1","2","3","4","5","6","7","8","9","/",".","%", NULL };
|
||||||
char* c;
|
char* c;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (c = chars[i]) {
|
while (c = chars[i]) {
|
||||||
|
|
@ -613,8 +616,8 @@ static void FPS_init(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static int FPS_blitChar(int n, int x, int y) {
|
static int FPS_blitChar(int n, int x, int y) {
|
||||||
SDL_BlitSurface(digits, &(SDL_Rect){n*DIGIT_WIDTH,0,DIGIT_WIDTH,DIGIT_HEIGHT}, screen, &(SDL_Rect){x,y});
|
if (n!=DIGIT_SPACE) SDL_BlitSurface(digits, &(SDL_Rect){n*DIGIT_WIDTH,0,DIGIT_WIDTH,DIGIT_HEIGHT}, screen, &(SDL_Rect){x,y});
|
||||||
return x + DIGIT_WIDTH;
|
return x + DIGIT_WIDTH + DIGIT_TRACKING;
|
||||||
}
|
}
|
||||||
static int FPS_blitDouble(double num, int x, int y) {
|
static int FPS_blitDouble(double num, int x, int y) {
|
||||||
int i = num;
|
int i = num;
|
||||||
|
|
@ -664,8 +667,10 @@ static void FPS_quit(void) {
|
||||||
|
|
||||||
static int cpu_ticks = 0;
|
static int cpu_ticks = 0;
|
||||||
static int fps_ticks = 0;
|
static int fps_ticks = 0;
|
||||||
|
static int use_ticks = 0;
|
||||||
static double fps_double = 0;
|
static double fps_double = 0;
|
||||||
static double cpu_double = 0;
|
static double cpu_double = 0;
|
||||||
|
static double use_double = 0;
|
||||||
static uint32_t sec_start = 0;
|
static uint32_t sec_start = 0;
|
||||||
|
|
||||||
// TODO: flesh out
|
// TODO: flesh out
|
||||||
|
|
@ -1266,12 +1271,19 @@ static void video_refresh_callback(const void *data, unsigned width, unsigned he
|
||||||
if (frame>=fps) frame -= fps;
|
if (frame>=fps) frame -= fps;
|
||||||
}
|
}
|
||||||
|
|
||||||
int x = 0;
|
if (1) {
|
||||||
int y = SCREEN_HEIGHT - DIGIT_HEIGHT;
|
int x = 0;
|
||||||
if (fps_double) x = FPS_blitDouble(fps_double, x,y);
|
int y = SCREEN_HEIGHT - DIGIT_HEIGHT;
|
||||||
if (cpu_double) {
|
if (fps_double) x = FPS_blitDouble(fps_double, x,y);
|
||||||
x = FPS_blitChar(DIGIT_SLASH,x,y);
|
if (cpu_double) {
|
||||||
FPS_blitDouble(cpu_double, x,y);
|
x = FPS_blitChar(DIGIT_SLASH,x,y);
|
||||||
|
x = FPS_blitDouble(cpu_double, x,y);
|
||||||
|
}
|
||||||
|
if (use_double) {
|
||||||
|
x = FPS_blitChar(DIGIT_SPACE,x,y);
|
||||||
|
x = FPS_blitDouble(use_double, x,y);
|
||||||
|
FPS_blitChar(DIGIT_PERCENT,x,y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GFX_flip(screen);
|
GFX_flip(screen);
|
||||||
|
|
@ -1308,9 +1320,6 @@ static int ignore_menu = 0;
|
||||||
static void input_poll_callback(void) {
|
static void input_poll_callback(void) {
|
||||||
PAD_poll();
|
PAD_poll();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: too heavy? maybe but regardless,
|
// TODO: too heavy? maybe but regardless,
|
||||||
// this will cause it to go to sleep after
|
// this will cause it to go to sleep after
|
||||||
// 30 seconds--even while playing!
|
// 30 seconds--even while playing!
|
||||||
|
|
@ -1934,6 +1943,30 @@ void Menu_loop(void) {
|
||||||
POW_disableAutosleep();
|
POW_disableAutosleep();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned getUsage(void) { // from picoarch
|
||||||
|
long unsigned ticks = 0;
|
||||||
|
long ticksps = 0;
|
||||||
|
FILE *file = NULL;
|
||||||
|
|
||||||
|
file = fopen("/proc/self/stat", "r");
|
||||||
|
if (!file)
|
||||||
|
goto finish;
|
||||||
|
|
||||||
|
if (!fscanf(file, "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %lu", &ticks))
|
||||||
|
goto finish;
|
||||||
|
|
||||||
|
ticksps = sysconf(_SC_CLK_TCK);
|
||||||
|
|
||||||
|
if (ticksps)
|
||||||
|
ticks = ticks * 100 / ticksps;
|
||||||
|
|
||||||
|
finish:
|
||||||
|
if (file)
|
||||||
|
fclose(file);
|
||||||
|
|
||||||
|
return ticks;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc , char* argv[]) {
|
int main(int argc , char* argv[]) {
|
||||||
// force a stack overflow to ensure asan is linked and actually working
|
// force a stack overflow to ensure asan is linked and actually working
|
||||||
// char tmp[2];
|
// char tmp[2];
|
||||||
|
|
@ -1978,14 +2011,22 @@ int main(int argc , char* argv[]) {
|
||||||
|
|
||||||
if (1) {
|
if (1) {
|
||||||
cpu_ticks += 1;
|
cpu_ticks += 1;
|
||||||
|
static int last_use_ticks = 0;
|
||||||
uint32_t now = SDL_GetTicks();
|
uint32_t now = SDL_GetTicks();
|
||||||
if (now - sec_start>=1000) {
|
if (now - sec_start>=1000) {
|
||||||
fps_double = fps_ticks / ((double)(now - sec_start) / 1000);
|
double last_time = (double)(now - sec_start) / 1000;
|
||||||
cpu_double = cpu_ticks / ((double)(now - sec_start) / 1000);
|
fps_double = fps_ticks / last_time;
|
||||||
// printf("fps: %f (%f)\n", fps_double, cpu_double); fflush(stdout);
|
cpu_double = cpu_ticks / last_time;
|
||||||
|
use_ticks = getUsage();
|
||||||
|
if (use_ticks && last_use_ticks) {
|
||||||
|
use_double = (use_ticks - last_use_ticks) / last_time;
|
||||||
|
}
|
||||||
|
last_use_ticks = use_ticks;
|
||||||
sec_start = now;
|
sec_start = now;
|
||||||
cpu_ticks = 0;
|
cpu_ticks = 0;
|
||||||
fps_ticks = 0;
|
fps_ticks = 0;
|
||||||
|
|
||||||
|
// printf("fps: %f (%f)\n", fps_double, cpu_double); fflush(stdout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue