diff --git a/ldms/python/ldmsd/ldmsd_communicator.py b/ldms/python/ldmsd/ldmsd_communicator.py index 3c26b092f..7b74fee45 100644 --- a/ldms/python/ldmsd/ldmsd_communicator.py +++ b/ldms/python/ldmsd/ldmsd_communicator.py @@ -156,7 +156,7 @@ 'thread_stats': {'req_attr':[], 'opt_attr': ['reset']}, 'prdcr_stats': {'req_attr':[], 'opt_attr': []}, 'set_route' : {'req_attr':['instance'], 'opt_attr':[]}, - 'set_stats': {'req_attr':[], 'opt_attr': []}, + 'set_stats': {'req_attr':[], 'opt_attr': ['summary']}, 'listen': {'req_attr':['xprt', 'port'], 'opt_attr': ['host', 'auth']}, 'metric_sets_default_authz': {'req_attr':[], 'opt_attr': ['uid', 'gid', 'perm']}, 'set_sec_mod' : {'req_attr': ['regex'], 'opt_attr': ['uid', 'gid', 'perm']}, @@ -275,7 +275,8 @@ class LDMSD_Req_Attr(object): RAIL = 38 CREDITS = 39 RX_RATE = 40 - LAST = 41 + SUMMARY = 41 + LAST = 42 NAME_ID_MAP = {'name': NAME, 'interval': INTERVAL, @@ -321,6 +322,7 @@ class LDMSD_Req_Attr(object): 'credits' : CREDITS, 'rx_rate' : RX_RATE, 'reconnect' : INTERVAL, + 'summary' : SUMMARY, 'TERMINATING': LAST } @@ -364,6 +366,7 @@ class LDMSD_Req_Attr(object): RAIL : 'rail', CREDITS : 'credits', RX_RATE : 'rx_rate', + SUMMARY : 'summary', LAST : 'TERMINATING' } @@ -3081,7 +3084,7 @@ def prdcr_stats(self): except Exception as e: return errno.ENOTCONN, str(e) - def set_stats(self): + def set_stats(self, summary = False): """ Query the daemon's set statistics @@ -3090,7 +3093,8 @@ def set_stats(self): - status is an errno from the errno module - data is the daemon's set statistics, or an error msg if status !=0 or None """ - req = LDMSD_Request(command_id=LDMSD_Request.SET_STATS) + attr_list = [ LDMSD_Req_Attr(attr_id = LDMSD_Req_Attr.SUMMARY, value = str(summary))] + req = LDMSD_Request(command_id=LDMSD_Request.SET_STATS, attrs = attr_list) try: req.send(self) resp = req.receive(self) diff --git a/ldms/python/ldmsd/ldmsd_controller b/ldms/python/ldmsd/ldmsd_controller index b8eb78c2c..6cecbb54e 100755 --- a/ldms/python/ldmsd/ldmsd_controller +++ b/ldms/python/ldmsd/ldmsd_controller @@ -2284,13 +2284,16 @@ class LdmsdCmdParser(cmd.Cmd): for n in stats: if n == 'compute_time': continue + if n == 'summary': + continue print(f"{n:20} {stats[n]:16}") def do_set_stats(self, arg): """ Query the daemon's set statistics """ - rc, msg = self.comm.set_stats() + arg = self.handle_args('set_stats', arg) + rc, msg = self.comm.set_stats(**arg) if msg == "": return if rc != 0: diff --git a/ldms/src/ldmsd/ldmsctl.c b/ldms/src/ldmsd/ldmsctl.c index 9f0247741..1d32dfa38 100644 --- a/ldms/src/ldmsd/ldmsctl.c +++ b/ldms/src/ldmsd/ldmsctl.c @@ -2259,6 +2259,7 @@ static void resp_set_stats(ldmsd_req_hdr_t resp, size_t len, uint32_t rsp_err) int rc; json_parser_t parser; json_entity_t stats, a; + int num_attr; ldmsd_req_attr_t attr = ldmsd_first_attr(resp); if (!attr->discrim || (attr->attr_id != LDMSD_ATTR_JSON)) @@ -2287,16 +2288,27 @@ static void resp_set_stats(ldmsd_req_hdr_t resp, size_t len, uint32_t rsp_err) else printf("Set Stats - N/A\n"); - printf("%-20s %-16s\n", "Name", "Count"); - printf("-------------------- ----------------\n"); - char *names[5] = { "active_count", "deleting_count", "mem_total_kb", "mem_used_kb", "mem_free_kb" }; + + a = json_value_find(stats, "summary"); + if (a) { + /* + * Only report the active and deleting counts + */ + num_attr = 2; + } else { + num_attr = 5; + } + printf("%-20s %-16s\n", "Name", "Count"); + printf("-------------------- ----------------\n"); + + int i; - for (i = 0; i < 5; i ++) { + for (i = 0; i < num_attr; i ++) { a = json_attr_find(stats, names[i]); if (a) printf("%-20s %-16ld\n", names[i], diff --git a/ldms/src/ldmsd/ldmsd_request.c b/ldms/src/ldmsd/ldmsd_request.c index ab2c8f5b7..44be61795 100644 --- a/ldms/src/ldmsd/ldmsd_request.c +++ b/ldms/src/ldmsd/ldmsd_request.c @@ -7412,7 +7412,7 @@ static int prdcr_stats_handler(ldmsd_req_ctxt_t req) * "compute_time" : * } */ -static char * __set_stats_as_json(size_t *json_sz) +static char * __set_stats_as_json(size_t *json_sz, int is_summary) { struct timespec start, end; char *buff, *s; @@ -7426,13 +7426,20 @@ static char * __set_stats_as_json(size_t *json_sz) ldmsd_updtr_t updtr = NULL; (void)clock_gettime(CLOCK_REALTIME, &start); - mm_stats(&stats); - buff = malloc(sz); if (!buff) goto __APPEND_ERR; s = buff; + if (is_summary > 0) { + /* + * Only report the active count and deleting count. + */ + goto do_json; + } + + mm_stats(&stats); + ldmsd_cfg_lock(LDMSD_CFGOBJ_UPDTR); for (updtr = ldmsd_updtr_first(); updtr; updtr = ldmsd_updtr_next(updtr)) { @@ -7483,13 +7490,19 @@ static char * __set_stats_as_json(size_t *json_sz) } ldmsd_cfg_unlock(LDMSD_CFGOBJ_UPDTR); +do_json: __APPEND("{"); __APPEND(" \"active_count\": %d,\n", ldms_set_count()); __APPEND(" \"deleting_count\": %d,\n", ldms_set_deleting_count()); + if (is_summary == 1) { + __APPEND(" \"summary\": \"true\",\n"); + goto done_json; + } __APPEND(" \"mem_total_kb\": %g,\n", (double)stats.size / 1024.0); __APPEND(" \"mem_free_kb\": %g,\n", (double)(stats.bytes * stats.grain) / 1024.0); __APPEND(" \"mem_used_kb\": %g,\n", (double)(stats.size - (stats.bytes * stats.grain)) / 1024.0); __APPEND(" \"set_load\": %g,\n", set_load); +done_json: (void)clock_gettime(CLOCK_REALTIME, &end); uint64_t compute_time = ldms_timespec_diff_us(&start, &end); __APPEND(" \"compute_time\": %ld\n", compute_time); @@ -7506,11 +7519,18 @@ static char * __set_stats_as_json(size_t *json_sz) static int set_stats_handler(ldmsd_req_ctxt_t req) { char *json_s; + char *value; + int is_summary = 0; size_t json_sz; struct ldmsd_req_attr_s attr; __dlog(DLOG_QUERY, "set_stats\n"); - json_s = __set_stats_as_json(&json_sz); + + value = ldmsd_req_attr_str_value_get_by_id(req, LDMSD_ATTR_SUMMARY); + if (0 == strcasecmp(value, "true")) + is_summary = 1; + + json_s = __set_stats_as_json(&json_sz, is_summary); if (!json_s) goto err; diff --git a/ldms/src/ldmsd/ldmsd_request.h b/ldms/src/ldmsd/ldmsd_request.h index b0933cc06..258f2b8a2 100644 --- a/ldms/src/ldmsd/ldmsd_request.h +++ b/ldms/src/ldmsd/ldmsd_request.h @@ -233,6 +233,7 @@ enum ldmsd_request_attr { LDMSD_ATTR_RAIL, LDMSD_ATTR_CREDITS, LDMSD_ATTR_RX_RATE, + LDMSD_ATTR_SUMMARY, LDMSD_ATTR_LAST, }; diff --git a/ldms/src/ldmsd/ldmsd_request_util.c b/ldms/src/ldmsd/ldmsd_request_util.c index 103605594..09f2aa5b5 100644 --- a/ldms/src/ldmsd/ldmsd_request_util.c +++ b/ldms/src/ldmsd/ldmsd_request_util.c @@ -186,6 +186,7 @@ const struct req_str_id attr_str_id_table[] = { { "schema", LDMSD_ATTR_SCHEMA }, { "stream", LDMSD_ATTR_STREAM }, { "string", LDMSD_ATTR_STRING }, + { "summary", LDMSD_ATTR_SUMMARY }, { "test", LDMSD_ATTR_TEST }, { "time", LDMSD_ATTR_TIME }, { "timeout_factor", LDMSD_ATTR_TIMEOUT_FACTOR },