process: processs tree (proc view).

Also add the command line evisum -p <pid> to the IPC.

Not done...WIP.
This commit is contained in:
Alastair Poole 2020-10-27 03:33:01 +00:00
parent 7f05af18d6
commit 860358c3c8
7 changed files with 171 additions and 22 deletions

View File

@ -27,12 +27,15 @@ _evisum_server_server_client_connect_cb(void *data EINA_UNUSED, int type EINA_UN
Ecore_Con_Event_Client_Data *ev; Ecore_Con_Event_Client_Data *ev;
Evisum_Action *action; Evisum_Action *action;
Ui *ui; Ui *ui;
int *pid;
ev = event; ev = event;
action = ev->data; action = ev->data;
ui = data; ui = data;
evisum_ui_activate(ui, *action); pid = ev->data + sizeof(int);
evisum_ui_activate(ui, *action, *pid);
ecore_con_client_del(ev->client); ecore_con_client_del(ev->client);
@ -69,6 +72,7 @@ evisum_server_init(void *data)
typedef struct _Evisum_Server_Client { typedef struct _Evisum_Server_Client {
Ecore_Con_Server *srv; Ecore_Con_Server *srv;
Evisum_Action action; Evisum_Action action;
int pid;
Eina_Bool success; Eina_Bool success;
} Evisum_Server_Client; } Evisum_Server_Client;
@ -120,13 +124,14 @@ _evisum_server_client_connect_cb(void *data, int type EINA_UNUSED, void *event E
if (client->srv != srv) return ECORE_CALLBACK_RENEW; if (client->srv != srv) return ECORE_CALLBACK_RENEW;
ecore_con_server_send(srv, &client->action, sizeof(Evisum_Action)); ecore_con_server_send(srv, &client->action, sizeof(Evisum_Action));
ecore_con_server_send(srv, &client->pid, sizeof(int));
ecore_con_server_flush(srv); ecore_con_server_flush(srv);
return ECORE_CALLBACK_DONE; return ECORE_CALLBACK_DONE;
} }
Eina_Bool Eina_Bool
evisum_server_client_add(Evisum_Action action) evisum_server_client_add(Evisum_Action action, int pid)
{ {
Evisum_Server_Client *client; Evisum_Server_Client *client;
Ecore_Con_Server *srv = ecore_con_server_connect(ECORE_CON_LOCAL_USER, LISTEN_SOCKET_NAME, 0, NULL); Ecore_Con_Server *srv = ecore_con_server_connect(ECORE_CON_LOCAL_USER, LISTEN_SOCKET_NAME, 0, NULL);
@ -139,6 +144,7 @@ evisum_server_client_add(Evisum_Action action)
if (!client) return EINA_FALSE; if (!client) return EINA_FALSE;
client->action = action; client->action = action;
client->pid = pid;
client->srv = srv; client->srv = srv;
ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, _evisum_server_client_connect_cb, client); ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, _evisum_server_client_connect_cb, client);

View File

@ -11,6 +11,6 @@ void
evisum_server_shutdown(void); evisum_server_shutdown(void);
Eina_Bool Eina_Bool
evisum_server_client_add(Evisum_Action action); evisum_server_client_add(Evisum_Action action, int pid);
#endif #endif

View File

