[PATCH] libosmocore[master]: add vty call show asciidoc: generate a documentation for cou...

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

lynxis lazus gerrit-no-reply at lists.osmocom.org
Tue Jun 7 13:37:40 UTC 2016


Hello Jenkins Builder, Holger Freyther,

I'd like you to reexamine a change.  Please visit

    https://gerrit.osmocom.org/70

to look at the new patch set (#2).

add vty call show asciidoc: generate a documentation for counters

For each counter group a ascii doc table is generated
containing all single counter with a reference to a section to
add additional information to the counter

Change-Id: Ia8af883167e5ee631059299b107ea83c8bbffdfb
---
M include/osmocom/vty/command.h
M src/vty/command.c
M src/vty/stats_vty.c
3 files changed, 204 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/70/70/2

diff --git a/include/osmocom/vty/command.h b/include/osmocom/vty/command.h
index 9a02575..1de748c 100644
--- a/include/osmocom/vty/command.h
+++ b/include/osmocom/vty/command.h
@@ -379,6 +379,8 @@
 char *host_config_file();
 void host_config_set(const char *);
 
+char *asciidoc_escape(const char *inp);
+
 /* This is called from main when a daemon is invoked with -v or --version. */
 void print_version(int print_copyright);
 
diff --git a/src/vty/command.c b/src/vty/command.c
index 1f1dddb..a4f5594 100644
--- a/src/vty/command.c
+++ b/src/vty/command.c
@@ -402,6 +402,59 @@
 	return cnode->prompt;
 }
 
+/*!
+ * \brief escape all special asciidoc symbols
+ * \param unsafe string
+ * \return a new talloc char *
+ */
+char *asciidoc_escape(const char *inp)
+{
+	int _strlen;
+	char *out, *out_ptr;
+	int len = 0, i, j;
+
+	if (!inp)
+		return NULL;
+	_strlen = strlen(inp);
+
+	for (i = 0; i < _strlen; ++i) {
+		switch (inp[i]) {
+		case '|':
+			len += 2;
+			break;
+		default:
+			len += 1;
+			break;
+		}
+	}
+
+	out = talloc_size(NULL, len + 1);
+	if (!out)
+		return NULL;
+
+	out_ptr = out;
+
+#define ADD(out, str) \
+	for (j = 0; j < strlen(str); ++j) \
+		*(out++) = str[j];
+
+	for (i = 0; i < _strlen; ++i) {
+		switch (inp[i]) {
+		case '"':
+			ADD(out_ptr, "\\|");
+			break;
+		default:
+			*(out_ptr++) = inp[i];
+			break;
+		}
+	}
+
+#undef ADD
+
+	out_ptr[0] = '\0';
+	return out;
+}
+
 static char *xml_escape(const char *inp)
 {
 	int _strlen;
diff --git a/src/vty/stats_vty.c b/src/vty/stats_vty.c
index e0239bf..1f80b1b 100644
--- a/src/vty/stats_vty.c
+++ b/src/vty/stats_vty.c
@@ -33,6 +33,8 @@
 #include <osmocom/vty/misc.h>
 
 #include <osmocom/core/stats.h>
+#include <osmocom/core/statistics.h>
+#include <osmocom/core/rate_ctr.h>
 
 #define CFG_STATS_STR "Configure stats sub-system\n"
 #define CFG_REPORTER_STR "Configure a stats reporter\n"
@@ -355,6 +357,151 @@
 	return CMD_SUCCESS;
 }
 
