CLI: improved show memory command
This commit is contained in:
parent
8d05432e98
commit
ef89561215
3 changed files with 98 additions and 34 deletions
|
|
@ -1845,8 +1845,10 @@ cli_show_statistics(clixon_handle h,
|
||||||
pt_head *ph;
|
pt_head *ph;
|
||||||
parse_tree *pt;
|
parse_tree *pt;
|
||||||
uint64_t nr;
|
uint64_t nr;
|
||||||
|
uint64_t tnr0;
|
||||||
uint64_t tnr;
|
uint64_t tnr;
|
||||||
size_t sz;
|
size_t sz;
|
||||||
|
size_t tsz0;
|
||||||
size_t tsz;
|
size_t tsz;
|
||||||
yang_stmt *yspec;
|
yang_stmt *yspec;
|
||||||
yang_stmt *yspec1;
|
yang_stmt *yspec1;
|
||||||
|
|
@ -1857,6 +1859,9 @@ cli_show_statistics(clixon_handle h,
|
||||||
cg_var *cv;
|
cg_var *cv;
|
||||||
cg_var *cv2;
|
cg_var *cv2;
|
||||||
cg_var *cv3;
|
cg_var *cv3;
|
||||||
|
cxobj *xp;
|
||||||
|
char *name;
|
||||||
|
cxobj *x;
|
||||||
|
|
||||||
if (argv != NULL && (cvec_len(argv) < 1 || cvec_len(argv) > 2)){
|
if (argv != NULL && (cvec_len(argv) < 1 || cvec_len(argv) > 2)){
|
||||||
clixon_err(OE_PLUGIN, EINVAL, "Expected arguments: [(cli|backend) [detail]]");
|
clixon_err(OE_PLUGIN, EINVAL, "Expected arguments: [(cli|backend) [detail]]");
|
||||||
|
|
@ -1888,16 +1893,19 @@ cli_show_statistics(clixon_handle h,
|
||||||
}
|
}
|
||||||
if (strcmp(what, "cli") == 0) {
|
if (strcmp(what, "cli") == 0) {
|
||||||
/* CLI */
|
/* CLI */
|
||||||
if (clicon_option_bool(h, "CLICON_YANG_SCHEMA_MOUNT"))
|
cligen_output(stdout, "%-25s %-10s", "YANG", "Mem[KiB]");
|
||||||
cligen_output(stdout, "%-25s %-8s %-10s %-8s %-8s\n", "YANG", "Nodes#", "Mem(KiB)", "Refs", "Pointer");
|
if (detail)
|
||||||
else
|
cligen_output(stdout, " %-8s\n", "Nodes[#]");
|
||||||
cligen_output(stdout, "%-25s %-8s %-10s\n", "YANG", "Nodes#", "Mem(KiB)");
|
cligen_output(stdout, "\n");
|
||||||
nr = 0; sz = 0;
|
nr = 0; sz = 0;
|
||||||
if (yang_stats(yspec, &nr, &sz) < 0)
|
if (yang_stats(yspec, &nr, &sz) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
tnr = nr;
|
tnr = nr;
|
||||||
tsz = sz;
|
tsz = sz;
|
||||||
cligen_output(stdout, "%-25s %-8" PRIu64 " %-8zu\n", "Top-level", nr, sz/1024);
|
cligen_output(stdout, "%-25s %-10" PRIu64 "", "Top-level", sz/1024);
|
||||||
|
if (detail)
|
||||||
|
cligen_output(stdout, " %-8zu", nr);
|
||||||
|
cligen_output(stdout, "\n");
|
||||||
if (clicon_option_bool(h, "CLICON_YANG_SCHEMA_MOUNT")) {
|
if (clicon_option_bool(h, "CLICON_YANG_SCHEMA_MOUNT")) {
|
||||||
if (yang_mount_yspec2ymnt(yspec, &cvv1) < 0)
|
if (yang_mount_yspec2ymnt(yspec, &cvv1) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
@ -1912,41 +1920,41 @@ cli_show_statistics(clixon_handle h,
|
||||||
if (yang_stats(yspec1, &nr, &sz) < 0)
|
if (yang_stats(yspec1, &nr, &sz) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
/* check if not duplicate */
|
/* check if not duplicate */
|
||||||
cv3 = NULL;
|
cv3 = cv2;
|
||||||
while ((cv3 = cvec_each(cvv2, cv3)) != NULL) {
|
while ((cv3 = cvec_each(cvv2, cv3)) != NULL) {
|
||||||
if (cv2 == cv3)
|
if (cv2 == cv3)
|
||||||
break;
|
continue;
|
||||||
yspec2 = cv_void_get(cv3);
|
yspec2 = cv_void_get(cv3);
|
||||||
if (yspec1 == yspec2)
|
if (yspec1 == yspec2)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (cv2 != cv3){
|
if (cv3 != NULL){
|
||||||
cligen_output(stdout, "%s \\\n", cv_name_get(cv2));
|
cligen_output(stdout, "%s\n", cv_name_get(cv2));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
tnr += nr;
|
tnr += nr;
|
||||||
tsz += sz;
|
tsz += sz;
|
||||||
if (strlen(cv_name_get(cv2)) > 25){
|
if (strlen(cv_name_get(cv2)) > 25)
|
||||||
cligen_output(stdout, "%s \\\n", cv_name_get(cv2));
|
cligen_output(stdout, "%s \n %-25s", cv_name_get(cv2), "");
|
||||||
cligen_output(stdout, "%-25s %-8" PRIu64 " %-10zu %-8d %-8p\n",
|
|
||||||
"",
|
|
||||||
nr, sz/1024,
|
|
||||||
yang_ref_get(yspec1), ymnt);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
cligen_output(stdout, "%-25s %-8" PRIu64 " %-10zu %-8d %-8p\n",
|
cligen_output(stdout, "%-25s", cv_name_get(cv2));
|
||||||
cv_name_get(cv2),
|
cligen_output(stdout, "%-10" PRIu64 "", sz/1024);
|
||||||
nr, sz/1024,
|
if (detail)
|
||||||
yang_ref_get(yspec1), ymnt);
|
cligen_output(stdout, " %-8zu", nr);
|
||||||
|
cligen_output(stdout, "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cligen_output(stdout, "%-25s %-8" PRIu64 " %-8zu\n", "YANG Total", tnr, tsz/1024);
|
cligen_output(stdout, "%-25s %-10" PRIu64 "", "YANG Total", tsz/1024);
|
||||||
}
|
if (detail)
|
||||||
if (strcmp(what, "cli") == 0) {
|
cligen_output(stdout, " %-10zu", tnr);
|
||||||
cligen_output(stdout, "%-25s %-8s %-8s\n", "CLIspecs", "Nodes#", "Mem(KiB)");
|
cligen_output(stdout, "\n");
|
||||||
|
if (detail)
|
||||||
|
cligen_output(stdout, "%s\n", "CLIspec trees");
|
||||||
|
tnr0 = tnr;
|
||||||
|
tsz0 = tsz;
|
||||||
tnr = 0;
|
tnr = 0;
|
||||||
tsz = 0;
|
tsz = 0;
|
||||||
ph = NULL;
|
ph = NULL;
|
||||||
|
|
@ -1960,16 +1968,22 @@ cli_show_statistics(clixon_handle h,
|
||||||
if (detail){
|
if (detail){
|
||||||
if (strlen(cligen_ph_name_get(ph)) > 25){
|
if (strlen(cligen_ph_name_get(ph)) > 25){
|
||||||
cligen_output(stdout, "%s \\\n", cligen_ph_name_get(ph));
|
cligen_output(stdout, "%s \\\n", cligen_ph_name_get(ph));
|
||||||
cligen_output(stdout, "%-25s %-8" PRIu64 " %-8zu\n", "", nr, sz/1024);
|
cligen_output(stdout, "%-25s %-10" PRIu64 " %-8zu\n", "", sz/1024, nr);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
cligen_output(stdout, "%-25s %-8" PRIu64 " %-8zu\n", cligen_ph_name_get(ph), nr, sz/1024);
|
cligen_output(stdout, "%-25s %-10" PRIu64 " %-8zu\n", cligen_ph_name_get(ph), sz/1024, nr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cligen_output(stdout, "%-25s %-8" PRIu64 " %-8zu\n", "CLIspec Total", tnr, tsz/1024);
|
cligen_output(stdout, "%-25s %-10" PRIu64 "", "CLIspec Total", tsz/1024);
|
||||||
|
if (detail)
|
||||||
|
cligen_output(stdout, "%-8zu\n", tnr);
|
||||||
|
cligen_output(stdout, "\n");
|
||||||
|
cligen_output(stdout, "%-25s %-10" PRIu64 "", "Mem Total", (tsz0+tsz)/1024);
|
||||||
|
if (detail)
|
||||||
|
cligen_output(stdout, "%-8zu\n", (tnr0+tnr));
|
||||||
|
cligen_output(stdout, "\n");
|
||||||
}
|
}
|
||||||
if (strcmp(what, "backend") == 0) {
|
if (strcmp(what, "backend") == 0) {
|
||||||
/* Backend */
|
|
||||||
cprintf(cb, "<rpc xmlns=\"%s\"", NETCONF_BASE_NAMESPACE);
|
cprintf(cb, "<rpc xmlns=\"%s\"", NETCONF_BASE_NAMESPACE);
|
||||||
cprintf(cb, " %s", NETCONF_MESSAGE_ID_ATTR); /* XXX: use incrementing sequence */
|
cprintf(cb, " %s", NETCONF_MESSAGE_ID_ATTR); /* XXX: use incrementing sequence */
|
||||||
cprintf(cb, ">");
|
cprintf(cb, ">");
|
||||||
|
|
@ -1984,9 +1998,56 @@ cli_show_statistics(clixon_handle h,
|
||||||
clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get configuration");
|
clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get configuration");
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
cligen_output(stdout, "Backend (nr nodes, size of mem\n");
|
if (xml_rootchild(xret, 0, &xret) < 0)
|
||||||
if (clixon_xml2file(stdout, xml_child_i(xret, 0), 0, 1, NULL, cligen_output, 0, 1) < 0)
|
|
||||||
goto done;
|
goto done;
|
||||||
|
if (detail) {
|
||||||
|
cligen_output(stdout, "Backend (nr nodes, size of mem\n");
|
||||||
|
if (clixon_xml2file(stdout, xret, 0, 1, NULL, cligen_output, 0, 1) < 0)
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cligen_output(stdout, "%-25s %-10s\n", "XML Datastore", "Mem[KiB]");
|
||||||
|
tsz = 0;
|
||||||
|
if ((xp = xml_find_type(xret, NULL, "datastores", CX_ELMNT)) != NULL){
|
||||||
|
x = NULL;
|
||||||
|
while ((x = xml_child_each(xp, x, CX_ELMNT)) != NULL) {
|
||||||
|
if (strcmp(xml_name(x), "datastore") != 0)
|
||||||
|
continue;
|
||||||
|
parse_uint64(xml_find_body(x, "size"), &sz, NULL);
|
||||||
|
tsz += sz;
|
||||||
|
name = xml_find_body(x, "name");
|
||||||
|
if (strlen(name) > 25){
|
||||||
|
cligen_output(stdout, "%s \\\n", name);
|
||||||
|
cligen_output(stdout, "%-25s %-10" PRIu64 "\n", "", sz/1024);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
cligen_output(stdout, "%-25s %-10" PRIu64 "\n", name, sz/1024);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cligen_output(stdout, "%-25s %-10" PRIu64 "\n", "XML Total", tsz/1024);
|
||||||
|
tsz0 = tsz;
|
||||||
|
tsz = 0;
|
||||||
|
cligen_output(stdout, "%s\n", "YANG");
|
||||||
|
if ((xp = xml_find_type(xret, NULL, "module-sets", CX_ELMNT)) != NULL){
|
||||||
|
x = NULL;
|
||||||
|
while ((x = xml_child_each(xp, x, CX_ELMNT)) != NULL) {
|
||||||
|
if (strcmp(xml_name(x), "module-set") != 0)
|
||||||
|
continue;
|
||||||
|
parse_uint64(xml_find_body(x, "size"), &sz, NULL);
|
||||||
|
tsz += sz;
|
||||||
|
name = xml_find_body(x, "name");
|
||||||
|
if (strlen(name) > 25){
|
||||||
|
cligen_output(stdout, "%s \\\n", name);
|
||||||
|
cligen_output(stdout, "%-25s %-10" PRIu64 "\n", "", sz/1024);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
cligen_output(stdout, "%-25s %-10" PRIu64 "\n", name, sz/1024);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cligen_output(stdout, "%-25s %-10" PRIu64 "\n", "YANG Total*", tsz/1024);
|
||||||
|
cligen_output(stdout, "%-25s %-10" PRIu64 "\n", "Mem Total*", (tsz0+tsz)/1024);
|
||||||
|
cligen_output(stdout, "(*) May be shared YANG\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
|
|
||||||
|
|
@ -1558,7 +1558,7 @@ xml_rm(cxobj *xc)
|
||||||
/*! Remove all children of specific type
|
/*! Remove all children of specific type
|
||||||
*
|
*
|
||||||
* @param[in] x XML node
|
* @param[in] x XML node
|
||||||
* @param[in] type Remove all children of xn of this type
|
* @param[in] type Remove all children of xn of this type, or -1 for all
|
||||||
* @retval 0 OK
|
* @retval 0 OK
|
||||||
* @retval -1 Error
|
* @retval -1 Error
|
||||||
*/
|
*/
|
||||||
|
|
@ -2069,11 +2069,14 @@ xml_copy(cxobj *x0,
|
||||||
|
|
||||||
/*! Create and return a copy of xml tree.
|
/*! Create and return a copy of xml tree.
|
||||||
*
|
*
|
||||||
|
* @param[in] x0 Old object
|
||||||
|
* @retval x1 New object, free with xml_free
|
||||||
|
* @retval NULL Error
|
||||||
* @code
|
* @code
|
||||||
* cxobj *x1;
|
* cxobj *x1;
|
||||||
* x1 = xml_dup(x0);
|
* if ((x1 = xml_dup(x0)) == NULL)
|
||||||
|
* err;
|
||||||
* @endcode
|
* @endcode
|
||||||
* Note, returned tree should be freed as: xml_free(x1)
|
|
||||||
* @see xml_cp
|
* @see xml_cp
|
||||||
*/
|
*/
|
||||||
cxobj *
|
cxobj *
|
||||||
|
|
|
||||||
|
|
@ -314,7 +314,7 @@ sleep 1
|
||||||
|
|
||||||
new "Check running subfile not changed"
|
new "Check running subfile not changed"
|
||||||
s2=$(stat -c "%Y" $dir/running.d/${subfilename})
|
s2=$(stat -c "%Y" $dir/running.d/${subfilename})
|
||||||
if [ $s1 -ne $s2 ]; then
|
if [ $s1 -ne $s2 ]; then # XXX Sometimes fails
|
||||||
err "Timestamp not changed" "$s1 != $s2"
|
err "Timestamp not changed" "$s1 != $s2"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue