Top/ps process monitor
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2073 lines
58 KiB

2 years ago
#include "config.h"
#include "evisum_config.h"
2 years ago
#include "ui.h"
#include "ui/ui_process_list.h"
2 years ago
#include "ui/ui_process_view.h"
#include <stdio.h>
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
2 years ago
#include <sys/types.h>
#include <sys/resource.h>
#include <pwd.h>
#define PROGRESS_CUSTOM_FORMAT 1
#define DIRTY_GENLIST_HACK 1
2 years ago
extern int EVISUM_EVENT_CONFIG_CHANGED;
typedef struct
{
2 years ago
Proc_Sort type;
int (*sort_cb)(const void *p1, const void *p2);
} Sorter;
typedef struct
{
Ecore_Thread *thread;
Evisum_Ui_Cache *cache;
Ecore_Event_Handler *handler[2];
2 years ago
Eina_Hash *cpu_times;
Eina_Bool skip_wait;
2 years ago
Sorter sorters[PROC_SORT_BY_MAX];
2 years ago
pid_t selected_pid;
int poll_count;
Ui *ui;
Ecore_Timer *resize_timer;
Evas_Object *win;
Evas_Object *main_menu;
Ecore_Timer *main_menu_timer;
Evas_Object *menu;
Eina_Bool transparant;
2 years ago
struct
{
char *text;
size_t len;
Ecore_Timer *timer;
Evas_Object *pop;
Evas_Object *entry;
Eina_Bool visible;
double keytime;
} search;
2 years ago
Evas_Object *tb_content;
2 years ago
Evas_Object *glist;
Elm_Genlist_Item_Class itc;
Evas_Object *btn_menu;
Evas_Object *btn_cmd;
2 years ago
Evas_Object *btn_uid;
Evas_Object *btn_pid;
Evas_Object *btn_threads;
2 years ago
Evas_Object *btn_cpu;
Evas_Object *btn_pri;
Evas_Object *btn_nice;
Evas_Object *btn_size;
Evas_Object *btn_rss;
2 years ago
Evas_Object *btn_state;
Evas_Object *btn_time;
Evas_Object *btn_cpu_usage;
2 years ago
Evas_Object *fields_menu;
struct
{
2 years ago
Evas_Object *fr;
Evas_Object *lb;
int total;
int running;
int sleeping;
int stopped;
int idle;
int dead;
int zombie;
int dsleep;
} summary;
} Ui_Data;
2 years ago
static Ui_Data *_pd = NULL;
#if PROGRESS_CUSTOM_FORMAT
static double _cpu_usage = 0.0;
2 years ago
#endif
2 years ago
typedef struct
{
Proc_Field id;
const char *name;
Eina_Bool enabled;
Evas_Object *btn;
} Field;
static Field _fields[PROC_FIELD_MAX];
static const char *
_field_name(Proc_Field id)
{
switch (id)
{
case PROC_FIELD_CMD:
return _("Command");
case PROC_FIELD_UID:
return _("User");
case PROC_FIELD_PID:
return _("PID");
case PROC_FIELD_THREADS:
return _("Threads");
case PROC_FIELD_CPU:
return _("CPU #");
case PROC_FIELD_PRI:
return _("Priority");
case PROC_FIELD_NICE:
return _("Nice");
case PROC_FIELD_SIZE:
return _("Size");
case PROC_FIELD_RSS:
return _("Reserved");
case PROC_FIELD_STATE:
return _("State");
case PROC_FIELD_TIME:
return _("Time");
case PROC_FIELD_CPU_USAGE:
return _("CPU Usage");
default:
break;
}
return "BUG";
}
static Eina_Bool
_field_enabled(Proc_Field id)
{
return _fields[id].enabled;
}
static void
_content_reset(Ui_Data *pd)
{
int j = 0;
elm_table_clear(pd->tb_content, 0);
elm_table_pack(pd->tb_content, pd->btn_menu, j++, 0, 1, 1);
for (int i = j; i < PROC_FIELD_MAX; i++)
{
Field *f = &_fields[i];
if (!f->enabled)
{
evas_object_hide(f->btn);
continue;
}
evas_object_show(f->btn);
elm_table_pack(pd->tb_content, f->btn, j++, 0, 1, 1);
}
elm_table_pack(pd->tb_content, pd->glist, 0, 1, j, 1);
elm_table_pack(pd->tb_content, pd->summary.fr, 0, 2, j, 1);
if (pd->cache)
evisum_ui_item_cache_reset(pd->cache);
elm_genlist_clear(pd->glist);
}
static void
_field_menu_check_changed_cb(void *data, Evas_Object *obj, void *event_info)
{
Field *f = data;
f->enabled = !f->enabled;
Ui *ui = _pd->ui;
_content_reset(_pd);
ui->proc.fields ^= (1 << f->id);
}
static Evas_Object *
_field_menu_create(Ui_Data *pd, Evas_Object *parent)
{
Evas_Object *o, *fr, *bx, *ck;
fr = elm_frame_add(parent);
elm_object_style_set(fr, "pad_small");
evas_object_show(fr);
bx = elm_box_add(parent);
evas_object_size_hint_weight_set(bx, EXPAND, EXPAND);
evas_object_size_hint_align_set(bx, FILL, FILL);
evas_object_show(bx);
elm_object_content_set(fr, bx);
for (int i = PROC_FIELD_UID; i < PROC_FIELD_MAX; i++)
{
ck = elm_check_add(parent);
evas_object_size_hint_weight_set(ck, EXPAND, EXPAND);
evas_object_size_hint_align_set(ck, FILL, FILL);
elm_object_text_set(ck, _fields[i].name);
elm_check_state_set(ck, _fields[i].enabled);
evas_object_smart_callback_add(ck, "changed",
_field_menu_check_changed_cb, &_fields[i]);
evas_object_show(ck);
elm_box_pack_end(bx, ck);
}
o = elm_ctxpopup_add(parent);
evas_object_size_hint_weight_set(o, EXPAND, EXPAND);
evas_object_size_hint_align_set(o, FILL, FILL);
elm_object_style_set(o, "noblock");
elm_object_content_set(o, fr);
return o;
}
static void
_field_mouse_up_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED,
Evas_Object *obj, void *event_info)
{
Evas_Event_Mouse_Up *ev;
Evas_Object *o;
Evas_Coord ox, oy, ow, oh;
Ui_Data *pd;
ev = event_info;
pd = data;
if (ev->button != 3) return;
if (pd->fields_menu) return;
evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
o = pd->fields_menu = _field_menu_create(pd, pd->win);
elm_ctxpopup_direction_priority_set(o, ELM_CTXPOPUP_DIRECTION_DOWN,
ELM_CTXPOPUP_DIRECTION_UP,
ELM_CTXPOPUP_DIRECTION_LEFT,
ELM_CTXPOPUP_DIRECTION_RIGHT);
evas_object_move(o, ox + (ow / 2), oy + oh);
evas_object_show(o);
}
static void
_fields_init(Ui_Data *pd)
{
for (int i = PROC_FIELD_CMD; i < PROC_FIELD_MAX; i++)
{
_fields[i].id = i;
_fields[i].name = _field_name(i);
_fields[i].enabled = 1;
if ((i != PROC_FIELD_CMD) && (!(pd->ui->proc.fields & (1UL << i))))
_fields[i].enabled = 0;
evas_object_event_callback_add(_fields[i].btn, EVAS_CALLBACK_MOUSE_UP,
_field_mouse_up_cb, pd);
}
}
2 years ago
static void
_item_unrealized_cb(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Evas_Object *o;
Ui_Data *pd;
2 years ago
Eina_List *contents = NULL;
pd = data;
2 years ago
elm_genlist_item_all_contents_unset(event_info, &contents);
EINA_LIST_FREE(contents, o)
{
if (!evisum_ui_item_cache_item_release(pd->cache, o))
{
evas_object_del(o);
}
2 years ago
}
}
static void
_item_del(void *data, Evas_Object *obj EINA_UNUSED)
{
Proc_Info *proc = data;
proc_info_free(proc);
}
static Evas_Object *
_item_column_add(Evas_Object *tb, const char *text, int col)
2 years ago
{
Evas_Object *rec, *lb;
2 years ago
lb = elm_label_add(tb);
evas_object_data_set(tb, text, lb);
evas_object_size_hint_align_set(lb, FILL, FILL);
evas_object_size_hint_weight_set(lb, EXPAND, EXPAND);
evas_object_show(lb);
2 years ago
rec = evas_object_rectangle_add(evas_object_evas_get(tb));
evas_object_data_set(lb, "rec", rec);
2 years ago
elm_table_pack(tb, rec, col, 0, 1, 1);
elm_table_pack(tb, lb, col, 0, 1, 1);
2 years ago
return lb;
2 years ago
}
#if PROGRESS_CUSTOM_FORMAT
static char *
_pb_format_cb(double val)
{
static char buf[32];
snprintf(buf, sizeof(buf), "%1.1f %%", _cpu_usage);
return strdup(buf);
}
static void
_pb_format_free_cb(char *str)
{
free(str);
}
2 years ago
#endif
2 years ago
static Evas_Object *
2 years ago
_item_create(Evas_Object *obj)
2 years ago
{
Evas_Object *tb, *lb, *ic, *rec;
2 years ago
Evas_Object *hbx, *pb;
int i = 0;
tb = elm_table_add(obj);
evas_object_size_hint_align_set(tb, FILL, FILL);
evas_object_size_hint_weight_set(tb, EXPAND, 0);
hbx = elm_box_add(tb);
2 years ago
elm_box_horizontal_set(hbx, 1);
evas_object_size_hint_align_set(hbx, 0.0, FILL);
evas_object_size_hint_weight_set(hbx, EXPAND, 0);
2 years ago
evas_object_show(hbx);
ic = elm_icon_add(tb);
2 years ago
evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
evas_object_size_hint_align_set(ic, FILL, FILL);
evas_object_size_hint_min_set(ic, ELM_SCALE_SIZE(16), ELM_SCALE_SIZE(16));
evas_object_size_hint_max_set(ic, ELM_SCALE_SIZE(16), ELM_SCALE_SIZE(16));
2 years ago
evas_object_show(ic);
evas_object_data_set(tb, "icon", ic);
2 years ago
elm_box_pack_end(hbx, ic);
elm_table_pack(tb, hbx, i, 0, 1, 1);
rec = evas_object_rectangle_add(evas_object_evas_get(tb));
2 years ago
evas_object_size_hint_min_set(rec, ELM_SCALE_SIZE(4), 1);
elm_box_pack_end(hbx, rec);
rec = evas_object_rectangle_add(evas_object_evas_get(tb));
evas_object_data_set(ic, "rec", rec);
elm_table_pack(tb, rec, i++, 0, 1, 1);
lb = elm_label_add(tb);
evas_object_size_hint_weight_set(lb, 0, EXPAND);
evas_object_data_set(tb, "proc_cmd", lb);
evas_object_data_set(lb, "hbx", hbx);
evas_object_show(lb);
elm_box_pack_end(hbx, lb);
2 years ago
if (_field_enabled(PROC_FIELD_UID))
{
lb = _item_column_add(tb, "proc_uid", i++);
evas_object_size_hint_align_set(lb, 1.0, FILL);
}
if (_field_enabled(PROC_FIELD_PID))
{
lb = _item_column_add(tb, "proc_pid", i++);
evas_object_size_hint_align_set(lb, 1.0, FILL);
}
if (_field_enabled(PROC_FIELD_THREADS))
{
lb = _item_column_add(tb, "proc_threads", i++);
evas_object_size_hint_align_set(lb, 1.0, FILL);
}
if (_field_enabled(PROC_FIELD_CPU))
{
lb = _item_column_add(tb, "proc_cpu", i++);
evas_object_size_hint_align_set(lb, 1.0, FILL);
}
if (_field_enabled(PROC_FIELD_PRI))
{
lb = _item_column_add(tb, "proc_prio", i++);
evas_object_size_hint_align_set(lb, 1.0, FILL);
}
if (_field_enabled(PROC_FIELD_NICE))
{
lb = _item_column_add(tb, "proc_nice", i++);
evas_object_size_hint_align_set(lb, 1.0, FILL);
}
if (_field_enabled(PROC_FIELD_SIZE))
{
lb = _item_column_add(tb, "proc_size", i++);
evas_object_size_hint_align_set(lb, 1.0, FILL);
}
if (_field_enabled(PROC_FIELD_RSS))
{
lb = _item_column_add(tb, "proc_rss", i++);
evas_object_size_hint_align_set(lb, 1.0, FILL);
}
if (_field_enabled(PROC_FIELD_STATE))
{
lb = _item_column_add(tb, "proc_state", i++);
evas_object_size_hint_align_set(lb, 1.0, FILL);
}
if (_field_enabled(PROC_FIELD_TIME))
{
lb = _item_column_add(tb, "proc_time", i++);
evas_object_size_hint_align_set(lb, 0.5, FILL);
}
if (_field_enabled(PROC_FIELD_CPU_USAGE))
{
pb = elm_progressbar_add(hbx);
evas_object_size_hint_weight_set(pb, EXPAND, EXPAND);
evas_object_size_hint_align_set(pb, FILL, FILL);
elm_progressbar_unit_format_set(pb, "%1.1f %%");
#if PROGRESS_CUSTOM_FORMAT
2 years ago
elm_progressbar_unit_format_function_set(pb,
_pb_format_cb,
_pb_format_free_cb);
2 years ago
#endif
2 years ago
elm_table_pack(tb, pb, i++, 0, 1, 1);
evas_object_data_set(tb, "proc_cpu_usage", pb);
}
2 years ago
return tb;
2 years ago
}
2 years ago
static void
_run_time_set(char *buf, size_t n, int64_t secs)
{
int rem;
if (secs < 86400)
snprintf(buf, n, "%02" PRIi64 ":%02"PRIi64, secs / 60, secs % 60);
2 years ago
else
{
rem = secs % 3600;
snprintf(buf, n, "%02" PRIi64 ":%02d:%02d", secs / 3600, rem / 60, rem % 60);
2 years ago
}
}
2 years ago
static Evas_Object *
_content_get(void *data, Evas_Object *obj, const char *source)
{
Proc_Info *proc;
struct passwd *pwd_entry;
Evas_Object *rec, *lb, *o, *hbx, *pb;
2 years ago
char buf[128];
2 years ago
Evas_Coord w, ow;
2 years ago
Ui_Data *pd = _pd;
2 years ago
proc = (void *) data;
if (strcmp(source, "elm.swallow.content")) return NULL;
if (!proc) return NULL;
Item_Cache *it = evisum_ui_item_cache_item_get(pd->cache);
2 years ago
if (!it)
{
fprintf(stderr, "Error: Object cache creation failed.\n");
exit(-1);
}
evas_object_geometry_get(pd->btn_menu, NULL, NULL, &ow, NULL);
evas_object_geometry_get(pd->btn_cmd, NULL, NULL, &w, NULL);
w += (ow - 8);
lb = evas_object_data_get(it->obj, "proc_cmd");
snprintf(buf, sizeof(buf), "%s", proc->command);
if (strcmp(buf, elm_object_text_get(lb)))
elm_object_text_set(lb, buf);
hbx = evas_object_data_get(lb, "hbx");
evas_object_geometry_get(hbx, NULL, NULL, &ow, NULL);
if (ow > w)
{
evas_object_size_hint_min_set(pd->btn_cmd, w, 1);
pd->skip_wait = 1;
}
rec = evas_object_data_get(lb, "rec");
evas_object_size_hint_min_set(rec, w, 1);
evas_object_show(lb);
elm_box_recalculate(hbx);
o = evas_object_data_get(it->obj, "icon");
const char *new = evisum_icon_path_get(evisum_icon_cache_find(proc));
const char *old = NULL;
elm_image_file_get(o, &old, NULL);
if (!old || strcmp(old, new))
elm_icon_standard_set(o, new);
rec = evas_object_data_get(o, "rec");
evas_object_size_hint_min_set(rec, w, 1);
evas_object_show(o);
2 years ago
if (_field_enabled(PROC_FIELD_UID))
2 years ago
{
2 years ago
evas_object_geometry_get(pd->btn_uid, NULL, NULL, &w, NULL);
lb = evas_object_data_get(it->obj, "proc_uid");
pwd_entry = getpwuid(proc->uid);
if (pwd_entry)
snprintf(buf, sizeof(buf), "%s", pwd_entry->pw_name);
else
snprintf(buf, sizeof(buf), "%i", proc->uid);
if (strcmp(buf, elm_object_text_get(lb)))
2 years ago
{
2 years ago
elm_object_text_set(lb, buf);
evas_object_geometry_get(lb, NULL, NULL, &ow, NULL);
if (ow > w)
{
evas_object_size_hint_min_set(pd->btn_uid, w, 1);
pd->skip_wait = 1;
}
2 years ago
}
2 years ago
rec = evas_object_data_get(lb, "rec");
evas_object_size_hint_min_set(rec, w, 1);
evas_object_show(lb);
2 years ago
}
2 years ago
if (_field_enabled(PROC_FIELD_PID))
{
evas_object_geometry_get(pd->btn_pid, NULL, NULL, &w, NULL);
lb = evas_object_data_get(it->obj, "proc_pid");
snprintf(buf, sizeof(buf), "%d", proc->pid);
if (strcmp(buf, elm_object_text_get(lb)))
elm_object_text_set(lb, buf);
rec = evas_object_data_get(lb, "rec");
evas_object_size_hint_min_set(rec, w, 1);
evas_object_show(lb);
}
2 years ago
2 years ago
if (_field_enabled(PROC_FIELD_THREADS))
{
evas_object_geometry_get(pd->btn_threads, NULL, NULL, &w, NULL);
lb = evas_object_data_get(it->obj, "proc_threads");
snprintf(buf, sizeof(buf), "%d", proc->numthreads);
if (strcmp(buf, elm_object_text_get(lb)))
elm_object_text_set(lb, buf);
rec = evas_object_data_get(lb, "rec");
evas_object_size_hint_min_set(rec, w, 1);
evas_object_show(lb);
}
2 years ago
if (_field_enabled(PROC_FIELD_CPU))
{
evas_object_geometry_get(pd->btn_cpu, NULL, NULL, &w, NULL);
lb = evas_object_data_get(it->obj, "proc_cpu");
snprintf(buf, sizeof(buf), "%d", proc->cpu_id);
if (strcmp(buf, elm_object_text_get(lb)))
elm_object_text_set(lb, buf);
rec = evas_object_data_get(lb, "rec");
evas_object_size_hint_min_set(rec, w, 1);
evas_object_show(lb);
}
2 years ago
if (_field_enabled(PROC_FIELD_PRI))
{
evas_object_geometry_get(pd->btn_pri, NULL, NULL, &w, NULL);
lb = evas_object_data_get(it->obj, "proc_prio");
snprintf(buf, sizeof(buf), "%d", proc->priority);
if (strcmp(buf, elm_object_text_get(lb)))
elm_object_text_set(lb, buf);
rec = evas_object_data_get(lb, "rec");
evas_object_size_hint_min_set(rec, w, 1);
evas_object_show(lb);
}
2 years ago
if (_field_enabled(PROC_FIELD_NICE))
{
evas_object_geometry_get(pd->btn_nice, NULL, NULL, &w, NULL);
lb = evas_object_data_get(it->obj, "proc_nice");
snprintf(buf, sizeof(buf), "%d", proc->nice);
if (strcmp(buf, elm_object_text_get(lb)))
elm_object_text_set(lb, buf);
rec = evas_object_data_get(lb, "rec");
evas_object_size_hint_min_set(rec, w, 1);
evas_object_show(lb);
}
2 years ago
2 years ago
if (_field_enabled(PROC_FIELD_SIZE))
{
evas_object_geometry_get(pd->btn_size, NULL, NULL, &w, NULL);
lb = evas_object_data_get(it->obj, "proc_size");
snprintf(buf, sizeof(buf), "%s", evisum_size_format(proc->mem_size));
if (strcmp(buf, elm_object_text_get(lb)))
elm_object_text_set(lb, buf);
rec = evas_object_data_get(lb, "rec");
evas_object_size_hint_min_set(rec, w, 1);
evas_object_show(lb);
}
2 years ago
2 years ago
if (_field_enabled(PROC_FIELD_RSS))
{
evas_object_geometry_get(pd->btn_rss, NULL, NULL, &w, NULL);
lb = evas_object_data_get(it->obj, "proc_rss");
snprintf(buf, sizeof(buf), "%s", evisum_size_format(proc->mem_rss));
if (strcmp(buf, elm_object_text_get(lb)))
elm_object_text_set(lb, buf);
rec = evas_object_data_get(lb, "rec");
evas_object_size_hint_min_set(rec, w, 1);
evas_object_show(lb);
}
2 years ago
2 years ago
if (_field_enabled(PROC_FIELD_STATE))
{
evas_object_geometry_get(pd->btn_state, NULL, NULL, &w, NULL);
lb = evas_object_data_get(it->obj, "proc_state");
snprintf(buf, sizeof(buf), "%s", proc->state);
if (strcmp(buf, elm_object_text_get(lb)))
elm_object_text_set(lb, buf);
rec = evas_object_data_get(lb, "rec");
evas_object_size_hint_min_set(rec, w, 1);
evas_object_show(lb);
}
if (_field_enabled(PROC_FIELD_TIME))
{
evas_object_geometry_get(pd->btn_time, NULL, NULL, &w, NULL);
lb = evas_object_data_get(it->obj, "proc_time");
_run_time_set(buf, sizeof(buf), proc->run_time);
if (strcmp(buf, elm_object_text_get(lb)))
elm_object_text_set(lb, buf);
rec = evas_object_data_get(lb, "rec");
evas_object_size_hint_min_set(rec, w, 1);
evas_object_show(lb);
}
2 years ago
2 years ago
if (_field_enabled(PROC_FIELD_CPU_USAGE))
{
pb = evas_object_data_get(it->obj, "proc_cpu_usage");
#if PROGRESS_CUSTOM_FORMAT
2 years ago
_cpu_usage = proc->cpu_usage;
#endif
2 years ago
double value = proc->cpu_usage / 100.0;
double last = elm_progressbar_value_get(pb);
if (!EINA_DBL_EQ(value, last))
elm_progressbar_value_set(pb, proc->cpu_usage / 100.0);
evas_object_show(pb);
}
2 years ago
return it->obj;
}
static void
2 years ago
_glist_ensure_n_items(Evas_Object *glist, unsigned int items,
Elm_Genlist_Item_Class *itc)
2 years ago
{
Elm_Object_Item *it;
2 years ago
unsigned int i, existing = elm_genlist_items_count(glist);
2 years ago
if (items < existing)
{
for (i = existing - items; i > 0; i--)
{
2 years ago
it = elm_genlist_last_item_get(glist);
2 years ago
if (it)
{
elm_object_item_del(it);
}
2 years ago
}
}
if (items == existing) return;
for (i = existing; i < items; i++)
{
2 years ago
elm_genlist_item_append(glist, itc, NULL, NULL,
2 years ago
ELM_GENLIST_ITEM_NONE, NULL, NULL);
}
}
static Eina_Bool
_bring_in(void *data)
{
Ui_Data *pd;
2 years ago
int h_page, v_page;
pd = data;
2 years ago
elm_scroller_gravity_set(pd->glist, 0.0, 0.0);
elm_scroller_last_page_get(pd->glist, &h_page, &v_page);
elm_scroller_page_bring_in(pd->glist, h_page, v_page);
elm_genlist_realized_items_update(pd->glist);
evas_object_show(pd->glist);
2 years ago
return 0;
2 years ago
}
static void
_summary_reset(Ui_Data *pd)
{
pd->summary.total = pd->summary.running = pd->summary.sleeping = 0;
pd->summary.stopped = pd->summary.idle = pd->summary.zombie = 0;
2 years ago
pd->summary.dsleep = pd->summary.dead = 0;
}
static void
_summary_update(Ui_Data *pd)
{
Eina_Strbuf *buf = eina_strbuf_new();
eina_strbuf_append_printf(buf, "%i processes: ", pd->summary.total);
if (pd->summary.running)
eina_strbuf_append_printf(buf, "%i running, ", pd->summary.running);
if (pd->summary.sleeping)
eina_strbuf_append_printf(buf, "%i sleeping, ", pd->summary.sleeping);
if (pd->summary.stopped)
eina_strbuf_append_printf(buf, "%i stopped, ", pd->summary.stopped);
if (pd->summary.idle)
eina_strbuf_append_printf(buf, "%i idle, ", pd->summary.idle);
if (pd->summary.dead)
eina_strbuf_append_printf(buf, "%i dead, ", pd->summary.dead);
if (pd->summary.dsleep)
eina_strbuf_append_printf(buf, "%i dsleep, ", pd->summary.dsleep);
if (pd->summary.zombie)
eina_strbuf_append_printf(buf, "%i zombie, ", pd->summary.zombie);
eina_strbuf_replace_last(buf, ",", ".");
elm_object_text_set(pd->summary.lb, eina_strbuf_string_get(buf));
eina_strbuf_free(buf);
}
static void
_summary_total(Ui_Data *pd, Proc_Info *proc)
{
pd->summary.total++;
if (!strcmp(proc->state, "run"))
pd->summary.running++;
pd->summary.sleeping += proc->ssleep;
if (!strcmp(proc->state, "stop"))
pd->summary.stopped++;
if (!strcmp(proc->state, "idle"))
pd->summary.idle++;
if (!strcmp(proc->state, "zombie"))
pd->summary.zombie++;
if (!strcmp(proc->state, "dead"))
pd->summary.dead++;
if (!strcmp(proc->state, "dsleep"))
pd->summary.dsleep++;
}
static Eina_List *
_process_list_sort(Eina_List *list, Ui_Data *pd)
2 years ago
{
Ui *ui;
Sorter s;
ui = pd->ui;
s = pd->sorters[ui->proc.sort_type];
list = eina_list_sort(list, eina_list_count(list), s.sort_cb);
if (ui->proc.sort_reverse)
list = eina_list_reverse(list);
return list;
}
static Eina_List *
_process_list_uid_trim(Eina_List *list, uid_t uid)
{
Proc_Info *proc;
Eina_List *l, *l_next;
2 years ago
EINA_LIST_FOREACH_SAFE(list, l, l_next, proc)
{
if (proc->uid != uid)
2 years ago
{
proc_info_free(proc);
list = eina_list_remove_list(list, l);
2 years ago
}
}
return list;
}
static void
_cpu_times_free_cb(void *data)
{
int64_t *cpu_time = data;
free(cpu_time);
}
static Eina_List *
_process_list_search_trim(Eina_List *list, Ui_Data *pd)
{
Eina_List *l, *l_next;
Proc_Info *proc;
Ui *ui = pd->ui;
_summary_reset(pd);
2 years ago
EINA_LIST_FOREACH_SAFE(list, l, l_next, proc)
{
if ((proc->pid == ui->program_pid) ||
2 years ago
((pd->search.len) &&
(strncasecmp(proc->command, pd->search.text, pd->search.len) &&
(!strstr(proc->command, pd->search.text))))
)
2 years ago
{
proc_info_free(proc);
list = eina_list_remove_list(list, l);
}
else
{
int64_t *cpu_time, id = proc->pid;
if ((cpu_time = eina_hash_find(pd->cpu_times, &id)))
{
if (*cpu_time)
proc->cpu_usage = (double) (proc->cpu_time - *cpu_time) /