counter/stats. More...
#include "pt.h"

Go to the source code of this file.
:
Example usage: 1. register (must be before forking, e.g. from mod_init()): counter_handle_t h; counter_register(&h, "my_counters", "foo", 0, 0, 0, "test counter", 0); 2. increment/add: counter_inc(h); counter_add(h, 100); 3. get and existing counter handle, knowing its group and name counter_lookup(&h, "my_counters", "foo"); 4. get a counter value (the handle can be obtained like above) val = counter_get(h);
Definition in file counters.h.
| #define counter_pprocess_val | ( | p_no, | ||
| h | ||||
| ) | _cnts_vals[(p_no) * _cnts_row_len + (h).id].v |
Note that if used before counter_prefork_init() process_no is 0 and _cnts_vals will point into a temporary one "row" array.
Definition at line 116 of file counters.h.
Referenced by counter_add(), counter_get_raw_val(), counter_inc(), counter_reset(), and counters_prefork_init().
| static void counter_add | ( | counter_handle_t | handle, | |
| int | v | |||
| ) | [inline, static] |
| handle | - counter handle. | |
| v | - value. |
Definition at line 135 of file counters.h.
References counter_pprocess_val, and process_no.
| char* counter_get_doc | ( | counter_handle_t | handle | ) |
| handle | - counter handle obtained using counter_lookup() or counter_register(). |
Definition at line 721 of file counters.c.
References _cnts_vals.
| char* counter_get_group | ( | counter_handle_t | handle | ) |
| handle | - counter handle obtained using counter_lookup() or counter_register(). |
Definition at line 698 of file counters.c.
References _cnts_vals.
| char* counter_get_name | ( | counter_handle_t | handle | ) |
| handle | - counter handle obtained using counter_lookup() or counter_register(). |
Definition at line 675 of file counters.c.
References _cnts_vals.
| counter_val_t counter_get_raw_val | ( | counter_handle_t | handle | ) |
| handle | - counter handle obtained using counter_lookup() or counter_register(). |
Definition at line 599 of file counters.c.
References _cnts_vals, and counter_pprocess_val.
Referenced by counter_get_val().

| counter_val_t counter_get_val | ( | counter_handle_t | handle | ) |
| handle | - counter handle obtained using counter_lookup() or counter_register(). |
Definition at line 625 of file counters.c.
References _cnts_vals, and counter_get_raw_val().

| static void counter_inc | ( | counter_handle_t | handle | ) | [inline, static] |
| handle | - counter handle. |
Definition at line 124 of file counters.h.
References counter_pprocess_val, and process_no.
Referenced by db_mysql_fetch_result(), db_mysql_new_connection(), db_mysql_store_result(), and db_mysql_submit_query().

| void counter_iterate_grp_names | ( | void(*)(void *p, str *grp_name) | cbk, | |
| void * | p | |||
| ) |
| cbk | - pointer to a callback function that will be called for each group name. | |
| p | - parameter that will be passed to the callback function (along the group name). |
Definition at line 745 of file counters.c.
| void counter_iterate_grp_var_names | ( | const char * | group, | |
| void(*)(void *p, str *var_name) | cbk, | |||
| void * | p | |||
| ) |
| group | - group name. | |
| cbk | - pointer to a callback function that will be called for each variable name. | |
| p | - parameter that will be passed to the callback function (along the variable name). |
Definition at line 762 of file counters.c.
References grp_hash_lookup(), _str::len, and _str::s.

| void counter_iterate_grp_vars | ( | const char * | group, | |
| void(*)(void *p, str *g, str *n, counter_handle_t h) | cbk, | |||
| void * | p | |||
| ) |
| group | - group name. | |
| cbk | - pointer to a callback function that will be called for each [variable name, variable handle] pair. | |
| p | - parameter that will be passed to the callback function (along the group name, variable name and variable handle). |
Definition at line 787 of file counters.c.
References grp_hash_lookup(), _str::len, and _str::s.

| int counter_lookup | ( | counter_handle_t * | handle, | |
| const char * | group, | |||
| const char * | name | |||
| ) |
| handle | - filled with the corresp. handle on success. | |
| group | - counter group name. If 0 or "" the first matching counter with the given name will be returned (k compat). | |
| name | - counter name. |
Definition at line 559 of file counters.c.
References counter_lookup_str(), _str::len, and _str::s.

| handle | - filled with the corresp. handle on success. | |
| group | - counter group name. If "" the first matching counter with the given name will be returned (k compat). | |
| name | - counter name. |
Definition at line 536 of file counters.c.
References cnt_hash_lookup().
Referenced by counter_lookup().


| int counter_register | ( | counter_handle_t * | handle, | |
| const char * | group, | |||
| const char * | name, | |||
| int | flags, | |||
| counter_cbk_f | cbk, | |||
| void * | cbk_param, | |||
| const char * | doc, | |||
| int | reg_flags | |||
| ) |
Can be called only before forking (e.g. from mod_init() or init_child(PROC_INIT)).
| handle | - result parameter, it will be filled with the counter handle on success (can be null if not needed). | |
| group | - group name | |
| name | - counter name (group.name must be unique). | |
| flags | - counter flags: one of CNT_F_*. | |
| cbk | - read callback function (if set it will be called each time someone will call counter_get()). | |
| cbk_param | - callback param. | |
| doc | - description/documentation string. | |
| reg_flags | - register flags: 1 - don't fail if counter already registered (act like counter_lookup(handle, group, name). |
Definition at line 483 of file counters.c.
References cnt_hash_get_create(), cnt_hash_lookup(), _str::len, and _str::s.
Referenced by add_script_counter(), and counter_register_array().


| int counter_register_array | ( | const char * | group, | |
| counter_def_t * | defs | |||
| ) |
| group | - counters group. | |
| defs | - null terminated array containing counters definitions. |
Definition at line 579 of file counters.c.
References counter_register().

| void counter_reset | ( | counter_handle_t | handle | ) |
Reset a counter, unless it has the CNT_F_NO_RESET flag set.
| handle | - counter handle obtained using counter_lookup() or counter_register(). Note: it's racy. |
Definition at line 648 of file counters.c.
References _cnts_vals, and counter_pprocess_val.
| int counters_prefork_init | ( | int | max_process_no | ) |
shm must be available.
Definition at line 187 of file counters.c.
References _cnts_vals, counter_pprocess_val, and process_no.
| int init_counters | ( | void | ) |
Definition at line 102 of file counters.c.
References cnts_hash_table, and grp_hash_table.
| counter_array_t* _cnts_vals |
a[proc_no][counter_id] => _cnst_vals[proc_no*cnts_no+counter_id]
Definition at line 92 of file counters.c.
Referenced by cnt_hash_add(), counter_get_doc(), counter_get_group(), counter_get_name(), counter_get_raw_val(), counter_get_val(), counter_reset(), and counters_prefork_init().
1.7.1