Store count of how many times a hook is fired and the last time.

This commit is contained in:
nicm
2026-07-27 19:15:58 +00:00
committed by tmux update bot
parent f751d3f2c1
commit 27ab96b284
6 changed files with 128 additions and 20 deletions

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: monitor.c,v 1.6 2026/07/10 15:20:06 nicm Exp $ */
/* $OpenBSD: monitor.c,v 1.7 2026/07/27 19:15:58 nicm Exp $ */
/*
* Copyright (c) 2026 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -59,6 +59,9 @@ struct monitor_item {
struct monitor_panes panes;
struct monitor_windows windows;
u_int fire_count;
time_t fire_time;
RB_ENTRY(monitor_item) entry;
};
RB_HEAD(monitor_items, monitor_item);
@@ -180,6 +183,9 @@ monitor_report(struct monitor_set *ms, struct monitor_item *me,
log_debug("%s: %s changed to %s", __func__, me->name, value);
me->fire_count++;
me->fire_time = current_time;
change.name = me->name;
change.value = value;
change.last = last;
@@ -659,3 +665,25 @@ monitor_remove(struct monitor_set *ms, const char *name)
if (RB_EMPTY(&ms->items) && evtimer_initialized(&ms->timer))
evtimer_del(&ms->timer);
}
/* Get subscription firing count. */
u_int
monitor_get_fire_count(struct monitor_set *ms, const char *name)
{
struct monitor_item *me, find = { .name = (char *)name };
if ((me = RB_FIND(monitor_items, &ms->items, &find)) == NULL)
return (0);
return (me->fire_count);
}
/* Get subscription firing time. */
time_t
monitor_get_fire_time(struct monitor_set *ms, const char *name)
{
struct monitor_item *me, find = { .name = (char *)name };
if ((me = RB_FIND(monitor_items, &ms->items, &find)) == NULL)
return (0);
return (me->fire_time);
}