Change in libosmocore[master]: stat, rate_ctr: Introduce new API to get counter at given index

pespin gerrit-no-reply at lists.osmocom.org
Tue Jun 1 21:06:55 UTC 2021


pespin has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/24469 )

Change subject: stat,rate_ctr: Introduce new API to get counter at given index
......................................................................

stat,rate_ctr: Introduce new API to get counter at given index

Having this API and forcing apps to use it will allow easily adding new
members to the group structure without having so much impact in users of
this struct.

Related: SYS#5456
Change-Id: Iebbf401f11e36645f8964d389460918eb9e0910e
---
M include/osmocom/core/rate_ctr.h
M include/osmocom/core/stat_item.h
M src/rate_ctr.c
M src/stat_item.c
4 files changed, 25 insertions(+), 3 deletions(-)

Approvals:
  laforge: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/include/osmocom/core/rate_ctr.h b/include/osmocom/core/rate_ctr.h
index 1669ce4..17ee672 100644
--- a/include/osmocom/core/rate_ctr.h
+++ b/include/osmocom/core/rate_ctr.h
@@ -61,7 +61,7 @@
 	const struct rate_ctr_group_desc *desc;
 	/*! The index of this ctr_group within its class */
 	unsigned int idx;
-	/*! Actual counter structures below */
+	/*! Actual counter structures below. Don't access it directly, use APIs below! */
 	struct rate_ctr ctr[0];
 };
 
@@ -74,6 +74,8 @@
 	grp->idx = idx;
 }
 
+struct rate_ctr *rate_ctr_group_get_ctr(struct rate_ctr_group *grp, unsigned int idx);
+
 void rate_ctr_group_free(struct rate_ctr_group *grp);
 
 /*! Increment the counter by \a inc
@@ -93,7 +95,7 @@
  *  \param idx index into \a ctrg counter group */
 static inline void rate_ctr_inc2(struct rate_ctr_group *ctrg, unsigned int idx)
 {
-	rate_ctr_inc(&ctrg->ctr[idx]);
+	rate_ctr_inc(rate_ctr_group_get_ctr(ctrg, idx));
 }
 
 
diff --git a/include/osmocom/core/stat_item.h b/include/osmocom/core/stat_item.h
index 29e35ef..3cace08 100644
--- a/include/osmocom/core/stat_item.h
+++ b/include/osmocom/core/stat_item.h
@@ -79,7 +79,7 @@
 {
 	grp->idx = idx;
 }
-
+struct osmo_stat_item *osmo_stat_item_group_get_item(struct osmo_stat_item_group *grp, unsigned int idx);
 void osmo_stat_item_group_free(struct osmo_stat_item_group *statg);
 
 void osmo_stat_item_inc(struct osmo_stat_item *item, int32_t value);
diff --git a/src/rate_ctr.c b/src/rate_ctr.c
index 9043a2c..c3a5286 100644
--- a/src/rate_ctr.c
+++ b/src/rate_ctr.c
@@ -263,6 +263,16 @@
 	talloc_free(grp);
 }
 
+/*! Get rate counter from group, identified by index idx
+ *  \param[in] grp Rate counter group
+ *  \param[in] idx Index of the counter to retrieve
+ *  \returns rate counter requested
+ */
+struct rate_ctr *rate_ctr_group_get_ctr(struct rate_ctr_group *grp, unsigned int idx)
+{
+	return &grp->ctr[idx];
+}
+
 /*! Add a number to the counter */
 void rate_ctr_add(struct rate_ctr *ctr, int inc)
 {
diff --git a/src/stat_item.c b/src/stat_item.c
index 40374a7..a6f86cb 100644
--- a/src/stat_item.c
+++ b/src/stat_item.c
@@ -167,6 +167,16 @@
 	talloc_free(grp);
 }
 
+/*! Get statistics item from group, identified by index idx
+ *  \param[in] grp Rate counter group
+ *  \param[in] idx Index of the counter to retrieve
+ *  \returns rate counter requested
+ */
+struct osmo_stat_item *osmo_stat_item_group_get_item(struct osmo_stat_item_group *grp, unsigned int idx)
+{
+	return grp->items[idx];
+}
+
 /*! Increase the stat_item to the given value.
  *  This function adds a new value for the given stat_item at the end of
  *  the FIFO.

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/24469
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Iebbf401f11e36645f8964d389460918eb9e0910e
Gerrit-Change-Number: 24469
Gerrit-PatchSet: 3
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy at sysmocom.de>
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: osmith <osmith at sysmocom.de>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210601/c0a9791a/attachment.htm>


More information about the gerrit-log mailing list