Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the summary mode to the set_stats command #1356

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions ldms/python/ldmsd/ldmsd_communicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']},
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -321,6 +322,7 @@ class LDMSD_Req_Attr(object):
'credits' : CREDITS,
'rx_rate' : RX_RATE,
'reconnect' : INTERVAL,
'summary' : SUMMARY,
'TERMINATING': LAST
}

Expand Down Expand Up @@ -364,6 +366,7 @@ class LDMSD_Req_Attr(object):
RAIL : 'rail',
CREDITS : 'credits',
RX_RATE : 'rx_rate',
SUMMARY : 'summary',
LAST : 'TERMINATING'
}

Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion ldms/python/ldmsd/ldmsd_controller
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 16 additions & 4 deletions ldms/src/ldmsd/ldmsctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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],
Expand Down
28 changes: 24 additions & 4 deletions ldms/src/ldmsd/ldmsd_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -7412,7 +7412,7 @@ static int prdcr_stats_handler(ldmsd_req_ctxt_t req)
* "compute_time" : <int>
* }
*/
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;
Expand All @@ -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)) {
Expand Down Expand Up @@ -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);
Expand All @@ -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;

Expand Down
1 change: 1 addition & 0 deletions ldms/src/ldmsd/ldmsd_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ enum ldmsd_request_attr {
LDMSD_ATTR_RAIL,
LDMSD_ATTR_CREDITS,
LDMSD_ATTR_RX_RATE,
LDMSD_ATTR_SUMMARY,
LDMSD_ATTR_LAST,
};

Expand Down
1 change: 1 addition & 0 deletions ldms/src/ldmsd/ldmsd_request_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
Loading