1
/* The statsobj object.
3
* Copyright 2010 Rainer Gerhards and Adiscon GmbH.
5
* This file is part of the rsyslog runtime library.
7
* The rsyslog runtime library is free software: you can redistribute it and/or modify
8
* it under the terms of the GNU Lesser General Public License as published by
9
* the Free Software Foundation, either version 3 of the License, or
10
* (at your option) any later version.
12
* The rsyslog runtime library 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 Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public License
18
* along with the rsyslog runtime library. If not, see <http://www.gnu.org/licenses/>.
20
* A copy of the GPL can be found in the file "COPYING" in this distribution.
21
* A copy of the LGPL can be found in the file "COPYING.LESSER" in this distribution.
23
#ifndef INCLUDED_STATSOBJ_H
24
#define INCLUDED_STATSOBJ_H
28
/* The following data item is somewhat dirty, in that it does not follow
29
* our usual object calling conventions. However, much like with "Debug", we
30
* do this to gain speed. If we finally come to a platform that does not
31
* provide resolution of names for dynamically loaded modules, we need to find
32
* a work-around, but until then, we use the direct access.
33
* If set to 0, statistics are not gathered, otherwise they are.
35
extern int GatherStats;
37
/* our basic counter type -- need 32 bit on 32 bit platform.
38
* IMPORTANT: this type *MUST* be supported by atomic instructions!
40
typedef uint64 intctr_t;
43
typedef enum statsCtrType_e {
49
/* helper entity, the counter */
50
typedef struct ctr_s {
52
statsCtrType_t ctrType;
57
struct ctr_s *next, *prev;
60
/* the statsobj object */
62
BEGINobjInstance; /* Data to implement generic object - MUST be the first data element! */
64
pthread_mutex_t mutCtr; /* to guard counter linked-list ops */
65
ctr_t *ctrRoot; /* doubly-linked list of statsobj counters */
67
/* used to link ourselves together */
74
BEGINinterface(statsobj) /* name must also be changed in ENDinterface macro! */
75
INTERFACEObjDebugPrint(statsobj);
76
rsRetVal (*Construct)(statsobj_t **ppThis);
77
rsRetVal (*ConstructFinalize)(statsobj_t *pThis);
78
rsRetVal (*Destruct)(statsobj_t **ppThis);
79
rsRetVal (*SetName)(statsobj_t *pThis, uchar *name);
80
rsRetVal (*GetStatsLine)(statsobj_t *pThis, cstr_t **ppcstr);
81
rsRetVal (*GetAllStatsLines)(rsRetVal(*cb)(void*, cstr_t*), void *usrptr);
82
rsRetVal (*AddCounter)(statsobj_t *pThis, uchar *ctrName, statsCtrType_t ctrType, void *pCtr);
83
rsRetVal (*EnableStats)(void);
84
ENDinterface(statsobj)
85
#define statsobjCURR_IF_VERSION 1 /* increment whenever you change the interface structure! */
89
PROTOTYPEObj(statsobj);
92
/* macros to handle stats counters
93
* These are to be used by "counter providers". Note that we MUST
94
* specify the mutex name, even though at first it looks like it
95
* could be automatically be generated via e.g. "mut##ctr".
96
* Unfortunately, this does not work if counter is e.g. "pThis->ctr".
97
* So we decided, for clarity, to always insist on specifying the mutex
98
* name (after all, it's just a few more keystrokes...).
100
#define STATSCOUNTER_DEF(ctr, mut) \
102
DEF_ATOMIC_HELPER_MUT64(mut);
104
#define STATSCOUNTER_INIT(ctr, mut) \
105
INIT_ATOMIC_HELPER_MUT64(mut); \
108
#define STATSCOUNTER_INC(ctr, mut) \
110
ATOMIC_INC_uint64(&ctr, &mut);
112
#define STATSCOUNTER_DEC(ctr, mut) \
114
ATOMIC_DEC_uint64(&ctr, mut);
116
/* the next macro works only if the variable is already guarded
117
* by mutex (or the users risks a wrong result). It is assumed
118
* that there are not concurrent operations that modify the counter.
120
#define STATSCOUNTER_SETMAX_NOMUT(ctr, newmax) \
121
if(GatherStats && ((newmax) > (ctr))) \
124
#endif /* #ifndef INCLUDED_STATSOBJ_H */