2 * Copyright (c) 2012 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.
18 #include <sys/types.h>
21 #include <netinet/in.h>
28 #include <vppinfra/clib.h>
29 #include <vppinfra/vec.h>
30 #include <vppinfra/hash.h>
31 #include <vppinfra/bitmap.h>
32 #include <vppinfra/fifo.h>
33 #include <vppinfra/time.h>
34 #include <vppinfra/mheap.h>
35 #include <vppinfra/heap.h>
36 #include <vppinfra/pool.h>
37 #include <vppinfra/format.h>
39 #include <vlib/vlib.h>
40 #include <vlib/unix/unix.h>
45 svmdb_client_t *svmdb_client;
49 vlib_main_t *vlib_main;
53 static inline u64 vnet_get_aggregate_rx_packets (void)
56 #include <vnet/vnet.h>
57 #include <vnet/devices/dpdk/dpdk.h>
60 gmon_main_t gmon_main;
63 gmon_process (vlib_main_t * vm,
64 vlib_node_runtime_t * rt,
68 u64 input_packets, last_input_packets;
69 f64 last_runtime, dt, now;
70 gmon_main_t *gm = &gmon_main;
74 *gm->vpef_pid_ptr = vpefpid;
77 last_input_packets = 0;
80 last_input_packets = 0;
83 vlib_process_suspend (vm, 5.0);
84 vector_rate = vlib_last_vector_length_per_node (vm);
85 *gm->vector_rate_ptr = vector_rate;
86 now = vlib_time_now(vm);
87 dt = now - last_runtime;
88 input_packets = vnet_get_aggregate_rx_packets();
89 *gm->input_rate_ptr = (f64)(input_packets - last_input_packets) / dt;
91 last_input_packets = input_packets;
94 return 0; /* not so much */
97 VLIB_REGISTER_NODE (gmon_process_node,static) = {
98 .function = gmon_process,
99 .type = VLIB_NODE_TYPE_PROCESS,
100 .name = "gmon-process",
103 static clib_error_t *
104 gmon_init (vlib_main_t *vm)
106 gmon_main_t *gm = &gmon_main;
111 gm->svmdb_client = svmdb_map();
113 /* Find or create, set to zero */
115 svmdb_local_set_vec_variable(gm->svmdb_client,
117 (char *)v, sizeof (*v));
120 svmdb_local_set_vec_variable(gm->svmdb_client,
122 (char *)v, sizeof (*v));
126 svmdb_local_set_vec_variable(gm->svmdb_client,
128 (char *)swp, sizeof (*swp));
131 /* the value cell will never move, so acquire a reference to it */
132 gm->vector_rate_ptr =
133 svmdb_local_get_variable_reference (gm->svmdb_client,
137 svmdb_local_get_variable_reference (gm->svmdb_client,
141 svmdb_local_get_variable_reference (gm->svmdb_client,
147 VLIB_INIT_FUNCTION (gmon_init);
149 static clib_error_t *gmon_exit (vlib_main_t *vm)
151 gmon_main_t *gm = &gmon_main;
153 if (gm->vector_rate_ptr) {
154 *gm->vector_rate_ptr = 0.0;
155 *gm->vpef_pid_ptr = 0;
156 *gm->input_rate_ptr = 0.0;
157 svmdb_unmap (gm->svmdb_client);
161 VLIB_MAIN_LOOP_EXIT_FUNCTION (gmon_exit);