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 3ba7f97fe7781406647020b272a54480b83b7c36
Author: Alastair Poole <[email protected]>
AuthorDate: Mon Apr 27 23:44:43 2026 +0100

    engine: caching of log boundaries.
---
 src/bin/engine/evisum_engine.c      | 144 ++++++++++++++++++++++++++++-----
 src/bin/ui/evisum_ui_process_list.c | 153 +++++++++++++++++++++++++++---------
 2 files changed, 244 insertions(+), 53 deletions(-)

diff --git a/src/bin/engine/evisum_engine.c b/src/bin/engine/evisum_engine.c
index 6f06caa..78d8c79 100644
--- a/src/bin/engine/evisum_engine.c
+++ b/src/bin/engine/evisum_engine.c
@@ -32,6 +32,9 @@ typedef struct {
     uint32_t history_time;
     Eina_List *history_logs;
     time_t history_logs_scan_at;
+    Eina_List *history_recent_logs;
+    uint32_t history_recent_since;
+    time_t history_recent_logs_scan_at;
 } Evisum_Engine_State;
 
 typedef struct {
@@ -129,6 +132,10 @@ evisum_engine_shutdown(void)
     _engine_history_logs_free(_state.history_logs);
     _state.history_logs = NULL;
     _state.history_logs_scan_at = 0;
+    _engine_history_logs_free(_state.history_recent_logs);
+    _state.history_recent_logs = NULL;
+    _state.history_recent_since = 0;
+    _state.history_recent_logs_scan_at = 0;
 
     _state.started = EINA_FALSE;
     _state.history_enabled = EINA_FALSE;
@@ -294,6 +301,7 @@ _engine_history_archive_name_is_valid(const char *name)
 
     len = strlen(name);
     if (len > 5 && !strcmp(name + len - 5, ".size")) return EINA_FALSE;
+    if (len > 7 && !strcmp(name + len - 7, ".bounds")) return EINA_FALSE;
 
     if (len > 4 && !strcmp(name + len - 4, ".lz4")) len -= 4;
     if (len < 2) return EINA_FALSE;
@@ -323,32 +331,103 @@ _engine_history_log_sort_cb(const void *d1, const void *d2)
     return 0;
 }
 
+static char *
+_engine_history_log_bounds_cache_path_get(const char *path)
+{
+    char buf[PATH_MAX];
+
+    if (!path) return NULL;
+
+    snprintf(buf, sizeof(buf), "%s.bounds", path);
+    return strdup(buf);
+}
+
 static Eina_Bool
