Enlightenment: Fix cpumonitor gadget to do per core.
This commit is contained in:
parent
4c2116ac0f
commit
ea9dbba34d
|
@ -5,21 +5,26 @@ typedef struct _Thread_Config Thread_Config;
|
||||||
struct _Thread_Config
|
struct _Thread_Config
|
||||||
{
|
{
|
||||||
int interval;
|
int interval;
|
||||||
|
int cores;
|
||||||
Instance *inst;
|
Instance *inst;
|
||||||
int status;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_cpumonitor_face_update(Instance *inst, int status)
|
_cpumonitor_face_update(Instance *inst)
|
||||||
{
|
{
|
||||||
Edje_Message_Int_Set *usage_msg;
|
Edje_Message_Int_Set *usage_msg;
|
||||||
|
Eina_List *l;
|
||||||
|
CPU_Core *core;
|
||||||
|
|
||||||
usage_msg = malloc(sizeof(Edje_Message_Int_Set) + 1 * sizeof(int));
|
usage_msg = malloc(sizeof(Edje_Message_Int_Set) + 1 * sizeof(int));
|
||||||
EINA_SAFETY_ON_NULL_RETURN(usage_msg);
|
EINA_SAFETY_ON_NULL_RETURN(usage_msg);
|
||||||
usage_msg->count = 1;
|
EINA_LIST_FOREACH(inst->cfg->cpumonitor.cores, l, core)
|
||||||
usage_msg->val[0] = status;
|
{
|
||||||
edje_object_message_send(elm_layout_edje_get(inst->cfg->cpumonitor.o_gadget), EDJE_MESSAGE_INT_SET, 1,
|
usage_msg->count = 1;
|
||||||
|
usage_msg->val[0] = core->percent;
|
||||||
|
edje_object_message_send(elm_layout_edje_get(core->layout), EDJE_MESSAGE_INT_SET, 1,
|
||||||
usage_msg);
|
usage_msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -29,7 +34,7 @@ _cpumonitor_cb_usage_check_main(void *data, Ecore_Thread *th)
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
if (ecore_thread_check(th)) break;
|
if (ecore_thread_check(th)) break;
|
||||||
thc->status = _cpumonitor_proc_getusage(thc->inst);
|
_cpumonitor_proc_getusage(thc->inst);
|
||||||
ecore_thread_feedback(th, NULL);
|
ecore_thread_feedback(th, NULL);
|
||||||
if (ecore_thread_check(th)) break;
|
if (ecore_thread_check(th)) break;
|
||||||
usleep((1000000.0 / 8.0) * (double)thc->interval);
|
usleep((1000000.0 / 8.0) * (double)thc->interval);
|
||||||
|
@ -47,16 +52,39 @@ _cpumonitor_cb_usage_check_notify(void *data,
|
||||||
|
|
||||||
if (inst->cfg->esm != E_SYSINFO_MODULE_CPUMONITOR && inst->cfg->esm != E_SYSINFO_MODULE_SYSINFO) return;
|
if (inst->cfg->esm != E_SYSINFO_MODULE_CPUMONITOR && inst->cfg->esm != E_SYSINFO_MODULE_SYSINFO) return;
|
||||||
if (!inst->cfg) return;
|
if (!inst->cfg) return;
|
||||||
_cpumonitor_face_update(inst, thc->status);
|
_cpumonitor_face_update(inst);
|
||||||
|
}
|
||||||
|
|
||||||
|
Evas_Object *
|
||||||
|
_cpumonitor_add_layout(Instance *inst)
|
||||||
|
{
|
||||||
|
Evas_Object *layout;
|
||||||
|
|
||||||
|
layout = elm_layout_add(inst->cfg->cpumonitor.o_gadget);
|
||||||
|
e_theme_edje_object_set(layout, "base/theme/modules/cpumonitor",
|
||||||
|
"e/modules/cpumonitor/main");
|
||||||
|
E_EXPAND(layout);
|
||||||
|
E_FILL(layout);
|
||||||
|
elm_box_pack_end(inst->cfg->cpumonitor.o_gadget, layout);
|
||||||
|
evas_object_show(layout);
|
||||||
|
|
||||||
|
return layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
_cpumonitor_config_updated(Instance *inst)
|
_cpumonitor_config_updated(Instance *inst)
|
||||||
{
|
{
|
||||||
Thread_Config *thc;
|
Thread_Config *thc;
|
||||||
|
CPU_Core *core;
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
if (inst->cfg->cpumonitor.usage_check_thread)
|
if (inst->cfg->cpumonitor.usage_check_thread)
|
||||||
{
|
{
|
||||||
|
EINA_LIST_FREE(inst->cfg->cpumonitor.cores, core)
|
||||||
|
{
|
||||||
|
evas_object_del(core->layout);
|
||||||
|
E_FREE_FUNC(core, free);
|
||||||
|
}
|
||||||
ecore_thread_cancel(inst->cfg->cpumonitor.usage_check_thread);
|
ecore_thread_cancel(inst->cfg->cpumonitor.usage_check_thread);
|
||||||
inst->cfg->cpumonitor.usage_check_thread = NULL;
|
inst->cfg->cpumonitor.usage_check_thread = NULL;
|
||||||
}
|
}
|
||||||
|
@ -65,7 +93,16 @@ _cpumonitor_config_updated(Instance *inst)
|
||||||
{
|
{
|
||||||
thc->inst = inst;
|
thc->inst = inst;
|
||||||
thc->interval = inst->cfg->cpumonitor.poll_interval;
|
thc->interval = inst->cfg->cpumonitor.poll_interval;
|
||||||
thc->status = 0;
|
thc->cores = _cpumonitor_proc_getcores();
|
||||||
|
for (i = 0; i < thc->cores; i++)
|
||||||
|
{
|
||||||
|
core = E_NEW(CPU_Core, 1);
|
||||||
|
core->layout = _cpumonitor_add_layout(inst);
|
||||||
|
core->percent = 0;
|
||||||
|
core->total = 0;
|
||||||
|
core->idle = 0;
|
||||||
|
inst->cfg->cpumonitor.cores = eina_list_append(inst->cfg->cpumonitor.cores, core);
|
||||||
|
}
|
||||||
inst->cfg->cpumonitor.usage_check_thread =
|
inst->cfg->cpumonitor.usage_check_thread =
|
||||||
ecore_thread_feedback_run(_cpumonitor_cb_usage_check_main,
|
ecore_thread_feedback_run(_cpumonitor_cb_usage_check_main,
|
||||||
_cpumonitor_cb_usage_check_notify,
|
_cpumonitor_cb_usage_check_notify,
|
||||||
|
@ -78,6 +115,7 @@ static void
|
||||||
_cpumonitor_removed_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_data)
|
_cpumonitor_removed_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_data)
|
||||||
{
|
{
|
||||||
Instance *inst = data;
|
Instance *inst = data;
|
||||||
|
CPU_Core *core;
|
||||||
|
|
||||||
if (inst->o_main != event_data) return;
|
if (inst->o_main != event_data) return;
|
||||||
|
|
||||||
|
@ -86,7 +124,11 @@ _cpumonitor_removed_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_dat
|
||||||
ecore_thread_cancel(inst->cfg->cpumonitor.usage_check_thread);
|
ecore_thread_cancel(inst->cfg->cpumonitor.usage_check_thread);
|
||||||
inst->cfg->cpumonitor.usage_check_thread = NULL;
|
inst->cfg->cpumonitor.usage_check_thread = NULL;
|
||||||
}
|
}
|
||||||
|
EINA_LIST_FREE(inst->cfg->cpumonitor.cores, core)
|
||||||
|
{
|
||||||
|
evas_object_del(core->layout);
|
||||||
|
E_FREE_FUNC(core, free);
|
||||||
|
}
|
||||||
sysinfo_config->items = eina_list_remove(sysinfo_config->items, inst->cfg);
|
sysinfo_config->items = eina_list_remove(sysinfo_config->items, inst->cfg);
|
||||||
E_FREE(inst->cfg);
|
E_FREE(inst->cfg);
|
||||||
}
|
}
|
||||||
|
@ -94,11 +136,18 @@ _cpumonitor_removed_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_dat
|
||||||
void
|
void
|
||||||
sysinfo_cpumonitor_remove(Instance *inst)
|
sysinfo_cpumonitor_remove(Instance *inst)
|
||||||
{
|
{
|
||||||
|
CPU_Core *core;
|
||||||
|
|
||||||
if (inst->cfg->cpumonitor.usage_check_thread)
|
if (inst->cfg->cpumonitor.usage_check_thread)
|
||||||
{
|
{
|
||||||
ecore_thread_cancel(inst->cfg->cpumonitor.usage_check_thread);
|
ecore_thread_cancel(inst->cfg->cpumonitor.usage_check_thread);
|
||||||
inst->cfg->cpumonitor.usage_check_thread = NULL;
|
inst->cfg->cpumonitor.usage_check_thread = NULL;
|
||||||
}
|
}
|
||||||
|
EINA_LIST_FREE(inst->cfg->cpumonitor.cores, core)
|
||||||
|
{
|
||||||
|
evas_object_del(core->layout);
|
||||||
|
E_FREE_FUNC(core, free);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -106,9 +155,7 @@ _cpumonitor_created_cb(void *data, Evas_Object *obj, void *event_data EINA_UNUSE
|
||||||
{
|
{
|
||||||
Instance *inst = data;
|
Instance *inst = data;
|
||||||
|
|
||||||
inst->cfg->cpumonitor.o_gadget = elm_layout_add(inst->o_main);
|
inst->cfg->cpumonitor.o_gadget = elm_box_add(inst->o_main);
|
||||||
e_theme_edje_object_set(inst->cfg->cpumonitor.o_gadget, "base/theme/modules/cpumonitor",
|
|
||||||
"e/modules/cpumonitor/main");
|
|
||||||
E_EXPAND(inst->cfg->cpumonitor.o_gadget);
|
E_EXPAND(inst->cfg->cpumonitor.o_gadget);
|
||||||
E_FILL(inst->cfg->cpumonitor.o_gadget);
|
E_FILL(inst->cfg->cpumonitor.o_gadget);
|
||||||
elm_box_pack_end(inst->o_main, inst->cfg->cpumonitor.o_gadget);
|
elm_box_pack_end(inst->o_main, inst->cfg->cpumonitor.o_gadget);
|
||||||
|
@ -120,9 +167,7 @@ _cpumonitor_created_cb(void *data, Evas_Object *obj, void *event_data EINA_UNUSE
|
||||||
Evas_Object *
|
Evas_Object *
|
||||||
sysinfo_cpumonitor_create(Evas_Object *parent, Instance *inst)
|
sysinfo_cpumonitor_create(Evas_Object *parent, Instance *inst)
|
||||||
{
|
{
|
||||||
inst->cfg->cpumonitor.o_gadget = elm_layout_add(parent);
|
inst->cfg->cpumonitor.o_gadget = elm_box_add(parent);
|
||||||
e_theme_edje_object_set(inst->cfg->cpumonitor.o_gadget, "base/theme/modules/cpumonitor",
|
|
||||||
"e/modules/cpumonitor/main");
|
|
||||||
E_EXPAND(inst->cfg->cpumonitor.o_gadget);
|
E_EXPAND(inst->cfg->cpumonitor.o_gadget);
|
||||||
E_FILL(inst->cfg->cpumonitor.o_gadget);
|
E_FILL(inst->cfg->cpumonitor.o_gadget);
|
||||||
evas_object_show(inst->cfg->cpumonitor.o_gadget);
|
evas_object_show(inst->cfg->cpumonitor.o_gadget);
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "../sysinfo.h"
|
#include "../sysinfo.h"
|
||||||
|
|
||||||
void _cpuclock_config_updated(Instance *inst);
|
void _cpuclock_config_updated(Instance *inst);
|
||||||
int _cpumonitor_proc_getusage(Instance *inst);
|
int _cpumonitor_proc_getcores(void);
|
||||||
|
void _cpumonitor_proc_getusage(Instance *inst);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,42 +1,78 @@
|
||||||
#include "cpumonitor.h"
|
#include "cpumonitor.h"
|
||||||
|
|
||||||
int _cpumonitor_proc_getusage(Instance *inst)
|
int
|
||||||
|
_cpumonitor_proc_getcores(void)
|
||||||
{
|
{
|
||||||
long total = 0, i = 0, idle = 0, use, total_change, idle_change;
|
char buf[4096], *tok;
|
||||||
int percent = 0;
|
|
||||||
char buf[4096], *line, *tok;
|
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
int cores = 0, i = 0;
|
||||||
|
|
||||||
f = fopen("/proc/stat", "r");
|
f = fopen("/proc/stat", "r");
|
||||||
if (f)
|
if (f)
|
||||||
{
|
{
|
||||||
if (fgets(buf, sizeof(buf), f) == NULL)
|
while (fgets(buf, sizeof(buf), f))
|
||||||
{
|
{
|
||||||
fclose(f);
|
if (i > 0)
|
||||||
return 0;
|
{
|
||||||
|
tok = strtok(buf, " ");
|
||||||
|
if (!strncmp(tok, "cpu", 3))
|
||||||
|
cores++;
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
fclose (f);
|
||||||
|
}
|
||||||
|
return cores;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
_cpumonitor_proc_getusage(Instance *inst)
|
||||||
|
{
|
||||||
|
long total = 0, idle = 0, use, total_change, idle_change;
|
||||||
|
int percent = 0, i = 0, j = 0, k = 0;
|
||||||
|
char buf[4096], *line, *tok;
|
||||||
|
FILE *f;
|
||||||
|
CPU_Core *core;
|
||||||
|
|
||||||
|
f = fopen("/proc/stat", "r");
|
||||||
|
if (f)
|
||||||
|
{
|
||||||
|
while (fgets(buf, sizeof(buf), f))
|
||||||
|
{
|
||||||
|
if (k > 0)
|
||||||
|
{
|
||||||
|
if (!strncmp(buf, "cpu", 3))
|
||||||
|
{
|
||||||
|
line = strchr(buf, ' ');
|
||||||
|
tok = strtok(line, " ");
|
||||||
|
while (tok)
|
||||||
|
{
|
||||||
|
use = atol(tok);
|
||||||
|
total += use;
|
||||||
|
i++;
|
||||||
|
if (i == 4)
|
||||||
|
idle = use;
|
||||||
|
tok = strtok(NULL, " ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else break;
|
||||||
|
core = eina_list_nth(inst->cfg->cpumonitor.cores, j);
|
||||||
|
total_change = total - core->total;
|
||||||
|
idle_change = idle - core->idle;
|
||||||
|
if (total_change != 0)
|
||||||
|
percent = 100 * (1 - ((float)idle_change / (float)total_change));
|
||||||
|
if (percent > 100) percent = 100;
|
||||||
|
else if (percent < 0) percent = 0;
|
||||||
|
core->percent = percent;
|
||||||
|
core->total = total;
|
||||||
|
core->idle = idle;
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
k++;
|
||||||
}
|
}
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
line = strchr(buf, ' ')+1;
|
|
||||||
tok = strtok(line, " ");
|
|
||||||
while (tok)
|
|
||||||
{
|
|
||||||
use = atol(tok);
|
|
||||||
total += use;
|
|
||||||
i++;
|
|
||||||
if (i == 4)
|
|
||||||
idle = use;
|
|
||||||
tok = strtok(NULL, " ");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
total_change = total - inst->cfg->cpumonitor.total;
|
|
||||||
idle_change = idle - inst->cfg->cpumonitor.idle;
|
|
||||||
if (total_change != 0)
|
|
||||||
percent = 100 * (1 - ((float)idle_change / (float)total_change));
|
|
||||||
if (percent > 100) percent = 100;
|
|
||||||
else if (percent < 0) percent = 0;
|
|
||||||
inst->cfg->cpumonitor.total = total;
|
|
||||||
inst->cfg->cpumonitor.idle = idle;
|
|
||||||
|
|
||||||
return percent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,7 @@ typedef enum _Unit
|
||||||
|
|
||||||
typedef struct _Tempthread Tempthread;
|
typedef struct _Tempthread Tempthread;
|
||||||
typedef struct _Cpu_Status Cpu_Status;
|
typedef struct _Cpu_Status Cpu_Status;
|
||||||
|
typedef struct _CPU_Core CPU_Core;
|
||||||
typedef struct _Config Config;
|
typedef struct _Config Config;
|
||||||
typedef struct _Config_Item Config_Item;
|
typedef struct _Config_Item Config_Item;
|
||||||
typedef struct _Instance Instance;
|
typedef struct _Instance Instance;
|
||||||
|
@ -92,6 +93,14 @@ struct _Cpu_Status
|
||||||
unsigned char pstate_turbo;
|
unsigned char pstate_turbo;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct _CPU_Core
|
||||||
|
{
|
||||||
|
int percent;
|
||||||
|
long total;
|
||||||
|
long idle;
|
||||||
|
Evas_Object *layout;
|
||||||
|
};
|
||||||
|
|
||||||
struct _Config
|
struct _Config
|
||||||
{
|
{
|
||||||
Eina_List *items;
|
Eina_List *items;
|
||||||
|
@ -173,6 +182,7 @@ struct _Config_Item
|
||||||
long total;
|
long total;
|
||||||
long idle;
|
long idle;
|
||||||
Ecore_Thread *usage_check_thread;
|
Ecore_Thread *usage_check_thread;
|
||||||
|
Eina_List *cores;
|
||||||
} cpumonitor;
|
} cpumonitor;
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue