Skip to content

Commit

Permalink
Add stream_client_stats reset=true support
Browse files Browse the repository at this point in the history
  • Loading branch information
nichamon authored and tom95858 committed Jan 12, 2024
1 parent bc841cb commit edf1a8d
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 20 deletions.
4 changes: 2 additions & 2 deletions ldms/python/ldms.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -820,9 +820,9 @@ cdef extern from "ldms.h" nogil:
void ldms_stream_stats_tq_free(ldms_stream_stats_tq_s *tq)
char *ldms_stream_stats_tq_to_str(ldms_stream_stats_tq_s *tq)
char *ldms_stream_stats_str(char *match, int is_regex)
ldms_stream_client_stats_tq_s *ldms_stream_client_stats_tq_get()
ldms_stream_client_stats_tq_s *ldms_stream_client_stats_tq_get(int is_reset)
void ldms_stream_client_stats_tq_free(ldms_stream_client_stats_tq_s *tq)
ldms_stream_client_stats_s *ldms_stream_client_get_stats(ldms_stream_client_t cli)
ldms_stream_client_stats_s *ldms_stream_client_get_stats(ldms_stream_client_t cli, int is_reset)
void ldms_stream_client_stats_free(ldms_stream_client_stats_s *cs)
char *ldms_stream_client_stats_tq_to_str(ldms_stream_client_stats_tq_s *tq)
char *ldms_stream_client_stats_str()
Expand Down
8 changes: 4 additions & 4 deletions ldms/python/ldms.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4003,11 +4003,11 @@ def stream_stats_get(stream_match=None, is_regex=0, is_reset=0):
ldms_stream_stats_tq_free(tq)
return ret

def stream_client_stats_get():
def stream_client_stats_get(is_reset=0):
"""Get a collection of stats of stream clients in this process"""
cdef ldms_stream_client_stats_tq_s *tq
cdef ldms_stream_client_stats_s *cs
tq = ldms_stream_client_stats_tq_get()
tq = ldms_stream_client_stats_tq_get(is_reset)
ret = list()
if not tq:
if errno == ENOENT:
Expand Down Expand Up @@ -4071,12 +4071,12 @@ cdef class StreamClient(object):
except Empty as e:
return None

def stats(self):
def stats(self, is_reset=0):
"""Get the client stats"""
cdef ldms_stream_client_stats_s *cs;
if not self.c:
raise RuntimeError("client has been closed")
cs = ldms_stream_client_get_stats(self.c)
cs = ldms_stream_client_get_stats(self.c, is_reset)
if not cs:
raise RuntimeError(f"error: {ERRNO_SYM(errno)}({errno})")
try:
Expand Down
9 changes: 6 additions & 3 deletions ldms/python/ldmsd/ldmsd_communicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
'stream_client_dump': {'req_attr': [], 'opt_attr': []},
'stream_status' : {'req_attr': [], 'opt_attr': ['reset']},
'stream_stats' : {'req_attr': [], 'opt_attr': ['regex', 'stream', 'json', 'reset']},
'stream_client_stats' : {'req_attr': [], 'opt_attr': ['json']},
'stream_client_stats' : {'req_attr': [], 'opt_attr': ['json', 'reset']},
##### Daemon #####
'daemon_status': {'req_attr': [], 'opt_attr': ['thread_stats']},
##### Misc. #####
Expand Down Expand Up @@ -1417,15 +1417,18 @@ def stream_stats(self, regex=None, stream=None, reset=None):
except Exception as e:
return errno.ENOTCONN, str(e)

def stream_client_stats(self):
def stream_client_stats(self, reset=None):
"""
Dump stream stats
Parameters:
regex - The regular expression matching the stream names
stream - The exact match of the stearm name
"""
req = LDMSD_Request(command_id=LDMSD_Request.STREAM_CLIENT_STATS, attrs = [])
attr_list = []
if reset is not None:
attr_list = [LDMSD_Req_Attr(attr_name='reset', value=reset)]
req = LDMSD_Request(command_id=LDMSD_Request.STREAM_CLIENT_STATS, attrs = attr_list)
try:
req.send(self)
resp = req.receive(self)
Expand Down
2 changes: 1 addition & 1 deletion ldms/python/ldmsd/ldmsd_controller
Original file line number Diff line number Diff line change
Expand Up @@ -2617,7 +2617,7 @@ class LdmsdCmdParser(cmd.Cmd):
arg = self.handle_args('stream_stats', arg)
if arg is None:
return
rc, msg = self.comm.stream_client_stats()
rc, msg = self.comm.stream_client_stats(arg['reset'])
if rc:
emsg = f"stream_client_stats error: {rc}, msg: {msg}"
print(emsg)
Expand Down
13 changes: 10 additions & 3 deletions ldms/src/core/ldms.h
Original file line number Diff line number Diff line change
Expand Up @@ -1349,8 +1349,10 @@ char *ldms_stream_stats_str(const char *match, int is_regex, int is_reset);

/**
* Returns a collection of stats of stream clients.
*
* \param is_reset A non-zero value means to reset the statistics
*/
struct ldms_stream_client_stats_tq_s *ldms_stream_client_stats_tq_get();
struct ldms_stream_client_stats_tq_s *ldms_stream_client_stats_tq_get(int is_reset);

