wip: remove the blocky
This commit is contained in:
parent
85d0782533
commit
981b377523
|
@ -6,24 +6,29 @@
|
||||||
static Eina_List *batteries = NULL;
|
static Eina_List *batteries = NULL;
|
||||||
static Eina_List *sensors = NULL;
|
static Eina_List *sensors = NULL;
|
||||||
static Eina_List *network_interfaces = NULL;
|
static Eina_List *network_interfaces = NULL;
|
||||||
|
static Eina_List *cores = NULL;
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
Eina_List *l;
|
||||||
|
Cpu_Core *core;
|
||||||
ecore_init();
|
ecore_init();
|
||||||
|
|
||||||
puts("CORES:");
|
puts("CORES:");
|
||||||
|
|
||||||
Cpu_Core **cores;
|
cores = cores_find();
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
int ncpu = 0;
|
|
||||||
cores = system_cpu_usage_delayed_get(&ncpu, 1000000);
|
|
||||||
for (int i = 0; i < ncpu; i++)
|
|
||||||
{
|
{
|
||||||
printf("core %i = %1.2f%%\n", cores[i]->id, cores[i]->percent);
|
cores_check(cores);
|
||||||
free(cores[i]);
|
EINA_LIST_FOREACH(cores, l, core)
|
||||||
|
{
|
||||||
|
printf("core %i = %1.2f%%\n", core->id, core->percent);
|
||||||
}
|
}
|
||||||
free(cores);
|
usleep(1000000);
|
||||||
|
}
|
||||||
|
EINA_LIST_FREE(cores, core)
|
||||||
|
free(core);
|
||||||
|
|
||||||
puts("BATTERIES:");
|
puts("BATTERIES:");
|
||||||
Battery *bat;
|
Battery *bat;
|
||||||
|
|
|
@ -104,6 +104,15 @@ battery_check(Battery *bat);
|
||||||
Eina_List *
|
Eina_List *
|
||||||
sensors_find(void);
|
sensors_find(void);
|
||||||
|
|
||||||
|
void
|
||||||
|
memory_info(Meminfo *memory);
|
||||||
|
|
||||||
|
void
|
||||||
|
cores_check(Eina_List *cores);
|
||||||
|
|
||||||
|
Eina_List *
|
||||||
|
cores_find(void);
|
||||||
|
|
||||||
void
|
void
|
||||||
sensor_free(Sensor *sensor);
|
sensor_free(Sensor *sensor);
|
||||||
|
|
||||||
|
@ -113,21 +122,8 @@ sensor_check(Sensor *sensor);
|
||||||
Eina_List *
|
Eina_List *
|
||||||
network_interfaces_find(void);
|
network_interfaces_find(void);
|
||||||
|
|
||||||
int
|
|
||||||
system_cpu_online_count_get(void);
|
|
||||||
|
|
||||||
int
|
|
||||||
system_cpu_count_get(void);
|
|
||||||
|
|
||||||
Cpu_Core **
|
|
||||||
system_cpu_usage_get(int *ncpu);
|
|
||||||
|
|
||||||
Cpu_Core **
|
|
||||||
system_cpu_usage_delayed_get(int *ncpu, int usecs);
|
|
||||||
|
|
||||||
Cpu_Core **
|
|
||||||
system_cpu_state_get(int *ncpu);
|
|
||||||
|
|
||||||
|
// XXX
|
||||||
int
|
int
|
||||||
system_cpu_frequency_get(void);
|
system_cpu_frequency_get(void);
|
||||||
|
|
||||||
|
@ -146,7 +142,4 @@ system_cpu_frequency_min_max_get(int *min, int *max);
|
||||||
void
|
void
|
||||||
system_cpu_topology_get(int *ids, int ncpus);
|
system_cpu_topology_get(int *ids, int ncpus);
|
||||||
|
|
||||||
void
|
|
||||||
system_memory_usage_get(Meminfo *memory);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -71,27 +71,29 @@ system_cpu_online_count_get(void)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
void
|
||||||
_cpu_state_get(Cpu_Core **cores, int ncpu)
|
cores_check(Eina_List *cores)
|
||||||
{
|
{
|
||||||
int diff_total, diff_idle;
|
int diff_total, diff_idle;
|
||||||
double ratio, percent;
|
double ratio, percent;
|
||||||
unsigned long total, idle, used;
|
unsigned long total, idle, used;
|
||||||
Cpu_Core *core;
|
Cpu_Core *core;
|
||||||
|
int ncpu = eina_list_count(cores);
|
||||||
|
if (!ncpu) return;
|
||||||
|
|
||||||
#if defined(__FreeBSD__) || defined(__DragonFly__)
|
#if defined(__FreeBSD__) || defined(__DragonFly__)
|
||||||
size_t size;
|
size_t size;
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
if (!ncpu)
|
|
||||||
return;
|
|
||||||
size = sizeof(unsigned long) * (CPU_STATES * ncpu);
|
size = sizeof(unsigned long) * (CPU_STATES * ncpu);
|
||||||
unsigned long cpu_times[ncpu][CPU_STATES];
|
unsigned long cpu_times[ncpu][CPU_STATES];
|
||||||
|
|
||||||
if (sysctlbyname("kern.cp_times", cpu_times, &size, NULL, 0) < 0)
|
if (sysctlbyname("kern.cp_times", cpu_times, &size, NULL, 0) < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (i = 0; i < ncpu; i++) {
|
for (i = 0; i < ncpu; i++)
|
||||||
core = cores[i];
|
{
|
||||||
|
core = eina_list_nth(cores, i);
|
||||||
unsigned long *cpu = cpu_times[i];
|
unsigned long *cpu = cpu_times[i];
|
||||||
|
|
||||||
total = 0;
|
total = 0;
|
||||||
|
@ -115,7 +117,6 @@ _cpu_state_get(Cpu_Core **cores, int ncpu)
|
||||||
core->percent = percent;
|
core->percent = percent;
|
||||||
core->total = total;
|
core->total = total;
|
||||||
core->idle = idle;
|
core->idle = idle;
|
||||||
core->id = i;
|
|
||||||
}
|
}
|
||||||
#elif defined(__OpenBSD__)
|
#elif defined(__OpenBSD__)
|
||||||
static struct cpustats cpu_times[CPU_STATES];
|
static struct cpustats cpu_times[CPU_STATES];
|
||||||
|
@ -124,11 +125,10 @@ _cpu_state_get(Cpu_Core **cores, int ncpu)
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
memset(&cpu_times, 0, CPU_STATES * sizeof(struct cpustats));
|
memset(&cpu_times, 0, CPU_STATES * sizeof(struct cpustats));
|
||||||
if (!ncpu)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (i = 0; i < ncpu; i++) {
|
for (i = 0; i < ncpu; i++)
|
||||||
core = cores[i];
|
{
|
||||||
|
core = eina_list_nth(cores, i);
|
||||||
size = sizeof(struct cpustats);
|
size = sizeof(struct cpustats);
|
||||||
cpu_time_mib[2] = i;
|
cpu_time_mib[2] = i;
|
||||||
if (sysctl(cpu_time_mib, 3, &cpu_times[i], &size, NULL, 0) < 0)
|
if (sysctl(cpu_time_mib, 3, &cpu_times[i], &size, NULL, 0) < 0)
|
||||||
|
@ -155,7 +155,6 @@ _cpu_state_get(Cpu_Core **cores, int ncpu)
|
||||||
core->percent = percent;
|
core->percent = percent;
|
||||||
core->total = total;
|
core->total = total;
|
||||||
core->idle = idle;
|
core->idle = idle;
|
||||||
core->id = i;
|
|
||||||
}
|
}
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
char *buf, name[128];
|
char *buf, name[128];
|
||||||
|
@ -164,8 +163,9 @@ _cpu_state_get(Cpu_Core **cores, int ncpu)
|
||||||
buf = file_contents("/proc/stat");
|
buf = file_contents("/proc/stat");
|
||||||
if (!buf) return;
|
if (!buf) return;
|
||||||
|
|
||||||
for (i = 0; i < ncpu; i++) {
|
for (i = 0; i < ncpu; i++)
|
||||||
core = cores[i];
|
{
|
||||||
|
core = eina_list_nth(cores, i);
|
||||||
snprintf(name, sizeof(name), "cpu%d", i);
|
snprintf(name, sizeof(name), "cpu%d", i);
|
||||||
char *line = strstr(buf, name);
|
char *line = strstr(buf, name);
|
||||||
if (line)
|
if (line)
|
||||||
|
@ -194,7 +194,6 @@ _cpu_state_get(Cpu_Core **cores, int ncpu)
|
||||||
core->percent = percent;
|
core->percent = percent;
|
||||||
core->total = total;
|
core->total = total;
|
||||||
core->idle = idle;
|
core->idle = idle;
|
||||||
core->id = i;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(buf);
|
free(buf);
|
||||||
|
@ -205,7 +204,7 @@ _cpu_state_get(Cpu_Core **cores, int ncpu)
|
||||||
unsigned int cpu_count;
|
unsigned int cpu_count;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
cpu_count = ncpu;
|
cpu_count = eina_list_count(cores);
|
||||||
|
|
||||||
count = HOST_CPU_LOAD_INFO_COUNT;
|
count = HOST_CPU_LOAD_INFO_COUNT;
|
||||||
mach_port = mach_host_self();
|
mach_port = mach_host_self();
|
||||||
|
@ -213,8 +212,9 @@ _cpu_state_get(Cpu_Core **cores, int ncpu)
|
||||||
(processor_info_array_t *)&load, &count) != KERN_SUCCESS)
|
(processor_info_array_t *)&load, &count) != KERN_SUCCESS)
|
||||||
exit(-1);
|
exit(-1);
|
||||||
|
|
||||||
for (i = 0; i < ncpu; i++) {
|
for (i = 0; i < ncpu; i++)
|
||||||
core = cores[i];
|
{
|
||||||
|
core = eina_list_nth(cores, i);
|
||||||
|
|
||||||
total = load[i].cpu_ticks[CPU_STATE_USER] +
|
total = load[i].cpu_ticks[CPU_STATE_USER] +
|
||||||
load[i].cpu_ticks[CPU_STATE_SYSTEM] +
|
load[i].cpu_ticks[CPU_STATE_SYSTEM] +
|
||||||
|
@ -236,57 +236,27 @@ _cpu_state_get(Cpu_Core **cores, int ncpu)
|
||||||
core->percent = percent;
|
core->percent = percent;
|
||||||
core->total = total;
|
core->total = total;
|
||||||
core->idle = idle;
|
core->idle = idle;
|
||||||
core->id = i;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Cpu_Core **
|
Eina_List *
|
||||||
system_cpu_state_get(int *ncpu)
|
cores_find(void)
|
||||||
{
|
{
|
||||||
Cpu_Core **cores;
|
Eina_List *cores = NULL;
|
||||||
int i;
|
Cpu_Core *core;
|
||||||
|
int i, ncpu;
|
||||||
*ncpu = cpu_count();
|
|
||||||
cores = malloc((*ncpu) * sizeof(Cpu_Core *));
|
|
||||||
for (i = 0; i < *ncpu; i++)
|
|
||||||
cores[i] = calloc(1, sizeof(Cpu_Core));
|
|
||||||
|
|
||||||
_cpu_state_get(cores, *ncpu);
|
|
||||||
|
|
||||||
|
ncpu = cpu_count();
|
||||||
|
for (i = 0; i < ncpu; i++)
|
||||||
|
{
|
||||||
|
core = calloc(1, sizeof(Cpu_Core));
|
||||||
|
core->id = i;
|
||||||
|
cores = eina_list_append(cores, core);
|
||||||
|
}
|
||||||
return cores;
|
return cores;
|
||||||
}
|
}
|
||||||
|
|
||||||
Cpu_Core **
|
|
||||||
system_cpu_usage_delayed_get(int *ncpu, int usecs)
|
|
||||||
{
|
|
||||||
Cpu_Core **cores;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
*ncpu = cpu_count();
|
|
||||||
|
|
||||||
cores = malloc((*ncpu) * sizeof(Cpu_Core *));
|
|
||||||
if (!cores) return NULL;
|
|
||||||
|
|
||||||
for (i = 0; i < *ncpu; i++)
|
|
||||||
{
|
|
||||||
cores[i] = calloc(1, sizeof(Cpu_Core));
|
|
||||||
if (!cores[i]) return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
_cpu_state_get(cores, *ncpu);
|
|
||||||
usleep(usecs);
|
|
||||||
_cpu_state_get(cores, *ncpu);
|
|
||||||
|
|
||||||
return cores;
|
|
||||||
}
|
|
||||||
|
|
||||||
Cpu_Core **
|
|
||||||
system_cpu_usage_get(int *ncpu)
|
|
||||||
{
|
|
||||||
return system_cpu_usage_delayed_get(ncpu, 1000000);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int _cpu_temp_min = 0;
|
static int _cpu_temp_min = 0;
|
||||||
static int _cpu_temp_max = 100;
|
static int _cpu_temp_max = 100;
|
||||||
static char _core_temps[256][512];
|
static char _core_temps[256][512];
|
||||||
|
|
|
@ -16,7 +16,7 @@ _meminfo_parse_line(const char *line)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
system_memory_usage_get(Meminfo *memory)
|
memory_info(Meminfo *memory)
|
||||||
{
|
{
|
||||||
memset(memory, 0, sizeof(Meminfo));
|
memset(memory, 0, sizeof(Meminfo));
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
|
|
Loading…
Reference in New Issue