CLI show mem: show as MiB/GiB etc
This commit is contained in:
parent
c53877eb78
commit
68bf76201c
2 changed files with 82 additions and 24 deletions
|
|
@ -1816,6 +1816,45 @@ clixon_cli2cbuf(clixon_handle h,
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Transform uin64 to KiB / MiB / GiB / TiB and postfix
|
||||||
|
*
|
||||||
|
* @param[in] inr Input number
|
||||||
|
* @param[out] onr Translated number
|
||||||
|
* @param[out] unit Multiple byte unit: K/M/G/T
|
||||||
|
* @retval 0
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
translatenumber(uint64_t inr,
|
||||||
|
uint64_t *onr,
|
||||||
|
char **unit)
|
||||||
|
{
|
||||||
|
if (inr/(10*1024) == 0) {
|
||||||
|
*onr = inr;
|
||||||
|
*unit = "";
|
||||||
|
}
|
||||||
|
else if (inr/(10LL*1024LL*1024LL*1024LL*1024LL) != 0) {
|
||||||
|
*onr = inr/(1024LL*1024LL*1024LL*1024LL);
|
||||||
|
*unit = "T";
|
||||||
|
}
|
||||||
|
else if (inr/(10LL*1024LL*1024LL*1024LL) != 0) {
|
||||||
|
*onr = inr/(1024LL*1024LL*1024LL);
|
||||||
|
*unit = "G";
|
||||||
|
}
|
||||||
|
else if (inr/(10LL*1024LL*1024LL) != 0) {
|
||||||
|
*onr = inr/(1024LL*1024LL);
|
||||||
|
*unit = "M";
|
||||||
|
}
|
||||||
|
else if (inr/(10LL*1024LL) != 0) {
|
||||||
|
*onr = inr/(1024LL);
|
||||||
|
*unit = "K";
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
*onr = inr;
|
||||||
|
*unit = "";
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*! CLI callback show memory statistics (and numbers)
|
/*! CLI callback show memory statistics (and numbers)
|
||||||
*
|
*
|
||||||
* mempry in KiB
|
* mempry in KiB
|
||||||
|
|
@ -1858,6 +1897,9 @@ cli_show_statistics(clixon_handle h,
|
||||||
cxobj *xp;
|
cxobj *xp;
|
||||||
char *name;
|
char *name;
|
||||||
cxobj *x;
|
cxobj *x;
|
||||||
|
uint64_t u64;
|
||||||
|
char *unit;
|
||||||
|
|
||||||
|
|
||||||
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|all) [detail]]");
|
clixon_err(OE_PLUGIN, EINVAL, "Expected arguments: [(cli|backend|all) [detail]]");
|
||||||
|
|
@ -1893,7 +1935,7 @@ cli_show_statistics(clixon_handle h,
|
||||||
}
|
}
|
||||||
if (cli) {
|
if (cli) {
|
||||||
if (!detail) {
|
if (!detail) {
|
||||||
cligen_output(stdout, "%-25s %-10s\n", "YANG", "Mem[KiB]");
|
cligen_output(stdout, "%-25s %-10s\n", "YANG", "Mem");
|
||||||
}
|
}
|
||||||
nr = 0; sz = 0;
|
nr = 0; sz = 0;
|
||||||
if (yang_stats(yspec, &nr, &sz) < 0)
|
if (yang_stats(yspec, &nr, &sz) < 0)
|
||||||
|
|
@ -1904,8 +1946,10 @@ cli_show_statistics(clixon_handle h,
|
||||||
cligen_output(stdout, "YANG-top-level-size: %" PRIu64 "\n", sz);
|
cligen_output(stdout, "YANG-top-level-size: %" PRIu64 "\n", sz);
|
||||||
cligen_output(stdout, "YANG-top-level-nr: %" PRIu64 "\n", nr);
|
cligen_output(stdout, "YANG-top-level-nr: %" PRIu64 "\n", nr);
|
||||||
}
|
}
|
||||||
else
|
else{
|
||||||
cligen_output(stdout, "%-25s %-10" PRIu64 "\n", "Top-level", sz/1024);
|
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 (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;
|
||||||
|
|
@ -1930,7 +1974,9 @@ cli_show_statistics(clixon_handle h,
|
||||||
}
|
}
|
||||||
if (cv3 != NULL){
|
if (cv3 != NULL){
|
||||||
if (detail){
|
if (detail){
|
||||||
cligen_output(stdout, "YANG-mount-point-%s: shared\n", cv_name_get(cv2));
|
/* Maybe use "0" instead of "shared"? */
|
||||||
|
cligen_output(stdout, "YANG-mount-point-%s-size: shared\n", cv_name_get(cv2));
|
||||||
|
cligen_output(stdout, "YANG-mount-point-%s-nr: shared\n", cv_name_get(cv2));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
cligen_output(stdout, "%s\n", cv_name_get(cv2));
|
cligen_output(stdout, "%s\n", cv_name_get(cv2));
|
||||||
|
|
@ -1948,7 +1994,8 @@ cli_show_statistics(clixon_handle h,
|
||||||
cligen_output(stdout, "%s \n %-25s", cv_name_get(cv2), "");
|
cligen_output(stdout, "%s \n %-25s", cv_name_get(cv2), "");
|
||||||
else
|
else
|
||||||
cligen_output(stdout, "%-25s", cv_name_get(cv2));
|
cligen_output(stdout, "%-25s", cv_name_get(cv2));
|
||||||
cligen_output(stdout, "%-10" PRIu64 "\n", sz/1024);
|
translatenumber(sz, &u64, &unit);
|
||||||
|
cligen_output(stdout, "%" PRIu64 "%-10s\n", u64, unit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1959,9 +2006,10 @@ cli_show_statistics(clixon_handle h,
|
||||||
cligen_output(stdout, "YANG-total-size: %" PRIu64 "\n", sz);
|
cligen_output(stdout, "YANG-total-size: %" PRIu64 "\n", sz);
|
||||||
cligen_output(stdout, "YANG-total-nr: %" PRIu64 "\n", sz);
|
cligen_output(stdout, "YANG-total-nr: %" PRIu64 "\n", sz);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
cligen_output(stdout, "%-25s %-10" PRIu64 "\n", "YANG Total", tsz/1024);
|
translatenumber(sz, &u64, &unit);
|
||||||
|
cligen_output(stdout, "%-25s %" PRIu64 "%-10s\n", "YANG Total", u64, unit);
|
||||||
|
}
|
||||||
tnr0 = tnr;
|
tnr0 = tnr;
|
||||||
tsz0 = tsz;
|
tsz0 = tsz;
|
||||||
tnr = 0;
|
tnr = 0;
|
||||||
|
|
@ -1986,8 +2034,10 @@ cli_show_statistics(clixon_handle h,
|
||||||
cligen_output(stdout, "Mem-Total-nr: %" PRIu64 "\n", tnr0+tnr);
|
cligen_output(stdout, "Mem-Total-nr: %" PRIu64 "\n", tnr0+tnr);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cligen_output(stdout, "%-25s %-10" PRIu64 "\n", "CLIspec Total", tsz/1024);
|
translatenumber(tsz, &u64, &unit);
|
||||||
cligen_output(stdout, "%-25s %-10" PRIu64 "\n", "Mem Total", (tsz0+tsz)/1024);
|
cligen_output(stdout, "%-25s %" PRIu64 "%-10s\n", "CLIspec Total", u64, unit);
|
||||||
|
translatenumber(tsz0+tsz, &u64, &unit);
|
||||||
|
cligen_output(stdout, "%-25s %" PRIu64 "%-10s\n", "Mem Total", u64, unit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (backend) {
|
if (backend) {
|
||||||
|
|
@ -2013,7 +2063,7 @@ cli_show_statistics(clixon_handle h,
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cligen_output(stdout, "%-25s %-10s\n", "XML Datastore", "Mem[KiB]");
|
cligen_output(stdout, "%-25s %-10s\n", "XML Datastore", "Mem");
|
||||||
tsz = 0;
|
tsz = 0;
|
||||||
if ((xp = xml_find_type(xret, NULL, "datastores", CX_ELMNT)) != NULL){
|
if ((xp = xml_find_type(xret, NULL, "datastores", CX_ELMNT)) != NULL){
|
||||||
x = NULL;
|
x = NULL;
|
||||||
|
|
@ -2023,15 +2073,18 @@ cli_show_statistics(clixon_handle h,
|
||||||
parse_uint64(xml_find_body(x, "size"), &sz, NULL);
|
parse_uint64(xml_find_body(x, "size"), &sz, NULL);
|
||||||
tsz += sz;
|
tsz += sz;
|
||||||
name = xml_find_body(x, "name");
|
name = xml_find_body(x, "name");
|
||||||
|
translatenumber(sz, &u64, &unit);
|
||||||
if (strlen(name) > 25){
|
if (strlen(name) > 25){
|
||||||
cligen_output(stdout, "%s \\\n", name);
|
cligen_output(stdout, "%s \\\n", name);
|
||||||
cligen_output(stdout, "%-25s %-10" PRIu64 "\n", "", sz/1024);
|
cligen_output(stdout, "%-25s %" PRIu64 "%-10s\n", "", u64, unit);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
cligen_output(stdout, "%-25s %" PRIu64 "%-10s\n", name, u64, unit);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
cligen_output(stdout, "%-25s %-10" PRIu64 "\n", name, sz/1024);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cligen_output(stdout, "%-25s %-10" PRIu64 "\n", "XML Total", tsz/1024);
|
translatenumber(tsz, &u64, &unit);
|
||||||
|
cligen_output(stdout, "%-25s %" PRIu64 "%-10s\n", "XML Total", u64, unit);
|
||||||
tsz0 = tsz;
|
tsz0 = tsz;
|
||||||
tsz = 0;
|
tsz = 0;
|
||||||
cligen_output(stdout, "%s\n", "YANG");
|
cligen_output(stdout, "%s\n", "YANG");
|
||||||
|
|
@ -2043,17 +2096,22 @@ cli_show_statistics(clixon_handle h,
|
||||||
parse_uint64(xml_find_body(x, "size"), &sz, NULL);
|
parse_uint64(xml_find_body(x, "size"), &sz, NULL);
|
||||||
tsz += sz;
|
tsz += sz;
|
||||||
name = xml_find_body(x, "name");
|
name = xml_find_body(x, "name");
|
||||||
|
translatenumber(sz, &u64, &unit);
|
||||||
if (strlen(name) > 25){
|
if (strlen(name) > 25){
|
||||||
cligen_output(stdout, "%s \\\n", name);
|
cligen_output(stdout, "%s\n", name);
|
||||||
cligen_output(stdout, "%-25s %-10" PRIu64 "\n", "", sz/1024);
|
if (sz != 0){
|
||||||
|
cligen_output(stdout, "%-25s %" PRIu64 "%-10s\n", "", u64, unit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
cligen_output(stdout, "%-25s %" PRIu64 "%-10s\n", name, u64, unit);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
cligen_output(stdout, "%-25s %-10" PRIu64 "\n", name, sz/1024);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cligen_output(stdout, "%-25s %-10" PRIu64 "\n", "YANG Total*", tsz/1024);
|
translatenumber(tsz, &u64, &unit);
|
||||||
cligen_output(stdout, "%-25s %-10" PRIu64 "\n", "Mem Total*", (tsz0+tsz)/1024);
|
cligen_output(stdout, "%-25s %" PRIu64 "%-10s\n", "YANG Total", u64, unit);
|
||||||
cligen_output(stdout, "(*) May be shared YANG\n");
|
translatenumber(tsz0+tsz, &u64, &unit);
|
||||||
|
cligen_output(stdout, "%-25s %" PRIu64 "%-10s\n", "Mem Total", u64, unit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
retval = 0;
|
retval = 0;
|
||||||
|
|
|
||||||
|
|
@ -1094,8 +1094,8 @@ yang_parse_filename(clixon_handle h,
|
||||||
* @param[in] revision Revision (or NULL)
|
* @param[in] revision Revision (or NULL)
|
||||||
* @param[in] yspec Yang statement
|
* @param[in] yspec Yang statement
|
||||||
* @param[in] origname Name of yang module triggering this parsing, for logging
|
* @param[in] origname Name of yang module triggering this parsing, for logging
|
||||||
* @retval 0 OK
|
* @retval ymod YANG (sub)module
|
||||||
* @retval -1 Error
|
* @retval NULL Failed
|
||||||
*
|
*
|
||||||
* See top of file for diagram of calling order
|
* See top of file for diagram of calling order
|
||||||
* @note does not check wether the module is already loaded
|
* @note does not check wether the module is already loaded
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue