22 #undef HAVE_MEMFD_CREATE 102 next_vector_index =
i;
107 return next_vector_index;
146 memset (e, 0,
sizeof (*e));
168 char *stat_segment_name =
178 memset (e, 0,
sizeof (*e));
191 char *stat_segment_name;
218 strncpy (e.
name, stat_segment_name, 128 - 1);
321 char *mem_name =
"stat segment";
322 void *heap, *memaddr;
325 if (memory_size == 0)
337 if ((ftruncate (mfd, memory_size)) == -1)
357 shared_header->
base = memaddr;
367 shared_header->
epoch = 1;
372 strcpy(sm->directory_vector[STAT_COUNTER_##E].name, #p "/" #n); \ 373 sm->directory_vector[STAT_COUNTER_##E].type = STAT_DIR_TYPE_##t; 396 return strcmp ((
char *) n1->
name, (
char *) n2->
name);
407 format_string =
"%-74s %-10s %10lld";
412 type_name =
"ScalarPtr";
417 type_name =
"CMainPtr";
421 type_name =
"ErrIndex";
425 type_name =
"NameVector";
433 type_name =
"illegal!";
437 return format (s, format_string, ep->
name, type_name, 0);
463 for (i = 0; i <
vec_len (show_data); i++)
487 .path =
"show statistics segment",
488 .short_help =
"show statistics segment [verbose]",
507 static u32 no_max_nodes = 0;
513 &node_dups, &stat_vms);
520 if (l > no_max_nodes)
542 for (i = 0; i <
vec_len (nodes); i++)
556 for (j = 0; j <
vec_len (node_dups); j++)
560 for (i = 0; i <
vec_len (nodes); i++)
598 static int num_worker_threads_set;
612 num_worker_threads_set = 1;
626 f64 this_vector_rate;
633 vector_rate += this_vector_rate;
642 vector_rate /= (
f64) (i > 1 ? i - 1 : 1);
724 template.file_descriptor = s->fd;
725 template.description =
format (0,
"stats segment listener %s", s->config);
803 memset (&e, 0,
sizeof (e));
818 gauge->
fn = update_fn;
841 memset (&e, 0,
sizeof (e));
855 *index = vector_index;
907 else if (
unformat (input,
"default"))
909 else if (
unformat (input,
"size %U",
912 else if (
unformat (input,
"page-size %U",
915 else if (
unformat (input,
"per-node-counters on"))
917 else if (
unformat (input,
"per-node-counters off"))
986 .name =
"statseg-collector-process",
static clib_error_t * statseg_config(vlib_main_t *vm, unformat_input_t *input)
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
static void stat_set_simple_counter(stat_segment_directory_entry_t *ep, u32 thread_index, u32 index, u64 value)
__clib_export int clib_mem_vm_create_fd(clib_mem_page_sz_t log2_page_size, char *fmt,...)
void vlib_node_get_nodes(vlib_main_t *vm, u32 max_threads, int include_stats, int barrier_sync, vlib_node_t ****node_dupsp, vlib_main_t ***stat_vmsp)
Get list of nodes.
#define CLIB_MEM_VM_MAP_FAILED
#define hash_set(h, key, value)
static_always_inline void clib_spinlock_unlock(clib_spinlock_t *p)
static_always_inline void clib_spinlock_lock(clib_spinlock_t *p)
void vlib_stats_pop_heap2(u64 *error_vector, u32 thread_index, void *oldheap, int lock)
stat_segment_gauges_pool_t * gauges
#define hash_unset(h, key)
static u64 vnet_get_aggregate_rx_packets(void)
stat_segment_shared_header_t * shared_header
static clib_error_t * stats_socket_accept_ready(clib_file_t *uf)
stat_segment_main_t stat_segment_main
#define pool_foreach(VAR, POOL)
Iterate through pool.
void clib_mem_get_heap_usage(clib_mem_heap_t *heap, clib_mem_usage_t *usage)
clib_mem_heap_t * clib_mem_create_heap(void *base, uword size, int is_locked, char *fmt,...)
stat_segment_directory_entry_t * directory_vector
__clib_export void * clib_mem_vm_map_shared(void *base, uword size, int fd, uword offset, char *fmt,...)
static f64 vlib_time_now(vlib_main_t *vm)
static clib_mem_heap_t * clib_mem_set_heap(clib_mem_heap_t *heap)
static void stat_validate_counter_vector(stat_segment_directory_entry_t *ep, u32 max)
#define STAT_SEGMENT_DEFAULT_SIZE
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
#define vec_terminate_c_string(V)
(If necessary) NULL terminate a vector containing a c-string.
void * vlib_stats_push_heap(void *old)
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
#define foreach_stat_segment_counter_name
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
#define vec_foreach_index_backwards(var, v)
Iterate over vector indices (reverse).
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
static_always_inline uword clib_mem_get_page_size(void)
vlib_main_t ** vlib_mains
void(* stat_segment_update_fn)(stat_segment_directory_entry_t *e, u32 i)
__clib_export clib_error_t * clib_socket_init(clib_socket_t *s)
clib_file_function_t * read_function
static void create_hash_index(u8 *name, u32 index)
#define CLIB_SOCKET_F_IS_SERVER
static u32 vlib_stats_get_next_vector_index()
static uword vlib_process_suspend(vlib_main_t *vm, f64 dt)
Suspend a vlib cooperative multi-tasking thread for a period of time.
vlib_node_stats_t stats_last_clear
static void do_stat_segment_updates(stat_segment_main_t *sm)
#define VLIB_INIT_FUNCTION(x)
static u32 vlib_stats_create_counter(stat_segment_directory_entry_t *e, void *oldheap)
void vlib_stats_pop_heap(void *cm_arg, void *oldheap, u32 cindex, stat_directory_type_t type)
static char * vlib_unix_get_runtime_dir(void)
static clib_error_t * clib_socket_sendmsg(clib_socket_t *s, void *msg, int msglen, int fds[], int num_fds)
uint64_t counter_t
64bit counters
description fragment has unexpected format
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
static vnet_sw_interface_t * vnet_get_sup_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
#define clib_error_return(e, args...)
clib_file_main_t file_main
#define hash_get_pair(h, key)
stat_segment_update_fn fn
static clib_error_t * statseg_init(vlib_main_t *vm)
A collection of simple counters.
static u32 lookup_hash_index(u8 *name)
static clib_error_t * stats_segment_socket_init(void)
#define hash_create_string(elts, value_bytes)
static void clib_spinlock_init(clib_spinlock_t *p)
char * name
The counter collection's name.
vl_api_fib_path_type_t type
static void vlib_stats_delete_counter(u32 index, void *oldheap)
vlib_node_stats_t stats_total
f64 time_last_runtime_stats_clear
static clib_error_t * clib_socket_close(clib_socket_t *sock)
static u8 * format_stat_dir_entry(u8 *s, va_list *args)
void vlib_stat_segment_unlock(void)
static clib_error_t * stats_segment_socket_exit(vlib_main_t *vm)
#define vec_dup(V)
Return copy of vector (no header, no alignment)
#define VLIB_EARLY_CONFIG_FUNCTION(x, n,...)
#define VLIB_REGISTER_NODE(x,...)
clib_error_t * stat_segment_register_gauge(u8 *name, stat_segment_update_fn update_fn, u32 caller_index)
static_always_inline uword vlib_get_thread_index(void)
sll srl srl sll sra u16x4 i
#define vec_free(V)
Free vector's memory (no header).
static void vlib_clear_internal_node_vector_rate(vlib_main_t *vm)
__clib_export clib_error_t * clib_socket_accept(clib_socket_t *server, clib_socket_t *client)
#define VLIB_MAIN_LOOP_EXIT_FUNCTION(x)
static vlib_node_registration_t stat_segment_collector
(constructor) VLIB_REGISTER_NODE (stat_segment_collector)
void vlib_stat_segment_lock(void)
VNET_SW_INTERFACE_ADD_DEL_FUNCTION(statseg_sw_interface_add_del)
#define STAT_SEGMENT_SOCKET_FILENAME
#define VLIB_CLI_COMMAND(x,...)
static clib_mem_heap_t * clib_mem_get_heap(void)
clib_error_t * stat_segment_deregister_state_counter(u32 index)
u8 * format_clib_mem_heap(u8 *s, va_list *va)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
static uword clib_file_add(clib_file_main_t *um, clib_file_t *template)
f64 vlib_get_stat_segment_update_rate(void)
#define clib_error_report(e)
struct _socket_t clib_socket_t
static void * clib_mem_alloc(uword size)
#define CLIB_SOCKET_F_SEQPACKET
#define STAT_SEGMENT_VERSION
volatile u64 ** error_vector
static_always_inline clib_error_t * clib_mem_get_last_error(void)
static uword stat_segment_collector_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
uword * directory_vector_by_name
char * stat_segment_name
Name in stat segment directory.
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
vlib_node_main_t node_main
#define CLIB_SOCKET_F_PASSCRED
static void update_node_counters(stat_segment_main_t *sm)
#define vec_sort_with_function(vec, f)
Sort a vector using the supplied element comparison function.
static int name_sort_cmp(void *a1, void *a2)
static clib_error_t * statseg_sw_interface_add_del(vnet_main_t *vnm, u32 sw_if_index, u32 is_add)
static clib_error_t * show_stat_segment_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
counter_t ** counters
Per-thread u64 non-atomic counters.
vnet_sw_interface_type_t type
static vlib_thread_main_t * vlib_get_thread_main()
void vlib_stats_delete_cm(void *cm_arg)
void vlib_stats_register_error_index(void *oldheap, u8 *name, u64 *em_vec, u64 index)
#define CLIB_CACHE_LINE_BYTES
#define CLIB_SOCKET_F_ALLOW_GROUP_WRITE
clib_error_t * vlib_map_stat_segment_init(void)
static f64 vlib_internal_node_vector_rate(vlib_main_t *vm)
__clib_export u8 * format_clib_error(u8 *s, va_list *va)
#define STAT_SEGMENT_INDEX_INVALID
clib_mem_page_sz_t log2_page_sz
vl_api_interface_index_t sw_if_index
clib_error_t * stat_segment_register_state_counter(u8 *name, u32 *index)
void stat_segment_set_state_counter(u32 index, u64 value)
clib_spinlock_t * stat_segment_lockp
stat_directory_type_t type