Skip to content

Commit

Permalink
lib: agentx add counters on locktry failure
Browse files Browse the repository at this point in the history
add counters for pthread_mutex_locktry fail.
currently used for limiting logs

Signed-off-by: Francois Dumontet <[email protected]>
  • Loading branch information
fdumontet6WIND committed Oct 14, 2024
1 parent e464755 commit 845a60d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/agentx.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ static pthread_mutex_t ax_mtx;
/* mutex dedicated to send/read exclusion */
static pthread_mutex_t ax_io_mtx;

/* counters */
static uint64_t nb_locktry_read_fail;
static uint64_t nb_locktry_timeout_fail;


static void agentx_pthreads_init(void)
{
assert(!agentx_pth);
Expand Down Expand Up @@ -83,7 +88,10 @@ static void agentx_timeout(struct event *t)
snmp_timeout();
run_alarms();
} else {
zlog_err("%s mutex already locked", __func__);
if (0 == nb_locktry_timeout_fail % 100)
zlog_err("%s mutex already locked %llu times",
__func__, nb_locktry_timeout_fail);
nb_locktry_timeout_fail++;
agentx_events_update(NULL);
return;
}
Expand Down Expand Up @@ -131,7 +139,9 @@ static void agentx_read(struct event *t)
netsnmp_large_fd_setfd(t->u.fd, &lfds);
snmp_read2(&lfds);
} else {
zlog_err("%s mutex already locked", __func__);
zlog_err("%s mutex already locked %llu times",
__func__, nb_locktry_read_fail);
nb_locktry_read_fail++;
agentx_events_update(NULL);
return;
}
Expand Down

0 comments on commit 845a60d

Please sign in to comment.