diff --git a/config.def.h b/config.def.h index 60658fc8d9..b634f2ee07 100644 --- a/config.def.h +++ b/config.def.h @@ -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 diff --git a/configuration.c b/configuration.c index a8eeac4c32..d48e5d6f05 100644 --- a/configuration.c +++ b/configuration.c @@ -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 diff --git a/configuration.h b/configuration.h index 16cf0ade4d..74fb519a64 100644 --- a/configuration.h +++ b/configuration.h @@ -493,6 +493,7 @@ typedef struct settings unsigned audio_latency; unsigned fps_update_interval; + unsigned memory_update_interval; unsigned input_block_timeout; diff --git a/intl/msg_hash_lbl.h b/intl/msg_hash_lbl.h index c3111c8163..e8bca9e7bd 100644 --- a/intl/msg_hash_lbl.h +++ b/intl/msg_hash_lbl.h @@ -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" diff --git a/intl/msg_hash_us.h b/intl/msg_hash_us.h index 7f478bef0f..cec622b0cb 100644 --- a/intl/msg_hash_us.h +++ b/intl/msg_hash_us.h @@ -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." diff --git a/menu/cbs/menu_cbs_sublabel.c b/menu/cbs/menu_cbs_sublabel.c index e0f9e2cb31..09f0c8e0e0 100644 --- a/menu/cbs/menu_cbs_sublabel.c +++ b/menu/cbs/menu_cbs_sublabel.c @@ -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; diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index a4250ffe88..2cbbf19dd6 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -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; diff --git a/menu/menu_setting.c b/menu/menu_setting.c index 43c0781fd4..b8259a47ed 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -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, diff --git a/msg_hash.h b/msg_hash.h index abfd0de30c..88a721bbdd 100644 --- a/msg_hash.h +++ b/msg_hash.h @@ -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), diff --git a/retroarch.c b/retroarch.c index 48f7427228..3fd3232fb1 100644 --- a/retroarch.c +++ b/retroarch.c @@ -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)); diff --git a/ui/drivers/qt/options/osd.cpp b/ui/drivers/qt/options/osd.cpp index 38b3206ef7..512c57ddda 100644 --- a/ui/drivers/qt/options/osd.cpp +++ b/ui/drivers/qt/options/osd.cpp @@ -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);