stats: adding symlinks for nodes and interfaces in the stat segment
[vpp.git] / src / vpp / stats / stat_segment.h
1 /*
2  * Copyright (c) 2018 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #ifndef included_stat_segment_h
17 #define included_stat_segment_h
18
19 #include <vlib/vlib.h>
20 #include <vppinfra/socket.h>
21 #include <vpp/stats/stat_segment_shared.h>
22
23 typedef enum
24 {
25  STAT_COUNTER_VECTOR_RATE = 0,
26  STAT_COUNTER_NUM_WORKER_THREADS,
27  STAT_COUNTER_VECTOR_RATE_PER_WORKER,
28  STAT_COUNTER_INPUT_RATE,
29  STAT_COUNTER_LAST_UPDATE,
30  STAT_COUNTER_LAST_STATS_CLEAR,
31  STAT_COUNTER_HEARTBEAT,
32  STAT_COUNTER_NODE_CLOCKS,
33  STAT_COUNTER_NODE_VECTORS,
34  STAT_COUNTER_NODE_CALLS,
35  STAT_COUNTER_NODE_SUSPENDS,
36  STAT_COUNTER_INTERFACE_NAMES,
37  STAT_COUNTER_NODE_NAMES,
38  STAT_COUNTER_MEM_STATSEG_TOTAL,
39  STAT_COUNTER_MEM_STATSEG_USED,
40  STAT_COUNTERS
41 } stat_segment_counter_t;
42
43 /* clang-format off */
44 #define foreach_stat_segment_node_counter_name                                \
45   _ (NODE_CLOCKS, COUNTER_VECTOR_SIMPLE, clocks, /sys/node)                   \
46   _ (NODE_VECTORS, COUNTER_VECTOR_SIMPLE, vectors, /sys/node)                 \
47   _ (NODE_CALLS, COUNTER_VECTOR_SIMPLE, calls, /sys/node)                     \
48   _ (NODE_SUSPENDS, COUNTER_VECTOR_SIMPLE, suspends, /sys/node)
49
50 #define foreach_stat_segment_counter_name                                     \
51   _ (VECTOR_RATE, SCALAR_INDEX, vector_rate, /sys)                            \
52   _ (VECTOR_RATE_PER_WORKER, COUNTER_VECTOR_SIMPLE, vector_rate_per_worker,   \
53      /sys)                                                                    \
54   _ (NUM_WORKER_THREADS, SCALAR_INDEX, num_worker_threads, /sys)              \
55   _ (INPUT_RATE, SCALAR_INDEX, input_rate, /sys)                              \
56   _ (LAST_UPDATE, SCALAR_INDEX, last_update, /sys)                            \
57   _ (LAST_STATS_CLEAR, SCALAR_INDEX, last_stats_clear, /sys)                  \
58   _ (HEARTBEAT, SCALAR_INDEX, heartbeat, /sys)                                \
59   _ (INTERFACE_NAMES, NAME_VECTOR, names, /if)                                \
60   _ (NODE_NAMES, NAME_VECTOR, names, /sys/node)                               \
61   _ (MEM_STATSEG_TOTAL, SCALAR_INDEX, total, /mem/statseg)                    \
62   _ (MEM_STATSEG_USED, SCALAR_INDEX, used, /mem/statseg)                      \
63   foreach_stat_segment_node_counter_name
64 /* clang-format on */
65
66 /* Default stat segment 32m */
67 #define STAT_SEGMENT_DEFAULT_SIZE       (32<<20)
68
69 /* Shared segment memory layout version */
70 #define STAT_SEGMENT_VERSION            2
71
72 #define STAT_SEGMENT_INDEX_INVALID      UINT32_MAX
73
74 typedef void (*stat_segment_update_fn)(stat_segment_directory_entry_t * e, u32 i);
75
76 typedef struct {
77   u32 directory_index;
78   stat_segment_update_fn fn;
79   u32 caller_index;
80 } stat_segment_gauges_pool_t;
81
82 typedef struct
83 {
84   /* internal, does not point to shared memory */
85   stat_segment_gauges_pool_t *gauges;
86
87   /* statistics segment */
88   uword *directory_vector_by_name;
89   stat_segment_directory_entry_t *directory_vector;
90   volatile u64 **error_vector;
91   u8 **interfaces;
92   u8 **nodes;
93
94   /* Update interval */
95   f64 update_interval;
96
97   clib_spinlock_t *stat_segment_lockp;
98   clib_socket_t *socket;
99   u8 *socket_name;
100   ssize_t memory_size;
101   clib_mem_page_sz_t log2_page_sz;
102   u8 node_counters_enabled;
103   void *last;
104   void *heap;
105   stat_segment_shared_header_t *shared_header;  /* pointer to shared memory segment */
106   int memfd;
107
108   u64 last_input_packets; // OLE REMOVE?
109 } stat_segment_main_t;
110
111 extern stat_segment_main_t stat_segment_main;
112
113 clib_error_t *
114 stat_segment_register_gauge (u8 *names, stat_segment_update_fn update_fn, u32 index);
115 clib_error_t *
116 stat_segment_register_state_counter(u8 *name, u32 *index);
117 clib_error_t *
118 stat_segment_deregister_state_counter(u32 index);
119 void stat_segment_set_state_counter (u32 index, u64 value);
120
121 #endif