Show memory information in System Information

This commit is contained in:
twinaphex 2016-06-12 13:20:54 +02:00
parent c3056a0d06
commit d7c2201385
4 changed files with 90 additions and 8 deletions

View File

@ -1881,14 +1881,14 @@ static void frontend_linux_exitspawn(char *core_path, size_t core_path_size)
}
#endif
static uint32_t frontend_linux_get_mem_total(void)
static uint64_t frontend_linux_get_mem_total(void)
{
long pages = sysconf(_SC_PHYS_PAGES);
long page_size = sysconf(_SC_PAGE_SIZE);
return pages * page_size;
}
static uint32_t frontend_linux_get_mem_free(void)
static uint64_t frontend_linux_get_mem_free(void)
{
long pages = sysconf(_SC_AVPHYS_PAGES);
long page_size = sysconf(_SC_PAGE_SIZE);

View File

@ -309,7 +309,7 @@ enum frontend_architecture frontend_driver_get_cpu_architecture(void)
return frontend->get_architecture();
}
uint32_t frontend_driver_get_total_memory(void)
uint64_t frontend_driver_get_total_memory(void)
{
frontend_ctx_driver_t *frontend = frontend_get_ptr();
if (!frontend || !frontend->get_total_mem)
@ -317,7 +317,7 @@ uint32_t frontend_driver_get_total_memory(void)
return frontend->get_total_mem();
}
uint32_t frontend_driver_get_free_memory(void)
uint64_t frontend_driver_get_free_memory(void)
{
frontend_ctx_driver_t *frontend = frontend_get_ptr();
if (!frontend || !frontend->get_free_mem)

View File

@ -80,8 +80,8 @@ typedef struct frontend_ctx_driver
enum frontend_architecture (*get_architecture)(void);
enum frontend_powerstate (*get_powerstate)(int *seconds, int *percent);
int (*parse_drive_list)(void*);
uint32_t (*get_total_mem)(void);
uint32_t (*get_free_mem)(void);
uint64_t (*get_total_mem)(void);
uint64_t (*get_free_mem)(void);
const char *ident;
@ -155,9 +155,9 @@ bool frontend_driver_get_core_extension(char *s, size_t len);
bool frontend_driver_get_salamander_basename(char *s, size_t len);
uint32_t frontend_driver_get_total_memory(void);
uint64_t frontend_driver_get_total_memory(void);
uint32_t frontend_driver_get_free_memory(void);
uint64_t frontend_driver_get_free_memory(void);
RETRO_END_DECLS

View File

@ -597,6 +597,21 @@ static int menu_displaylist_parse_network_info(menu_displaylist_info_t *info)
#endif
#endif
static uint64_t bytes_to_kb(uint64_t bytes)
{
return bytes / 1024;
}
static uint64_t bytes_to_mb(uint64_t bytes)
{
return bytes / 1024 / 1024;
}
static uint64_t bytes_to_gb(uint64_t bytes)
{
return bytes_to_kb(bytes) / 1024 / 1024;
}
static int menu_displaylist_parse_system_info(menu_displaylist_info_t *info)
{
int controller;
@ -765,6 +780,73 @@ static int menu_displaylist_parse_system_info(menu_displaylist_info_t *info)
menu_entries_add(info->list, tmp, "",
MENU_SETTINGS_CORE_INFO_NONE, 0, 0);
{
char tmp[PATH_MAX_LENGTH] = {0};
char tmp2[PATH_MAX_LENGTH] = {0};
char tmp3[PATH_MAX_LENGTH] = {0};
uint64_t memory_free = frontend_driver_get_free_memory();
uint64_t memory_total = frontend_driver_get_total_memory();
if (memory_free != 0 && memory_total != 0)
{
#ifdef _WIN32
snprintf(tmp, sizeof(tmp),
"Memory (in bytes): %Iu/%Iu B",
memory_free,
memory_total
);
snprintf(tmp2, sizeof(tmp2),
"Memory (in megabytes): %Iu/%Iu MB",
bytes_to_mb(memory_free),
bytes_to_mb(memory_total)
);
snprintf(tmp3, sizeof(tmp3),
"Memory (in gigabytes): %Iu/%Iu GB",
bytes_to_gb(memory_free),
bytes_to_gb(memory_total)
);
#elif defined(__STDC_VERSION__) && __STDC_VERSION__>=199901L
snprintf(tmp, sizeof(tmp),
"Memory (in bytes) : %zu/%zu B",
memory_free,
memory_total
);
snprintf(tmp2, sizeof(tmp2),
"Memory (in megabytes) : %zu/%zu MB",
bytes_to_mb(memory_free),
bytes_to_mb(memory_total)
);
snprintf(tmp3, sizeof(tmp3),
"Memory (in gigabytes): %zu/%zu GB",
bytes_to_gb(memory_free),
bytes_to_gb(memory_total)
);
#else
snprintf(tmp, sizeof(tmp),
"Memory (in bytes): %lu/%lu B",
memory_free,
memory_total
);
snprintf(tmp2, sizeof(tmp2),
"Memory (in megabytes) : %1u/%1u MB",
bytes_to_mb(memory_free),
bytes_to_mb(memory_total)
);
snprintf(tmp3, sizeof(tmp3),
"Memory (in gigabytes) : %1u/%1u GB",
bytes_to_gb(memory_free),
bytes_to_gb(memory_total)
);
#endif
menu_entries_add(info->list, tmp, "",
MENU_SETTINGS_CORE_INFO_NONE, 0, 0);
menu_entries_add(info->list, tmp2, "",
MENU_SETTINGS_CORE_INFO_NONE, 0, 0);
menu_entries_add(info->list, tmp3, "",
MENU_SETTINGS_CORE_INFO_NONE, 0, 0);
}
}
if (frontend->get_powerstate)
{
int seconds = 0, percent = 0;