(Menu/OSD) Implement configurable update interval for memory usage display

Obtaining system memory metrics is generally an expensive operation.
This commit is contained in:
Hugo Hromic 2020-07-19 17:52:57 +01:00
parent 897a9de5be
commit 1e3fb9505c
11 changed files with 57 additions and 4 deletions

View File

@ -826,6 +826,9 @@ static const bool audio_enable_menu_bgm = false;
/* FPS display will be updated at the set interval (in frames) */
#define DEFAULT_FPS_UPDATE_INTERVAL 256
/* Memory status display will be updated at the set interval (in frames) */
#define DEFAULT_MEMORY_UPDATE_INTERVAL 256
/* Enables displaying the current frame count. */
#define DEFAULT_FRAMECOUNT_SHOW false

View File

@ -1816,6 +1816,7 @@ static struct config_uint_setting *populate_settings_uint(
SETTING_UINT("input_turbo_default_button", &settings->uints.input_turbo_default_button, true, turbo_default_btn, false);
SETTING_UINT("input_max_users", input_driver_get_uint(INPUT_ACTION_MAX_USERS), true, input_max_users, false);
SETTING_UINT("fps_update_interval", &settings->uints.fps_update_interval, true, DEFAULT_FPS_UPDATE_INTERVAL, false);
SETTING_UINT("memory_update_interval", &settings->uints.memory_update_interval, true, DEFAULT_MEMORY_UPDATE_INTERVAL, false);
SETTING_UINT("input_menu_toggle_gamepad_combo", &settings->uints.input_menu_toggle_gamepad_combo, true, menu_toggle_gamepad_combo, false);
SETTING_UINT("input_hotkey_block_delay", &settings->uints.input_hotkey_block_delay, true, DEFAULT_INPUT_HOTKEY_BLOCK_DELAY, false);
#ifdef GEKKO

View File

@ -493,6 +493,7 @@ typedef struct settings
unsigned audio_latency;
unsigned fps_update_interval;
unsigned memory_update_interval;
unsigned input_block_timeout;

View File

@ -4372,6 +4372,10 @@ MSG_HASH(
MENU_ENUM_LABEL_FPS_UPDATE_INTERVAL,
"fps_update_interval"
)
MSG_HASH(
MENU_ENUM_LABEL_MEMORY_UPDATE_INTERVAL,
"memory_update_interval"
)
MSG_HASH(
MENU_ENUM_LABEL_QUICK_MENU_SHOW_RESUME_CONTENT,
"quick_menu_show_resume_content"

View File

@ -3384,6 +3384,14 @@ MSG_HASH(
MENU_ENUM_LABEL_VALUE_MEMORY_SHOW,
"Display Memory Usage"
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_MEMORY_UPDATE_INTERVAL,
"Memory Usage Update Interval (In Frames)"
)
MSG_HASH(
MENU_ENUM_SUBLABEL_MEMORY_UPDATE_INTERVAL,
"Memory usage display will be updated at the set interval (in frames)."
)
MSG_HASH(
MENU_ENUM_SUBLABEL_MEMORY_SHOW,
"Displays the used and total amount of memory on the system."

View File

@ -216,6 +216,7 @@ DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_fps_show, MENU_
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_fps_update_interval, MENU_ENUM_SUBLABEL_FPS_UPDATE_INTERVAL)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_framecount_show, MENU_ENUM_SUBLABEL_FRAMECOUNT_SHOW)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_memory_show, MENU_ENUM_SUBLABEL_MEMORY_SHOW)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_memory_update_interval, MENU_ENUM_SUBLABEL_MEMORY_UPDATE_INTERVAL)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_statistics_show, MENU_ENUM_SUBLABEL_STATISTICS_SHOW)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_netplay_settings, MENU_ENUM_SUBLABEL_NETPLAY)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_user_bind_settings, MENU_ENUM_SUBLABEL_INPUT_USER_BINDS)
@ -3347,6 +3348,9 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs,
case MENU_ENUM_LABEL_MEMORY_SHOW:
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_memory_show);
break;
case MENU_ENUM_LABEL_MEMORY_UPDATE_INTERVAL:
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_memory_update_interval);
break;
case MENU_ENUM_LABEL_MENU_VIEWS_SETTINGS:
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_menu_views_settings_list);
break;

View File

