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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef included_stat_segment_h
17 #define included_stat_segment_h
19 #include <stdatomic.h>
20 #include <vlib/vlib.h>
21 #include <vppinfra/socket.h>
23 /* Default socket to exchange segment fd */
24 #define STAT_SEGMENT_SOCKET_FILE "/run/vpp/stats.sock"
28 STAT_DIR_TYPE_ILLEGAL = 0,
29 STAT_DIR_TYPE_SCALAR_INDEX,
30 STAT_DIR_TYPE_COUNTER_VECTOR_SIMPLE,
31 STAT_DIR_TYPE_COUNTER_VECTOR_COMBINED,
32 STAT_DIR_TYPE_ERROR_INDEX,
33 } stat_directory_type_t;
37 STAT_COUNTER_VECTOR_RATE = 0,
38 STAT_COUNTER_INPUT_RATE,
39 STAT_COUNTER_LAST_UPDATE,
40 STAT_COUNTER_LAST_STATS_CLEAR,
41 STAT_COUNTER_HEARTBEAT,
42 STAT_COUNTER_NODE_CLOCKS,
43 STAT_COUNTER_NODE_VECTORS,
44 STAT_COUNTER_NODE_CALLS,
45 STAT_COUNTER_NODE_SUSPENDS,
47 } stat_segment_counter_t;
49 #define foreach_stat_segment_counter_name \
50 _(VECTOR_RATE, SCALAR_INDEX, vector_rate,) \
51 _(INPUT_RATE, SCALAR_INDEX, input_rate,) \
52 _(LAST_UPDATE, SCALAR_INDEX, last_update,) \
53 _(LAST_STATS_CLEAR, SCALAR_INDEX, last_stats_clear,) \
54 _(HEARTBEAT, SCALAR_INDEX, heartbeat,) \
55 _(NODE_CLOCKS, COUNTER_VECTOR_SIMPLE, clocks, /node) \
56 _(NODE_VECTORS, COUNTER_VECTOR_SIMPLE, vectors, /node) \
57 _(NODE_CALLS, COUNTER_VECTOR_SIMPLE, calls, /node) \
58 _(NODE_SUSPENDS, COUNTER_VECTOR_SIMPLE, suspends, /node)
62 stat_directory_type_t type;
68 uint64_t offset_vector;
69 char name[128]; // TODO change this to pointer to "somewhere"
70 } stat_segment_directory_entry_t;
72 /* Default stat segment 32m */
73 #define STAT_SEGMENT_DEFAULT_SIZE (32<<20)
76 * Shared header first in the shared memory segment.
80 atomic_int_fast64_t epoch;
81 atomic_int_fast64_t in_progress;
82 atomic_int_fast64_t directory_offset;
83 atomic_int_fast64_t error_offset;
84 atomic_int_fast64_t stats_offset;
85 } stat_segment_shared_header_t;
87 static inline uint64_t
88 stat_segment_offset (void *start, void *data)
90 return (char *) data - (char *) start;
94 stat_segment_pointer (void *start, uint64_t offset)
96 return ((char *) start + offset);
101 /* statistics segment */
102 uword *directory_vector_by_name;
103 stat_segment_directory_entry_t *directory_vector;
104 clib_spinlock_t *stat_segment_lockp;
105 clib_socket_t *socket;
108 u8 node_counters_enabled;
110 stat_segment_shared_header_t *shared_header; /* pointer to shared memory segment */
113 u64 last_input_packets;
114 } stat_segment_main_t;
116 extern stat_segment_main_t stat_segment_main;