-_engine_history_log_add(Eina_List **logs, char *path)
+_engine_history_log_bounds_cache_get(const char *path, const struct stat *st, uint32_t *start_time, uint32_t *end_time)
+{
+    char *cache_path;
+    FILE *f;
+    long long mtime = 0, size = 0;
+    uint32_t start = 0, end = 0;
+    Eina_Bool ok = EINA_FALSE;
+
+    if (!path || !st || !start_time || !end_time) return EINA_FALSE;
+
+    cache_path = _engine_history_log_bounds_cache_path_get(path);
+    if (!cache_path) return EINA_FALSE;
+
+    f = fopen(cache_path, "r");
+    free(cache_path);
+    if (!f) return EINA_FALSE;
+
+    if (fscanf(f, "%lld %lld %u %u", &mtime, &size, &start, &end) == 4) {
+        ok = ((mtime == (long long) st->st_mtime) && (size == (long long) st->st_size) && start && end);
+    }
+    fclose(f);
+
+    if (!ok) return EINA_FALSE;
+
+    *start_time = start;
+    *end_time = end;
+
+    return EINA_TRUE;
+}
+
+static void
+_engine_history_log_bounds_cache_set(const char *path, const struct stat *st, uint32_t start_time, uint32_t end_time)
+{
+    char *cache_path;
+    FILE *f;
+
+    if (!path || !st || !start_time || !end_time) return;
+
+    cache_path = _engine_history_log_bounds_cache_path_get(path);
+    if (!cache_path) return;
+
+    f = fopen(cache_path, "w");
+    free(cache_path);
+    if (!f) return;
+
+    fprintf(f, "%lld %lld %u %u\n", (long long) st->st_mtime, (long long) st->st_size, start_time, end_time);
+    fclose(f);
+}
+
+static Eina_Bool
+_engine_history_log_add(Eina_List **logs, char *path, const struct stat *st_in)
 {
     Enigmatic_Client *client;
     Evisum_Engine_History_Log *log;
     uint32_t start_time = 0, end_time = 0;
+    struct stat st;
 
     if (!logs || !path) {
         free(path);
         return EINA_FALSE;
     }
 
-    client = _engine_history_client_for_path_read(strdup(path), 0);
-    if (!client) {
+    if (st_in) st = *st_in;
+    else if (stat(path, &st) == -1) {
         free(path);
         return EINA_FALSE;
     }
 
-    if (!enigmatic_client_time_bounds_get(client, &start_time, &end_time) || !start_time || !end_time) {
+    if (!_engine_history_log_bounds_cache_get(path, &st, &start_time, &end_time)) {
+        client = _engine_history_client_for_path_read(strdup(path), 0);
+        if (!client) {
+            free(path);
+            return EINA_FALSE;
+        }
+
+        if (!enigmatic_client_time_bounds_get(client, &start_time, &end_time) || !start_time || !end_time) {
+            enigmatic_client_del(client);
+            free(path);
+            return EINA_FALSE;
+        }
+
         enigmatic_client_del(client);
-        free(path);
-        return EINA_FALSE;
+        _engine_history_log_bounds_cache_set(path, &st, start_time, end_time);
     }
 
-    enigmatic_client_del(client);
-
     log = calloc(1, sizeof(*log));
     if (!log) {
         free(path);
@@ -373,7 +452,7 @@ _engine_history_logs_scan(uint32_t since)
     char *dir, *current_path;
 
     current_path = enigmatic_log_path();
-    _engine_history_log_add(&logs, current_path);
+    _engine_history_log_add(&logs, current_path, NULL);
 
     dir = enigmatic_log_directory();
     if (!dir) return logs;
@@ -396,7 +475,7 @@ _engine_history_logs_scan(uint32_t since)
         if (access(path, R_OK) != 0) continue;
         if (since && st.st_mtime && ((uint32_t) st.st_mtime < since)) continue;
 
-        _engine_history_log_add(&logs, strdup(path));
+        _engine_history_log_add(&logs, strdup(path), &st);
     }
 
     closedir(dp);
@@ -405,6 +484,23 @@ _engine_history_logs_scan(uint32_t since)
     return eina_list_sort(logs, eina_list_count(logs), _engine_history_log_sort_cb);
 }
 
+static Eina_List *
+_engine_history_logs_since_trim(Eina_List *logs, uint32_t since)
+{
+    Eina_List *l, *l_next;
+    Evisum_Engine_History_Log *log;
+
+    if (!since) return logs;
+
+    EINA_LIST_FOREACH_SAFE(logs, l, l_next, log) {
+        if (log && log->end_time && (log->end_time >= since)) continue;
+        logs = eina_list_remove_list(logs, l);
+        _engine_history_log_free(log);
+    }
+
+    return logs;
+}
+
 static Eina_List *
 _engine_history_logs_get(Eina_Bool refresh, uint32_t since)
 {
@@ -413,23 +509,35 @@ _engine_history_logs_get(Eina_Bool refresh, uint32_t since)
 
     now = time(NULL);
 
-    if (!since && !refresh && _state.lock_init) {
+    if (!refresh && _state.lock_init) {
         LOCK();
-        if (_state.history_logs && ((now - _state.history_logs_scan_at) < HISTORY_LOG_CACHE_TTL))
-            copy = _engine_history_logs_clone(_state.history_logs);
+        if (!since) {
+            if (_state.history_logs && ((now - _state.history_logs_scan_at) < HISTORY_LOG_CACHE_TTL))
+                copy = _engine_history_logs_clone(_state.history_logs);
+        } else if (_state.history_recent_logs && (since >= _state.history_recent_since)
+                   && ((now - _state.history_recent_logs_scan_at) < HISTORY_LOG_CACHE_TTL)) {
+            copy = _engine_history_logs_clone(_state.history_recent_logs);
+        }
         UNLOCK();
-        if (copy) return copy;
+        if (copy) return _engine_history_logs_since_trim(copy, since);
     }
 
     logs = _engine_history_logs_scan(since);
     if (!logs) return NULL;
 
-    if (!since && _state.lock_init) {
+    if (_state.lock_init) {
         copy = _engine_history_logs_clone(logs);
         LOCK();
-        _engine_history_logs_free(_state.history_logs);
-        _state.history_logs = copy;
-        _state.history_logs_scan_at = now;
+        if (since) {
+            _engine_history_logs_free(_state.history_recent_logs);
+            _state.history_recent_logs = copy;
+            _state.history_recent_since = since;
+            _state.history_recent_logs_scan_at = now;
+        } else {
+            _engine_history_logs_free(_state.history_logs);
+            _state.history_logs = copy;
+            _state.history_logs_scan_at = now;
+        }
         UNLOCK();
     }
 
diff --git a/src/bin/ui/evisum_ui_process_list.c b/src/bin/ui/evisum_ui_process_list.c
index 4ef170d..c5dd93f 100644
--- a/src/bin/ui/evisum_ui_process_list.c
+++ b/src/bin/ui/evisum_ui_process_list.c
@@ -81,6 +81,7 @@ typedef struct {
         Eina_Bool whole;
         Ecore_Timer *timer;
         Ecore_Timer *apply_timer;
+        Ecore_Thread *bounds_thread;
         uint32_t start_time;
         uint32_t end_time;
         uint32_t requested_time;
@@ -109,6 +110,15 @@ typedef struct {
     int (*sort_cb)(const void *p1, const void *p2);
 } Proc_Field_Info;
 
+typedef struct {
+    Evisum_Ui_Process_List_View *view;
+    Eina_Bool whole;
+    Eina_Bool ok;
+    uint32_t since;
+    uint32_t start_time;
+    uint32_t end_time;
+} History_Bounds_Request;
+
 static const Proc_Field_Info _proc_field_info[PROC_FIELD_MAX] = {
     [PROC_FIELD_CMD] =        { N_("COMMAND"), N_("Command"),         PROC_SORT_BY_CMD,        proc_sort_by_cmd        },
     [PROC_FIELD_UID] =        { N_("USER"),    N_("User"),            PROC_SORT_BY_UID,        proc_sort_by_uid        },
@@ -845,43 +855,11 @@ _evisum_ui_process_list_history_live_state_set(Evisum_Ui_Process_List_View *view
 }
 
 static void
-_evisum_ui_process_list_history_bounds_update(Evisum_Ui_Process_List_View *view) {
-    uint32_t start_time = 0, end_time = 0;
-    uint32_t live_time, now, since = 0;
+_evisum_ui_process_list_history_bounds_apply(Evisum_Ui_Process_List_View *view, uint32_t start_time, uint32_t end_time) {
     Eina_Bool live;
 
     if (!view->summary.history_slider) return;
 
-    now = (uint32_t) time(NULL);
-    live_time = evisum_engine_live_time_get();
-
-    /* The default history view is the recent contiguous range only.  Whole
-     * history mode deliberately keeps the older broad bounds behaviour. */
-    if (view->history.whole != view->ui->proc.history_whole) {
-        view->history.whole = view->ui->proc.history_whole;
-        view->history.start_time = 0;
-        view->history.end_time = 0;
-    }
-    if (!view->ui->proc.history_whole) since = now > 3600 ? now - 3600 : 0;
-    if ((view->history.start_time) && (!since || (view->history.start_time >= since))
-        && (now >= view->history.start_time)) {
-        start_time = view->history.start_time;
-        end_time = live_time > now ? live_time : now;
-    } else {
-        if (since) {
-            if (!evisum_engine_history_contiguous_bounds_since_get(since, &start_time, &end_time)) {
-                elm_object_disabled_set(view->summary.history_slider, 1);
-                elm_object_disabled_set(view->summary.history_live_btn, 1);
-                return;
-            }
-        } else if (!evisum_engine_history_bounds_get(&start_time, &end_time)) {
-            elm_object_disabled_set(view->summary.history_slider, 1);
-            elm_object_disabled_set(view->summary.history_live_btn, 1);
-            return;
-        }
-    }
-
-    if (since && (start_time < since)) start_time = since;
     if (end_time <= start_time) end_time = start_time + 1;
 
     view->history.start_time = start_time;
@@ -901,6 +879,110 @@ _evisum_ui_process_list_history_bounds_update(Evisum_Ui_Process_List_View *view)
     }
 }
 
+static void
+_evisum_ui_process_list_history_bounds_worker_cb(void *data, Ecore_Thread *thread) {
+    History_Bounds_Request *req = data;
+
+    if (ecore_thread_check(thread)) return;
+
+    if (req->whole) req->ok = evisum_engine_history_bounds_get(&req->start_time, &req->end_time);
+    else req->ok = evisum_engine_history_contiguous_bounds_since_get(req->since, &req->start_time, &req->end_time);
+}
+
+static void
+_evisum_ui_process_list_history_bounds_done_cb(void *data, Ecore_Thread *thread) {
+    History_Bounds_Request *req = data;
+    Evisum_Ui_Process_List_View *view = req->view;
+    uint32_t start_time, end_time;
+
+    if (view->history.bounds_thread == thread) view->history.bounds_thread = NULL;
+
+    if (req->ok) {
+        start_time = req->start_time;
+        end_time = req->end_time;
+        if (req->since && (start_time < req->since)) start_time = req->since;
+        _evisum_ui_process_list_history_bounds_apply(view, start_time, end_time);
+    } else if (!view->history.start_time) {
+        elm_object_disabled_set(view->summary.history_slider, 1);
+        elm_object_disabled_set(view->summary.history_live_btn, 1);
+    }
+
+    free(req);
+}
+
+static void
+_evisum_ui_process_list_history_bounds_cancel_cb(void *data, Ecore_Thread *thread) {
+    History_Bounds_Request *req = data;
+    Evisum_Ui_Process_List_View *view = req->view;
+
+    if (view && (view->history.bounds_thread == thread)) view->history.bounds_thread = NULL;
+
+    free(req);
+}
+
+static void
+_evisum_ui_process_list_history_bounds_refresh(Evisum_Ui_Process_List_View *view, Eina_Bool whole, uint32_t since) {
+    History_Bounds_Request *req;
+
+    if (view->history.bounds_thread) return;
+
+    req = calloc(1, sizeof(*req));
+    if (!req) return;
+
+    req->view = view;
+    req->whole = whole;
+    req->since = since;
+
+    view->history.bounds_thread = ecore_thread_run(_evisum_ui_process_list_history_bounds_worker_cb,
+                                                   _evisum_ui_process_list_history_bounds_done_cb,
+                                                   _evisum_ui_process_list_history_bounds_cancel_cb, req);
+    if (!view->history.bounds_thread) free(req);
+}
+
+static void
+_evisum_ui_process_list_history_bounds_refresh_cancel(Evisum_Ui_Process_List_View *view) {
+    if (!view->history.bounds_thread) return;
+
+    ecore_thread_cancel(view->history.bounds_thread);
+    ecore_thread_wait(view->history.bounds_thread, 0.5);
+    view->history.bounds_thread = NULL;
+}
+
+static void
+_evisum_ui_process_list_history_bounds_update(Evisum_Ui_Process_List_View *view) {
+    uint32_t start_time = 0, end_time = 0;
+    uint32_t live_time, now, since = 0;
+
+    if (!view->summary.history_slider) return;
+
+    now = (uint32_t) time(NULL);
+    live_time = evisum_engine_live_time_get();
+
+    /* The default history view is the recent contiguous range only.  Whole
+     * history mode deliberately keeps the older broad bounds behaviour. */
+    if (view->history.whole != view->ui->proc.history_whole) {
+        view->history.whole = view->ui->proc.history_whole;
+        view->history.start_time = 0;
+        view->history.end_time = 0;
+    }
+    if (!view->ui->proc.history_whole) since = now > 3600 ? now - 3600 : 0;
+    if ((view->history.start_time) && (!since || (view->history.end_time >= since))
+        && (now >= view->history.start_time)) {
+        start_time = view->history.start_time;
+        end_time = live_time > now ? live_time : now;
+    } else {
+        _evisum_ui_process_list_history_bounds_refresh(view, view->ui->proc.history_whole, since);
+        if (!view->history.start_time) {
+            elm_object_disabled_set(view->summary.history_slider, 1);
+            elm_object_disabled_set(view->summary.history_live_btn, 1);
+        }
+        return;
+    }
+
+    if (since && (start_time < since)) start_time = since;
+    _evisum_ui_process_list_history_bounds_apply(view, start_time, end_time);
+}
+
 static uint32_t
 _evisum_ui_process_list_history_time_at_x_get(Evisum_Ui_Process_List_View *view, Evas_Coord canvas_x) {
     Evas_Coord x, w;
@@ -1084,8 +1166,6 @@ _evisum_ui_process_list_summary_update(Evisum_Ui_Process_List_View *view) {
     elm_object_part_text_set(view->summary.pb_mem, "elm.text.status", eina_strbuf_string_get(buf));
 
     eina_strbuf_free(buf);
-
-    _evisum_ui_process_list_history_bounds_update(view);
 }
 
 static void
@@ -2112,6 +2192,7 @@ _evisum_ui_process_list_config_changed_cb(void *data, int type EINA_UNUSED, void
     if (view->summary.visible && (view->history.whole != ui->proc.history_whole)) {
         uint32_t since = 0, history_time;
 
+        _evisum_ui_process_list_history_bounds_refresh_cancel(view);
         view->history.start_time = 0;
         view->history.end_time = 0;
 
@@ -2151,6 +2232,7 @@ _evisum_ui_process_list_config_changed_cb(void *data, int type EINA_UNUSED, void
             ecore_timer_del(view->history.apply_timer);
             view->history.apply_timer = NULL;
         }
+        _evisum_ui_process_list_history_bounds_refresh_cancel(view);
         _evisum_ui_process_list_loader_hide(view);
         elm_box_clear(view->summary.hbx);
         view->summary.visible = 0;
@@ -2194,6 +2276,7 @@ _evisum_ui_process_list_win_del_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED,
     if (view->main_menu_timer) ecore_timer_del(view->main_menu_timer);
     if (view->history.timer) ecore_timer_del(view->history.timer);
     if (view->history.apply_timer) ecore_timer_del(view->history.apply_timer);
+    _evisum_ui_process_list_history_bounds_refresh_cancel(view);
 
     if (view->menu) evas_object_del(view->menu);
     if (view->main_menu) evas_object_del(view->main_menu);

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

Reply via email to