Harald Welte | bdbb744 | 2009-12-22 19:07:32 +0100 | [diff] [blame] | 1 | /* utility routines for keeping some statistics */ |
| 2 | |
| 3 | /* (C) 2009 by Harald Welte <laforge@gnumonks.org> |
| 4 | * |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along |
| 18 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | |
| 24 | #include <sys/types.h> |
| 25 | |
| 26 | #include <openbsc/gsm_data.h> |
| 27 | #include <openbsc/signal.h> |
| 28 | #include <openbsc/linuxlist.h> |
| 29 | #include <openbsc/talloc.h> |
| 30 | #include <openbsc/statistics.h> |
| 31 | #include <openbsc/db.h> |
| 32 | #include <openbsc/timer.h> |
| 33 | |
| 34 | static LLIST_HEAD(counters); |
| 35 | |
Harald Welte | 4d02dae | 2009-12-24 10:04:09 +0100 | [diff] [blame] | 36 | void *tall_ctr_ctx; |
| 37 | |
Harald Welte | bdbb744 | 2009-12-22 19:07:32 +0100 | [diff] [blame] | 38 | struct counter *counter_alloc(const char *name) |
| 39 | { |
Harald Welte | 4d02dae | 2009-12-24 10:04:09 +0100 | [diff] [blame] | 40 | struct counter *ctr = talloc_zero(tall_ctr_ctx, struct counter); |
Harald Welte | bdbb744 | 2009-12-22 19:07:32 +0100 | [diff] [blame] | 41 | |
| 42 | if (!ctr) |
| 43 | return NULL; |
| 44 | |
| 45 | ctr->name = name; |
| 46 | llist_add_tail(&ctr->list, &counters); |
| 47 | |
| 48 | return ctr; |
| 49 | } |
| 50 | |
| 51 | void counter_free(struct counter *ctr) |
| 52 | { |
| 53 | llist_del(&ctr->list); |
| 54 | talloc_free(ctr); |
| 55 | } |
| 56 | |
Holger Hans Peter Freyther | 76037f0 | 2009-12-23 05:29:04 +0100 | [diff] [blame] | 57 | int counters_for_each(int (*handle_counter)(struct counter *, void *), void *data) |
Harald Welte | bdbb744 | 2009-12-22 19:07:32 +0100 | [diff] [blame] | 58 | { |
| 59 | struct counter *ctr; |
| 60 | int rc = 0; |
| 61 | |
| 62 | llist_for_each_entry(ctr, &counters, list) { |
Holger Hans Peter Freyther | 76037f0 | 2009-12-23 05:29:04 +0100 | [diff] [blame] | 63 | rc = handle_counter(ctr, data); |
Harald Welte | bdbb744 | 2009-12-22 19:07:32 +0100 | [diff] [blame] | 64 | if (rc < 0) |
| 65 | return rc; |
| 66 | } |
| 67 | |
| 68 | return rc; |
| 69 | } |
| 70 | |