diff options
author | neonloop | 2021-08-24 15:09:09 +0000 |
---|---|---|
committer | neonloop | 2021-08-24 15:09:09 +0000 |
commit | 702d6adc2133e21861e227cdb1ae8b0e4a89e410 (patch) | |
tree | e8c1d630c194d0254cfe4b203c3609e54e151479 | |
parent | 38a49a2794e82568031c4315a0c797d23a920d69 (diff) | |
download | picoarch-702d6adc2133e21861e227cdb1ae8b0e4a89e410.tar.gz picoarch-702d6adc2133e21861e227cdb1ae8b0e4a89e410.tar.bz2 picoarch-702d6adc2133e21861e227cdb1ae8b0e4a89e410.zip |
Adds option for CPU % display
-rw-r--r-- | config.c | 1 | ||||
-rw-r--r-- | main.c | 42 | ||||
-rw-r--r-- | main.h | 2 | ||||
-rw-r--r-- | menu.c | 4 | ||||
-rw-r--r-- | options.c | 2 | ||||
-rw-r--r-- | options.h | 2 | ||||
-rw-r--r-- | plat.h | 2 | ||||
-rw-r--r-- | plat_sdl.c | 26 |
8 files changed, 68 insertions, 13 deletions
@@ -23,6 +23,7 @@ static const struct { void *val; } config_data[] = { CE_NUM(show_fps), + CE_NUM(show_cpu), CE_NUM(limit_frames), CE_NUM(audio_buffer_size), CE_NUM(scale_size), @@ -30,8 +30,6 @@ static int last_screenshot = 0; static uint32_t vsyncs; static uint32_t renders; -static float vsyncsps; -static float rendersps; static void extract_core_name(const char* core_file) { char *suffix = NULL; @@ -212,6 +210,8 @@ finish: void set_defaults(void) { show_fps = 0; + show_cpu = 0; + show_hud = 1; limit_frames = 1; enable_audio = 1; audio_buffer_size = 5; @@ -378,8 +378,8 @@ void handle_emu_action(emu_action action) } #endif break; - case EACTION_TOGGLE_FPS: - show_fps = !show_fps; + case EACTION_TOGGLE_HUD: + show_hud = !show_hud; /* Force the hud to clear */ plat_video_set_msg(NULL, 0, 0); break; @@ -443,26 +443,46 @@ void pa_track_render(void) { renders++; } +#define CPU_MSG_LEN 10 static void count_fps(void) { char msg[HUD_LEN]; - static unsigned int nextsec = 0; + static unsigned last_cpu_ticks = 0; unsigned int ticks = 0; - if (show_fps) { + if (show_hud && (show_fps || show_cpu)) { ticks = plat_get_ticks_ms(); if (ticks > nextsec) { float last_time = (ticks - nextsec + 1000) / 1000.0f; if (last_time > 0) { - vsyncsps = vsyncs / last_time; - rendersps = renders / last_time; - vsyncs = 0; - renders = 0; + char cpu_msg[CPU_MSG_LEN]; + char fps_msg[HUD_LEN - CPU_MSG_LEN]; + + cpu_msg[0] = fps_msg[0] = '\0'; nextsec = ticks + 1000; - snprintf(msg, HUD_LEN, "FPS: %.1f (%.0f)", rendersps, vsyncsps); + if (show_fps) { + float vsyncsps = vsyncs / last_time; + float rendersps = renders / last_time; + vsyncs = 0; + renders = 0; + snprintf(fps_msg, sizeof(fps_msg), "FPS: %.1f (%.0f)", rendersps, vsyncsps); + } + + if (show_cpu) { + unsigned cpu_ticks = plat_cpu_ticks(); + if (cpu_ticks && last_cpu_ticks) { + float cpu_percent = (cpu_ticks - last_cpu_ticks) / last_time; + snprintf(cpu_msg, sizeof(cpu_msg), "%.1f%%", cpu_percent); + } + last_cpu_ticks = cpu_ticks; + } + + snprintf(msg, HUD_LEN, "%-*s%*s", + (HUD_LEN - CPU_MSG_LEN - 1), fps_msg, + CPU_MSG_LEN - 1, cpu_msg); plat_video_set_msg(msg, 1, 1100); } } @@ -10,7 +10,7 @@ typedef enum { EACTION_NONE = 0, EACTION_MENU, - EACTION_TOGGLE_FPS, + EACTION_TOGGLE_HUD, EACTION_TOGGLE_FF, EACTION_SAVE_STATE, EACTION_LOAD_STATE, @@ -59,7 +59,7 @@ me_bind_action emuctrl_actions[] = { { "Save State ", 1 << EACTION_SAVE_STATE }, { "Load State ", 1 << EACTION_LOAD_STATE }, - { "Show/Hide FPS ", 1 << EACTION_TOGGLE_FPS }, + { "Toggle FPS/CPU% ", 1 << EACTION_TOGGLE_HUD }, { "Toggle FF ", 1 << EACTION_TOGGLE_FF }, { "Take Screenshot ", 1 << EACTION_SCREENSHOT }, { NULL, 0 } @@ -232,6 +232,7 @@ static const char h_rm_config_game[] = "Removes game-specific config file"; static const char h_restore_def[] = "Switches back to default settings"; static const char h_show_fps[] = "Shows frames and vsyncs per second"; +static const char h_show_cpu[] = "Shows CPU usage"; static const char h_audio_buffer_size[] = "The size of the audio buffer, in frames. Higher\n" @@ -255,6 +256,7 @@ static const char *men_scale_filter[] = { "Nearest", "Sharp", "Smooth", NULL}; static menu_entry e_menu_video_options[] = { mee_onoff_h ("Show FPS", 0, show_fps, 1, h_show_fps), + mee_onoff_h ("Show CPU %", 0, show_cpu, 1, h_show_cpu), mee_enum_h ("Screen size", 0, scale_size, men_scale_size, h_scale_size), mee_enum_h ("Filter", 0, scale_filter, men_scale_filter, h_scale_filter), mee_range_h ("Audio buffer", 0, audio_buffer_size, 1, 15, h_audio_buffer_size), @@ -7,6 +7,8 @@ #include "util.h" int show_fps; +int show_cpu; +int show_hud; int limit_frames; int enable_audio; unsigned audio_buffer_size; @@ -4,6 +4,8 @@ #include "scale.h" extern int show_fps; +extern int show_cpu; +extern int show_hud; extern int limit_frames; extern int enable_audio; extern unsigned audio_buffer_size; @@ -24,6 +24,8 @@ void plat_video_process(const void *data, unsigned width, unsigned height, size_ void plat_video_flip(void); void plat_video_close(void); +unsigned plat_cpu_ticks(void); + float plat_sound_capacity(void); void plat_sound_write(const struct audio_frame *data, int frames); void plat_sound_resize_buffer(void); @@ -1,4 +1,5 @@ #include <SDL/SDL.h> +#include <unistd.h> #include "core.h" #include "libpicofe/fonts.h" #include "libpicofe/plat.h" @@ -227,6 +228,31 @@ void plat_video_close(void) { } +unsigned plat_cpu_ticks(void) +{ + 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; +} + static void plat_sound_callback(void *unused, uint8_t *stream, int len) { int16_t *p = (int16_t *)stream; |