blob: 9452b16e1505bbeacc99ccd8f03817933c5a8e3b [file] [log] [blame]
Harald Welteffa55a42009-12-22 19:07:32 +01001/* 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
34static LLIST_HEAD(counters);
35
Harald Welte026a6c32009-12-24 10:04:09 +010036void *tall_ctr_ctx;
37
Harald Welteffa55a42009-12-22 19:07:32 +010038struct counter *counter_alloc(const char *name)
39{
Harald Welte026a6c32009-12-24 10:04:09 +010040 struct counter *ctr = talloc_zero(tall_ctr_ctx, struct counter);
Harald Welteffa55a42009-12-22 19:07:32 +010041
42 if (!ctr)
43 return NULL;
44
45 ctr->name = name;
46 llist_add_tail(&ctr->list, &counters);
47
48 return ctr;
49}
50
51void counter_free(struct counter *ctr)
52{
53 llist_del(&ctr->list);
54 talloc_free(ctr);
55}
56
Holger Hans Peter Freyther079353a2009-12-23 05:29:04 +010057int counters_for_each(int (*handle_counter)(struct counter *, void *), void *data)
Harald Welteffa55a42009-12-22 19:07:32 +010058{
59 struct counter *ctr;
60 int rc = 0;
61
62 llist_for_each_entry(ctr, &counters, list) {
Holger Hans Peter Freyther079353a2009-12-23 05:29:04 +010063 rc = handle_counter(ctr, data);
Harald Welteffa55a42009-12-22 19:07:32 +010064 if (rc < 0)
65 return rc;
66 }
67
68 return rc;
69}
70