Improved show memory

This commit is contained in:
Olof hagsand 2024-06-20 19:26:45 +02:00
parent 1f118ecacc
commit 8a2217ff6d
2 changed files with 100 additions and 66 deletions

View file

@ -1821,15 +1821,9 @@ clixon_cli2cbuf(clixon_handle h,
* mempry in KiB
* @param[in] h Clixon handle
* @param[in] cvv Vector of cli string and instantiated variables
* @param[in] argv Arguments given at the callback: [(cli|backend) [detail]]
* @param[in] argv Arguments given at the callback: [(cli|backend|all) [detail]]
* @retval 0 OK
* @retval -1 Error
* where level means:
* <null> : Show mounts and summary clispec
* cli : Show mounts and summary clispec
* cli detail : Show mounts and per parse-tree clispec
* backend : Show summary mem
* backend detail : Per-module
*/
int
cli_show_statistics(clixon_handle h,
@ -1841,6 +1835,8 @@ cli_show_statistics(clixon_handle h,
cxobj *xret = NULL;
cxobj *xerr;
char *what = NULL;
int cli = 0;
int backend = 0;
int detail = 0;
pt_head *ph;
parse_tree *pt;
@ -1863,16 +1859,23 @@ cli_show_statistics(clixon_handle h,
char *name;
cxobj *x;
if (argv != NULL && (cvec_len(argv) < 1 || cvec_len(argv) > 2)){
clixon_err(OE_PLUGIN, EINVAL, "Expected arguments: [(cli|backend) [detail]]");
if (argv == NULL || (cvec_len(argv) < 1 || cvec_len(argv) > 2)){
clixon_err(OE_PLUGIN, EINVAL, "Expected arguments: [(cli|backend|all) [detail]]");
goto done;
}
yspec = clicon_dbspec_yang(h);
if (argv){
cv = cvec_i(argv, 0);
what = cv_string_get(cv);
if (strcmp(what, "cli") != 0 && strcmp(what, "backend") != 0){
clixon_err(OE_PLUGIN, EINVAL, "Unexpected argument: %s, expected: cli|backend", what);
if (strcmp(what, "cli") == 0)
cli++;
else if (strcmp(what, "backend") == 0)
backend++;
else if (strcmp(what, "all") == 0){
cli++;
backend++;
}
else {
clixon_err(OE_PLUGIN, EINVAL, "Unexpected argument: %s, expected: cli|backend|all", what);
goto done;
}
if (cvec_len(argv) > 1 &&
@ -1884,28 +1887,25 @@ cli_show_statistics(clixon_handle h,
}
detail = 1;
}
}
else
what = "cli";
if ((cb = cbuf_new()) == NULL){
clixon_err(OE_PLUGIN, errno, "cbuf_new");
goto done;
}
if (strcmp(what, "cli") == 0) {
/* CLI */
cligen_output(stdout, "%-25s %-10s", "YANG", "Mem[KiB]");
if (detail)
cligen_output(stdout, " %-8s\n", "Nodes[#]");
cligen_output(stdout, "\n");
if (cli) {
if (!detail) {
cligen_output(stdout, "%-25s %-10s\n", "YANG", "Mem[KiB]");
}
nr = 0; sz = 0;
if (yang_stats(yspec, &nr, &sz) < 0)
goto done;
tnr = nr;
tsz = sz;
cligen_output(stdout, "%-25s %-10" PRIu64 "", "Top-level", sz/1024);
if (detail)
cligen_output(stdout, " %-8zu", nr);
cligen_output(stdout, "\n");
if (detail) {
cligen_output(stdout, "YANG-top-level-size: %" PRIu64 "\n", sz);
cligen_output(stdout, "YANG-top-level-nr: %" PRIu64 "\n", nr);
}
else
cligen_output(stdout, "%-25s %-10" PRIu64 "\n", "Top-level", sz/1024);
if (clicon_option_bool(h, "CLICON_YANG_SCHEMA_MOUNT")) {
if (yang_mount_yspec2ymnt(yspec, &cvv1) < 0)
goto done;
@ -1929,30 +1929,39 @@ cli_show_statistics(clixon_handle h,
break;
}
if (cv3 != NULL){
if (detail){
cligen_output(stdout, "YANG-mount-point-%s: shared\n", cv_name_get(cv2));
}
else
cligen_output(stdout, "%s\n", cv_name_get(cv2));
}
else {
tnr += nr;
tsz += sz;
if (detail) {
cligen_output(stdout, "YANG-mount-point-%s-size: %" PRIu64 "\n", cv_name_get(cv2), sz);
cligen_output(stdout, "YANG-mount-point-%s-nr: %" PRIu64 "\n", cv_name_get(cv2), nr);
}
else{
if (strlen(cv_name_get(cv2)) > 25)
cligen_output(stdout, "%s \n %-25s", cv_name_get(cv2), "");
else
cligen_output(stdout, "%-25s", cv_name_get(cv2));
cligen_output(stdout, "%-10" PRIu64 "", sz/1024);
if (detail)
cligen_output(stdout, " %-8zu", nr);
cligen_output(stdout, "\n");
cligen_output(stdout, "%-10" PRIu64 "\n", sz/1024);
}
}
}
}
}
cligen_output(stdout, "%-25s %-10" PRIu64 "", "YANG Total", tsz/1024);
if (detail)
cligen_output(stdout, " %-10zu", tnr);
cligen_output(stdout, "\n");
if (detail)
cligen_output(stdout, "%s\n", "CLIspec trees");
}
if (detail){
cligen_output(stdout, "YANG-total-size: %" PRIu64 "\n", sz);
cligen_output(stdout, "YANG-total-nr: %" PRIu64 "\n", sz);
}
else
cligen_output(stdout, "%-25s %-10" PRIu64 "\n", "YANG Total", tsz/1024);
tnr0 = tnr;
tsz0 = tsz;
tnr = 0;
@ -1966,24 +1975,22 @@ cli_show_statistics(clixon_handle h,
tnr += nr;
tsz += sz;
if (detail){
if (strlen(cligen_ph_name_get(ph)) > 25){
cligen_output(stdout, "%s \\\n", cligen_ph_name_get(ph));
cligen_output(stdout, "%-25s %-10" PRIu64 " %-8zu\n", "", sz/1024, nr);
}
else
cligen_output(stdout, "%-25s %-10" PRIu64 " %-8zu\n", cligen_ph_name_get(ph), sz/1024, nr);
cligen_output(stdout, "CLIspec-%s-size: %" PRIu64 "\n", cligen_ph_name_get(ph), sz);
cligen_output(stdout, "CLIspec-%s-nr: %" PRIu64 "\n", cligen_ph_name_get(ph), nr);
}
}
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 (detail){
cligen_output(stdout, "CLIspec-total-size: %" PRIu64 "\n", tsz);
cligen_output(stdout, "CLIspec-total-nr: %" PRIu64 "\n", tnr);
cligen_output(stdout, "Mem-Total-size: %" PRIu64 "\n", tsz0+tsz);
cligen_output(stdout, "Mem-Total-nr: %" PRIu64 "\n", tnr0+tnr);
}
if (strcmp(what, "backend") == 0) {
else {
cligen_output(stdout, "%-25s %-10" PRIu64 "\n", "CLIspec Total", tsz/1024);
cligen_output(stdout, "%-25s %-10" PRIu64 "\n", "Mem Total", (tsz0+tsz)/1024);
}
}
if (backend) {
cprintf(cb, "<rpc xmlns=\"%s\"", NETCONF_BASE_NAMESPACE);
cprintf(cb, " %s", NETCONF_MESSAGE_ID_ATTR); /* XXX: use incrementing sequence */
cprintf(cb, ">");

View file

@ -753,6 +753,8 @@ yang_schema_mount_statistics(clixon_handle h,
char *xpath = NULL;
uint64_t nr;
size_t sz;
cg_var *cv1;
yang_stmt *yspec1;
if (yang_mount_xtop2xmnt(xtop, &cvv) < 0)
goto done;
@ -770,6 +772,27 @@ yang_schema_mount_statistics(clixon_handle h,
xml_chardata_cbuf_append(cb, 0, xpath);
cprintf(cb, "</name>");
nr = 0; sz = 0;
cv1 = NULL; /* For detecting shared YANGs */
if (yspec) {
cv1 = cv;
while ((cv1 = cvec_each(cvv, cv1)) != NULL) {
if (cv == cv1)
continue;
if ((ret = xml_yang_mount_get(h, cv_void_get(cv1), NULL, &yspec1)) < 0)
goto done;
if (yspec1 && yspec == yspec1)
break;
}
}
if (cv1 != NULL || yspec == NULL){
cprintf(cb, "<nr>%" PRIu64 "</nr><size>%zu</size>", nr, sz);
cprintf(cb, "</module-set>");
if (xpath){
free(xpath);
xpath = NULL;
}
continue;
}
if (yang_stats(yspec, &nr, &sz) < 0)
goto done;
cprintf(cb, "<nr>%" PRIu64 "</nr><size>%zu</size>", nr, sz);
@ -802,6 +825,7 @@ yang_schema_mount_statistics(clixon_handle h,
#ifdef YANG_SCHEMA_CMP_KLUDGE
/*! XXX: This comparison is kludgy since xyanglib is not proper RFC8525
* XXX: it should be enough to compare xyanglib with xmodst
* XXX openconfig xy2 have submodules but in xy1 they are modules and the counting is wrong
* @param[in] h CLixon handle
* @param[in] xyanglib Only modules
* @param[in] xmodst Has submodules
@ -885,7 +909,10 @@ yang_schema_cmp_kludge(clixon_handle h,
}
nr2++;
}
if (nr1 != nr2){
/* kludge in kludge, does not work with submodules, eg openconfig:
* xy2 have submodules but in xy1 they are modules and the counting is wrong
*/
if (0 && nr1 != nr2){
clixon_debug(CLIXON_DBG_YANG, "nr mismatch %d %d", nr1, nr2);
goto noteq;
}