Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 1 | /*! \file stat_item.c |
Harald Welte | 781951b | 2017-10-15 19:24:57 +0200 | [diff] [blame] | 2 | * utility routines for keeping statistical values */ |
Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 3 | /* |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 4 | * (C) 2009-2010 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | e08da97 | 2017-11-13 01:00:26 +0900 | [diff] [blame] | 5 | * (C) 2015 by sysmocom - s.f.m.c. GmbH |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 6 | * |
| 7 | * All Rights Reserved |
| 8 | * |
Harald Welte | e08da97 | 2017-11-13 01:00:26 +0900 | [diff] [blame] | 9 | * SPDX-License-Identifier: GPL-2.0+ |
| 10 | * |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License along |
| 22 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 23 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 24 | * |
| 25 | */ |
| 26 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 27 | /*! \addtogroup osmo_stat_item |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 28 | * @{ |
Harald Welte | 781951b | 2017-10-15 19:24:57 +0200 | [diff] [blame] | 29 | * |
| 30 | * This osmo_stat_item module adds instrumentation capabilities to |
| 31 | * gather measurement and statistical values in a similar fashion to |
| 32 | * what we have as \ref osmo_counter_group. |
| 33 | * |
| 34 | * As opposed to counters, osmo_stat_item do not increment but consist |
| 35 | * of a configurable-sized FIFO, which can store not only the current |
| 36 | * (most recent) value, but also historic values. |
| 37 | * |
| 38 | * The only supported value type is an int32_t. |
| 39 | * |
| 40 | * Getting values from the osmo_stat_item does not modify its state to |
| 41 | * allow for multiple independent back-ends retrieving values (e.g. VTY |
| 42 | * and statd). |
| 43 | * |
| 44 | * Each value stored in the FIFO of an osmo_stat_item has an associated |
| 45 | * value_id. The value_id is derived from an application-wide globally |
| 46 | * incrementing counter, so (until the counter wraps) more recent |
| 47 | * values will have higher values. |
| 48 | * |
| 49 | * When a new value is set, the oldest value in the FIFO gets silently |
| 50 | * overwritten. Lost values are skipped when getting values from the |
| 51 | * item. |
| 52 | * |
| 53 | */ |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 54 | |
| 55 | #include <stdint.h> |
| 56 | #include <string.h> |
| 57 | |
| 58 | #include <osmocom/core/utils.h> |
| 59 | #include <osmocom/core/linuxlist.h> |
| 60 | #include <osmocom/core/talloc.h> |
| 61 | #include <osmocom/core/timer.h> |
| 62 | #include <osmocom/core/stat_item.h> |
| 63 | |
Harald Welte | 781951b | 2017-10-15 19:24:57 +0200 | [diff] [blame] | 64 | /*! global list of stat_item groups */ |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 65 | static LLIST_HEAD(osmo_stat_item_groups); |
Harald Welte | 781951b | 2017-10-15 19:24:57 +0200 | [diff] [blame] | 66 | /*! counter for assigning globally unique value identifiers */ |
Jacob Erlbeck | b27b352 | 2015-10-12 18:47:09 +0200 | [diff] [blame] | 67 | static int32_t global_value_id = 0; |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 68 | |
Harald Welte | 781951b | 2017-10-15 19:24:57 +0200 | [diff] [blame] | 69 | /*! talloc context from which we allocate */ |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 70 | static void *tall_stat_item_ctx; |
| 71 | |
Harald Welte | 781951b | 2017-10-15 19:24:57 +0200 | [diff] [blame] | 72 | /*! Allocate a new group of counters according to description. |
| 73 | * Allocate a group of stat items described in \a desc from talloc context \a ctx, |
| 74 | * giving the new group the index \a idx. |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 75 | * \param[in] ctx \ref talloc context |
| 76 | * \param[in] desc Statistics item group description |
| 77 | * \param[in] idx Index of new stat item group |
| 78 | */ |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 79 | struct osmo_stat_item_group *osmo_stat_item_group_alloc(void *ctx, |
| 80 | const struct osmo_stat_item_group_desc *desc, |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 81 | unsigned int idx) |
| 82 | { |
| 83 | unsigned int group_size; |
Harald Welte | b32a194 | 2015-11-20 10:22:14 +0100 | [diff] [blame] | 84 | unsigned long items_size = 0; |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 85 | unsigned int item_idx; |
| 86 | void *items; |
| 87 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 88 | struct osmo_stat_item_group *group; |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 89 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 90 | group_size = sizeof(struct osmo_stat_item_group) + |
| 91 | desc->num_items * sizeof(struct osmo_stat_item *); |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 92 | |
| 93 | if (!ctx) |
| 94 | ctx = tall_stat_item_ctx; |
| 95 | |
| 96 | group = talloc_zero_size(ctx, group_size); |
| 97 | if (!group) |
| 98 | return NULL; |
| 99 | |
| 100 | group->desc = desc; |
| 101 | group->idx = idx; |
| 102 | |
| 103 | /* Get combined size of all items */ |
| 104 | for (item_idx = 0; item_idx < desc->num_items; item_idx++) { |
| 105 | unsigned int size; |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 106 | size = sizeof(struct osmo_stat_item) + |
| 107 | sizeof(struct osmo_stat_item_value) * |
Jacob Erlbeck | b27b352 | 2015-10-12 18:47:09 +0200 | [diff] [blame] | 108 | desc->item_desc[item_idx].num_values; |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 109 | /* Align to pointer size */ |
| 110 | size = (size + sizeof(void *) - 1) & ~(sizeof(void *) - 1); |
| 111 | |
| 112 | /* Store offsets into the item array */ |
| 113 | group->items[item_idx] = (void *)items_size; |
| 114 | |
| 115 | items_size += size; |
| 116 | } |
| 117 | |
| 118 | items = talloc_zero_size(group, items_size); |
| 119 | if (!items) { |
| 120 | talloc_free(group); |
| 121 | return NULL; |
| 122 | } |
| 123 | |
| 124 | /* Update item pointers */ |
| 125 | for (item_idx = 0; item_idx < desc->num_items; item_idx++) { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 126 | struct osmo_stat_item *item = (struct osmo_stat_item *) |
Harald Welte | b32a194 | 2015-11-20 10:22:14 +0100 | [diff] [blame] | 127 | ((uint8_t *)items + (unsigned long)group->items[item_idx]); |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 128 | unsigned int i; |
| 129 | |
| 130 | group->items[item_idx] = item; |
| 131 | item->last_offs = desc->item_desc[item_idx].num_values - 1; |
| 132 | item->last_value_index = -1; |
| 133 | item->desc = &desc->item_desc[item_idx]; |
| 134 | |
Jacob Erlbeck | b27b352 | 2015-10-12 18:47:09 +0200 | [diff] [blame] | 135 | for (i = 0; i <= item->last_offs; i++) { |
| 136 | item->values[i].value = desc->item_desc[item_idx].default_value; |
Jacob Erlbeck | ac4ed17 | 2015-12-08 10:29:16 +0100 | [diff] [blame] | 137 | item->values[i].id = OSMO_STAT_ITEM_NOVALUE_ID; |
Jacob Erlbeck | b27b352 | 2015-10-12 18:47:09 +0200 | [diff] [blame] | 138 | } |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 139 | } |
| 140 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 141 | llist_add(&group->list, &osmo_stat_item_groups); |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 142 | |
| 143 | return group; |
| 144 | } |
| 145 | |
Harald Welte | 781951b | 2017-10-15 19:24:57 +0200 | [diff] [blame] | 146 | /*! Free the memory for the specified group of stat items */ |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 147 | void osmo_stat_item_group_free(struct osmo_stat_item_group *grp) |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 148 | { |
| 149 | llist_del(&grp->list); |
| 150 | talloc_free(grp); |
| 151 | } |
| 152 | |
Harald Welte | 781951b | 2017-10-15 19:24:57 +0200 | [diff] [blame] | 153 | /*! Set the a given stat_item to the given value. |
| 154 | * This function adds a new value for the given stat_item at the end of |
| 155 | * the FIFO. |
| 156 | * \param[in] item The stat_item whose \a value we want to set |
| 157 | * \param[in] value The numeric value we want to store at end of FIFO |
| 158 | */ |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 159 | void osmo_stat_item_set(struct osmo_stat_item *item, int32_t value) |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 160 | { |
| 161 | item->last_offs += 1; |
| 162 | if (item->last_offs >= item->desc->num_values) |
| 163 | item->last_offs = 0; |
| 164 | |
Jacob Erlbeck | b27b352 | 2015-10-12 18:47:09 +0200 | [diff] [blame] | 165 | global_value_id += 1; |
Jacob Erlbeck | ac4ed17 | 2015-12-08 10:29:16 +0100 | [diff] [blame] | 166 | if (global_value_id == OSMO_STAT_ITEM_NOVALUE_ID) |
Jacob Erlbeck | b27b352 | 2015-10-12 18:47:09 +0200 | [diff] [blame] | 167 | global_value_id += 1; |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 168 | |
Jacob Erlbeck | b27b352 | 2015-10-12 18:47:09 +0200 | [diff] [blame] | 169 | item->values[item->last_offs].value = value; |
| 170 | item->values[item->last_offs].id = global_value_id; |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 171 | } |
| 172 | |
Harald Welte | 781951b | 2017-10-15 19:24:57 +0200 | [diff] [blame] | 173 | /*! Retrieve the next value from the osmo_stat_item object. |
| 174 | * If a new value has been set, it is returned. The idx is used to decide |
| 175 | * which value to return. |
| 176 | * On success, *idx is updated to refer to the next unread value. If |
| 177 | * values have been missed due to FIFO overflow, *idx is incremented by |
| 178 | * (1 + num_lost). |
| 179 | * This way, the osmo_stat_item object can be kept stateless from the reader's |
| 180 | * perspective and therefore be used by several backends simultaneously. |
| 181 | * |
| 182 | * \param val the osmo_stat_item object |
| 183 | * \param idx identifies the next value to be read |
| 184 | * \param value a pointer to store the value |
| 185 | * \returns the increment of the index (0: no value has been read, |
| 186 | * 1: one value has been taken, |
| 187 | * (1+n): n values have been skipped, one has been taken) |
| 188 | */ |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 189 | int osmo_stat_item_get_next(const struct osmo_stat_item *item, int32_t *next_idx, |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 190 | int32_t *value) |
| 191 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 192 | const struct osmo_stat_item_value *next_value; |
| 193 | const struct osmo_stat_item_value *item_value = NULL; |
Jacob Erlbeck | b27b352 | 2015-10-12 18:47:09 +0200 | [diff] [blame] | 194 | int idx_delta; |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 195 | int next_offs; |
| 196 | |
Jacob Erlbeck | b27b352 | 2015-10-12 18:47:09 +0200 | [diff] [blame] | 197 | next_offs = item->last_offs; |
| 198 | next_value = &item->values[next_offs]; |
| 199 | |
| 200 | while (next_value->id - *next_idx >= 0 && |
Jacob Erlbeck | ac4ed17 | 2015-12-08 10:29:16 +0100 | [diff] [blame] | 201 | next_value->id != OSMO_STAT_ITEM_NOVALUE_ID) |
Jacob Erlbeck | b27b352 | 2015-10-12 18:47:09 +0200 | [diff] [blame] | 202 | { |
| 203 | item_value = next_value; |
| 204 | |
| 205 | next_offs -= 1; |
| 206 | if (next_offs < 0) |
| 207 | next_offs = item->desc->num_values - 1; |
| 208 | if (next_offs == item->last_offs) |
| 209 | break; |
| 210 | next_value = &item->values[next_offs]; |
| 211 | } |
| 212 | |
| 213 | if (!item_value) |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 214 | /* All items have been read */ |
| 215 | return 0; |
| 216 | |
Jacob Erlbeck | b27b352 | 2015-10-12 18:47:09 +0200 | [diff] [blame] | 217 | *value = item_value->value; |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 218 | |
Jacob Erlbeck | b27b352 | 2015-10-12 18:47:09 +0200 | [diff] [blame] | 219 | idx_delta = item_value->id + 1 - *next_idx; |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 220 | |
Jacob Erlbeck | b27b352 | 2015-10-12 18:47:09 +0200 | [diff] [blame] | 221 | *next_idx = item_value->id + 1; |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 222 | |
Jacob Erlbeck | b27b352 | 2015-10-12 18:47:09 +0200 | [diff] [blame] | 223 | return idx_delta; |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 224 | } |
| 225 | |
Harald Welte | 781951b | 2017-10-15 19:24:57 +0200 | [diff] [blame] | 226 | /*! Skip/discard all values of this item and update \a idx accordingly */ |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 227 | int osmo_stat_item_discard(const struct osmo_stat_item *item, int32_t *idx) |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 228 | { |
Jacob Erlbeck | b27b352 | 2015-10-12 18:47:09 +0200 | [diff] [blame] | 229 | int discarded = item->values[item->last_offs].id + 1 - *idx; |
| 230 | *idx = item->values[item->last_offs].id + 1; |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 231 | |
| 232 | return discarded; |
| 233 | } |
| 234 | |
Harald Welte | 781951b | 2017-10-15 19:24:57 +0200 | [diff] [blame] | 235 | /*! Skip all values of all items and update \a idx accordingly */ |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 236 | int osmo_stat_item_discard_all(int32_t *idx) |
Jacob Erlbeck | b27b352 | 2015-10-12 18:47:09 +0200 | [diff] [blame] | 237 | { |
| 238 | int discarded = global_value_id + 1 - *idx; |
| 239 | *idx = global_value_id + 1; |
| 240 | |
| 241 | return discarded; |
| 242 | } |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 243 | |
Harald Welte | 781951b | 2017-10-15 19:24:57 +0200 | [diff] [blame] | 244 | /*! Initialize the stat item module. Call this once from your program. |
| 245 | * \param[in] tall_ctx Talloc context from which this module allocates */ |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 246 | int osmo_stat_item_init(void *tall_ctx) |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 247 | { |
| 248 | tall_stat_item_ctx = tall_ctx; |
| 249 | |
| 250 | return 0; |
| 251 | } |
| 252 | |
Harald Welte | 781951b | 2017-10-15 19:24:57 +0200 | [diff] [blame] | 253 | /*! Search for item group based on group name and index |
| 254 | * \param[in] name Name of stats_item_group we want to find |
| 255 | * \param[in] idx Index of the group we want to find |
| 256 | * \returns pointer to group, if found; NULL otherwise */ |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 257 | struct osmo_stat_item_group *osmo_stat_item_get_group_by_name_idx( |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 258 | const char *name, const unsigned int idx) |
| 259 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 260 | struct osmo_stat_item_group *statg; |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 261 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 262 | llist_for_each_entry(statg, &osmo_stat_item_groups, list) { |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 263 | if (!statg->desc) |
| 264 | continue; |
| 265 | |
| 266 | if (!strcmp(statg->desc->group_name_prefix, name) && |
| 267 | statg->idx == idx) |
| 268 | return statg; |
| 269 | } |
| 270 | return NULL; |
| 271 | } |
| 272 | |
Harald Welte | 781951b | 2017-10-15 19:24:57 +0200 | [diff] [blame] | 273 | /*! Search for item based on group + item name |
| 274 | * \param[in] statg group in which to search for the item |
| 275 | * \param[in] name name of item to search within \a statg |
| 276 | * \returns pointer to item, if found; NULL otherwise */ |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 277 | const struct osmo_stat_item *osmo_stat_item_get_by_name( |
| 278 | const struct osmo_stat_item_group *statg, const char *name) |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 279 | { |
| 280 | int i; |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 281 | const struct osmo_stat_item_desc *item_desc; |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 282 | |
| 283 | if (!statg->desc) |
| 284 | return NULL; |
| 285 | |
| 286 | for (i = 0; i < statg->desc->num_items; i++) { |
| 287 | item_desc = &statg->desc->item_desc[i]; |
| 288 | |
| 289 | if (!strcmp(item_desc->name, name)) { |
| 290 | return statg->items[i]; |
| 291 | } |
| 292 | } |
| 293 | return NULL; |
| 294 | } |
| 295 | |
Harald Welte | 781951b | 2017-10-15 19:24:57 +0200 | [diff] [blame] | 296 | /*! Iterate over all items in group, call user-supplied function on each |
| 297 | * \param[in] statg stat_item group over whose items to iterate |
| 298 | * \param[in] handle_item Call-back function, aborts if rc < 0 |
| 299 | * \param[in] data Private data handed through to \a handle_item |
| 300 | */ |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 301 | int osmo_stat_item_for_each_item(struct osmo_stat_item_group *statg, |
| 302 | osmo_stat_item_handler_t handle_item, void *data) |
Jacob Erlbeck | c6a7108 | 2015-10-19 14:04:38 +0200 | [diff] [blame] | 303 | { |
| 304 | int rc = 0; |
| 305 | int i; |
| 306 | |
| 307 | for (i = 0; i < statg->desc->num_items; i++) { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 308 | struct osmo_stat_item *item = statg->items[i]; |
Jacob Erlbeck | c6a7108 | 2015-10-19 14:04:38 +0200 | [diff] [blame] | 309 | rc = handle_item(statg, item, data); |
| 310 | if (rc < 0) |
| 311 | return rc; |
| 312 | } |
| 313 | |
| 314 | return rc; |
| 315 | } |
| 316 | |
Harald Welte | 781951b | 2017-10-15 19:24:57 +0200 | [diff] [blame] | 317 | /*! Iterate over all stat_item groups in system, call user-supplied function on each |
| 318 | * \param[in] handle_group Call-back function, aborts if rc < 0 |
| 319 | * \param[in] data Private data handed through to \a handle_group |
| 320 | */ |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 321 | int osmo_stat_item_for_each_group(osmo_stat_item_group_handler_t handle_group, void *data) |
Jacob Erlbeck | c6a7108 | 2015-10-19 14:04:38 +0200 | [diff] [blame] | 322 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 323 | struct osmo_stat_item_group *statg; |
Jacob Erlbeck | c6a7108 | 2015-10-19 14:04:38 +0200 | [diff] [blame] | 324 | int rc = 0; |
| 325 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 326 | llist_for_each_entry(statg, &osmo_stat_item_groups, list) { |
Jacob Erlbeck | c6a7108 | 2015-10-19 14:04:38 +0200 | [diff] [blame] | 327 | rc = handle_group(statg, data); |
| 328 | if (rc < 0) |
| 329 | return rc; |
| 330 | } |
| 331 | |
| 332 | return rc; |
| 333 | } |
| 334 | |
Jacob Erlbeck | 9732cb4 | 2015-10-01 20:43:53 +0200 | [diff] [blame] | 335 | /*! @} */ |