~arges/ubuntu/quantal/rsyslog/fix-lp1059592

« back to all changes in this revision

Viewing changes to runtime/statsobj.h

Tags: 5.7.3-1
* New upstream release.
* Upload to unstable.
* debian/patches/02-typo_fix_equation_sign.patch
  - Removed, merged upstream.
* debian/patches/03-atomic_operations.patch
  - Removed, merged upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* The statsobj object.
 
2
 *
 
3
 * Copyright 2010 Rainer Gerhards and Adiscon GmbH.
 
4
 *
 
5
 * This file is part of the rsyslog runtime library.
 
6
 *
 
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.
 
11
 *
 
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.
 
16
 *
 
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/>.
 
19
 *
 
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.
 
22
 */
 
23
#ifndef INCLUDED_STATSOBJ_H
 
24
#define INCLUDED_STATSOBJ_H
 
25
 
 
26
#include "atomic.h"
 
27
 
 
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.
 
34
 */
 
35
extern int GatherStats;
 
36
 
 
37
/* our basic counter type -- need 32 bit on 32 bit platform. 
 
38
 * IMPORTANT: this type *MUST* be supported by atomic instructions!
 
39
 */
 
40
typedef uint64 intctr_t;
 
41
 
 
42
/* counter types */
 
43
typedef enum statsCtrType_e {
 
44
        ctrType_IntCtr,
 
45
        ctrType_Int
 
46
} statsCtrType_t;
 
47
 
 
48
 
 
49
/* helper entity, the counter */
 
50
typedef struct ctr_s {
 
51
        uchar *name;
 
52
        statsCtrType_t ctrType;
 
53
        union {
 
54
                intctr_t *pIntCtr;
 
55
                int *pInt;
 
56
        } val;
 
57
        struct ctr_s *next, *prev;
 
58
} ctr_t;
 
59
 
 
60
/* the statsobj object */
 
61
struct statsobj_s {
 
62
        BEGINobjInstance;               /* Data to implement generic object - MUST be the first data element! */
 
63
        uchar *name;
 
64
        pthread_mutex_t mutCtr;         /* to guard counter linked-list ops */
 
65
        ctr_t *ctrRoot;                 /* doubly-linked list of statsobj counters */
 
66
        ctr_t *ctrLast;
 
67
        /* used to link ourselves together */
 
68
        statsobj_t *prev;
 
69
        statsobj_t *next;
 
70
};
 
71
 
 
72
 
 
73
/* interfaces */
 
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! */
 
86
 
 
87
 
 
88
/* prototypes */
 
89
PROTOTYPEObj(statsobj);
 
90
 
 
91
 
 
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...).
 
99
 */
 
100
#define STATSCOUNTER_DEF(ctr, mut) \
 
101
        intctr_t ctr; \
 
102
        DEF_ATOMIC_HELPER_MUT64(mut);
 
103
 
 
104
#define STATSCOUNTER_INIT(ctr, mut) \
 
105
        INIT_ATOMIC_HELPER_MUT64(mut); \
 
106
        ctr = 0;
 
107
 
 
108
#define STATSCOUNTER_INC(ctr, mut) \
 
109
        if(GatherStats) \
 
110
                ATOMIC_INC_uint64(&ctr, &mut);
 
111
 
 
112
#define STATSCOUNTER_DEC(ctr, mut) \
 
113
        if(GatherStats) \
 
114
                ATOMIC_DEC_uint64(&ctr, mut);
 
115
 
 
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.
 
119
 */
 
120
#define STATSCOUNTER_SETMAX_NOMUT(ctr, newmax) \
 
121
        if(GatherStats && ((newmax) > (ctr))) \
 
122
                ctr = newmax;
 
123
 
 
124
#endif /* #ifndef INCLUDED_STATSOBJ_H */