@ -15,7 +15,7 @@ int
main(int argc, char **argv) main(int argc, char **argv)
{ {
Ui *ui; Ui *ui;
int i; int i, pid = -1;
Evisum_Action action = EVISUM_ACTION_DEFAULT; Evisum_Action action = EVISUM_ACTION_DEFAULT;
for (i = 0; i < argc; i++) for (i = 0; i < argc; i++)
@ -35,6 +35,11 @@ main(int argc, char **argv)
action = EVISUM_ACTION_STORAGE; action = EVISUM_ACTION_STORAGE;
else if (!strcmp(argv[i], "-s")) else if (!strcmp(argv[i], "-s"))
action = EVISUM_ACTION_SENSORS; action = EVISUM_ACTION_SENSORS;
else if (!strcmp(argv[i], "-p") && i < (argc -1))
{
action = EVISUM_ACTION_PROCESS;
pid = atoi(argv[i+1]);
}
} }
eina_init(); eina_init();
@ -49,7 +54,7 @@ main(int argc, char **argv)
textdomain(PACKAGE); textdomain(PACKAGE);
#endif #endif
if (evisum_server_client_add(action)) if (evisum_server_client_add(action, pid))
{ {
ecore_main_loop_begin(); ecore_main_loop_begin();
return 0; return 0;
@ -59,7 +64,7 @@ main(int argc, char **argv)
if (!ui) return 1; if (!ui) return 1;
evisum_server_init(ui); evisum_server_init(ui);
evisum_ui_activate(ui, action); evisum_ui_activate(ui, action, pid);
ecore_main_loop_begin(); ecore_main_loop_begin();

View File

@ -925,24 +925,30 @@ _item_menu_actions_add(Evas_Object *menu, Elm_Object_Item *menu_it,
_("Debug"), _item_menu_debug_cb, ui); _("Debug"), _item_menu_debug_cb, ui);
} }
static void
_process_win_add(Evas_Object *parent, int pid, int delay)
{
Proc_Info *proc;
proc = proc_info_by_pid(pid);
if (!proc) return;
ui_process_win_add(parent, proc->pid, proc->command, delay);
proc_info_free(proc);
}
static void static void
_item_menu_properties_cb(void *data, Evas_Object *obj EINA_UNUSED, _item_menu_properties_cb(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED) void *event_info EINA_UNUSED)
{ {
Ui *ui; Ui *ui;
Proc_Info *proc;
ui = data; ui = data;
_item_menu_cancel_cb(ui, NULL, NULL); _item_menu_cancel_cb(ui, NULL, NULL);
proc = proc_info_by_pid(ui->selected_pid); _process_win_add(ui->win, ui->selected_pid, ui->settings.poll_delay);
if (!proc) return;
ui_process_win_add(ui->win, proc->pid, proc->command,
ui->settings.poll_delay);
proc_info_free(proc);
} }
static Evas_Object * static Evas_Object *
@ -1830,14 +1836,16 @@ _ui_init_system_probe(Ui *ui)
} }
void void
evisum_ui_activate(Ui *ui, Evisum_Action action) evisum_ui_activate(Ui *ui, Evisum_Action action, int pid)
{ {
switch (action) switch (action)
{ {
case EVISUM_ACTION_DEFAULT: case EVISUM_ACTION_DEFAULT:
case EVISUM_ACTION_PROCESS:
ui_main_win_add(ui); ui_main_win_add(ui);
break; break;
case EVISUM_ACTION_PROCESS:
_process_win_add(NULL, pid, 3);
break;
case EVISUM_ACTION_CPU: case EVISUM_ACTION_CPU:
ui_win_cpu_add(ui); ui_win_cpu_add(ui);
break; break;

View File

@ -126,6 +126,6 @@ void
evisum_ui_shutdown(Ui *ui); evisum_ui_shutdown(Ui *ui);
void void
evisum_ui_activate(Ui *ui, Evisum_Action action); evisum_ui_activate(Ui *ui, Evisum_Action action, int pid);
#endif #endif

View File

@ -326,9 +326,9 @@ _thread_info_set(Ui_Process *ui, Proc_Info *proc)
EINA_LIST_FREE(threads, t) EINA_LIST_FREE(threads, t)
{ {
if (!it) if (!it)
_item_del(t, NULL); _item_del(t, NULL);
else else
{ {
Thread_Info *prev = elm_object_item_data_get(it); Thread_Info *prev = elm_object_item_data_get(it);
if (prev) if (prev)
@ -361,6 +361,67 @@ _time_string(int64_t epoch)
return strdup(buf); return strdup(buf);
} }
static char *
_tree_text_get(void *data, Evas_Object *obj, const char *part)
{
Proc_Info *child = data;
char buf[256];
snprintf(buf, sizeof(buf), "%s (%d) ", child->command, child->pid);
return strdup(buf);
}
static void
_tree_populate(Evas_Object *genlist_tree, Elm_Object_Item *parent, Eina_List *children)
{
Elm_Genlist_Item_Class *itc;
Eina_List *l;
Elm_Object_Item *it;
Proc_Info *child;
itc = elm_genlist_item_class_new();
itc->item_style = "default";
itc->func.content_get = NULL;
itc->func.text_get = _tree_text_get;
itc->func.filter_get = NULL;
itc->func.del = NULL;
EINA_LIST_FOREACH(children, l, child)
{
it = elm_genlist_item_append(genlist_tree, itc, child, parent,
child->children ? ELM_GENLIST_ITEM_TREE : ELM_GENLIST_ITEM_NONE, NULL, NULL);
elm_genlist_item_update(it);
if (child->children)
_tree_populate(genlist_tree, it, child->children);
}
elm_genlist_item_class_free(itc);
}
static Eina_Bool
_tree_view_update(void *data)
{
Eina_List *children, *l;
Proc_Info *child;
Ui_Process *ui = data;
children = proc_info_pid_children_get(ui->selected_pid);
EINA_LIST_FOREACH(children, l, child)
{
if (child->pid == ui->selected_pid)
{
_tree_populate(ui->genlist_tree, NULL, child->children);
break;
}
}
elm_genlist_realized_items_update(ui->genlist_tree);
// XXX: free (tired now)...
return EINA_TRUE;
}
static Eina_Bool static Eina_Bool
_proc_info_update(void *data) _proc_info_update(void *data)
{ {
@ -856,6 +917,43 @@ _threads_tab_add(Evas_Object *parent, Ui_Process *ui)
return frame; return frame;
} }
static Evas_Object *
_tree_tab_add(Evas_Object *parent, Ui_Process *ui)
{
Evas_Object *frame, *box, *genlist;
int r, g, b, a;
frame = elm_frame_add(parent);
evas_object_size_hint_weight_set(frame, EXPAND, EXPAND);
evas_object_size_hint_align_set(frame, FILL, FILL);
elm_object_text_set(frame, _("Children"));
if (evisum_ui_effects_enabled_get())
{
evas_object_color_get(frame, &r, &g, &b, &a);
evas_object_color_set(frame, r * 0.75, g * 0.75, b * 0.75, a * 0.75);
}
box = elm_box_add(parent);
evas_object_size_hint_weight_set(box, EXPAND, EXPAND);
evas_object_size_hint_align_set(box, FILL, FILL);
evas_object_show(box);
elm_object_content_set(frame, box);
ui->genlist_tree = genlist = elm_genlist_add(parent);
evas_object_data_set(genlist, "ui", ui);
elm_object_focus_allow_set(genlist, EINA_FALSE);
elm_genlist_homogeneous_set(genlist, EINA_TRUE);
elm_genlist_select_mode_set(genlist, ELM_OBJECT_SELECT_MODE_NONE);
evas_object_size_hint_weight_set(genlist, EXPAND, EXPAND);
evas_object_size_hint_align_set(genlist, FILL, FILL);
evas_object_show(genlist);
elm_box_pack_end(box, genlist);
return frame;
}
static Evas_Object * static Evas_Object *
_info_tab_add(Evas_Object *parent, Ui_Process *ui) _info_tab_add(Evas_Object *parent, Ui_Process *ui)
{ {
@ -898,8 +996,10 @@ _hide_all(Ui_Process *ui, Evas_Object *btn)
elm_object_disabled_set(ui->btn_main, EINA_FALSE); elm_object_disabled_set(ui->btn_main, EINA_FALSE);
elm_object_disabled_set(ui->btn_info, EINA_FALSE); elm_object_disabled_set(ui->btn_info, EINA_FALSE);
elm_object_disabled_set(ui->btn_thread, EINA_FALSE); elm_object_disabled_set(ui->btn_thread, EINA_FALSE);
elm_object_disabled_set(ui->btn_tree, EINA_FALSE);
elm_object_disabled_set(btn, EINA_TRUE); elm_object_disabled_set(btn, EINA_TRUE);
evas_object_hide(ui->main_view); evas_object_hide(ui->main_view);
evas_object_hide(ui->tree_view);
evas_object_hide(ui->info_view); evas_object_hide(ui->info_view);
evas_object_hide(ui->thread_view); evas_object_hide(ui->thread_view);
} }
@ -916,6 +1016,18 @@ _btn_process_clicked_cb(void *data, Evas_Object *obj EINA_UNUSED,
evas_object_show(ui->main_view); evas_object_show(ui->main_view);
} }
static void
_btn_tree_clicked_cb(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Ui_Process *ui;
ui = data;
_hide_all(ui, obj);
evas_object_show(ui->tree_view);
}
static void static void
_btn_threads_clicked_cb(void *data, Evas_Object *obj EINA_UNUSED, _btn_threads_clicked_cb(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED) void *event_info EINA_UNUSED)
@ -956,7 +1068,7 @@ _btn_info_clicked_cb(void *data, Evas_Object *obj EINA_UNUSED,
elm_object_text_set(ui->entry_info, elm_object_text_set(ui->entry_info,
eina_slstr_printf(_("No documentation found for %s."), eina_slstr_printf(_("No documentation found for %s."),
ui->selected_cmd)); ui->selected_cmd));
} }
} }
else else
{ {
@ -1017,6 +1129,17 @@ _tabs_add(Evas_Object *parent, Ui_Process *ui)
evas_object_size_hint_align_set(pad, FILL, FILL); evas_object_size_hint_align_set(pad, FILL, FILL);
evas_object_show(pad); evas_object_show(pad);
btn = evisum_ui_tab_add(parent, &ui->btn_tree, _("Children"),
_btn_tree_clicked_cb, ui);
elm_object_content_set(pad, btn);
elm_box_pack_end(hbox, pad);
pad = elm_frame_add(parent);
elm_object_style_set(pad, "pad_small");
evas_object_size_hint_weight_set(pad, 0.0, EXPAND);
evas_object_size_hint_align_set(pad, FILL, FILL);
evas_object_show(pad);
btn = evisum_ui_tab_add(parent, &ui->btn_thread, _("Threads"), btn = evisum_ui_tab_add(parent, &ui->btn_thread, _("Threads"),
_btn_threads_clicked_cb, ui); _btn_threads_clicked_cb, ui);
elm_object_content_set(pad, btn); elm_object_content_set(pad, btn);
@ -1112,10 +1235,12 @@ ui_process_win_add(Evas_Object *parent_win, int pid, const char *cmd, int poll_d
evas_object_show(ui->content); evas_object_show(ui->content);
ui->main_view = _process_tab_add(win, ui); ui->main_view = _process_tab_add(win, ui);
ui->tree_view = _tree_tab_add(win, ui);
ui->thread_view = _threads_tab_add(win, ui); ui->thread_view = _threads_tab_add(win, ui);
ui->info_view = _info_tab_add(win, ui); ui->info_view = _info_tab_add(win, ui);
elm_table_pack(ui->content, ui->info_view, 0, 0, 1, 1); elm_table_pack(ui->content, ui->info_view, 0, 0, 1, 1);
elm_table_pack(ui->content, ui->tree_view, 0, 0, 1, 1);
elm_table_pack(ui->content, ui->main_view, 0, 0, 1, 1); elm_table_pack(ui->content, ui->main_view, 0, 0, 1, 1);
elm_table_pack(ui->content, ui->thread_view, 0, 0, 1, 1); elm_table_pack(ui->content, ui->thread_view, 0, 0, 1, 1);
@ -1126,8 +1251,9 @@ ui_process_win_add(Evas_Object *parent_win, int pid, const char *cmd, int poll_d
_win_resize_cb, ui); _win_resize_cb, ui);
evas_object_resize(win, 480 * elm_config_scale_get(), -1); evas_object_resize(win, 480 * elm_config_scale_get(), -1);
evas_object_geometry_get(parent_win, &x, &y, &w, &h); if (parent_win)
if (x > 0 && y > 0) evas_object_geometry_get(parent_win, &x, &y, &w, &h);
if (parent_win && x > 0 && y > 0)
evas_object_move(win, x + 20, y + 10); evas_object_move(win, x + 20, y + 10);
else else
elm_win_center(win, EINA_TRUE, EINA_TRUE); elm_win_center(win, EINA_TRUE, EINA_TRUE);
@ -1139,5 +1265,6 @@ ui_process_win_add(Evas_Object *parent_win, int pid, const char *cmd, int poll_d
eina_lock_new(&_lock); eina_lock_new(&_lock);
_proc_info_update(ui); _proc_info_update(ui);
_tree_view_update(ui);
} }

View File

@ -9,16 +9,19 @@ typedef struct _Ui_Process {
Evas_Object *content; Evas_Object *content;
Evas_Object *btn_main; Evas_Object *btn_main;
Evas_Object *btn_tree;
Evas_Object *btn_info; Evas_Object *btn_info;
Evas_Object *btn_thread; Evas_Object *btn_thread;
Evas_Object *main_view; Evas_Object *main_view;
Evas_Object *tree_view;
Evas_Object *info_view; Evas_Object *info_view;
Evas_Object *thread_view; Evas_Object *thread_view;
Evas_Object *entry_info; Evas_Object *entry_info;
Evas_Object *genlist_threads; Evas_Object *genlist_threads;
Evas_Object *genlist_tree;
Evisum_Ui_Cache *cache; Evisum_Ui_Cache *cache;
Evas_Object *entry_pid_cmd; Evas_Object *entry_pid_cmd;