]> git.hungrycats.org Git - bees/commitdiff
reporter: add stateful delta-counts and delta-rates tokens
authorZygo Blaxell <bees@furryterror.org>
Sun, 30 Aug 2026 07:00:13 +0000 (03:00 -0400)
committerZygo Blaxell <bees@furryterror.org>
Sat, 5 Sep 2026 04:03:59 +0000 (00:03 -0400)
The totals and rates tokens report since startup, which flattens out: an
hour into a run, a burst of activity moves the cumulative numbers so
little that the report stops answering "what is bees doing now".

Add delta-counts and delta-rates, which report the change in the event
counters since that token last rendered.  Each report builds its own
token objects, so two reports at different intervals each see the delta
over their own interval rather than fighting over one shared snapshot.
delta-rates divides by the measured elapsed time rather than the
configured interval, so a report that ran late reports the rate it
actually observed.

Assisted-by: Claude-Code:claude-opus-4-8
Assisted-by: Claude-Code:claude-opus-5
Signed-off-by: Zygo Blaxell <bees@furryterror.org>
docs/config-file.md
src/bees-config-v1.cc
src/bees-reporter.cc

index 3c075eb4e1c7de50105d61541a608dd4280adc87..24cbe96ea42b7c9aa9a27099ff914737f861fc8a 100644 (file)
@@ -403,6 +403,8 @@ not empty.
   * `idle` — idle task queue.
   * `tasks` — task dependency tree.
   * `hashtable` — hash table page-occupancy histogram.
+  * `delta-counts` — event-counter change since this report last rendered.
+  * `delta-rates` — that change divided by the elapsed time.
 
 ### Built-in reports
 
index 28e70992afab4d389c16d9531b4a714f3b342806..a17cbc3a5eccf343bea6ea8ebf16e9a97010b151 100644 (file)
@@ -175,8 +175,10 @@ static const char bees_config_v1[] = R"--v1-config--(
         #   workers   - worker thread list
         #   queue     - pending task queue
         #   idle      - idle task queue
-        #   tasks     - task dependency tree
-        #   hashtable - hash table page-occupancy histogram
+        #   tasks       - task dependency tree
+        #   hashtable   - hash table page-occupancy histogram
+        #   delta-counts- event-counter change since this report last rendered
+        #   delta-rates - that change divided by the elapsed time
         content =
 
 # [report.legacy] reproduces the $BEESSTATUS status file.  The default
index 58593cb4caf5c5913318c63acdd0d47fccab0e39..6c123850203d3b42408a82a01515e5d3812c794e 100644 (file)
@@ -37,6 +37,34 @@ public:
        }
 };
 
+/// Stateful token: the change in event counters since this token last
+/// rendered.  Each report owns its own DeltaToken instance (built fresh in
+/// add_report), so two reports at different intervals each see the delta over
+/// their own interval.  Counts mode prints the raw delta; Rates mode divides
+/// by the elapsed time.
+class DeltaToken : public BeesReportToken {
+public:
+       enum class Mode { Counts, Rates };
+private:
+       const Mode m_mode;
+       BeesStats m_last = BeesStats::s_global;
+       Timer m_timer;
+public:
+       explicit DeltaToken(Mode mode) : m_mode(mode) {}
+       void render(ostream &os) override {
+               const auto cur = BeesStats::s_global;
+               const auto age = m_timer.age();
+               const auto delta = cur - m_last;
+               if (m_mode == Mode::Counts) {
+                       os << "DELTA COUNTS (" << age << "s):\n\t" << delta << "\n";
+               } else {
+                       os << "DELTA RATES (" << age << "s):\n\t" << (delta / age) << "\n";
+               }
+               m_last = cur;
+               m_timer.lap();
+       }
+};
+
 }
 
 BeesReporter::BeesReporter(shared_ptr<BeesContext> ctx) :
@@ -88,6 +116,10 @@ BeesReporter::make_token(const string &name)
                                os << "\n";
                        }
                });
+       } else if (name == "delta-counts") {
+               return make_shared<DeltaToken>(DeltaToken::Mode::Counts);
+       } else if (name == "delta-rates") {
+               return make_shared<DeltaToken>(DeltaToken::Mode::Rates);
        } else {
                return make_shared<PlaceholderToken>(name);
        }