stats: Use a global index for stat item values
Currently each stat item has a separate index value which basically
counts each single value added to the item and which can be used by
a reporter to get all new values that have not been reported yet.
The drawback is, that such an index must be stored for each stat
item.
This commit introduces a global index which is incremented for each
new stat item value. This index is then stored together with the item
value. So a single stored index per reporter is sufficient to make
sure that only new values are reported.
Sponsored-by: On-Waves ehf
diff --git a/tests/stats/stats_test.c b/tests/stats/stats_test.c
index b414385..9da49a4 100644
--- a/tests/stats/stats_test.c
+++ b/tests/stats/stats_test.c
@@ -91,7 +91,7 @@
OSMO_ASSERT(value == 1);
rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value);
- OSMO_ASSERT(rc == 1);
+ OSMO_ASSERT(rc > 0);
OSMO_ASSERT(value == 1);
rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value);
@@ -102,11 +102,11 @@
stat_item_set(statg->items[TEST_B_ITEM], 1000 + i);
rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value);
- OSMO_ASSERT(rc == 1);
+ OSMO_ASSERT(rc > 0);
OSMO_ASSERT(value == i);
rc = stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value);
- OSMO_ASSERT(rc == 1);
+ OSMO_ASSERT(rc > 0);
OSMO_ASSERT(value == 1000 + i);
}
@@ -119,20 +119,20 @@
stat_item_set(statg->items[TEST_B_ITEM], 1000 + i);
rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value);
- OSMO_ASSERT(rc == 1);
+ OSMO_ASSERT(rc > 0);
OSMO_ASSERT(value == i-1);
rc = stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value);
- OSMO_ASSERT(rc == 1);
+ OSMO_ASSERT(rc > 0);
OSMO_ASSERT(value == 1000 + i-1);
}
rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value);
- OSMO_ASSERT(rc == 1);
+ OSMO_ASSERT(rc > 0);
OSMO_ASSERT(value == 64);
rc = stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value);
- OSMO_ASSERT(rc == 1);
+ OSMO_ASSERT(rc > 0);
OSMO_ASSERT(value == 1000 + 64);
/* Overrun FIFOs */
@@ -142,29 +142,29 @@
}
rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value);
- OSMO_ASSERT(rc == 93 - 65 + 1);
+ OSMO_ASSERT(rc > 0);
OSMO_ASSERT(value == 93);
for (i = 94; i <= 96; i++) {
rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value);
- OSMO_ASSERT(rc == 1);
+ OSMO_ASSERT(rc > 0);
OSMO_ASSERT(value == i);
}
rc = stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value);
- OSMO_ASSERT(rc == 90 - 65 + 1);
+ OSMO_ASSERT(rc > 0);
OSMO_ASSERT(value == 1000 + 90);
for (i = 91; i <= 96; i++) {
rc = stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value);
- OSMO_ASSERT(rc == 1);
+ OSMO_ASSERT(rc > 0);
OSMO_ASSERT(value == 1000 + i);
}
- /* Test Discard */
+ /* Test Discard (single item) */
stat_item_set(statg->items[TEST_A_ITEM], 97);
rc = stat_item_discard(statg->items[TEST_A_ITEM], &rd_a);
- OSMO_ASSERT(rc == 1);
+ OSMO_ASSERT(rc > 0);
rc = stat_item_discard(statg->items[TEST_A_ITEM], &rd_a);
OSMO_ASSERT(rc == 0);
@@ -174,12 +174,27 @@
stat_item_set(statg->items[TEST_A_ITEM], 98);
rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value);
- OSMO_ASSERT(rc == 1);
+ OSMO_ASSERT(rc > 0);
OSMO_ASSERT(value == 98);
rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value);
OSMO_ASSERT(rc == 0);
+ /* Test Discard (all items) */
+ stat_item_set(statg->items[TEST_A_ITEM], 99);
+ stat_item_set(statg->items[TEST_A_ITEM], 100);
+ stat_item_set(statg->items[TEST_A_ITEM], 101);
+ stat_item_set(statg->items[TEST_B_ITEM], 99);
+ stat_item_set(statg->items[TEST_B_ITEM], 100);
+
+ rc = stat_item_discard_all(&rd_a);
+ rc = stat_item_discard_all(&rd_b);
+
+ rc = stat_item_get_next(statg->items[TEST_A_ITEM], &rd_a, &value);
+ OSMO_ASSERT(rc == 0);
+ rc = stat_item_get_next(statg->items[TEST_B_ITEM], &rd_b, &value);
+ OSMO_ASSERT(rc == 0);
+
stat_item_group_free(statg);
sgrp2 = stat_item_get_group_by_name_idx("test.one", 0);