diff mbox

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

Message ID gerrit.1463500922637.Ia8af883167e5ee631059299b107ea83c8bbffdfb@gerrit.osmocom.org
State New
Headers show

Commit Message

gerrit-no-reply@lists.osmocom.org May 17, 2016, 4:02 p.m. UTC
From lynxis lazus <lynxis@fe80.eu>:

lynxis lazus has uploaded a new change for review.

  https://gerrit.osmocom.org/70

Change subject: add vty call show asciidoc: generate a documentation for counters
......................................................................

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 src/vty/stats_vty.c
1 file changed, 111 insertions(+), 0 deletions(-)


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

Comments

gerrit-no-reply@lists.osmocom.org May 17, 2016, 4:09 p.m. UTC | #1
From Holger Freyther <holger@freyther.de>:

Holger Freyther has posted comments on this change.

Change subject: add vty call show asciidoc: generate a documentation for counters
......................................................................


Patch Set 1: Code-Review+1

(3 comments)

https://gerrit.osmocom.org/#/c/70/1/src/vty/stats_vty.c
File src/vty/stats_vty.c:

Line 362: 	struct vty *vty = sctx_;
I think you will not find another place with a '_' as suffix to a parameter. What is the semantic for that? (I assume you use it in other projects?)


Line 363: 	const char *description = counter->description ? counter->description : "";
Have you encountered counters without a description?


Line 397: 		description,
For XML there is something like xml_escape. Do we need (and can we) escape characters for asciidoc? E.g. if the description includes '|'?
gerrit-no-reply@lists.osmocom.org May 18, 2016, 1:24 p.m. UTC | #2
Patch Set 1:

(3 comments)

https://gerrit.osmocom.org/#/c/70/1/src/vty/stats_vty.c
File src/vty/stats_vty.c:

Line 362: 	struct vty *vty = sctx_;
> I think you will not find another place with a '_' as suffix to a parameter
No idea what's the semantic, but I did it similiar to http://git.osmocom.org/libosmocore/tree/src/stats.c#n479


Line 363: 	const char *description = counter->description ? counter->description : "";
> Have you encountered counters without a description?
yes. `struct osmo_counter` doesn't have one.


Line 397: 		description,
> For XML there is something like xml_escape. Do we need (and can we) escape 
we can escape those by backslashes. Do we need this to do it right now? http://www.methods.co.nz/asciidoc/faq.html#_how_can_i_escape_asciidoc_markup
gerrit-no-reply@lists.osmocom.org May 23, 2016, 8:26 p.m. UTC | #3
Patch Set 1:

(1 comment)

https://gerrit.osmocom.org/#/c/70/1/src/vty/stats_vty.c
File src/vty/stats_vty.c:

Line 397: 		description,
> we can escape those by backslashes. Do we need this to do it right now? htt
What do you think? I think we should escape what needs to be escaped? I mean we do it for XML and it should be easy to copy that code?
gerrit-no-reply@lists.osmocom.org May 24, 2016, 1:57 p.m. UTC | #4
Patch Set 1:

(1 comment)

https://gerrit.osmocom.org/#/c/70/1/src/vty/stats_vty.c
File src/vty/stats_vty.c:

Line 397: 		description,
> What do you think? I think we should escape what needs to be escaped? I mea
I agree with holger, we should escape it, to prevent any strange future failures.
gerrit-no-reply@lists.osmocom.org May 25, 2016, 7:46 p.m. UTC | #5
Patch Set 1: Code-Review-1
gerrit-no-reply@lists.osmocom.org June 1, 2016, 1:58 p.m. UTC | #6
Patch Set 1:

Please add escaping of the strings as requested, so we can get this merged ASAP.
diff mbox

Patch

diff --git a/src/vty/stats_vty.c b/src/vty/stats_vty.c
index e0239bf..2193e70 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,113 @@ 
 	return CMD_SUCCESS;
 }
 
+static int ascii_handle_counter(struct osmo_counter *counter, void *sctx_)
+{
+	struct vty *vty = sctx_;
+	const char *description = counter->description ? counter->description : "";
+
+	/* | name | This document & | description | */
+	vty_out(vty, "| %s | <<ungroup_counter_%s>> | %s%s",
+		counter->name,
+		counter->name,
+		description,
+		VTY_NEWLINE);
+
+	return 0;
+}
+
+static void ascii_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(ascii_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_;
+	const char *description = desc->description ? desc->description : "";
+
+	/* | name | This document & | description | */
+	vty_out(vty, "| %s | <<%s_%s>> | %s%s",
+		desc->name,
+		ctrg->desc->group_name_prefix,
+		desc->name,
+		description,
+		VTY_NEWLINE);
+	return 0;
+}
+
+static int asciidoc_rate_ctr_group_handler(struct rate_ctr_group *ctrg, void *sctx_)
+{
+	struct vty *vty = sctx_;
+	vty_out(vty, "// rate_ctr_group table %s%s", ctrg->desc->group_description, VTY_NEWLINE);
+	vty_out(vty, ".%s - %s %s", ctrg->desc->group_name_prefix, ctrg->desc->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);
+
+	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_;
+
+	const char *description = item->desc->description ? item->desc->description : "";
+	const char *unit = item->desc->unit ? item->desc->unit : "";
+
+	/* | name | This document & | description | unit | */
+	vty_out(vty, "| %s | <<%s_%s>> | %s | %s%s",
+		item->desc->name,
+		statg->desc->group_name_prefix,
+		item->desc->name,
+		description,
+		unit,
+		VTY_NEWLINE);
+
+	return 0;
+}
+
+static int asciidoc_osmo_stat_item_group_handler(struct osmo_stat_item_group *statg, void *sctx_)
+{
+	struct vty *vty = sctx_;
+	vty_out(vty, "%s%s", statg->desc->group_description, VTY_NEWLINE);
+
+	vty_out(vty, "// osmo_stat_item_group table %s%s", statg->desc->group_description, VTY_NEWLINE);
+	vty_out(vty, ".%s - %s %s", statg->desc->group_name_prefix, statg->desc->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);
+
+
+	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);
+	ascii_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 +552,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);
 }