Skip to content

Commit

Permalink
Reworked cli show mem to yang domains
Browse files Browse the repository at this point in the history
  • Loading branch information
olofhagsand committed Sep 26, 2024
1 parent 212be7a commit 8901d00
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 199 deletions.
63 changes: 24 additions & 39 deletions apps/backend/backend_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1423,10 +1423,12 @@ from_client_stats(clixon_handle h,
char *str;
int modules = 0;
yang_stmt *yspec;
yang_stmt *ymodext;
yang_stmt *ymounts;
yang_stmt *ydomain;
cxobj *xt = NULL;
int ret;
char *name;
int inext;
int inext2;

if ((str = xml_find_body(xe, "modules")) != NULL)
modules = strcmp(str, "true") == 0;
Expand All @@ -1449,46 +1451,29 @@ from_client_stats(clixon_handle h,
if (clixon_stats_datastore_get(h, "startup", cbret) < 0)
goto done;
cprintf(cbret, "</datastores>");
/* per module-set, first configuration, then main dbspec, then mountpoints */
cprintf(cbret, "<module-sets xmlns=\"%s\">", CLIXON_LIB_NS);
cprintf(cbret, "<module-set><name>clixon-config</name>");
yspec = clicon_config_yang(h); /* Note switch yspec to config (not data) */
if (clixon_stats_module_get(h, yspec, cbret) < 0)
goto done;
if (modules){
inext = 0;
while ((ym = yn_iter(yspec, &inext)) != NULL) {
cprintf(cbret, "<module><name>%s</name>", yang_argument_get(ym));
if (clixon_stats_module_get(h, ym, cbret) < 0)
goto done;
cprintf(cbret, "</module>");
}
}
cprintf(cbret, "</module-set>");
cprintf(cbret, "<module-set><name>main</name>");
yspec = clicon_dbspec_yang(h);
if (clixon_stats_module_get(h, yspec, cbret) < 0)
if ((ymounts = clixon_yang_mounts_get(h)) == NULL){
clixon_err(OE_YANG, ENOENT, "Top-level yang mounts not found");
goto done;
if (modules){
inext = 0;
while ((ym = yn_iter(yspec, &inext)) != NULL) {
cprintf(cbret, "<module><name>%s</name>", yang_argument_get(ym));
if (clixon_stats_module_get(h, ym, cbret) < 0)
goto done;
cprintf(cbret, "</module>");
}
}
cprintf(cbret, "</module-set>");
/* Mountpoints */
if ((ymodext = yang_find(yspec, Y_MODULE, "ietf-yang-schema-mount")) != NULL){
if ((ret = xmldb_get0(h, "running", YB_MODULE, NULL, "/", 1, 0, &xt, NULL, NULL)) < 0)
goto done;
if (ret == 0){
clixon_err(OE_DB, 0, "Error when reading from running, unknown error");
goto done;
cprintf(cbret, "<module-sets xmlns=\"%s\">", CLIXON_LIB_NS);
inext = 0;
while ((ydomain = yn_iter(ymounts, &inext)) != NULL) {
name = yang_argument_get(ydomain);
/* per module-set, first configuration, then main dbspec, then mountpoints */
cprintf(cbret, "<module-set>");
cprintf(cbret, "<name>%s</name>", name);
if (clixon_stats_module_get(h, ydomain, cbret) < 0)
goto done;
if (modules){
inext2 = 0;
while ((ym = yn_iter(ydomain, &inext2)) != NULL) {
cprintf(cbret, "<module><name>%s</name>", yang_argument_get(ym));
if (clixon_stats_module_get(h, ym, cbret) < 0)
goto done;
cprintf(cbret, "</module>");
}
}
if (xt && yang_schema_mount_statistics(h, xt, modules, cbret) < 0)
goto done;
cprintf(cbret, "</module-set>");
}
cprintf(cbret, "</module-sets>");
cprintf(cbret, "</rpc-reply>");
Expand Down
1 change: 0 additions & 1 deletion apps/cli/cli_generate.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ You can see which CLISPEC it generates via clixon_cli -D 2:
#include <fcntl.h>
#include <syslog.h>
#include <signal.h>
#include <assert.h> // XXX
#include <sys/param.h>

/* cligen */
Expand Down
89 changes: 27 additions & 62 deletions apps/cli/cli_show.c
Original file line number Diff line number Diff line change
Expand Up @@ -1887,23 +1887,21 @@ cli_show_statistics(clixon_handle h,
size_t sz;
size_t tsz0;
size_t tsz;
yang_stmt *yspec;
cvec *cvv1 = NULL;
yang_stmt *ymounts;
yang_stmt *ydomain;
cg_var *cv;
cxobj *xp;
char *name;
cxobj *x;
uint64_t u64;
char *unit;
yang_stmt *ymounts;
int inext;
int i;

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);
ydomain = clicon_dbspec_yang(h);
cv = cvec_i(argv, 0);
what = cv_string_get(cv);
if (strcmp(what, "cli") == 0)
Expand Down Expand Up @@ -1931,67 +1929,29 @@ cli_show_statistics(clixon_handle h,
clixon_err(OE_PLUGIN, errno, "cbuf_new");
goto done;
}
if ((ymounts = clixon_yang_mounts_get(h)) == NULL){
clixon_err(OE_YANG, ENOENT, "Top-level yang mounts not found");
goto done;
}
if (cli) {
if (!detail) {
cligen_output(stdout, "%-25s %-10s\n", "YANG", "Mem");
}
nr = 0; sz = 0;
if (yang_stats(yspec, 0, &nr, &sz) < 0)
goto done;
tnr = nr;
tsz = sz;
if (detail) {
cligen_output(stdout, "YANG-top-level-size: %" PRIu64 "\n", sz);
cligen_output(stdout, "YANG-top-level-nr: %" PRIu64 "\n", nr);
}
else{
translatenumber(sz, &u64, &unit);
cligen_output(stdout, "%-25s %" PRIu64 "%-10s\n", "Top-level", u64, unit);
}
if (clicon_option_bool(h, "CLICON_YANG_SCHEMA_MOUNT")) {
if ((ymounts = clixon_yang_mounts_get(h)) == NULL){
clixon_err(OE_YANG, ENOENT, "Top-level yang mounts not found");
inext = 0;
while ((ydomain = yn_iter(ymounts, &inext)) != NULL) {
name = yang_argument_get(ydomain);
nr = 0; sz = 0;
if (yang_stats(ydomain, 0, &nr, &sz) < 0)
goto done;
tnr = nr;
tsz = sz;
if (detail) {
cligen_output(stdout, "YANG-%s-size: %" PRIu64 "\n", name, sz);
cligen_output(stdout, "YANG-%s-nr: %" PRIu64 "\n", name, nr);
}
inext = 0;
while ((yspec = yn_iter(ymounts, &inext)) != NULL) {
cvv1 = NULL;
if (yang_keyword_get(yspec) == Y_SPEC &&
yang_flag_get(yspec, YANG_FLAG_SPEC_MOUNT) != 0x0 &&
(cvv1 = yang_cvec_get(yspec)) != NULL){
nr = 0; sz = 0;
if (yang_stats(yspec, 0, &nr, &sz) < 0)
goto done;
tnr += nr;
tsz += sz;
i = 0;
cv = NULL;
while ((cv = cvec_each(cvv1, cv)) != NULL) {
if (detail){
if (i == cvec_len(cvv1)-1) {
cligen_output(stdout, "YANG-mount-point-%s-size: %" PRIu64 "\n", cv_name_get(cv), sz);
cligen_output(stdout, "YANG-mount-point-%s-nr: %" PRIu64 "\n", cv_name_get(cv), nr);
}
else {
cligen_output(stdout, "YANG-mount-point-%s-size: shared\n", cv_name_get(cv));
cligen_output(stdout, "YANG-mount-point-%s-nr: shared\n", cv_name_get(cv));
}
}
else {
if (i == cvec_len(cvv1)-1) {
if (strlen(cv_name_get(cv)) > 25)
cligen_output(stdout, "%s \n %-25s", cv_name_get(cv), "");
else
cligen_output(stdout, "%-25s", cv_name_get(cv));
translatenumber(sz, &u64, &unit);
cligen_output(stdout, "%" PRIu64 "%-10s\n", u64, unit);
}
else
cligen_output(stdout, "%s\n", cv_name_get(cv));
}
i++;
}
}
else{
translatenumber(sz, &u64, &unit);
cligen_output(stdout, "%-25s %" PRIu64 "%-10s\n", yang_argument_get(ydomain), u64, unit);
}
}
if (detail){
Expand All @@ -2002,6 +1962,9 @@ cli_show_statistics(clixon_handle h,
translatenumber(tsz, &u64, &unit);
cligen_output(stdout, "%-25s %" PRIu64 "%-10s\n", "YANG Total", u64, unit);
}
if (!detail) {
cligen_output(stdout, "%-25s\n", "CLIspec");
}
tnr0 = tnr;
tsz0 = tsz;
tnr = 0;
Expand Down Expand Up @@ -2031,6 +1994,7 @@ cli_show_statistics(clixon_handle h,
translatenumber(tsz0+tsz, &u64, &unit);
cligen_output(stdout, "%-25s %" PRIu64 "%-10s\n", "Mem Total", u64, unit);
}

}
if (backend) {
cprintf(cb, "<rpc xmlns=\"%s\"", NETCONF_BASE_NAMESPACE);
Expand All @@ -2055,7 +2019,7 @@ cli_show_statistics(clixon_handle h,
goto done;
}
else {
cligen_output(stdout, "%-25s %-10s\n", "XML Datastore", "Mem");
cligen_output(stdout, "%-25s %-10s\n", "Datastore", "Mem");
tsz = 0;
if ((xp = xml_find_type(xret, NULL, "datastores", CX_ELMNT)) != NULL){
x = NULL;
Expand Down Expand Up @@ -2085,9 +2049,10 @@ cli_show_statistics(clixon_handle h,
while ((x = xml_child_each(xp, x, CX_ELMNT)) != NULL) {
if (strcmp(xml_name(x), "module-set") != 0)
continue;
if ((name = xml_find_body(x, "name")) == NULL)
continue;
parse_uint64(xml_find_body(x, "size"), &sz, NULL);
tsz += sz;
name = xml_find_body(x, "name");
translatenumber(sz, &u64, &unit);
if (strlen(name) > 25){
cligen_output(stdout, "%s\n", name);
Expand Down
1 change: 0 additions & 1 deletion lib/clixon/clixon_yang_schema_mount.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ int xml_yang_mount_set(clixon_handle h, cxobj *x, yang_stmt *yspec);
int yang_mount_xtop2xmnt(cxobj *xtop, cvec **cvvp);
int yang_mount_yspec2ymnt(yang_stmt *yspec, cvec **cvvp);
int yang_schema_mount_statedata(clixon_handle h, yang_stmt *yspec, char *xpath, cvec *nsc, cxobj **xret, cxobj **xerr);
int yang_schema_mount_statistics(clixon_handle h, cxobj *xt, int modules, cbuf *cb);
int yang_schema_yanglib_parse_mount(clixon_handle h, cxobj *xt);
int yang_schema_get_child(clixon_handle h, cxobj *x1, cxobj *x1c, yang_stmt **yc);
int yang_schema_yspec_rm(clixon_handle h, cxobj *xmnt);
Expand Down
94 changes: 0 additions & 94 deletions lib/src/clixon_yang_schema_mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -695,100 +695,6 @@ yang_schema_mount_statedata(clixon_handle h,
goto done;
}

/*! Statistics about mountpoints
*
* @param[in] h Clixon handle
* @param[in] xtop Top XML node
* @param[in] modules
* @param[in] cb
* @retval 0 OK
* @retval -1 Error
* @see yang_schema_mount_statedata
*/
int
yang_schema_mount_statistics(clixon_handle h,
cxobj *xtop,
int modules,
cbuf *cb)
{
int retval = -1;
cvec *cvv = NULL;
cg_var *cv;
cxobj *xmnt;
yang_stmt *yspec;
yang_stmt *ym;
int ret;
char *xpath = NULL;
uint64_t nr;
size_t sz;
cg_var *cv1;
yang_stmt *yspec1;
int inext;

if (yang_mount_xtop2xmnt(xtop, &cvv) < 0)
goto done;
cv = NULL;
while ((cv = cvec_each(cvv, cv)) != NULL) {
if ((xmnt = cv_void_get(cv)) == NULL)
continue;
if ((ret = xml_yang_mount_get(h, xmnt, NULL, &xpath, &yspec)) < 0)
goto done;
if (ret == 0)
continue;
cprintf(cb, "<module-set><name>mountpoint: ");
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, 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, 0, &nr, &sz) < 0)
goto done;
cprintf(cb, "<nr>%" PRIu64 "</nr><size>%zu</size>", nr, sz);
if (modules){
inext = 0;
while ((ym = yn_iter(yspec, &inext)) != NULL) {
cprintf(cb, "<module><name>%s</name>", yang_argument_get(ym));
nr = 0; sz = 0;
if (yang_stats(ym, 0, &nr, &sz) < 0)
goto done;
cprintf(cb, "<nr>%" PRIu64 "</nr><size>%zu</size>", nr, sz);
cprintf(cb, "</module>");
}
}
cprintf(cb, "</module-set>");
if (xpath){
free(xpath);
xpath = NULL;
}
}
retval = 0;
done:
if (xpath)
free(xpath);
if (cvv)
cvec_free(cvv);
return retval;
}

/*! Get yanglib from user plugin callback, parse it and mount it
*
* Optionally check for shared yspec
Expand Down
4 changes: 2 additions & 2 deletions yang/clixon/clixon-lib@2024-08-01.yang
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,10 @@ module clixon-lib {
}
container module-sets{
list module-set{
description "Statistics per group of module, eg top-level and mount-points";
description "Statistics per domain, eg top-level and mount-points";
key "name";
leaf name{
description "Name of YANG module.";
description "Name of YANG domain.";
type string;
}
leaf nr{
Expand Down

0 comments on commit 8901d00

Please sign in to comment.