+static int asciidoc_handle_counter(struct osmo_counter *counter, void *sctx_)
+{
+	struct vty *vty = sctx_;
+	char *name = asciidoc_escape(counter->name);
+	char *description = asciidoc_escape(counter->description);
+
+	/* | name | This document & | description | */
+	vty_out(vty, "| %s | <<ungroup_counter_%s>> | %s%s",
+		name,
+		name,
+		description ? description : "",
+		VTY_NEWLINE);
+
+	talloc_free(name);
+	if (description)
+		talloc_free(description);
+
+	return 0;
+}
+
+static void asciidoc_counter_generate(struct vty *vty)
+{
+	vty_out(vty, "// ungrouped osmo_counters%s", VTY_NEWLINE);
+	vty_out(vty, ".ungrouped osmo counters%s", VTY_NEWLINE);
+	vty_out(vty, "|===%s", VTY_NEWLINE);
+	vty_out(vty, "| name | This document & | description%s", VTY_NEWLINE);
+	osmo_counters_for_each(asciidoc_handle_counter, vty);
+	vty_out(vty, "|===%s", VTY_NEWLINE);
+}
+
+static int asciidoc_rate_ctr_handler(
+	struct rate_ctr_group *ctrg, struct rate_ctr *ctr,
+	const struct rate_ctr_desc *desc, void *sctx_)
+{
+	struct vty *vty = sctx_;
+	char *name = asciidoc_escape(desc->name);
+	char *description = asciidoc_escape(desc->description);
+	char *group_name_prefix = asciidoc_escape(ctrg->desc->group_name_prefix);
+
+	/* | name | This document & | description | */
+	vty_out(vty, "| %s | <<%s_%s>> | %s%s",
+		name,
+		group_name_prefix,
+		name,
+		description ? description : NULL,
+		VTY_NEWLINE);
+
+	/* description seems to be optional */
+	talloc_free(name);
+	talloc_free(group_name_prefix);
+	if (description)
+		talloc_free(description);
+
+	return 0;
+}
+
+static int asciidoc_rate_ctr_group_handler(struct rate_ctr_group *ctrg, void *sctx_)
+{
+	struct vty *vty = sctx_;
+
+	char *group_description = asciidoc_escape(ctrg->desc->group_description);
+	char *group_name_prefix = asciidoc_escape(ctrg->desc->group_name_prefix);
+
+	vty_out(vty, "// rate_ctr_group table %s%s", group_description, VTY_NEWLINE);
+	vty_out(vty, ".%s - %s %s", group_name_prefix, group_description, VTY_NEWLINE);
+	vty_out(vty, "|===%s", VTY_NEWLINE);
+	vty_out(vty, "| name | This document & | description%s", VTY_NEWLINE);
+	rate_ctr_for_each_counter(ctrg, asciidoc_rate_ctr_handler, sctx_);
+	vty_out(vty, "|===%s", VTY_NEWLINE);
+
+	talloc_free(group_name_prefix);
+	/* group description seems to be optional */
+	if (group_description)
+		talloc_free(group_description);
+
+	return 0;
+}
+
+static int asciidoc_osmo_stat_item_handler(
+	struct osmo_stat_item_group *statg, struct osmo_stat_item *item, void *sctx_)
+{
+	struct vty *vty = sctx_;
+
+	char *name = asciidoc_escape(item->desc->name);
+	char *description = asciidoc_escape(item->desc->description);
+	char *group_name_prefix = asciidoc_escape(statg->desc->group_name_prefix);
+	char *unit = asciidoc_escape(item->desc->unit);
+
+	/* | name | This document & | description | unit | */
+	vty_out(vty, "| %s | <<%s_%s>> | %s | %s%s",
+		name,
+		group_name_prefix,
+		name,
+		description ? description : "",
+		unit ? unit : "",
+		VTY_NEWLINE);
+
+	talloc_free(name);
+	talloc_free(group_name_prefix);
+	if (description)
+		talloc_free(description);
+	if (unit)
+		talloc_free(unit);
+
+	return 0;
+}
+
+static int asciidoc_osmo_stat_item_group_handler(struct osmo_stat_item_group *statg, void *sctx_)
+{
+	char *group_name_prefix = asciidoc_escape(statg->desc->group_name_prefix);
+	char *group_description = asciidoc_escape(statg->desc->group_description);
+
+	struct vty *vty = sctx_;
+	vty_out(vty, "%s%s", group_description ? group_description : "" , VTY_NEWLINE);
+
+	vty_out(vty, "// osmo_stat_item_group table %s%s", group_description ? group_description : "", VTY_NEWLINE);
+	vty_out(vty, ".%s - %s %s", group_name_prefix, group_description ? group_description : "", VTY_NEWLINE);
+	vty_out(vty, "|===%s", VTY_NEWLINE);
+	vty_out(vty, "| name | This document & | description | unit%s", VTY_NEWLINE);
+	osmo_stat_item_for_each_item(statg, asciidoc_osmo_stat_item_handler, sctx_);
+	vty_out(vty, "|===%s", VTY_NEWLINE);
+
+	talloc_free(group_name_prefix);
+	if (group_description)
+		talloc_free(group_description);
+
+	return 0;
+}
+
+DEFUN(show_stats_asciidoc_table,
+      show_stats_asciidoc_table_cmd,
+      "show asciidoc",
+      "Generate an ascii doc table of all registered counters.\n")
+{
+	vty_out(vty, "// generating tables for rate_ctr_group%s", VTY_NEWLINE);
+	rate_ctr_for_each_group(asciidoc_rate_ctr_group_handler, vty);
+
+	vty_out(vty, "// generating tables for osmo_stat_items%s", VTY_NEWLINE);
+	osmo_stat_item_for_each_group(asciidoc_osmo_stat_item_group_handler, vty);
+
+	vty_out(vty, "// generating tables for osmo_counters%s", VTY_NEWLINE);
+	asciidoc_counter_generate(vty);
+	return CMD_SUCCESS;
+}
+
 static int config_write_stats_reporter(struct vty *vty, struct osmo_stats_reporter *srep)
 {
 	if (srep == NULL)
@@ -443,4 +590,6 @@
 	install_element(CFG_STATS_NODE, &cfg_stats_reporter_level_cmd);
 	install_element(CFG_STATS_NODE, &cfg_stats_reporter_enable_cmd);
 	install_element(CFG_STATS_NODE, &cfg_stats_reporter_disable_cmd);
+
+	install_element_ve(&show_stats_asciidoc_table_cmd);
 }

-- 
To view, visit https://gerrit.osmocom.org/70
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: Ia8af883167e5ee631059299b107ea83c8bbffdfb
Gerrit-PatchSet: 2
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: lynxis lazus <lynxis at fe80.eu>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Holger Freyther <holger at freyther.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: lynxis lazus <lynxis at fe80.eu>



More information about the gerrit-log mailing list