Defines | Functions | Variables

counters.h File Reference

counter/stats. More...

#include "pt.h"
Include dependency graph for counters.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

Functions

Variables


Detailed Description

:

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 Documentation

#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().


Function Documentation

static void counter_add ( counter_handle_t  handle,
int  v 
) [inline, static]
Parameters:
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  ) 
Parameters:
handle - counter handle obtained using counter_lookup() or counter_register().
Returns:
asciiz pointer on success, 0 on error.

Definition at line 721 of file counters.c.

References _cnts_vals.

char* counter_get_group ( counter_handle_t  handle  ) 
Parameters:
handle - counter handle obtained using counter_lookup() or counter_register().
Returns:
asciiz pointer on success, 0 on error.

Definition at line 698 of file counters.c.

References _cnts_vals.

char* counter_get_name ( counter_handle_t  handle  ) 
Parameters:
handle - counter handle obtained using counter_lookup() or counter_register().
Returns:
asciiz pointer on success, 0 on error.

Definition at line 675 of file counters.c.

References _cnts_vals.

counter_val_t counter_get_raw_val ( counter_handle_t  handle  ) 
Parameters:
handle - counter handle obtained using counter_lookup() or counter_register().
Returns:
counter value.

Definition at line 599 of file counters.c.

References _cnts_vals, and counter_pprocess_val.

Referenced by counter_get_val().

Here is the caller graph for this function:

counter_val_t counter_get_val ( counter_handle_t  handle  ) 
Parameters:
handle - counter handle obtained using counter_lookup() or counter_register().
Returns:
counter value.

Definition at line 625 of file counters.c.

References _cnts_vals, and counter_get_raw_val().

Here is the call graph for this function:

static void counter_inc ( counter_handle_t  handle  )  [inline, static]
Parameters:
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().

Here is the caller graph for this function:

void counter_iterate_grp_names ( void(*)(void *p, str *grp_name)  cbk,
void *  p 
)
Parameters:
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 
)
Parameters:
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.

Here is the call graph for this function:

void counter_iterate_grp_vars ( const char *  group,
void(*)(void *p, str *g, str *n, counter_handle_t h)  cbk,
void *  p 
)
Parameters:
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.

Here is the call graph for this function:

int counter_lookup ( counter_handle_t *  handle,
const char *  group,
const char *  name 
)
Parameters:
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.
Returns:
0 on success, < 0 on error

Definition at line 559 of file counters.c.

References counter_lookup_str(), _str::len, and _str::s.

Here is the call graph for this function:

int counter_lookup_str ( counter_handle_t *  handle,
str group,
str name 
)
Parameters:
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.
Returns:
0 on success, < 0 on error

Definition at line 536 of file counters.c.

References cnt_hash_lookup().

Referenced by counter_lookup().

Here is the call graph for this function:

Here is the caller graph for this function:

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)).

Parameters:
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).
Returns:
0 on succes, < 0 on error (-1 not init or malloc error, -2 already registered (and register_flags & 1 == 0).

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().

Here is the call graph for this function:

Here is the caller graph for this function:

int counter_register_array ( const char *  group,
counter_def_t *  defs 
)
Parameters:
group - counters group.
defs - null terminated array containing counters definitions.
Returns:
0 on success, < 0 on error ( - (counter_number+1))

Definition at line 579 of file counters.c.

References counter_register().

Here is the call graph for this function:

void counter_reset ( counter_handle_t  handle  ) 

Reset a counter, unless it has the CNT_F_NO_RESET flag set.

Parameters:
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.

Returns:
0 on success, < 0 on error

Definition at line 187 of file counters.c.

References _cnts_vals, counter_pprocess_val, and process_no.

int init_counters ( void   ) 
Returns:
0 on success, -1 on error.

Definition at line 102 of file counters.c.

References cnts_hash_table, and grp_hash_table.


Variable Documentation

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().