Harald Welte | ffa55a4 | 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 | ffa55a4 | 2009-12-22 19:07:32 +0100 | [diff] [blame] | 36 | struct counter *counter_alloc(const char *name) |
| 37 | { |
| 38 | struct counter *ctr = talloc_zero(tall_bsc_ctx, struct counter); |
| 39 | |
| 40 | if (!ctr) |
| 41 | return NULL; |
| 42 | |
| 43 | ctr->name = name; |
| 44 | llist_add_tail(&ctr->list, &counters); |
| 45 | |
| 46 | return ctr; |
| 47 | } |
| 48 | |
| 49 | void counter_free(struct counter *ctr) |
| 50 | { |
| 51 | llist_del(&ctr->list); |
| 52 | talloc_free(ctr); |
| 53 | } |
| 54 | |
Holger Hans Peter Freyther | 079353a | 2009-12-23 05:29:04 +0100 | [diff] [blame^] | 55 | int counters_for_each(int (*handle_counter)(struct counter *, void *), void *data) |
Harald Welte | ffa55a4 | 2009-12-22 19:07:32 +0100 | [diff] [blame] | 56 | { |
| 57 | struct counter *ctr; |
| 58 | int rc = 0; |
| 59 | |
| 60 | llist_for_each_entry(ctr, &counters, list) { |
Holger Hans Peter Freyther | 079353a | 2009-12-23 05:29:04 +0100 | [diff] [blame^] | 61 | rc = handle_counter(ctr, data); |
Harald Welte | ffa55a4 | 2009-12-22 19:07:32 +0100 | [diff] [blame] | 62 | if (rc < 0) |
| 63 | return rc; |
| 64 | } |
| 65 | |
| 66 | return rc; |
| 67 | } |
| 68 | |