libosmocore
0.9.3
Osmocom core library
Main Page
Modules
Data Structures
Files
File List
Globals
rate_ctr.h
Go to the documentation of this file.
1
#pragma once
2
9
#include <stdint.h>
10
11
#include <osmocom/core/linuxlist.h>
12
14
#define RATE_CTR_INTV_NUM 4
15
17
enum
rate_ctr_intv
{
18
RATE_CTR_INTV_SEC
,
19
RATE_CTR_INTV_MIN
,
20
RATE_CTR_INTV_HOUR
,
21
RATE_CTR_INTV_DAY
,
22
};
23
25
struct
rate_ctr_per_intv
{
26
uint64_t
last
;
27
uint64_t
rate
;
28
};
29
31
struct
rate_ctr
{
32
uint64_t
current
;
33
uint64_t
previous
;
35
struct
rate_ctr_per_intv
intv
[
RATE_CTR_INTV_NUM
];
36
};
37
39
struct
rate_ctr_desc
{
40
const
char
*
name
;
41
const
char
*
description
;
42
};
43
45
struct
rate_ctr_group_desc
{
47
const
char
*
group_name_prefix
;
49
const
char
*
group_description
;
51
int
class_id
;
53
const
unsigned
int
num_ctr
;
55
const
struct
rate_ctr_desc
*
ctr_desc
;
56
};
57
59
struct
rate_ctr_group
{
61
struct
llist_head
list
;
63
const
struct
rate_ctr_group_desc
*
desc
;
65
unsigned
int
idx
;
67
struct
rate_ctr
ctr
[0];
68
};
69
70
struct
rate_ctr_group
*
rate_ctr_group_alloc
(
void
*ctx,
71
const
struct
rate_ctr_group_desc
*
desc
,
72
unsigned
int
idx
);
73
74
static
inline
void
rate_ctr_group_upd_idx(
struct
rate_ctr_group
*grp,
unsigned
int
idx
)
75
{
76
grp->
idx
=
idx
;
77
}
78
79
void
rate_ctr_group_free
(
struct
rate_ctr_group
*grp);
80
81
void
rate_ctr_add
(
struct
rate_ctr
*
ctr
,
int
inc);
82
84
static
inline
void
rate_ctr_inc
(
struct
rate_ctr
*
ctr
)
85
{
86
rate_ctr_add
(ctr, 1);
87
}
88
90
int64_t
rate_ctr_difference
(
struct
rate_ctr
*
ctr
);
91
92
int
rate_ctr_init
(
void
*tall_ctx);
93
94
struct
rate_ctr_group
*
rate_ctr_get_group_by_name_idx
(
const
char
*name,
const
unsigned
int
idx
);
95
const
struct
rate_ctr
*
rate_ctr_get_by_name
(
const
struct
rate_ctr_group
*ctrg,
const
char
*name);
96
97
typedef
int (*rate_ctr_handler_t)(
98
struct
rate_ctr_group
*,
struct
rate_ctr
*,
99
const
struct
rate_ctr_desc
*,
void
*);
100
typedef
int (*rate_ctr_group_handler_t)(
struct
rate_ctr_group
*,
void
*);
101
102
107
int
rate_ctr_for_each_counter
(
struct
rate_ctr_group
*ctrg,
108
rate_ctr_handler_t handle_counter,
void
*data);
109
110
int
rate_ctr_for_each_group(rate_ctr_group_handler_t handle_group,
void
*data);
111
include
osmocom
core
rate_ctr.h
Generated on Fri Nov 11 2016 15:56:41 for libosmocore by
1.8.1.2