@ -7549,6 +7549,7 @@ unsigned menu_displaylist_build_list(
settings_t *settings = config_get_ptr();
bool video_font_enable = settings->bools.video_font_enable;
bool video_fps_show = settings->bools.video_fps_show;
bool video_memory_show = settings->bools.video_memory_show;
#ifdef HAVE_GFX_WIDGETS
bool widgets_supported = video_driver_has_widgets();
bool menu_enable_widgets = settings->bools.menu_enable_widgets;
@ -7559,6 +7560,7 @@ unsigned menu_displaylist_build_list(
{MENU_ENUM_LABEL_FRAMECOUNT_SHOW, PARSE_ONLY_BOOL, true },
{MENU_ENUM_LABEL_STATISTICS_SHOW, PARSE_ONLY_BOOL, false },
{MENU_ENUM_LABEL_MEMORY_SHOW, PARSE_ONLY_BOOL, true },
{MENU_ENUM_LABEL_MEMORY_UPDATE_INTERVAL, PARSE_ONLY_UINT, false },
{MENU_ENUM_LABEL_MENU_SHOW_LOAD_CONTENT_ANIMATION, PARSE_ONLY_BOOL, false },
{MENU_ENUM_LABEL_NOTIFICATION_SHOW_AUTOCONFIG, PARSE_ONLY_BOOL, true },
{MENU_ENUM_LABEL_NOTIFICATION_SHOW_CHEATS_APPLIED, PARSE_ONLY_BOOL, true },
@ -7576,6 +7578,10 @@ unsigned menu_displaylist_build_list(
if (video_fps_show)
build_list[i].checked = true;
break;
case MENU_ENUM_LABEL_MEMORY_UPDATE_INTERVAL:
if (video_memory_show)
build_list[i].checked = true;
break;
case MENU_ENUM_LABEL_STATISTICS_SHOW:
if (video_font_enable)
build_list[i].checked = true;

View File

@ -12527,6 +12527,23 @@ static bool setting_append_list(
general_write_handler,
general_read_handler,
SD_FLAG_NONE);
(*list)[list_info->index - 1].action_ok = &setting_bool_action_left_with_refresh;
(*list)[list_info->index - 1].action_left = &setting_bool_action_left_with_refresh;
(*list)[list_info->index - 1].action_right = &setting_bool_action_right_with_refresh;
CONFIG_UINT(
list, list_info,
&settings->uints.memory_update_interval,
MENU_ENUM_LABEL_MEMORY_UPDATE_INTERVAL,
MENU_ENUM_LABEL_VALUE_MEMORY_UPDATE_INTERVAL,
DEFAULT_MEMORY_UPDATE_INTERVAL,
&group_info,
&subgroup_info,
parent_group,
general_write_handler,
general_read_handler);
(*list)[list_info->index - 1].action_ok = &setting_action_ok_uint_special;
menu_settings_list_current_add_range(list, list_info, 1, 512, 1, true, true);
CONFIG_BOOL(
list, list_info,

View File

@ -1596,6 +1596,7 @@ enum msg_hash_enums
MENU_LABEL(FPS_SHOW),
MENU_LABEL(FPS_UPDATE_INTERVAL),
MENU_LABEL(MEMORY_SHOW),
MENU_LABEL(MEMORY_UPDATE_INTERVAL),
MENU_LABEL(STATISTICS_SHOW),
MENU_LABEL(FRAMECOUNT_SHOW),
MENU_LABEL(BSV_RECORD_TOGGLE),

View File

@ -32336,6 +32336,7 @@ static void video_driver_frame(const void *data, unsigned width,
static retro_time_t curr_time;
static retro_time_t fps_time;
static float last_fps, frame_time;
static uint64_t last_used_memory, last_total_memory;
retro_time_t new_time;
video_frame_info_t video_info;
struct rarch_state *p_rarch = &rarch_st;
@ -32384,6 +32385,8 @@ static void video_driver_frame(const void *data, unsigned width,
{
unsigned fps_update_interval =
settings->uints.fps_update_interval;
unsigned memory_update_interval =
settings->uints.memory_update_interval;
size_t buf_pos = 1;
/* set this to 1 to avoid an offset issue */
unsigned write_index =
@ -32414,13 +32417,17 @@ static void video_driver_frame(const void *data, unsigned width,
if (video_info.memory_show)
{
char mem[128];
uint64_t mem_bytes_total = frontend_driver_get_total_memory();
uint64_t mem_bytes_used = mem_bytes_total - frontend_driver_get_free_memory();
if ((p_rarch->video_driver_frame_count % memory_update_interval) == 0)
{
last_total_memory = frontend_driver_get_total_memory();
last_used_memory = last_total_memory - frontend_driver_get_free_memory();
}
mem[0] = '\0';
snprintf(
mem, sizeof(mem), "MEM: %.2f/%.2fMB", mem_bytes_used / (1024.0f * 1024.0f),
mem_bytes_total / (1024.0f * 1024.0f));
mem, sizeof(mem), "MEM: %.2f/%.2fMB", last_used_memory / (1024.0f * 1024.0f),
last_total_memory / (1024.0f * 1024.0f));
if (status_text[buf_pos-1] != '\0')
strlcat(status_text, " || ", sizeof(status_text));
strlcat(status_text, mem, sizeof(status_text));

View File

@ -34,6 +34,7 @@ QWidget *NotificationsPage::widget()
notificationsGroup->add(MENU_ENUM_LABEL_FPS_UPDATE_INTERVAL);
notificationsGroup->add(MENU_ENUM_LABEL_FRAMECOUNT_SHOW);
notificationsGroup->add(MENU_ENUM_LABEL_MEMORY_SHOW);
notificationsGroup->add(MENU_ENUM_LABEL_MEMORY_UPDATE_INTERVAL);
notificationsGroup->add(MENU_ENUM_LABEL_STATISTICS_SHOW);
notificationsGroup->add(MENU_ENUM_LABEL_VIDEO_FONT_PATH);
notificationsGroup->add(MENU_ENUM_LABEL_VIDEO_FONT_SIZE);