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 840ea825d420ba8a246a98b243be8c42fd9d5612
Author: Alastair Poole <[email protected]>
AuthorDate: Fri May 29 00:48:51 2026 +0100

    file_systems: use global cache and poll interval.
---
 src/bin/enigmatic/enigmatic_main.c       |  1 +
 src/bin/enigmatic/monitor/file_systems.c | 89 ++++++++++++++++++++++++++++++++
 src/bin/enigmatic/monitor/file_systems.h |  3 ++
 3 files changed, 93 insertions(+)

diff --git a/src/bin/enigmatic/enigmatic_main.c b/src/bin/enigmatic/enigmatic_main.c
index 3571315..14580f9 100644
--- a/src/bin/enigmatic/enigmatic_main.c
+++ b/src/bin/enigmatic/enigmatic_main.c
@@ -163,6 +163,7 @@ enigmatic_shutdown(Enigmatic *enigmatic)
    enigmatic_monitor_batteries_shutdown();
    enigmatic_monitor_sensors_shutdown();
    enigmatic_monitor_power_shutdown();
+   enigmatic_monitor_file_systems_shutdown();
 
    enigmatic_server_shutdown(enigmatic);
 
diff --git a/src/bin/enigmatic/monitor/file_systems.c b/src/bin/enigmatic/monitor/file_systems.c
index 1208e85..dd5bea6 100644
--- a/src/bin/enigmatic/monitor/file_systems.c
+++ b/src/bin/enigmatic/monitor/file_systems.c
@@ -3,12 +3,95 @@
 #include "uid.h"
 #include "enigmatic_log.h"
 
+typedef struct
+{
+   uint64_t read;
+   uint64_t write;
+   uint32_t sample_time;
+} File_System_Raw;
+
+static Eina_Hash *_file_system_raw_cache;
+
 void
 file_system_key(char *buf, size_t len, File_System *fs)
 {
    snprintf(buf, len, "%s:%s", fs->path, fs->mount);
 }
 
+static Eina_Hash *
+_file_system_raw_cache_get(void)
+{
+   if (!_file_system_raw_cache)
+     _file_system_raw_cache = eina_hash_string_superfast_new(free);
+
+   return _file_system_raw_cache;
+}
+
+static int64_t
+_file_system_elapsed_get(Enigmatic *enigmatic, File_System_Raw *raw)
+{
+   int64_t elapsed = 0;
+
+   if ((raw) && (enigmatic->poll_time > raw->sample_time))
+     elapsed = enigmatic->poll_time - raw->sample_time;
+   if (elapsed <= 0)
+     elapsed = enigmatic->interval;
+   if (elapsed <= 0)
+     elapsed = 1;
+
+   return elapsed;
+}
+
+static void
+_file_system_rates_update(Enigmatic *enigmatic, const char *key, File_System *fs)
+{
+   Eina_Hash *cache;
+   File_System_Raw *raw;
+   uint64_t raw_read, raw_write;
+   int64_t elapsed;
+
+   raw_read = fs->usage.read;
+   raw_write = fs->usage.write;
+   fs->usage.read = 0;
+   fs->usage.write = 0;
+
+   cache = _file_system_raw_cache_get();
+   if (!cache) return;
+
+   raw = eina_hash_find(cache, key);
+   if (!raw)
+     {
+        raw = calloc(1, sizeof(File_System_Raw));
+        if (!raw) return;
+
+        raw->read = raw_read;
+        raw->write = raw_write;
+        raw->sample_time = enigmatic->poll_time;
+        if (!eina_hash_add(cache, key, raw))
+          free(raw);
+        return;
+     }
+
+   elapsed = _file_system_elapsed_get(enigmatic, raw);
+   if (raw_read >= raw->read)
+     fs->usage.read = (raw_read - raw->read) / elapsed;
+   if (raw_write >= raw->write)
+     fs->usage.write = (raw_write - raw->write) / elapsed;
+
+   raw->read = raw_read;
+   raw->write = raw_write;
+   raw->sample_time = enigmatic->poll_time;
+}
+
+void
+enigmatic_monitor_file_systems_shutdown(void)
+{
+   if (!_file_system_raw_cache) return;
+
+   eina_hash_free(_file_system_raw_cache);
+   _file_system_raw_cache = NULL;
+}
+
 static void
 cb_file_system_free(void *data)
 {
@@ -82,6 +165,7 @@ enigmatic_monitor_file_systems(Enigmatic *enigmatic, Eina_Hash **cache_hash)
                   file_system_key(key, sizeof(key), fs);
                   DEBUG("fs add: %s", key);
 
+                  _file_system_rates_update(enigmatic, key, fs2);
                   fs2->unique_id = unique_id_find(&enigmatic->unique_ids);
                   eina_hash_add(*cache_hash, key, fs2);
               }
@@ -128,6 +212,8 @@ enigmatic_monitor_file_systems(Enigmatic *enigmatic, Eina_Hash **cache_hash)
 
         file_system_key(key, sizeof(key), fs);
         unique_id_release(&enigmatic->unique_ids, fs->unique_id);
+        if (_file_system_raw_cache)
+          eina_hash_del(_file_system_raw_cache, key, NULL);
         eina_hash_del(*cache_hash, key, NULL);
      }
 
@@ -138,6 +224,7 @@ enigmatic_monitor_file_systems(Enigmatic *enigmatic, Eina_Hash **cache_hash)
         if (!fs2)
           {
              fs->unique_id = unique_id_find(&enigmatic->unique_ids);
+             _file_system_rates_update(enigmatic, key, fs);
 
              Message msg;
              msg.type = MESG_ADD;
@@ -154,6 +241,8 @@ enigmatic_monitor_file_systems(Enigmatic *enigmatic, Eina_Hash **cache_hash)
         Message msg;
         msg.type = MESG_MOD;
 
+        _file_system_rates_update(enigmatic, key, fs);
+
         if (fs2->usage.total != fs->usage.total)
           {
              msg.object_type = FILE_SYSTEM_TOTAL;
diff --git a/src/bin/enigmatic/monitor/file_systems.h b/src/bin/enigmatic/monitor/file_systems.h
index 3fb9bfd..a9f6d8d 100644
--- a/src/bin/enigmatic/monitor/file_systems.h
+++ b/src/bin/enigmatic/monitor/file_systems.h
@@ -6,4 +6,7 @@
 Eina_Bool
 enigmatic_monitor_file_systems(Enigmatic *enigmatic, Eina_Hash **cache_hash);
 
+void
+enigmatic_monitor_file_systems_shutdown(void);
+
 #endif

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

Reply via email to