]> git.hungrycats.org Git - bees/commitdiff
task: export load tracking statistics
authorZygo Blaxell <bees@furryterror.org>
Mon, 5 Dec 2022 05:10:10 +0000 (00:10 -0500)
committerZygo Blaxell <bees@furryterror.org>
Wed, 21 Dec 2022 01:50:57 +0000 (20:50 -0500)
Provide an interface so that programs can monitor the Task load
average calculations.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
include/crucible/task.h
lib/task.cc

index 142a0fc95c1e0c18b1c4aa8da40940356623fb47..7b7d132cad97d79121a7ad8d509c6aca52ea3167 100644 (file)
@@ -93,6 +93,17 @@ namespace crucible {
                /// Gets the current number of active workers
                static size_t get_thread_count();
 
+               /// Gets the current load tracking statistics
+               struct LoadStats {
+                       /// Current load extracted from last two 5-second load average samples
+                       double current_load;
+                       /// Target thread count computed from previous thread count and current load
+                       double thread_target;
+                       /// Load average for last 60 seconds
+                       double loadavg;
+               };
+               static LoadStats get_current_load();
+
                /// Drop the current queue and discard new Tasks without
                /// running them.  Currently executing tasks are not
                /// affected (use set_thread_count(0) to wait for those
index c18ecd84585101c1e1d52780ed0aed63feb0deb3..c33cf87cda3dda3c7b6fb7ecf9b6b7bd68248103 100644 (file)
@@ -139,6 +139,7 @@ namespace crucible {
                double                                  m_thread_target;
                bool                                    m_cancelled = false;
                bool                                    m_paused = false;
+               TaskMaster::LoadStats                   m_load_stats;
 
        friend class TaskConsumer;
        friend class TaskMaster;
@@ -165,6 +166,7 @@ namespace crucible {
                static void push_front(TaskQueue &queue);
                size_t get_queue_count();
                size_t get_thread_count();
+               static TaskMaster::LoadStats get_current_load();
        };
 
        class TaskConsumer : public enable_shared_from_this<TaskConsumer> {
@@ -348,7 +350,8 @@ namespace crucible {
        TaskMasterState::TaskMasterState(size_t thread_max) :
                m_thread_max(thread_max),
                m_configured_thread_max(thread_max),
-               m_thread_target(thread_max)
+               m_thread_target(thread_max),
+               m_load_stats(TaskMaster::LoadStats { 0 })
        {
        }
 
@@ -422,6 +425,13 @@ namespace crucible {
                return s_tms->m_threads.size();
        }
 
+       TaskMaster::LoadStats
+       TaskMaster::get_current_load()
+       {
+               unique_lock<mutex> lock(s_tms->m_mutex);
+               return s_tms->m_load_stats;
+       }
+
        ostream &
        TaskMaster::print_queue(ostream &os)
        {
@@ -502,6 +512,12 @@ namespace crucible {
                        m_thread_target += m_load_target - current_load;
                }
 
+               m_load_stats = TaskMaster::LoadStats {
+                       .current_load = current_load,
+                       .thread_target = m_thread_target,
+                       .loadavg = loadavg,
+               };
+
                // Cannot exceed configured maximum thread count or less than zero
                m_thread_target = min(max(0.0, m_thread_target), double(m_configured_thread_max));