netstar pushed a commit to branch master.

http://git.enlightenment.org/apps/evisum.git/commit/?id=981b377523f8463b48c6c5aa75ab3e42c7ce0395

commit 981b377523f8463b48c6c5aa75ab3e42c7ce0395
Author: Alastair Poole <nets...@gmail.com>
Date:   Mon May 17 13:36:40 2021 +0100

    wip: remove the blocky
---
 src/bin/evisum_watcher.c      | 21 +++++++----
 src/bin/next/machine.h        | 27 +++++---------
 src/bin/next/machine/cpu.x    | 86 ++++++++++++++-----------------------------
 src/bin/next/machine/memory.x |  2 +-
 4 files changed, 52 insertions(+), 84 deletions(-)

diff --git a/src/bin/evisum_watcher.c b/src/bin/evisum_watcher.c
index 7e0063c..81f6536 100644
--- a/src/bin/evisum_watcher.c
+++ b/src/bin/evisum_watcher.c
@@ -6,24 +6,29 @@
 static Eina_List   *batteries = NULL;
 static Eina_List   *sensors = NULL;
 static Eina_List   *network_interfaces = NULL;
+static Eina_List   *cores = NULL;
 
 int
 main(int argc, char **argv)
 {
+   Eina_List *l;
+   Cpu_Core *core;
    ecore_init();
 
    puts("CORES:");
 
-   Cpu_Core **cores;
-
-   int ncpu = 0;
-   cores = system_cpu_usage_delayed_get(&ncpu, 1000000);
-   for (int i = 0; i < ncpu; i++)
+   cores = cores_find();
+   for (int i = 0; i < 10; i++)
      {
-        printf("core %i = %1.2f%%\n", cores[i]->id, cores[i]->percent);
-        free(cores[i]);
+        cores_check(cores);
+        EINA_LIST_FOREACH(cores, l, core)
+          {
+             printf("core %i = %1.2f%%\n", core->id, core->percent);
+          }
+       usleep(1000000);
      }
-   free(cores);
+   EINA_LIST_FREE(cores, core)
+     free(core);
 
    puts("BATTERIES:");
    Battery *bat;
diff --git a/src/bin/next/machine.h b/src/bin/next/machine.h
index 3b8cfc6..d0674d2 100644
--- a/src/bin/next/machine.h
+++ b/src/bin/next/machine.h
@@ -104,6 +104,15 @@ battery_check(Battery *bat);
 Eina_List *
 sensors_find(void);
 
+void
+memory_info(Meminfo *memory);
+
+void
+cores_check(Eina_List *cores);
+
+Eina_List *
+cores_find(void);
+
 void
 sensor_free(Sensor *sensor);
 
@@ -113,21 +122,8 @@ sensor_check(Sensor *sensor);
 Eina_List *
 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
 system_cpu_frequency_get(void);
 
@@ -146,7 +142,4 @@ system_cpu_frequency_min_max_get(int *min, int *max);
 void
 system_cpu_topology_get(int *ids, int ncpus);
 
-void
-system_memory_usage_get(Meminfo *memory);
-
 #endif
diff --git a/src/bin/next/machine/cpu.x b/src/bin/next/machine/cpu.x
index f34e7ec..66c7253 100644
--- a/src/bin/next/machine/cpu.x
+++ b/src/bin/next/machine/cpu.x
@@ -71,27 +71,29 @@ system_cpu_online_count_get(void)
 #endif
 }
 
