From b04cde56b84ff6347f08e325bee4e975662091f9 Mon Sep 17 00:00:00 2001 From: Alastair Poole Date: Sat, 3 Oct 2020 14:19:29 +0100 Subject: [PATCH] ui: options kthreads check. --- src/bin/evisum_config.c | 1 + src/bin/evisum_config.h | 3 +- src/bin/system/process.c | 104 +++++++++++++++++++++++++++++++++++++++ src/bin/system/process.h | 55 ++++----------------- src/bin/ui/ui.c | 62 ++++++++++++++++++++--- src/bin/ui/ui.h | 1 + 6 files changed, 171 insertions(+), 55 deletions(-) diff --git a/src/bin/evisum_config.c b/src/bin/evisum_config.c index 8895066..f272fa4 100644 --- a/src/bin/evisum_config.c +++ b/src/bin/evisum_config.c @@ -52,6 +52,7 @@ _config_init() Evisum_Config *cfg = calloc(1, sizeof(Evisum_Config)); cfg->version = CONFIG_VERSION; cfg->poll_delay = 3; + cfg->show_kthreads = 1; return cfg; } diff --git a/src/bin/evisum_config.h b/src/bin/evisum_config.h index ec3b30e..775ca3b 100644 --- a/src/bin/evisum_config.h +++ b/src/bin/evisum_config.h @@ -3,7 +3,7 @@ #include "ui/ui.h" -#define CONFIG_VERSION 0x0005 +#define CONFIG_VERSION 0x0006 typedef struct _Evisum_Config { @@ -14,6 +14,7 @@ typedef struct _Evisum_Config int height; int poll_delay; Eina_Bool effects; + Eina_Bool show_kthreads; } Evisum_Config; void config_init(void); diff --git a/src/bin/system/process.c b/src/bin/system/process.c index aaa81f3..f94152f 100644 --- a/src/bin/system/process.c +++ b/src/bin/system/process.c @@ -1111,3 +1111,107 @@ proc_info_all_get(void) return processes; } +static Eina_Bool +_child_add(Eina_List *parents, Proc_Info *child) +{ + Eina_List *l; + Proc_Info *parent; + + EINA_LIST_FOREACH(parents, l, parent) + { + if (parent->pid == child->ppid) + { + parent->children = eina_list_append(parent->children, child); + return 1; + } + } + + return 0; +} + +Eina_List * +proc_info_all_children_get() +{ + Proc_Info *proc; + Eina_List *l; + Eina_List *procs; + + procs = proc_info_all_get(); + + EINA_LIST_FOREACH(procs, l, proc) + { + int ok =_child_add(procs, proc); + (void) ok; + } + + return procs; +} + +Eina_List * +_append_wanted(Eina_List *wanted, Eina_List *tree) +{ + Eina_List *l; + Proc_Info *parent; + + EINA_LIST_FOREACH(tree, l, parent) + { + wanted = eina_list_append(wanted, parent); + if (parent->children) + wanted = _append_wanted(wanted, parent->children); + } + return wanted; +} + +Eina_List * +proc_info_pid_children_get(pid_t pid) +{ + Proc_Info *proc; + Eina_List *l, *procs, *wanted = NULL; + + procs = proc_info_all_children_get(); + + EINA_LIST_FOREACH(procs, l, proc) + { + if (!wanted && proc->pid == pid) + { + wanted = eina_list_append(wanted, proc); + if (proc->children) + wanted = _append_wanted(wanted, proc->children); + } + } + + EINA_LIST_FREE(procs, proc) + { + if (!eina_list_data_find(wanted, proc)) + { + proc_info_free(proc); + } + } + + return wanted; +} + +void +proc_info_all_children_free(Eina_List *pstree) +{ + Proc_Info *parent, *child; + + EINA_LIST_FREE(pstree, parent) + { + EINA_LIST_FREE(parent->children, child) + proc_info_pid_children_free(child); + proc_info_free(parent); + } +} + +void +proc_info_pid_children_free(Proc_Info *proc) +{ + Proc_Info *child; + + EINA_LIST_FREE(proc->children, child) + proc_info_free(child); + + proc_info_free(proc); +} + diff --git a/src/bin/system/process.h b/src/bin/system/process.h index 11b876c..83da6ae 100644 --- a/src/bin/system/process.h +++ b/src/bin/system/process.h @@ -1,21 +1,6 @@ #ifndef __PROC_H__ #define __PROC_H__ -/** - * @file - * @brief Routines for querying processes. - */ - -/** - * @brief Querying Processes - * @defgroup Proc - * - * @{ - * - * Query processes. - * - */ - #include #include #include @@ -50,53 +35,31 @@ typedef struct _Proc_Info char *thread_name; Eina_List *threads; + Eina_List *children; } Proc_Info; -/** - * Query a full list of running processes and return a list. - * - * @return A list of Proc_Info pointers for all processes. - */ Eina_List * proc_info_all_get(void); -/** - * Query a process for its current state. - * - * @param pid The process ID to query. - * - * @return A Proc_Info pointer containing the process information. - */ Proc_Info * proc_info_by_pid(int pid); -/** - * Free a Proc_Info * pointer; - * - * @param proc The object to free. - */ void proc_info_free(Proc_Info *proc); - -/** - * Enable or disable the listing of kernel threads. - * - * @param enabled Boolean true or false (show/hide). - */ void proc_info_kthreads_show_set(Eina_Bool enabled); -/** - * Return the current policy for listing kernel threads. - * - * @return True or false (enabled/disabled). - */ Eina_Bool proc_info_kthreads_show_get(void); -/** - * @} - */ +Eina_List * +proc_info_all_children_get(void); + +Eina_List * +proc_info_pid_children_get(pid_t pid); + +void +proc_info_pid_children_free(Proc_Info *procs); #endif diff --git a/src/bin/ui/ui.c b/src/bin/ui/ui.c index 44d146a..353a75e 100644 --- a/src/bin/ui/ui.c +++ b/src/bin/ui/ui.c @@ -33,6 +33,9 @@ _config_save(Ui *ui) _evisum_config->height = h; _evisum_config->effects = evisum_ui_effects_enabled_get(); _evisum_config->poll_delay = ui->poll_delay; + _evisum_config->show_kthreads = ui->show_kthreads; + + proc_info_kthreads_show_set(ui->show_kthreads); config_save(_evisum_config); } @@ -50,6 +53,9 @@ _config_load(Ui *ui) evas_object_resize(ui->win, _evisum_config->width, _evisum_config->height); evisum_ui_effects_enabled_set(_evisum_config->effects); + + ui->show_kthreads = _evisum_config->show_kthreads; + proc_info_kthreads_show_set(ui->show_kthreads); } static int @@ -1150,10 +1156,20 @@ _main_menu_slider_changed_cb(void *data EINA_UNUSED, Evas_Object *obj, void *eve _proc_pid_cpu_times_reset(ui); } +static void +_main_menu_show_threads_changed_cb(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED) +{ + Ui *ui = data; + + ui->show_kthreads = elm_check_state_get(obj); + _config_save(ui); +} + static void _main_menu_create(Ui *ui, Evas_Object *btn) { - Evas_Object *o, *bx, *hbox, *sep, *fr, *sli; + Evas_Object *o, *bx, *bx2, *hbox, *sep, *fr, *sli; + Evas_Object *chk; Evas_Coord ox, oy, ow, oh; evas_object_geometry_get(btn, &ox, &oy, &ow, &oh); @@ -1168,11 +1184,15 @@ _main_menu_create(Ui *ui, Evas_Object *btn) evas_object_show(bx); fr = elm_frame_add(o); - elm_object_text_set(fr, _("Options")); + elm_object_text_set(fr, _("Actions")); evas_object_size_hint_weight_set(fr, EXPAND, EXPAND); evas_object_size_hint_align_set(fr, FILL, FILL); evas_object_show(fr); + evas_object_size_hint_min_set(fr, 100, 100); + elm_object_content_set(fr, bx); + elm_object_content_set(o, fr); + hbox = elm_box_add(o); elm_box_horizontal_set(hbox, 1); evas_object_size_hint_align_set(hbox, FILL, FILL); @@ -1210,6 +1230,18 @@ _main_menu_create(Ui *ui, Evas_Object *btn) btn = _btn_create(hbox, "evisum", _("About"), _about_clicked_cb, ui); elm_box_pack_end(hbox, btn); + elm_box_pack_end(bx, hbox); + + fr = elm_frame_add(o); + elm_object_text_set(fr, _("Options")); + evas_object_size_hint_weight_set(fr, EXPAND, EXPAND); + evas_object_size_hint_align_set(fr, FILL, FILL); + evas_object_show(fr); + + bx2 = elm_box_add(o); + evas_object_size_hint_weight_set(bx2, EXPAND, EXPAND); + evas_object_size_hint_align_set(bx2, FILL, FILL); + evas_object_show(bx2); sli = elm_slider_add(o); evas_object_size_hint_weight_set(sli, EXPAND, EXPAND); @@ -1225,13 +1257,27 @@ _main_menu_create(Ui *ui, Evas_Object *btn) evas_object_smart_callback_add(sli, "changed", _main_menu_slider_changed_cb, ui); evas_object_show(sli); _main_menu_slider_changed_cb(ui, sli, NULL); + elm_box_pack_end(bx2, sli); - elm_box_pack_end(bx, hbox); - elm_box_pack_end(bx, sli); + sep = elm_separator_add(bx2); + evas_object_size_hint_align_set(sep, FILL, FILL); + evas_object_size_hint_weight_set(sep, EXPAND, EXPAND); + elm_separator_horizontal_set(sep, 1); + evas_object_show(sep); + elm_box_pack_end(bx2, sep); - evas_object_size_hint_min_set(fr, 100, 100); - elm_object_content_set(fr, bx); - elm_object_content_set(o, fr); + chk = elm_check_add(bx2); + evas_object_size_hint_weight_set(chk, EXPAND, EXPAND); + evas_object_size_hint_align_set(chk, FILL, FILL); + elm_object_text_set(chk, _("Show kernel threads?")); + elm_check_state_set(chk, _evisum_config->show_kthreads); + evas_object_show(chk); + evas_object_smart_callback_add(chk, "changed", + _main_menu_show_threads_changed_cb, ui); + elm_box_pack_end(bx2, chk); + + elm_object_content_set(fr, bx2); + elm_box_pack_end(bx, fr); elm_ctxpopup_direction_priority_set(o, ELM_CTXPOPUP_DIRECTION_UP, ELM_CTXPOPUP_DIRECTION_DOWN, ELM_CTXPOPUP_DIRECTION_LEFT, ELM_CTXPOPUP_DIRECTION_RIGHT); @@ -1534,7 +1580,7 @@ _evisum_key_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info) ui->show_self = !ui->show_self; if (ev->keyname[0] == 'k' || ev->keyname[0] == 'K') - proc_info_kthreads_show_set(!proc_info_kthreads_show_get()); + ui->show_kthreads = !ui->show_kthreads; _config_save(ui); } diff --git a/src/bin/ui/ui.h b/src/bin/ui/ui.h index fcc7fbe..c3c0132 100644 --- a/src/bin/ui/ui.h +++ b/src/bin/ui/ui.h @@ -104,6 +104,7 @@ typedef struct Ui Sort_Type sort_type; Eina_Bool sort_reverse; Eina_Bool show_self; + Eina_Bool show_kthreads; Eina_Bool shutdown_now; Ecore_Animator *animator;