This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository evisum.

View the commit online.

commit 9c177b5e7b5f0104ec17c427ce31dc8c8d1dd8f6
Author: Alastair Poole <[email protected]>
AuthorDate: Sun Mar 29 06:17:43 2026 +0100

    cpu_visuals: codex improvements.
    
    Implemented EMA smoothing for CPU percent rendering in both cpu_bars.c and cpu_basic.c to stabilize 30 Hz polling.
    Changes made:
    • Added per-core smoothing buffer in each visual state struct:
    ◦ int *cpu_smooth;
    • Allocated and initialized smoothing state during setup:
    ◦ ext->cpu_smooth = malloc(ext->cpu_count * sizeof(int));
    ◦ initialized each entry to -1 (means “no previous sample yet”).
    • Added allocation-failure handling:
    ◦ if cpu_order or cpu_smooth allocation fails, free allocated memory and return NULL.
    • Applied EMA in each feedback/render loop:
    ◦ percent = ((prev * 3) + current) / 4 when previous value exists.
    ◦ clamped to [0, 100].
    ◦ stored back to ext->cpu_smooth[i].
    • Switched rendering to use smoothed percent:
    ◦ cpu_bars.c: bar height and gradient color now use smoothed percent.
    ◦ cpu_basic.c: tile color and non-frequency size mode now use smoothed percent.
    • Freed smoothing buffer in teardown:
    ◦ free(ext->cpu_smooth);
---
 src/bin/ui/visuals/cpu_bars.c  | 22 ++++++++++++++++++++--
 src/bin/ui/visuals/cpu_basic.c | 22 ++++++++++++++++++++--
 2 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/src/bin/ui/visuals/cpu_bars.c b/src/bin/ui/visuals/cpu_bars.c
index 671c39a..4234dc7 100644
--- a/src/bin/ui/visuals/cpu_bars.c
+++ b/src/bin/ui/visuals/cpu_bars.c
@@ -7,6 +7,7 @@
 typedef struct {
     int cpu_count;
     int *cpu_order;
+    int *cpu_smooth;
     Eina_List *objects;
     Evas_Object *tb;
     Evas_Object *bg;
@@ -95,10 +96,17 @@ _core_times_feedback_cb(void *data, Ecore_Thread *thread EINA_UNUSED, void *msgd
     for (int i = 0; i < ext->cpu_count; i++) {
         Core *core = &cores[i];
         Evas_Object *rec = eina_list_nth(ext->objects, i);
+        int percent = core->percent;
+        int prev = ext->cpu_smooth[i];
+        if (prev >= 0) percent = ((prev * 3) + percent) / 4;
+        if (percent < 0) percent = 0;
+        else if (percent > 100)
+            percent = 100;
+        ext->cpu_smooth[i] = percent;
         evas_object_geometry_get(rec, &ox, NULL, NULL, NULL);
-        unsigned int c_top = cpu_colormap[core->percent & 0xff];
+        unsigned int c_top = cpu_colormap[percent];
         unsigned int c_bottom = cpu_colormap[0];
-        int h = core->percent * step;
+        int h = percent * step;
         if (!h) h = 1;
         evas_object_resize(rec, ELM_SCALE_SIZE(BAR_WIDTH), ELM_SCALE_SIZE(h));
         evas_object_move(rec, ox, oy - ELM_SCALE_SIZE(h));
@@ -115,6 +123,7 @@ _cb_free(void *data) {
 
     eina_list_free(ext->objects);
 
+    free(ext->cpu_smooth);
     free(ext->cpu_order);
     free(ext);
 }
@@ -137,7 +146,16 @@ cpu_visual_bars(Evas_Object *parent_bx) {
     /* Populate lookup table to match id with topology core id */
     ext->cpu_count = system_cpu_count_get();
     ext->cpu_order = malloc((ext->cpu_count) * sizeof(int));
+    ext->cpu_smooth = malloc((ext->cpu_count) * sizeof(int));
     for (i = 0; i < ext->cpu_count; i++) ext->cpu_order[i] = i;
+    if (!ext->cpu_order || !ext->cpu_smooth) {
+        free(ext->cpu_order);
+        free(ext->cpu_smooth);
+        free(ext);
+        free(pd);
+        return NULL;
+    }
+    for (i = 0; i < ext->cpu_count; i++) ext->cpu_smooth[i] = -1;
     system_cpu_topology_get(ext->cpu_order, ext->cpu_count);
 
     container = elm_table_add(parent_bx);
diff --git a/src/bin/ui/visuals/cpu_basic.c b/src/bin/ui/visuals/cpu_basic.c
index bab2cf1..acf18d6 100644
--- a/src/bin/ui/visuals/cpu_basic.c
+++ b/src/bin/ui/visuals/cpu_basic.c
@@ -8,6 +8,7 @@
 typedef struct {
     int cpu_count;
     int *cpu_order;
+    int *cpu_smooth;
     Evas_Object *container;
     Eina_List *objects;
     Eina_List *pads;
@@ -74,9 +75,16 @@ _core_times_feedback_cb(void *data, Ecore_Thread *thread EINA_UNUSED, void *msgd
     }
     for (int i = 0; i < ext->cpu_count; i++) {
         Core *core = &cores[i];
+        int percent = core->percent;
+        int prev = ext->cpu_smooth[i];
+        if (prev >= 0) percent = ((prev * 3) + percent) / 4;
+        if (percent < 0) percent = 0;
+        else if (percent > 100)
+            percent = 100;
+        ext->cpu_smooth[i] = percent;
         Evas_Object *pad = eina_list_nth(ext->pads, i);
         Evas_Object *rec = eina_list_nth(ext->objects, i);
-        int c = cpu_colormap[core->percent & 0xff];
+        int c = cpu_colormap[percent];
         int size = CORE_MIN_SIZE;
 
         if (ext->cpu_freq) {
@@ -89,7 +97,7 @@ _core_times_feedback_cb(void *data, Ecore_Thread *thread EINA_UNUSED, void *msgd
                 size = CORE_MIN_SIZE + ((v * (tile - CORE_MIN_SIZE)) / 100);
             }
         } else {
-            size = CORE_MIN_SIZE + ((core->percent * (tile - CORE_MIN_SIZE)) / 100);
+            size = CORE_MIN_SIZE + ((percent * (tile - CORE_MIN_SIZE)) / 100);
         }
 
         if (size > tile) size = tile;
@@ -110,6 +118,7 @@ _cb_free(void *data) {
     eina_list_free(ext->objects);
     eina_list_free(ext->pads);
 
+    free(ext->cpu_smooth);
     free(ext->cpu_order);
     free(ext);
 }
@@ -155,7 +164,16 @@ cpu_visual_basic(Evas_Object *parent_bx) {
     /* Populate lookup table to match id with topology core id */
     ext->cpu_count = system_cpu_count_get();
     ext->cpu_order = malloc((ext->cpu_count) * sizeof(int));
+    ext->cpu_smooth = malloc((ext->cpu_count) * sizeof(int));
     for (int i = 0; i < ext->cpu_count; i++) ext->cpu_order[i] = i;
+    if (!ext->cpu_order || !ext->cpu_smooth) {
+        free(ext->cpu_order);
+        free(ext->cpu_smooth);
+        free(ext);
+        free(pd);
+        return NULL;
+    }
+    for (int i = 0; i < ext->cpu_count; i++) ext->cpu_smooth[i] = -1;
     system_cpu_topology_get(ext->cpu_order, ext->cpu_count);
 
     container = elm_table_add(parent_bx);

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to