/**
* Free the stats entries in the \c tq and the \c tq itself.
Expand All @@ -1359,8 +1361,11 @@ void ldms_stream_client_stats_tq_free(struct ldms_stream_client_stats_tq_s *tq);

/**
* Get stats from a client.
*
* \param is_reset A non-zero value means to reset the statistics
*/
struct ldms_stream_client_stats_s *ldms_stream_client_get_stats(ldms_stream_client_t cli);
struct ldms_stream_client_stats_s *
ldms_stream_client_get_stats(ldms_stream_client_t cli, int is_reset);

/**
* Free the stream client stats obtained form \c ldms_stream_client_get_stats().
Expand All @@ -1378,8 +1383,10 @@ char *ldms_stream_client_stats_tq_to_str(struct ldms_stream_client_stats_tq_s *t
* \brief Return a string describing statuses/statistics of stream clients in this process.
* \retval str The string describing the stats.
* \note The caller is responsible for freeing the returned string.
*
* \param is_reset non-zero means to reset the statistics
*/
char *ldms_stream_client_stats_str();
char *ldms_stream_client_stats_str(int is_reset);

/** \} */

Expand Down
21 changes: 15 additions & 6 deletions ldms/src/core/ldms_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -1762,7 +1762,7 @@ char *ldms_stream_stats_str(const char *match, int is_regex, int is_reset)
}

struct ldms_stream_client_stats_s *
ldms_stream_client_get_stats(ldms_stream_client_t cli)
ldms_stream_client_get_stats(ldms_stream_client_t cli, int is_reset)
{
struct ldms_stream_client_stats_s *cs = NULL;
struct ldms_stream_client_entry_s *sce;
Expand All @@ -1781,6 +1781,11 @@ ldms_stream_client_get_stats(ldms_stream_client_t cli)
cs->tx = cli->tx;
cs->is_regex = cli->is_regex;

if (is_reset) {
LDMS_STREAM_COUNTERS_INIT(&cli->tx);
LDMS_STREAM_COUNTERS_INIT(&cli->drops);
}

TAILQ_FOREACH(sce, &cli->stream_tq, client_stream_entry) {
/* name_len included '\0' */
cps = malloc(sizeof(*cps) + sce->stream->name_len);
Expand All @@ -1794,6 +1799,10 @@ ldms_stream_client_get_stats(ldms_stream_client_t cli)
cps->is_regex = sce->client->is_regex;
cps->tx = sce->tx;
cps->drops = sce->drops;
if (is_reset) {
LDMS_STREAM_COUNTERS_INIT(&sce->tx);
LDMS_STREAM_COUNTERS_INIT(&sce->drops);
}
TAILQ_INSERT_TAIL(&cs->pair_tq, cps, entry);
}

Expand All @@ -1820,7 +1829,7 @@ void ldms_stream_client_stats_free(struct ldms_stream_client_stats_s *cs)
free(cs);
}

struct ldms_stream_client_stats_tq_s *ldms_stream_client_stats_tq_get()
struct ldms_stream_client_stats_tq_s *ldms_stream_client_stats_tq_get(int is_reset)
{
struct ldms_stream_client_stats_tq_s *tq;
struct ldms_stream_client_stats_s *cs;
Expand All @@ -1838,7 +1847,7 @@ struct ldms_stream_client_stats_tq_s *ldms_stream_client_stats_tq_get()

/* go through regex clients first */
TAILQ_FOREACH(cli, &__regex_client_tq, entry) {
cs = ldms_stream_client_get_stats(cli);
cs = ldms_stream_client_get_stats(cli, is_reset);
if (!cs)
goto err_0;
TAILQ_INSERT_TAIL(tq, cs, entry);
Expand All @@ -1854,7 +1863,7 @@ struct ldms_stream_client_stats_tq_s *ldms_stream_client_stats_tq_get()
continue;
if (cli->is_regex)
continue; /* already handled above */
cs = ldms_stream_client_get_stats(cli);
cs = ldms_stream_client_get_stats(cli, is_reset);
if (!cs) {
pthread_rwlock_unlock(&s->rwlock);
goto err_0;
Expand Down Expand Up @@ -1948,11 +1957,11 @@ char *ldms_stream_client_stats_tq_to_str(struct ldms_stream_client_stats_tq_s *t
return ret;
}

char *ldms_stream_client_stats_str()
char *ldms_stream_client_stats_str(int is_reset)
{
struct ldms_stream_client_stats_tq_s *tq;
char *ret = NULL;
tq = ldms_stream_client_stats_tq_get();
tq = ldms_stream_client_stats_tq_get(is_reset);
if (!tq) {
if (errno == ENOENT) {
ret = strdup("[]");
Expand Down
7 changes: 6 additions & 1 deletion ldms/src/ldmsd/ldmsd_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -8049,8 +8049,13 @@ static int stream_client_stats_handler(ldmsd_req_ctxt_t reqc)
int rc = 0;
size_t len;
struct ldmsd_req_attr_s attr;
char *reset_s = ldmsd_req_attr_str_value_get_by_id(reqc, LDMSD_ATTR_RESET);
int is_reset = 0;

if (reset_s && (0 == strcasecmp(reset_s, "true")))
is_reset = 1;

s = ldms_stream_client_stats_str();
s = ldms_stream_client_stats_str(is_reset);
if (!s) {
reqc->errcode = errno;
snprintf(buff, sizeof(buff), "ldms_stream_client_stats_str() error: %d",
Expand Down

0 comments on commit edf1a8d

Please sign in to comment.