libosmocore
1.6.0
Osmocom core library
|
Go to the source code of this file.
Routines for helping with the osmocom application setup.
◆ osmo_daemonize()
int osmo_daemonize |
( |
void |
| ) |
|
Turn the current process into a background daemon.
This function will fork the process, exit the parent and set umask, create a new session, close stdin/stdout/stderr and chdir to /tmp
References pid.
◆ osmo_init_ignore_signals()
void osmo_init_ignore_signals |
( |
void |
| ) |
|
Ignore SIGPIPE, SIGALRM, SIGHUP and SIGIO.
References sighup_hdlr().
◆ osmo_init_logging()
int osmo_init_logging |
( |
const struct log_info * |
log_info | ) |
|
Initialize the osmocom logging framework.
- Parameters
-
[in] | log_info | Array of available logging sub-systems |
- Returns
- 0 on success, -1 in case of error
This function initializes the osmocom logging systems. It also creates the default (stderr) logging target.
References osmo_init_logging2().
◆ osmo_init_logging2()
int osmo_init_logging2 |
( |
void * |
ctx, |
|
|
const struct log_info * |
log_info |
|
) |
| |
◆ osmo_stderr_target
unsigned int have_net_config
Definition: stats.h:67
int osmo_gettimeofday(struct timeval *tv, struct timezone *tz)
shim around gettimeofday to be able to set the time manually.
Definition: timer_gettimeofday.c:60
char ** buffer
storage for messages
Definition: strrb.h:42
int osmo_counter_difference(struct osmo_counter *ctr)
Compute difference between current and previous counter value.
Definition: counter.c:106
A structure representing a single instance of a timer.
Definition: timer.h:56
const struct value_string osmo_tdef_unit_names[]
Definition: tdef.c:360
static void flush_all_reporters()
Definition: stats.c:760
int osmo_stats_reporter_disable(struct osmo_stats_reporter *srep)
Disable the given stats_reporter.
Definition: stats.c:439
bool _osmo_strrb_is_bufindex_valid(const struct osmo_strrb *rb, unsigned int bufi)
Definition: strrb.c:119
uint16_t start
index of the first slot
Definition: strrb.h:39
@ OSMO_STATS_CLASS_GLOBAL
global counter/stat_item
Definition: stats.h:49
uint64_t total_sum
Overall cumulative sum.
Definition: time_cc.h:165
static struct osmo_use_count_entry * osmo_use_count_repurpose_zero_entry(struct osmo_use_count *uc, const char *use)
Find a use count entry that currently has zero count, and re-use that for this new use token.
Definition: use_count.c:181
int rate_ctr_for_each_counter(struct rate_ctr_group *ctrg, rate_ctr_handler_t handle_counter, void *data)
Iterate over each counter in group and call function.
Definition: rate_ctr.c:417
int dest_port
destination (UDP) port
Definition: stats.h:74
#define TRACE(probe)
Definition: stats.c:100
void osmo_stats_reporter_free(struct osmo_stats_reporter *srep)
Destroy a given stats_reporter.
Definition: stats.c:233
#define timerclear(tvp)
Definition: timer_compat.h:43
void osmo_time_cc_init(struct osmo_time_cc *tc)
rate counter description
Definition: rate_ctr.h:37
bool osmo_is_hexstr(const char *str, int min_digits, int max_digits, bool require_even)
Validate that a given string is a hex string within given size limits.
Definition: utils.c:615
int osmo_strrb_add(struct osmo_strrb *rb, const char *data)
Add a string to the osmo_strrb.
Definition: strrb.c:152
struct osmo_stats_reporter * osmo_stats_reporter_alloc(enum osmo_stats_reporter_type type, const char *name)
Definition: stats.c:215
@ OSMO_TDEF_S
most T are in seconds, keep 0 as default.
Definition: tdef.h:39
static void osmo_stats_reporter_sanitize_name(char *buf)
Replace all illegal ':' in the stats name, but not when used as value seperator.
Definition: stats_statsd.c:75
struct osmo_stat_item_period reported
The results of the previous reporting period.
Definition: stat_item_internal.h:32
uint8_t osmo_char2bcd(char c)
Convert number in ASCII to BCD value.
Definition: utils.c:126
#define timeradd(a, b, result)
Definition: timer_compat.h:54
int running
is this reporter running
Definition: stats.h:83
unsigned int flush_period
period between regular flushes
Definition: stats.h:76
unsigned int current_length
current length of write queue
Definition: write_queue.h:40
void osmo_str2lower(char *out, const char *in) OSMO_DEPRECATED("Use osmo_str_tolower() or osmo_str_tolower_buf() instead
Convert an entire string to lower case.
Definition: utils.c:473
int T_gran
Update gran_usec from this T timer value, or zero to not use any T timer.
Definition: time_cc.h:118
char * osmo_ubit_dump_buf(char *buf, size_t buf_len, const uint8_t *bits, unsigned int len)
Convert a sequence of unpacked bits to ASCII string, in user-supplied buffer.
Definition: utils.c:345
int bind_addr_len
length of bind_addr in bytes
Definition: stats.h:87
const char * get_value_string(const struct value_string *vs, uint32_t val)
get human-readable string for given value
Definition: utils.c:58
void rate_ctr_add(struct rate_ctr *ctr, int inc)
Increment the counter by inc.
Definition: rate_ctr.c:287
const struct osmo_tdef_state_timeout * osmo_tdef_get_state_timeout(uint32_t state, const struct osmo_tdef_state_timeout *timeouts_array)
Using osmo_tdef for osmo_fsm_inst: find a given state's osmo_tdef_state_timeout entry.
Definition: tdef.c:318
size_t osmo_quote_cstr_buf(char *buf, size_t bufsize, const char *str, int in_len)
Like osmo_escape_str_buf2(), but returns double-quotes around a string, or "NULL" for a NULL string.
Definition: utils.c:986
void osmo_time_cc_set_flag(struct osmo_time_cc *tc, bool flag)
const struct rate_ctr_group_desc * desc
Pointer to the counter group class.
Definition: rate_ctr.h:61
static size_t len(const char *str)
struct sockaddr dest_addr
destination address of socket
Definition: stats.h:84
int32_t max
Largest value seen in a reporting period.
Definition: stat_item_internal.h:17
write Write running configuration to or terminal n Write configuration to the copy running config startup Copy configuration n Copy running config to n Copy running config to startup write Write running configuration to or terminal n Write to terminal n
void osmo_timer_add(struct osmo_timer_list *timer)
add a new timer to the timer management
Definition: timer.c:84
@ OSMO_STATS_REPORTER_LOG
libosmocore logging
Definition: stats.h:56
struct osmo_time_cc_cfg cfg
Definition: time_cc.h:159
static int osmo_stats_reporter_statsd_send_counter(struct osmo_stats_reporter *srep, const struct rate_ctr_group *ctrg, const struct rate_ctr_desc *desc, int64_t value, int64_t delta)
Definition: stats_statsd.c:160
char * osmo_quote_str_buf2(char *buf, size_t bufsize, const char *str, int in_len)
Like osmo_escape_str_buf2(), but returns double-quotes around a string, or "NULL" for a NULL string.
Definition: utils.c:899
#define OSMO_ASSERT(exp)
Helper macro to terminate when an assertion fails.
Definition: utils.h:104
osmo_stats_class
Statistics Class definitions.
Definition: stats.h:47
static int osmo_stats_reporter_log_send_item(struct osmo_stats_reporter *srep, const struct osmo_stat_item_group *statg, const struct osmo_stat_item_desc *desc, int64_t value)
Definition: stats.c:611
One instance of a counter group class.
Definition: stat_item.h:45
static bool count_safe(int32_t *val_p, int32_t add)
Add two int32_t but make sure to min- and max-clamp at INT32_MIN and INT32_MAX, respectively.
Definition: use_count.c:47
static unsigned char * msgb_put(struct msgb *msgb, unsigned int len)
append data to end of message buffer
Definition: msgb.h:238
static void __add_timer(struct osmo_timer_list *timer)
Definition: timer.c:48
int class_id
The class to which this group belongs.
Definition: rate_ctr.h:49
static int rate_ctr_group_handler(struct rate_ctr_group *ctrg, void *sctx_)
Definition: stats.c:672
static __thread struct rb_root timer_root
Definition: timer.c:46
unsigned int idx
The index of this value group within its class.
Definition: stat_item.h:51
unsigned int max_length
maximum length of write queue
Definition: write_queue.h:38
uint16_t size
max number of messages to store
Definition: strrb.h:41
char alias("osmo_hexdump_nospc")))
void osmo_identifier_sanitize_buf(char *str, const char *sep_chars, char replace_with)
Replace characters in the given string buffer so that it is guaranteed to pass osmo_separated_identif...
Definition: utils.c:687
int(* write_cb)(struct osmo_fd *fd, struct msgb *msg)
call-back in case qeueue is writable.
Definition: write_queue.h:48
unsigned long val
Currently active timeout value, e.g.
Definition: tdef.h:80
int osmo_stats_reporter_send_buffer(struct osmo_stats_reporter *srep)
size_t osmo_escape_cstr_buf(char *buf, size_t bufsize, const char *str, int in_len)
Return the string with all non-printable characters escaped.
Definition: utils.c:956
size_t osmo_strrb_elements(const struct osmo_strrb *rb)
Count the number of log messages in an osmo_strrb.
Definition: strrb.c:136
uint64_t last_counted_time
CLOCK_MONOTONIC reading in microseconds, at the time when the osmo_time_cc last evaluated the flag st...
Definition: time_cc.h:173
int osmo_stats_reporter_set_local_addr(struct osmo_stats_reporter *srep, const char *addr)
struct llist_head use_counts
List of use tokens.
Definition: use_count.h:179
data we keep for each actual item
Definition: stat_item_internal.h:23
struct llist_head osmo_stats_reporter_list
const char * osmo_escape_str(const char *str, int len)
Return the string with all non-printable characters escaped.
Definition: utils.c:847
int(* cb)(struct osmo_fd *fd, unsigned int what)
call-back function to be called once file descriptor becomes available
Definition: select.h:41
void osmo_talloc_replace_string_fmt(void *ctx, char **dst, const char *fmt,...)
Replace a string using talloc and release its prior content (if any).
Definition: utils.c:1501
int(* send_item)(struct osmo_stats_reporter *srep, const struct osmo_stat_item_group *statg, const struct osmo_stat_item_desc *desc, int64_t value)
Definition: stats.h:101
#define STATS_DEFAULT_BUFLEN
Definition: stats.c:107
static struct osmo_use_count_entry * osmo_use_count_create(struct osmo_use_count *uc, const char *use)
Allocate a new use count entry, happens implicitly in osmo_use_count_get_put().
Definition: use_count.c:196
Report the cumulative counter of time for which a flag is true as rate counter.
Definition: time_cc.h:158
int _osmo_tdef_fsm_inst_state_chg(struct osmo_fsm_inst *fi, uint32_t state, const struct osmo_tdef_state_timeout *timeouts_array, const struct osmo_tdef *tdefs, long default_timeout, const char *file, int line)
See invocation macro osmo_tdef_fsm_inst_state_chg() instead.
Definition: tdef.c:332
uint64_t round_threshold_usec
Nr of microseconds above n * gran_usec at which to trigger a counter increment.
Definition: time_cc.h:111
uint64_t osmo_decode_big_endian(const uint8_t *data, size_t data_len)
Generic retrieval of 1..8 bytes as big-endian uint64_t.
Definition: utils.c:528
int osmo_clock_gettime(clockid_t clk_id, struct timespec *tp)
int fd
file descriptor of socket
Definition: stats.h:88
struct gsm48_classmark3 __attribute__
fls64 - find last set bit in a 64-bit word @x: the word to search
Definition: log2.h:61
bool osmo_separated_identifiers_valid(const char *str, const char *sep_chars)
Determine if a given identifier is valid, i.e.
Definition: utils.c:645
#define RB_ROOT
Definition: linuxrbtree.h:131
int osmo_timers_nearest_ms(void)
Determine time between now and the nearest timer in milliseconds.
Definition: timer.c:190
int _osmo_fsm_inst_state_chg(struct osmo_fsm_inst *fi, uint32_t new_state, unsigned long timeout_secs, int T, const char *file, int line)
perform a state change of the given FSM instance
Definition: fsm.c:744
int get_string_value(const struct value_string *vs, const char *str)
get numeric value for given human-readable string
Definition: utils.c:97
struct llist_head * next
Pointer to next and previous item.
Definition: linuxlist.h:48
char * osmo_str_tolower_c(const void *ctx, const char *src)
Convert a string to lowercase, dynamically allocating the output from given talloc context See also o...
Definition: utils.c:1093
static int msgb_tailroom(const struct msgb *msgb)
determine how much tail room is left in msgb
Definition: msgb.h:209
const char * get_value_string_or_null(const struct value_string *vs, uint32_t val)
get human-readable string or NULL for given value
Definition: utils.c:74
char * osmo_escape_cstr_c(void *ctx, const char *str, int in_len)
Return the string with all non-printable characters escaped, in dynamically-allocated buffer.
Definition: utils.c:968
const char * osmo_strrb_get_nth(const struct osmo_strrb *rb, unsigned int string_index)
Return a pointer to the Nth string in the osmo_strrb.
Definition: strrb.c:106
static int osmo_stat_item_handler(struct osmo_stat_item_group *statg, struct osmo_stat_item *item, void *sctx_)
Definition: stats.c:692
int osmo_timers_update(void)
fire all timers...
Definition: timer.c:237
enum osmo_stats_reporter_type type
Type of the reporter (log, statsd)
Definition: stats.h:63
struct osmo_stat_item_period value
Current reporting period / current value.
Definition: stat_item_internal.h:28
static void llist_del_init(struct llist_head *entry)
Delete a single entry from a linked list and reinitialize it.
Definition: linuxlist.h:138
#define OSMO_FD_READ
Indicate interest in reading from the file descriptor.
Definition: select.h:17
void osmo_tdefs_reset(struct osmo_tdef *tdefs)
Set all osmo_tdef values to the default_val.
Definition: tdef.c:154
#define INIT_LLIST_HEAD(ptr)
Initialize a llist_head to point back to itself.
Definition: linuxlist.h:65
void osmo_gettimeofday_override_add(time_t secs, suseconds_t usecs)
convenience function to advance the fake time.
Definition: timer_gettimeofday.c:72
struct osmo_stats_reporter * osmo_stats_reporter_create_statsd(const char *name)
Create a stats_reporter reporting to statsd.
Definition: stats_statsd.c:57
size_t osmo_strlcpy(char *dst, const char *src, size_t siz)
Copy a C-string into a sized buffer.
Definition: utils.c:569
unsigned int flush_period_counter
count sends between forced flushes
Definition: stats.h:92
static void update_nearest(struct timeval *cand, struct timeval *current)
Definition: timer.c:203
@ OSMO_STATS_REPORTER_STATSD
statsd backend
Definition: stats.h:57
Define a GSM timer of the form Tnnn, with unit, default value and doc string.
Definition: tdef.h:65
int32_t osmo_use_count_total(const struct osmo_use_count *uc)
Return the sum of all use counts, min- and max-clamped at INT32_MIN and INT32_MAX.
Definition: use_count.c:71
One statistics reporter instance.
Definition: stats.h:61
#define container_of(ptr, type, member)
Cast a member of a structure out to the containing structure.
Definition: linuxlist.h:32
LLIST_HEAD(osmo_stats_reporter_list)
int(* close)(struct osmo_stats_reporter *srep)
Definition: stats.h:96
uint64_t sum
Internal cumulative counter of time that flag_state was true.
Definition: time_cc.h:177
bool keep_timer
If true, call osmo_fsm_inst_state_chg_keep_timer().
Definition: tdef.h:118
#define timersub(a, b, result)
Definition: timer_compat.h:67
const char * osmo_quote_str(const char *str, int in_len)
Like osmo_quote_str_buf() but returns the result in a static buffer.
Definition: utils.c:929
a single instanceof an osmocom finite state machine
Definition: fsm.h:87
#define OSMO_NAME_C_IMPL(CTX, INITIAL_BUFSIZE, ON_ERROR, FUNC_BUF, FUNC_BUF_ARGS...)
Translate a buffer function to a talloc context function.
Definition: utils.h:315
static int rate_ctr_handler(struct rate_ctr_group *ctrg, struct rate_ctr *ctr, const struct rate_ctr_desc *desc, void *sctx_)
Definition: stats.c:645
static void msgb_enqueue_count(struct llist_head *queue, struct msgb *msg, unsigned int *count)
Enqueue message buffer to tail of a queue and increment queue size counter.
Definition: msgb.h:97
enum osmo_tdef_unit unit
Definition: tdef.h:74
Structure representing a single counter.
Definition: counter.h:9
uint16_t msgb_length(const struct msgb *msg)
get length of message buffer
Definition: msgb.c:289
static const char osmo_identifier_illegal_chars[]
Definition: utils.c:638
static void llist_del(struct llist_head *entry)
Delete a single entry from a linked list.
Definition: linuxlist.h:128
size_t chars_needed
After all OSMO_STRBUF_APPEND operations, reflects the total number of characters that would be writte...
Definition: utils.h:185
struct osmo_stats_reporter * osmo_stats_reporter_find(enum osmo_stats_reporter_type type, const char *name)
Find a stats_reporter of given type and name.
Definition: stats.c:253
const unsigned long default_val
Timeout duration (according to unit), default value; type corresponds to osmo_fsm_inst_state_chg()'s ...
Definition: tdef.h:73
int force_single_flush
set to 1 to force a flush (send even unchanged stats values)
Definition: stats.h:91
struct timeval timeout
expiration time
Definition: timer.h:59
struct osmo_tdef * T_defs
Look up T_gran and T_forget_sum in this list of timers, or NULL to not use any T timers.
Definition: time_cc.h:124
const char * use
Use token string that was passed to osmo_use_count_get_put().
Definition: use_count.h:200
#define BACKSLASH_CASE(c, repr)
Osmocom message buffer.
Definition: msgb.h:35
void rb_insert_color(struct rb_node *, struct rb_root *)
Definition: rbtree.c:74
void osmo_clock_override_add(clockid_t clk_id, time_t secs, long nsecs)
static int osmo_stats_reporter_send_counter(struct osmo_stats_reporter *srep, const struct rate_ctr_group *ctrg, const struct rate_ctr_desc *desc, int64_t value, int64_t delta)
Definition: stats.c:634
#define LOGL_INFO
general information
Definition: logging.h:98
static __thread struct timeval * nearest_p
Definition: timer.c:44
Use counter state for one used object, managing N distinct named counters.
Definition: use_count.h:172
One named counter in the list managed by osmo_use_count.
Definition: use_count.h:194
Definition: linuxrbtree.h:109
static void * osmo_stats_ctx
Definition: stats.c:110
int(* read_cb)(struct osmo_fd *fd)
call-back in case qeueue is readable.
Definition: write_queue.h:46
int dest_addr_len
length of dest_addr in bytes
Definition: stats.h:85
const struct osmo_stat_item_desc * desc
back-reference to the item description
Definition: stat_item_internal.h:25
char * dest_addr_str
destination IP address
Definition: stats.h:72
One instance of a counter group class.
Definition: rate_ctr.h:57
const char * osmo_escape_str_buf(const char *str, int in_len, char *buf, size_t bufsize)
Like osmo_escape_str_buf2, but with unusual ordering of arguments, and may sometimes return string co...
Definition: utils.c:710
int T
Timer number to match struct osmo_tdef.T, and to pass to osmo_fsm_inst_state_chg().
Definition: tdef.h:115
bool osmo_tdef_val_in_range(struct osmo_tdef *tdef, unsigned long new_val)
Check if value new_val is in range of valid possible values for timer entry tdef.
Definition: tdef.c:261
static int osmo_stats_reporter_send_item(struct osmo_stats_reporter *srep, const struct osmo_stat_item_group *statg, const struct osmo_stat_item_desc *desc, int32_t value)
Definition: stats.c:681
static struct osmo_stats_config s_stats_config
Definition: stats.c:113
struct rb_node * rb_first(const struct rb_root *)
Definition: rbtree.c:289
void osmo_panic(const char *fmt,...) __attribute__((noreturn))
Terminate the current program with a panic.
Definition: panic.c:75
int osmo_stats_reporter_udp_open(struct osmo_stats_reporter *srep)
int _osmo_fsm_inst_state_chg_keep_timer(struct osmo_fsm_inst *fi, uint32_t new_state, const char *file, int line)
perform a state change while keeping the current timer running.
Definition: fsm.c:776
void msgb_free(struct msgb *m)
Release given message buffer.
Definition: msgb.c:121
@ OSMO_TDEF_M
minutes
Definition: tdef.h:41
int T_forget_sum
Update forget_sum_usec from this T timer value, or zero to not use any T timer.
Definition: time_cc.h:122
osmo_tdef_unit
Definition: tdef.h:38
static int osmo_stats_reporter_statsd_send_item(struct osmo_stats_reporter *srep, const struct osmo_stat_item_group *statg, const struct osmo_stat_item_desc *desc, int64_t value)
Definition: stats_statsd.c:183
char * osmo_hexdump_c(const void *ctx, const unsigned char *buf, int len)
Convert binary sequence to hexadecimal ASCII string.
Definition: utils.c:411
int osmo_wqueue_enqueue_quiet(struct osmo_wqueue *queue, struct msgb *data)
Enqueue a new Message buffers into a write queue (without logging full queue events)
Definition: write_queue.c:111
int osmo_use_count_to_str_buf(char *buf, size_t buf_len, const struct osmo_use_count *uc)
Write a comprehensive listing of use counts to a string buffer.
Definition: use_count.c:121
void * data
user data for callback
Definition: timer.h:63
int32_t osmo_use_count_by(const struct osmo_use_count *uc, const char *use)
Return use count by a single use token.
Definition: use_count.c:90
char * osmo_ubit_dump(const uint8_t *bits, unsigned int len)
Convert a sequence of unpacked bits to ASCII string, in static buffer.
Definition: utils.c:380
unsigned long min_val
Minimum timer value (in this tdef unit), checked if set (not zero).
Definition: tdef.h:82
int osmo_stats_reporter_set_max_class(struct osmo_stats_reporter *srep, enum osmo_stats_class class_id)
Definition: stats.c:367
const char * osmo_use_count_name_buf(char *buf, size_t buf_len, const struct osmo_use_count *uc)
Write a comprehensive listing of use counts to a string buffer.
Definition: use_count.c:108
const char * str
human-readable string
Definition: utils.h:44
int value
numeric value
Definition: utils.h:43
int osmo_wqueue_enqueue(struct osmo_wqueue *queue, struct msgb *data)
Enqueue a new Message buffers into a write queue.
Definition: write_queue.c:127
struct rate_ctr * rate_ctr
Rate counter to report to, or NULL to not use it.
Definition: time_cc.h:115
void osmo_timer_schedule(struct osmo_timer_list *timer, int seconds, int microseconds)
schedule a timer at a given future relative time
Definition: timer.c:103
uint64_t reported_sum
The amount of time that already reported cfg.rate_ctr increments account for.
Definition: time_cc.h:180
static unsigned long osmo_tdef_round(unsigned long val, enum osmo_tdef_unit from_unit, enum osmo_tdef_unit to_unit)
Definition: tdef.c:129
char * name
Optional string-based identifier to be used instead of index at report time.
Definition: stat_item.h:53
void osmo_clock_override_enable(clockid_t clk_id, bool enable)
write queue instance
Definition: write_queue.h:34
bool osmo_gettimeofday_override
Definition: timer_gettimeofday.c:48
size_t osmo_str_tolower_buf(char *dest, size_t dest_len, const char *src)
Convert a string to lowercase, while checking buffer size boundaries.
Definition: utils.c:1055
int32_t count
Current use count amount for only this use token string.
Definition: use_count.h:203
int osmo_int_to_float_str_buf(char *buf, size_t buflen, int64_t val, unsigned int precision)
Convert an integer to a floating point string using a decimal quotient (fixed-point precision).
Definition: utils.c:1343
const int T
T1234 or X1234 number, corresponding to struct osmo_fsm_inst::T.
Definition: tdef.h:70
static int osmo_stats_reporter_log_send_counter(struct osmo_stats_reporter *srep, const struct rate_ctr_group *ctrg, const struct rate_ctr_desc *desc, int64_t value, int64_t delta)
Definition: stats.c:595
void osmo_timers_prepare(void)
Find the nearest time and update nearest_p.
Definition: timer.c:219
unsigned int when
bit-mask or of OSMO_FD_READ, OSMO_FD_WRITE and/or OSMO_FD_EXCEPT
Definition: select.h:38
static struct osmo_fd osmo_stats_timer
Definition: stats.c:118
int(* send_counter)(struct osmo_stats_reporter *srep, const struct rate_ctr_group *ctrg, const struct rate_ctr_desc *desc, int64_t value, int64_t delta)
Definition: stats.h:97
int(* open)(struct osmo_stats_reporter *srep)
Definition: stats.h:95
#define OSMO_STRBUF_APPEND(STRBUF, func, args...)
Append a string to a buffer, as printed by an snprintf()-like function and with similar bounds checki...
Definition: utils.h:224
int osmo_stat_item_for_each_group(osmo_stat_item_group_handler_t handle_group, void *data)
Iterate over all stat_item groups in system, call user-supplied function on each.
Definition: stat_item.c:415
Using osmo_tdef for osmo_fsm_inst: array entry for a mapping of state numbers to timeout definitions.
Definition: tdef.h:111
int osmo_stats_reporter_udp_close(struct osmo_stats_reporter *srep)
struct timeval * osmo_timers_nearest(void)
Determine time between now and the nearest timer.
Definition: timer.c:179
int osmo_counters_for_each(int(*handle_counter)(struct osmo_counter *, void *), void *data)
Iterate over all counters; call handle_cunter call-back for each.
Definition: counter.c:65
int osmo_tdef_set(struct osmo_tdef *tdefs, int T, unsigned long val, enum osmo_tdef_unit val_unit)
Set value in entry matching T, converting val from val_unit to unit of T.
Definition: tdef.c:241
static struct msgb * msgb_dequeue_count(struct llist_head *queue, unsigned int *count)
Dequeue message buffer from head of queue and decrement queue size counter.
Definition: msgb.h:113
void osmo_stat_item_flush(struct osmo_stat_item *item)
Indicate that a reporting period has elapsed, and prepare the stat item for a new period of collectin...
Definition: stat_item.c:303
char * osmo_int_to_float_str_c(void *ctx, int64_t val, unsigned int precision)
Convert an integer with a factor of a million to a floating point string.
Definition: utils.c:1397
int osmo_bcd2str(char *dst, size_t dst_size, const uint8_t *bcd, int start_nibble, int end_nibble, bool allow_hex)
Convert BCD to string.
Definition: utils.c:152
static int update_srep_config(struct osmo_stats_reporter *srep)
Definition: stats.c:128
struct rb_node * rb_next(const struct rb_node *)
Definition: rbtree.c:313
const char * osmo_hexdump_buf(char *out_buf, size_t out_buf_size, const unsigned char *buf, int len, const char *delim, bool delim_after_last)
Convert binary sequence to hexadecimal ASCII string.
Definition: utils.c:303
char * bind_addr_str
local bind IP address
Definition: stats.h:73
int osmo_float_str_to_int(int64_t *val, const char *str, unsigned int precision)
Convert a string of a floating point number to a signed int, with a decimal factor (fixed-point preci...
Definition: utils.c:1218
const char * osmo_quote_str_buf(const char *str, int in_len, char *buf, size_t bufsize)
Like osmo_quote_str_buf2, but with unusual ordering of arguments, and may sometimes return string con...
Definition: utils.c:913
int osmo_print_n(char *buf, size_t bufsize, const char *str, size_t n)
Copy N characters to a buffer with a function signature useful for OSMO_STRBUF_APPEND().
Definition: utils.c:727
#define timercmp(a, b, CMP)
Definition: timer_compat.h:47
bool osmo_identifier_valid(const char *str)
Determine if a given identifier is valid, i.e.
Definition: utils.c:675
int osmo_timerfd_disable(struct osmo_fd *ofd)
disable the osmocom-wrapped timerfd
Definition: select.c:486
char osmo_bcd2char(uint8_t bcd)
Convert BCD-encoded digit into printable character.
Definition: utils.c:114
int _osmo_use_count_get_put(struct osmo_use_count *uc, const char *use, int32_t change, const char *file, int line)
Implementation for osmo_use_count_get_put(), which can also be directly invoked to pass source file i...
Definition: use_count.c:237
int(* except_cb)(struct osmo_fd *fd)
call-back in case qeueue has exceptions.
Definition: write_queue.h:50
(double) linked list header structure
Definition: linuxlist.h:46
@ OSMO_TDEF_MS
milliseconds
Definition: tdef.h:40
int osmo_stats_reporter_set_remote_addr(struct osmo_stats_reporter *srep, const char *addr)
void osmo_time_cc_cleanup(struct osmo_time_cc *tc)
if(vty->type==VTY_SHELL_SERV)
struct abis_rsl_common_hdr c
struct sockaddr bind_addr
local bind address of socket
Definition: stats.h:86
int osmo_stats_reporter_set_flush_period(struct osmo_stats_reporter *srep, unsigned int period)
Set the regular flush period for a given stats_reporter.
Definition: stats.c:401
struct llist_head list
internal list header
Definition: timer.h:58
enum osmo_stats_class max_class
Maximum class/index to report.
Definition: stats.h:79
int osmo_hexparse(const char *str, uint8_t *b, int max_len)
Parse a string containing hexadecimal digits.
Definition: utils.c:244
int osmo_str_to_int64(int64_t *result, const char *str, int base, int64_t min_val, int64_t max_val)
Convert a string of a number to int64_t, including all common strtoll() validity checks.
Definition: utils.c:1416
static int msgb_trim(struct msgb *msg, int len)
Trim the msgb to a given absolute length.
Definition: msgb.h:493
struct llist_head list
Definition: stats.h:94
void osmo_wqueue_init(struct osmo_wqueue *queue, int max_length)
Initialize a osmo_wqueue structure.
Definition: write_queue.c:95
uint64_t forget_sum_usec
Forget counted sub-gran time after the flag was false for this long.
Definition: time_cc.h:113
struct rb_node node
rb-tree node header
Definition: timer.h:57
void osmo_timer_setup(struct osmo_timer_list *timer, void(*cb)(void *data), void *data)
set up timer callback and data
Definition: timer.c:74
static __thread char namebuf[255]
Definition: utils.c:45
int osmo_stats_reporter_set_name_prefix(struct osmo_stats_reporter *srep, const char *prefix)
Set the name prefix of a given stats_reporter.
Definition: stats.c:416
unsigned long osmo_tdef_get(const struct osmo_tdef *tdefs, int T, enum osmo_tdef_unit as_unit, long val_if_not_present)
Return the value of a T timer from a list of osmo_tdef, in the given unit.
Definition: tdef.c:206
int osmo_stats_reporter_enable(struct osmo_stats_reporter *srep)
Enable the given stats_reporter.
Definition: stats.c:429
int osmo_tdef_range_str_buf(char *buf, size_t buf_len, struct osmo_tdef *t)
Write string representation of osmo_tdef range into buf.
Definition: tdef.c:274
struct rb_node * rb_node
Definition: linuxrbtree.h:111
#define STATS_DEFAULT_INTERVAL
Definition: stats.c:106
uint32_t osmo_isqrt32(uint32_t x)
perform an integer square root operation on unsigned 32bit integer.
Definition: utils.c:1008
int osmo_timerfd_setup(struct osmo_fd *ofd, int(*cb)(struct osmo_fd *, unsigned int), void *data)
setup osmocom-wrapped timerfd
Definition: select.c:528
int mtu
Maximum Transmission Unit.
Definition: stats.h:75
const char * osmo_str_toupper(const char *src)
Convert a string to uppercase, using a static buffer.
Definition: utils.c:1139
const char * group_name_prefix
The prefix to the name of all counters in this group.
Definition: rate_ctr.h:45
int64_t rate_ctr_difference(struct rate_ctr *ctr)
Return the counter difference since the last call to this function.
Definition: rate_ctr.c:293
struct msgb * buffer
message buffer for log output
Definition: stats.h:89
#define llist_for_each_entry(pos, head, member)
Iterate over a linked list of a given type.
Definition: linuxlist.h:299
uint8_t * osmo_encode_big_endian(uint64_t value, size_t data_len)
Generic big-endian encoding of big endian number up to 64bit.
Definition: utils.c:549
const struct osmo_stat_item_group_desc * desc
Pointer to the counter group class.
Definition: stat_item.h:49
char * buf
Point to the start of a string buffer.
Definition: utils.h:177
int agg_enabled
is aggregation enabled?
Definition: stats.h:90
#define LOGL_NOTICE
abnormal/unexpected condition
Definition: logging.h:99
struct timeval osmo_gettimeofday_override_time
Definition: timer_gettimeofday.c:49
void osmo_use_count_make_static_entries(struct osmo_use_count *uc, struct osmo_use_count_entry *buf, size_t buf_n_entries)
Add N static use token entries to avoid dynamic allocation of use count tokens.
Definition: use_count.c:293
static void llist_add(struct llist_head *_new, struct llist_head *head)
Add a new entry into a linked list (at head).
Definition: linuxlist.h:92
A mapping between human-readable string and numeric value.
Definition: utils.h:42
static int handle_counter(struct osmo_counter *counter, void *sctx_)
Definition: stats.c:731
const char * osmo_str_tolower(const char *src)
Convert a string to lowercase, using a static buffer.
Definition: utils.c:1081
#define OSMO_T_FMT_ARGS(T)
Definition: fsm.h:203
static int osmo_stats_timer_cb(struct osmo_fd *ofd, unsigned int what)
Definition: stats.c:156
osmo_stats_reporter_type
Statistics Reporter Type.
Definition: stats.h:55
char osmo_luhn(const char *in, int in_len)
Calculate the Luhn checksum (as used for IMEIs).
Definition: utils.c:1166
int osmo_stats_report()
Definition: stats.c:783
int osmo_timerfd_schedule(struct osmo_fd *ofd, const struct timespec *first, const struct timespec *interval)
schedule the osmocom-wrapped timerfd to occur first at first, then periodically at interval
Definition: select.c:500
int T_round_threshold
Update round_threshold_usec from this T timer value, or zero to not use any T timer.
Definition: time_cc.h:120
struct timespec * osmo_clock_override_gettimespec(clockid_t clk_id)
static void llist_add_tail(struct llist_head *_new, struct llist_head *head)
Add a new entry into a linked list (at tail).
Definition: linuxlist.h:104
#define timespecadd(a, b, result)
Definition: timer_compat.h:97
enum osmo_sub_auth_type type
#define ARRAY_SIZE(x)
Determine number of elements in an array of static size.
Definition: utils.h:19
bool flag_state
Definition: time_cc.h:161
struct llist_head entry
Entry in osmo_use_count->use_counts.
Definition: use_count.h:196
bool osmo_str_startswith(const char *str, const char *startswith_str)
Compare start of a string.
Definition: utils.c:1197
@ OSMO_STATS_CLASS_UNKNOWN
unknown class
Definition: stats.h:48
struct osmo_fd bfd
osmocom file descriptor
Definition: write_queue.h:36
const char * group_name_prefix
The prefix to the name of all values in this group.
Definition: stat_item.h:33
void(* cb)(void *)
call-back called at timeout
Definition: timer.h:62
static __thread char capsbuf[128]
Definition: utils.c:47
static int is_initialised
Definition: stats.c:111
static __thread struct timeval nearest
Definition: timer.c:43
char * osmo_escape_str_buf2(char *buf, size_t bufsize, const char *str, int in_len)
Return the string with all non-printable characters escaped.
Definition: utils.c:835
int osmo_timer_pending(const struct osmo_timer_list *timer)
check if given timer is still pending
Definition: timer.c:138
#define RB_MAX_MESSAGE_SIZE
A structure representing an osmocom string ringbuffer.
Definition: strrb.h:37
char * osmo_quote_str_c(const void *ctx, const char *str, int in_len)
Like osmo_quote_str_buf() but returns the result in a dynamically-allocated buffer.
Definition: utils.c:940
void osmo_timer_del(struct osmo_timer_list *timer)
delete a timer from timer management
Definition: timer.c:120
uint64_t start_time
CLOCK_MONOTONIC reading in microseconds, at the time when the osmo_time_cc instance started counting.
Definition: time_cc.h:170
const char * name
human-readable name
Definition: counter.h:11
struct osmo_use_count * use_count
Parent use count and backpointer to the talloc_object.
Definition: use_count.h:198
char * name
Human-readable name of this reporter.
Definition: stats.h:65
State for OSMO_STRBUF_APPEND() and OSMO_STRBUF_PRINTF().
Definition: utils.h:175
int osmo_stats_reporter_set_mtu(struct osmo_stats_reporter *srep, int mtu)
char * osmo_quote_cstr_c(void *ctx, const char *str, int in_len)
Return the string quoted and with all non-printable characters escaped, in dynamically-allocated buff...
Definition: utils.c:998
uint16_t end
index of the last slot
Definition: strrb.h:40
#define DLSTATS
Statistics.
Definition: logging.h:113
pid_t osmo_gettid(void)
Wrapper around Linux's gettid() to make it easily accessible on different system versions.
Definition: thread.c:50
#define OSMO_FD_WRITE
Indicate interest in writing to the file descriptor.
Definition: select.h:19
uint64_t current
current value
Definition: rate_ctr.h:30
static unsigned long osmo_tdef_factor(enum osmo_tdef_unit a, enum osmo_tdef_unit b)
a = return_val * b.
Definition: tdef.c:89
@ OSMO_TDEF_CUSTOM
unspecified unit, explained in osmo_tdef.desc.
Definition: tdef.h:42
struct osmo_strrb * osmo_strrb_create(TALLOC_CTX *ctx, size_t rb_size)
Create an empty, initialized osmo_strrb.
Definition: strrb.c:59
static int osmo_stats_reporter_log_send(struct osmo_stats_reporter *srep, const char *type, const char *name1, unsigned int index1, const char *name2, int value, const char *unit)
Definition: stats.c:580
const char * osmo_strnchr(const char *str, size_t str_size, char c)
Find first occurence of a char in a size limited string.
Definition: utils.c:589
void * talloc_object
Context to talloc-allocate use count entries from (if at all necessary); back-pointer to the owning o...
Definition: use_count.h:175
write Write running configuration to or terminal n Write configuration to the file(same as write file)\n") ALIAS(config_write_file
uint8_t * msgb_data(const struct msgb *msg)
get pointer to data section of message buffer
Definition: msgb.c:188
Definition: linuxrbtree.h:99
#define DLGLOBAL
global logging
Definition: logging.h:104
unsigned int active
is it active?
Definition: timer.h:60
struct osmo_stats_reporter * osmo_stats_reporter_create_log(const char *name)
Create a stats_reporter that logs via libosmocore logging.
Definition: stats.c:567
Structure representing a file dsecriptor.
Definition: select.h:31
osmo_use_count_cb_t use_cb
If not NULL, this is invoked for each use count change.
Definition: use_count.h:177
#define LOGP(ss, level, fmt, args...)
Log a new message through the Osmocom logging framework.
Definition: logging.h:43
char * osmo_hexdump_nospc_c(const void *ctx, const unsigned char *buf, int len)
Convert binary sequence to hexadecimal ASCII string.
Definition: utils.c:447
unsigned long max_val
Maximum timer value (in this tdef unit), checked if set (not zero).
Definition: tdef.h:84
struct msgb * msgb_alloc(uint16_t size, const char *name)
Allocate a new message buffer from tall_msgb_ctx.
Definition: msgb.c:112
static int llist_empty(const struct llist_head *head)
Test whether a linked list is empty.
Definition: linuxlist.h:169
int osmo_timers_check(void)
Check how many timers we have in the system.
Definition: timer.c:283
#define OSMO_STRBUF_PRINTF(STRBUF, fmt, args...)
Shortcut for OSMO_STRBUF_APPEND() invocation using snprintf().
Definition: utils.h:256
@ OSMO_TDEF_US
microseconds
Definition: tdef.h:43
size_t osmo_str_toupper_buf(char *dest, size_t dest_len, const char *src)
Convert a string to uppercase, while checking buffer size boundaries.
Definition: utils.c:1113
int enabled
is this reporter enabled
Definition: stats.h:70
char * osmo_osmo_hexdump_nospc(const unsigned char *buf, int len) __attribute__((__deprecated__))
static __thread char hexd_buff[4096]
Definition: utils.c:284
void osmo_use_count_free(struct osmo_use_count_entry *use_count_entry)
Deallocate a use count entry.
Definition: use_count.c:224
static int start_timer()
Definition: stats.c:181
char * osmo_hexdump_nospc(const unsigned char *buf, int len)
Convert binary sequence to hexadecimal ASCII string.
Definition: utils.c:432
const char * description
humn-readable description
Definition: counter.h:12
int osmo_wqueue_bfd_cb(struct osmo_fd *fd, unsigned int what)
Select loop function for write queue handling.
Definition: write_queue.c:43
#define osmo_htons(x)
Definition: byteswap.h:44
static size_t _osmo_escape_str_buf(char *buf, size_t bufsize, const char *str, int in_len, bool legacy_format)
Return the string with all non-printable characters escaped.
Definition: utils.c:761
char * osmo_hexdump(const unsigned char *buf, int len)
Convert binary sequence to hexadecimal ASCII string.
Definition: utils.c:396
void rb_erase(struct rb_node *, struct rb_root *)
Definition: rbtree.c:219
struct osmo_use_count_entry * osmo_use_count_find(const struct osmo_use_count *uc, const char *use)
Definition: use_count.c:168
static void msgb_put_u8(struct msgb *msgb, uint8_t word)
append a uint8 value to the end of the message
Definition: msgb.h:257
int osmo_stats_reporter_set_remote_port(struct osmo_stats_reporter *srep, int port)
#define osmo_tdef_for_each(t, tdefs)
Iterate an array of struct osmo_tdef, the last item should be fully zero, i.e.
Definition: tdef.h:98
@ OSMO_STATS_CLASS_SUBSCRIBER
subscriber
Definition: stats.h:51
int rate_ctr_for_each_group(rate_ctr_group_handler_t handle_group, void *data)
Iterate over all counter groups.
Definition: rate_ctr.c:439
int interval
Definition: stats.h:108
char * osmo_str_toupper_c(const void *ctx, const char *src)
Convert a string to uppercase, dynamically allocating the output from given talloc context See also o...
Definition: utils.c:1151
int osmo_str2bcd(uint8_t *dst, size_t dst_size, const char *digits, int start_nibble, int end_nibble, bool allow_hex)
Convert string to BCD.
Definition: utils.c:195
static int osmo_stats_reporter_check_config(struct osmo_stats_reporter *srep, unsigned int index, int class_id)
Definition: stats.c:622
Statistics item description.
Definition: stat_item.h:22
#define OSMO_T_FMT
Definition: fsm.h:202
struct msgb * msgb_dequeue(struct llist_head *queue)
Dequeue message buffer from head of queue.
Definition: msgb.c:145
char * name_prefix
prefix for counter names
Definition: stats.h:71
int osmo_timer_remaining(const struct osmo_timer_list *timer, const struct timeval *now, struct timeval *remaining)
compute the remaining time of a timer
Definition: timer.c:152
#define OSMO_SNPRINTF_RET(ret, rem, offset, len)
Definition: utils.h:90
int class_id
The class to which this group belongs.
Definition: stat_item.h:37
struct llist_head msg_queue
actual linked list implementing the queue
Definition: write_queue.h:43
static const char hex_chars[]
Definition: utils.c:285
int fd
actual operating-system level file decriptor
Definition: select.h:35
struct osmo_tdef * osmo_tdef_get_entry(struct osmo_tdef *tdefs, int T)
Find tdef entry matching T.
Definition: tdef.c:223
void osmo_stats_init(void *ctx)
Initialize the stats reporting module; call this once in your program.
Definition: stats.c:242
int osmo_stat_item_for_each_item(struct osmo_stat_item_group *statg, osmo_stat_item_handler_t handle_item, void *data)
Iterate over all items in group, call user-supplied function on each.
Definition: stat_item.c:395
#define OSMO_MIN(a, b)
Return the minimum of two specified values.
Definition: utils.h:24
unsigned long value
current value
Definition: counter.h:13
static int osmo_stat_item_group_handler(struct osmo_stat_item_group *statg, void *sctx_)
Definition: stats.c:722
bool osmo_strrb_is_empty(const struct osmo_strrb *rb)
Check if an osmo_strrb is empty.
Definition: strrb.c:92
char * osmo_escape_str_c(const void *ctx, const char *str, int in_len)
Return the string with all non-printable characters escaped, in dynamically-allocated buffer.
Definition: utils.c:857
#define LOGL_ERROR
error condition, requires user action
Definition: logging.h:100
int osmo_stats_set_interval(int interval)
Set the reporting interval (common for all reporters)
Definition: stats.c:381
static void osmo_store64be_ext(uint64_t x, void *p, uint8_t n)
store unaligned n-byte integer (big-endian encoding) from uint64_t
Definition: bit64gen.h:93
int osmo_constant_time_cmp(const uint8_t *exp, const uint8_t *rel, const int count)
Wishful thinking to generate a constant time compare.
Definition: utils.c:506
data we keep for each actual value
Definition: rate_ctr.h:29
struct osmo_timer_list timer
Definition: time_cc.h:167
#define OSMO_FD_EXCEPT
Indicate interest in exceptions from the file descriptor.
Definition: select.h:21
#define OSMO_MAX(a, b)
Return the maximum of two specified values.
Definition: utils.h:22
static int osmo_stats_reporter_statsd_send(struct osmo_stats_reporter *srep, const char *name1, const char *index1, const char *name2, int64_t value, const char *unit)
Definition: stats_statsd.c:91
int osmo_str_to_int(int *result, const char *str, int base, int min_val, int max_val)
Convert a string of a number to int, including all common strtoll() validity checks.
Definition: utils.c:1475
int osmo_stats_reporter_send(struct osmo_stats_reporter *srep, const char *data, int data_len)
char * osmo_use_count_to_str_c(void *ctx, const struct osmo_use_count *uc)
Write a comprehensive listing of use counts to a talloc allocated string buffer.
Definition: use_count.c:158
void osmo_wqueue_clear(struct osmo_wqueue *queue)
Clear a osmo_wqueue.
Definition: write_queue.c:143
char * name
Optional string-based identifier to be used instead of index at report time.
Definition: rate_ctr.h:65
static size_t _osmo_quote_str_buf(char *buf, size_t bufsize, const char *str, int in_len, bool legacy_format)
Return a quoted and escaped representation of the string.
Definition: utils.c:877
void osmo_str2upper(char *out, const char *in) OSMO_DEPRECATED("Use osmo_str_toupper() or osmo_str_toupper_buf() instead
Convert an entire string to upper case.
Definition: utils.c:486
static void rb_link_node(struct rb_node *node, struct rb_node *parent, struct rb_node **rb_link)
Definition: linuxrbtree.h:151
unsigned int idx
The index of this ctr_group within its class.
Definition: rate_ctr.h:63
uint64_t gran_usec
Granularity in microseconds: nr of microseconds that one rate_ctr increment represents.
Definition: time_cc.h:108
int _osmo_fsm_inst_state_chg_keep_or_start_timer(struct osmo_fsm_inst *fi, uint32_t new_state, unsigned long timeout_secs, int T, const char *file, int line)
perform a state change while keeping the current timer if running, or starting a timer otherwise.
Definition: fsm.c:804