-static void
-_cpu_state_get(Cpu_Core **cores, int ncpu)
+void
+cores_check(Eina_List *cores)
 {
    int diff_total, diff_idle;
    double ratio, percent;
    unsigned long total, idle, used;
    Cpu_Core *core;
+   int ncpu = eina_list_count(cores);
+   if (!ncpu) return;
+
 #if defined(__FreeBSD__) || defined(__DragonFly__)
    size_t size;
    int i, j;
 
-   if (!ncpu)
-     return;
    size = sizeof(unsigned long) * (CPU_STATES * ncpu);
    unsigned long cpu_times[ncpu][CPU_STATES];
 
    if (sysctlbyname("kern.cp_times", cpu_times, &size, NULL, 0) < 0)
      return;
 
-   for (i = 0; i < ncpu; i++) {
-        core = cores[i];
+   for (i = 0; i < ncpu; i++)
+     {
+        core = eina_list_nth(cores, i);
         unsigned long *cpu = cpu_times[i];
 
         total = 0;
@@ -115,7 +117,6 @@ _cpu_state_get(Cpu_Core **cores, int ncpu)
         core->percent = percent;
         core->total = total;
         core->idle = idle;
-        core->id = i;
      }
 #elif defined(__OpenBSD__)
    static struct cpustats cpu_times[CPU_STATES];
@@ -124,11 +125,10 @@ _cpu_state_get(Cpu_Core **cores, int ncpu)
    int i, j;
 
    memset(&cpu_times, 0, CPU_STATES * sizeof(struct cpustats));
-   if (!ncpu)
-     return;
 
-   for (i = 0; i < ncpu; i++) {
-        core = cores[i];
+   for (i = 0; i < ncpu; i++)
+     {
+        core = eina_list_nth(cores, i);
         size = sizeof(struct cpustats);
         cpu_time_mib[2] = i;
         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->total = total;
         core->idle = idle;
-        core->id = i;
      }
 #elif defined(__linux__)
    char *buf, name[128];
@@ -164,8 +163,9 @@ _cpu_state_get(Cpu_Core **cores, int ncpu)
    buf = file_contents("/proc/stat");
    if (!buf) return;
 
-   for (i = 0; i < ncpu; i++) {
-        core = cores[i];
+   for (i = 0; i < ncpu; i++)
+     {
+        core = eina_list_nth(cores, i);
         snprintf(name, sizeof(name), "cpu%d", i);
         char *line = strstr(buf, name);
         if (line)
@@ -194,7 +194,6 @@ _cpu_state_get(Cpu_Core **cores, int ncpu)
              core->percent = percent;
              core->total = total;
              core->idle = idle;
-             core->id = i;
           }
      }
    free(buf);
@@ -205,7 +204,7 @@ _cpu_state_get(Cpu_Core **cores, int ncpu)
    unsigned int cpu_count;
    int i;
 
-   cpu_count = ncpu;
+   cpu_count = eina_list_count(cores);
 
    count = HOST_CPU_LOAD_INFO_COUNT;
    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)
      exit(-1);
 
-   for (i = 0; i < ncpu; i++) {
-        core = cores[i];
+   for (i = 0; i < ncpu; i++)
+     {
+        core = eina_list_nth(cores, i);
 
         total = load[i].cpu_ticks[CPU_STATE_USER] +
            load[i].cpu_ticks[CPU_STATE_SYSTEM] +
@@ -236,57 +236,27 @@ _cpu_state_get(Cpu_Core **cores, int ncpu)
         core->percent = percent;
         core->total = total;
         core->idle = idle;
-        core->id = i;
      }
 #endif
 }
 
-Cpu_Core **
-system_cpu_state_get(int *ncpu)
-{
-   Cpu_Core **cores;
-   int i;
-
-   *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);
-
-   return cores;
-}
-
-Cpu_Core **
-system_cpu_usage_delayed_get(int *ncpu, int usecs)
+Eina_List *
+cores_find(void)
 {
-   Cpu_Core **cores;
-   int i;
-
-   *ncpu = cpu_count();
-
-   cores = malloc((*ncpu) * sizeof(Cpu_Core *));
-   if (!cores) return NULL;
+   Eina_List *cores = NULL;
+   Cpu_Core *core;
+   int i, ncpu;
 
-   for (i = 0; i < *ncpu; i++)
+   ncpu = cpu_count();
+   for (i = 0; i < ncpu; i++)
      {
-        cores[i] = calloc(1, sizeof(Cpu_Core));
-        if (!cores[i]) return NULL;
+        core = calloc(1, sizeof(Cpu_Core));
+        core->id = i;
+        cores = eina_list_append(cores, core);
      }
-
-   _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_max = 100;
 static char _core_temps[256][512];
diff --git a/src/bin/next/machine/memory.x b/src/bin/next/machine/memory.x
index 501ef7b..e688aca 100644
--- a/src/bin/next/machine/memory.x
+++ b/src/bin/next/machine/memory.x
@@ -16,7 +16,7 @@ _meminfo_parse_line(const char *line)
 #endif
 
 void
-system_memory_usage_get(Meminfo *memory)
+memory_info(Meminfo *memory)
 {
    memset(memory, 0, sizeof(Meminfo));
 #if defined(__linux__)

-- 


Reply via email to