diff options
author | Burt P <pburt0@gmail.com> | 2019-06-20 17:34:19 -0500 |
---|---|---|
committer | Leandro A. F. Pereira <leandro@hardinfo.org> | 2019-06-20 21:10:32 -0700 |
commit | 80c9eede822f4d2466bdead6d0b58ec49477401b (patch) | |
tree | baceec7307f97f4f91c73060a2796d070d60b682 | |
parent | db75710e03bdfa66aa972dcc4e30012364369046 (diff) |
move devices/memory to computer/memory usage
As discussed in
https://github.com/lpereira/hardinfo/issues/345
Signed-off-by: Burt P <pburt0@gmail.com>
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | includes/computer.h | 5 | ||||
-rw-r--r-- | includes/devices.h | 5 | ||||
-rw-r--r-- | modules/benchmark.c | 2 | ||||
-rw-r--r-- | modules/benchmark/bench_results.c | 2 | ||||
-rw-r--r-- | modules/computer.c | 48 | ||||
-rw-r--r-- | modules/computer/memory_usage.c (renamed from modules/devices/devmemory.c) | 7 | ||||
-rw-r--r-- | modules/devices.c | 43 |
8 files changed, 59 insertions, 55 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index c531ab1c..3806b1d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -135,6 +135,7 @@ set(MODULE_computer_SOURCES modules/computer/languages.c modules/computer/loadavg.c modules/computer/memory.c + modules/computer/memory_usage.c modules/computer/modules.c modules/computer/os.c modules/computer/uptime.c @@ -146,7 +147,6 @@ set(MODULE_devices_SOURCES modules/devices/${HARDINFO_ARCH}/processor.c modules/devices/gpu.c modules/devices/battery.c - modules/devices/devmemory.c modules/devices/dmi.c modules/devices/devicetree.c modules/devices/inputdevices.c diff --git a/includes/computer.h b/includes/computer.h index 9b70ae9a..05db78c3 100644 --- a/includes/computer.h +++ b/includes/computer.h @@ -159,4 +159,9 @@ void scan_modules_do(void); void scan_filesystems(void); void scan_users_do(void); +/* Memory Usage */ +extern GHashTable *memlabels; +void init_memory_labels(void); +void scan_memory_do(void); + #endif /* __COMPUTER_H__ */ diff --git a/includes/devices.h b/includes/devices.h index 7223b91e..71d125fe 100644 --- a/includes/devices.h +++ b/includes/devices.h @@ -48,10 +48,6 @@ gchar *processor_describe_default(GSList * processors); gchar *processor_describe_by_counting_names(GSList * processors); gchar *processor_frequency_desc(GSList *processors); -/* Memory */ -void init_memory_labels(void); -void scan_memory_do(void); - /* Printers */ void init_cups(void); @@ -85,7 +81,6 @@ extern gchar *storage_icons; extern gchar *storage_list; extern gchar *usb_list; extern gchar *usb_icons; -extern GHashTable *memlabels; extern GHashTable *_pci_devices; extern GHashTable *sensor_compute; extern GHashTable *sensor_labels; diff --git a/modules/benchmark.c b/modules/benchmark.c index 1a72e983..6af4d5c1 100644 --- a/modules/benchmark.c +++ b/modules/benchmark.c @@ -652,7 +652,7 @@ static gchar *get_benchmark_results() gchar *machine = module_call_method("devices::getProcessorName"); gchar *machineclock = module_call_method("devices::getProcessorFrequency"); - gchar *machineram = module_call_method("devices::getMemoryTotal"); + gchar *machineram = module_call_method("computer::getMemoryTotal"); gchar *result = g_strdup_printf("[param]\n" "machine=%s\n" "machineclock=%s\n" diff --git a/modules/benchmark/bench_results.c b/modules/benchmark/bench_results.c index d0239326..a4335151 100644 --- a/modules/benchmark/bench_results.c +++ b/modules/benchmark/bench_results.c @@ -156,7 +156,7 @@ bench_machine *bench_machine_this() { m->cpu_config = module_call_method("devices::getProcessorFrequencyDesc"); m->gpu_desc = module_call_method("devices::getGPUList"); m->ogl_renderer = module_call_method("computer::getOGLRenderer"); - tmp = module_call_method("devices::getMemoryTotal"); + tmp = module_call_method("computer::getMemoryTotal"); m->memory_kiB = atoi(tmp); free(tmp); diff --git a/modules/computer.c b/modules/computer.c index 2a8c56b5..4173f98b 100644 --- a/modules/computer.c +++ b/modules/computer.c @@ -47,6 +47,7 @@ gchar *callback_security(void); gchar *callback_modules(void); gchar *callback_boots(void); gchar *callback_locales(void); +gchar *callback_memory_usage(); gchar *callback_fs(void); gchar *callback_display(void); gchar *callback_network(void); @@ -65,6 +66,7 @@ void scan_modules(gboolean reload); void scan_boots(gboolean reload); void scan_locales(gboolean reload); void scan_fs(gboolean reload); +void scan_memory_usage(gboolean reload); void scan_display(gboolean reload); void scan_network(gboolean reload); void scan_users(gboolean reload); @@ -81,6 +83,7 @@ static ModuleEntry entries[] = { {N_("Kernel Modules"), "module.png", callback_modules, scan_modules, MODULE_FLAG_NONE}, {N_("Boots"), "boot.png", callback_boots, scan_boots, MODULE_FLAG_NONE}, {N_("Languages"), "language.png", callback_locales, scan_locales, MODULE_FLAG_NONE}, + {N_("Memory Usage"), "memory.png", callback_memory_usage, scan_memory_usage, MODULE_FLAG_NONE}, {N_("Filesystems"), "dev_removable.png", callback_fs, scan_fs, MODULE_FLAG_NONE}, {N_("Display"), "monitor.png", callback_display, scan_display, MODULE_FLAG_NONE}, {N_("Environment Variables"), "environment.png", callback_env_var, scan_env_var, MODULE_FLAG_NONE}, @@ -92,9 +95,10 @@ static ModuleEntry entries[] = { {NULL}, }; - gchar *module_list = NULL; Computer *computer = NULL; +gchar *meminfo = NULL; +gchar *lginterval = NULL; gchar *hi_more_info(gchar * entry) { @@ -126,7 +130,11 @@ gchar *hi_get_field(gchar * field) } else if (g_str_equal(field, _("Available entropy in /dev/random"))) { tmp = computer_get_entropy_avail(); } else { - tmp = g_strdup_printf("Unknown field: %s", field); + gchar *info = moreinfo_lookup_with_prefix("DEV", field); + if (info) + tmp = g_strdup(info); + else + tmp = g_strdup_printf("Unknown field: %s", field); } return tmp; } @@ -182,6 +190,13 @@ void scan_fs(gboolean reload) SCAN_END(); } +void scan_memory_usage(gboolean reload) +{ + SCAN_START(); + scan_memory_do(); + SCAN_END(); +} + void scan_display(gboolean reload) { SCAN_START(); @@ -316,6 +331,23 @@ gchar *callback_dev(void) } #endif /* GLIB_CHECK_VERSION(2,14,0) */ +gchar *callback_memory_usage() +{ + return g_strdup_printf("[Memory]\n" + "%s\n" + "[$ShellParam$]\n" + "ViewType=2\n" + "LoadGraphSuffix= kB\n" + "RescanInterval=2000\n" + "ColumnTitle$TextValue=%s\n" + "ColumnTitle$Extra1=%s\n" + "ColumnTitle$Value=%s\n" + "ShowColumnHeaders=true\n" + "%s\n", meminfo, + _("Field"), _("Description"), _("Value"), /* column labels */ + lginterval); +} + static gchar *detect_machine_type(void) { GDir *dir; @@ -780,6 +812,12 @@ gchar *get_audio_cards(void) return computer_get_alsacards(computer); } +gchar *get_memory_total(void) +{ + scan_memory_usage(FALSE); + return moreinfo_lookup ("DEV:MemTotal"); +} + ShellModuleMethod *hi_exported_methods(void) { static ShellModuleMethod m[] = { @@ -789,6 +827,7 @@ ShellModuleMethod *hi_exported_methods(void) {"getOGLRenderer", get_ogl_renderer}, {"getAudioCards", get_audio_cards}, {"getKernelModuleDescription", get_kernel_module_description}, + {"getMemoryTotal", get_memory_total}, {NULL} }; @@ -827,7 +866,7 @@ gchar *hi_module_get_summary(void) "Method=devices::getProcessorNameAndDesc\n" "[%s]\n" "Icon=memory.png\n" - "Method=devices::getMemoryTotal\n" + "Method=computer::getMemoryTotal\n" "[%s]\n" "Icon=module.png\n" "Method=devices::getMotherboard\n" @@ -851,6 +890,8 @@ gchar *hi_module_get_summary(void) void hi_module_deinit(void) { + g_hash_table_destroy(memlabels); + if (computer->os) { g_free(computer->os->kernel); g_free(computer->os->libc); @@ -883,6 +924,7 @@ void hi_module_deinit(void) void hi_module_init(void) { computer = g_new0(Computer, 1); + init_memory_labels(); } ModuleAbout *hi_module_get_about(void) diff --git a/modules/devices/devmemory.c b/modules/computer/memory_usage.c index 29094dd8..041d1591 100644 --- a/modules/devices/devmemory.c +++ b/modules/computer/memory_usage.c @@ -29,7 +29,12 @@ void scan_memory_do(void) if (offset == -1) { /* gah. linux 2.4 adds three lines of data we don't need in - /proc/meminfo */ + * /proc/meminfo. + * The lines look something like this: + * total: used: free: shared: buffers: cached: + * Mem: 3301101568 1523159040 1777942528 0 3514368 1450356736 + * Swap: 0 0 0 + */ gchar *os_kernel = module_call_method("computer::getOSKernel"); if (os_kernel) { offset = strstr(os_kernel, "Linux 2.4") ? 3 : 0; diff --git a/modules/devices.c b/modules/devices.c index a03ff9f9..a07bdcaa 100644 --- a/modules/devices.c +++ b/modules/devices.c @@ -42,7 +42,6 @@ gchar *callback_processors(); gchar *callback_gpu(); -gchar *callback_memory(); gchar *callback_battery(); gchar *callback_pci(); gchar *callback_sensors(); @@ -57,7 +56,6 @@ gchar *callback_device_resources(); void scan_processors(gboolean reload); void scan_gpu(gboolean reload); -void scan_memory(gboolean reload); void scan_battery(gboolean reload); void scan_pci(gboolean reload); void scan_sensors(gboolean reload); @@ -78,7 +76,6 @@ gchar *hi_more_info(gchar *entry); enum { ENTRY_DTREE, ENTRY_PROCESSOR, - ENTRY_MEMORY, ENTRY_GPU, ENTRY_PCI, ENTRY_USB, @@ -94,7 +91,6 @@ enum { static ModuleEntry entries[] = { [ENTRY_PROCESSOR] = {N_("Processor"), "processor.png", callback_processors, scan_processors, MODULE_FLAG_NONE}, - [ENTRY_MEMORY] = {N_("Memory"), "memory.png", callback_memory, scan_memory, MODULE_FLAG_NONE}, [ENTRY_GPU] = {N_("Graphics Processors"), "devices.png", callback_gpu, scan_gpu, MODULE_FLAG_NONE}, [ENTRY_PCI] = {N_("PCI Devices"), "devices.png", callback_pci, scan_pci, MODULE_FLAG_NONE}, [ENTRY_USB] = {N_("USB Devices"), "usb.png", callback_usb, scan_usb, MODULE_FLAG_NONE}, @@ -121,7 +117,6 @@ gchar *pci_list = NULL; gchar *input_list = NULL; gchar *storage_list = NULL; gchar *battery_list = NULL; -gchar *meminfo = NULL; gchar *lginterval = NULL; #include <vendor.h> @@ -343,12 +338,6 @@ gchar *get_processor_max_frequency(void) } } -gchar *get_memory_total(void) -{ - scan_memory(FALSE); - return moreinfo_lookup ("DEV:MemTotal"); -} - gchar *get_motherboard(void) { gchar *board_name, *board_vendor, *board_version; @@ -501,7 +490,6 @@ ShellModuleMethod *hi_exported_methods(void) {"getProcessorNameAndDesc", get_processor_name_and_desc}, {"getProcessorFrequency", get_processor_max_frequency}, {"getProcessorFrequencyDesc", get_processor_frequency_desc}, - {"getMemoryTotal", get_memory_total}, {"getStorageDevices", get_storage_devices}, {"getPrinters", get_printers}, {"getInputDevices", get_input_devices}, @@ -525,11 +513,6 @@ gchar *hi_more_info(gchar * entry) gchar *hi_get_field(gchar * field) { - gchar *info = moreinfo_lookup_with_prefix("DEV", field); - - if (info) - return g_strdup(info); - return g_strdup(field); } @@ -562,13 +545,6 @@ void scan_processors(gboolean reload) SCAN_END(); } -void scan_memory(gboolean reload) -{ - SCAN_START(); - scan_memory_do(); - SCAN_END(); -} - void scan_battery(gboolean reload) { SCAN_START(); @@ -653,23 +629,6 @@ gchar *callback_dtree() "ViewType=1\n", dtree_info); } -gchar *callback_memory() -{ - return g_strdup_printf("[Memory]\n" - "%s\n" - "[$ShellParam$]\n" - "ViewType=2\n" - "LoadGraphSuffix= kB\n" - "RescanInterval=2000\n" - "ColumnTitle$TextValue=%s\n" - "ColumnTitle$Extra1=%s\n" - "ColumnTitle$Value=%s\n" - "ShowColumnHeaders=true\n" - "%s\n", meminfo, - _("Field"), _("Description"), _("Value"), /* column labels */ - lginterval); -} - gchar *callback_battery() { return g_strdup_printf("%s\n" @@ -782,7 +741,6 @@ void hi_module_init(void) } #endif /* defined(ARCH_x86) */ - init_memory_labels(); init_cups(); sensors_init(); udisks2_init(); @@ -793,7 +751,6 @@ void hi_module_deinit(void) moreinfo_del_with_prefix("DEV"); sensors_shutdown(); udisks2_shutdown(); - g_hash_table_destroy(memlabels); g_module_close(cups); } |