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>
38 #include <vlibapi/api.h>
39 #include <vlibmemory/api.h>
41 #include <vlib/vlib.h>
42 #include <vlib/unix/unix.h>
47 svmdb_client_t *svmdb_client;
51 vlib_main_t *vlib_main;
55 static inline u64 vnet_get_aggregate_rx_packets (void)
58 #include <vnet/vnet.h>
59 #include <vnet/devices/dpdk/dpdk.h>
62 gmon_main_t gmon_main;
65 gmon_process (vlib_main_t * vm,
66 vlib_node_runtime_t * rt,
70 u64 input_packets, last_input_packets;
71 f64 last_runtime, dt, now;
72 gmon_main_t *gm = &gmon_main;
76 *gm->vpef_pid_ptr = vpefpid;
79 last_input_packets = 0;
82 last_input_packets = 0;
85 vlib_process_suspend (vm, 5.0);
86 vector_rate = vlib_last_vector_length_per_node (vm);
87 *gm->vector_rate_ptr = vector_rate;
88 now = vlib_time_now(vm);
89 dt = now - last_runtime;
90 input_packets = vnet_get_aggregate_rx_packets();
91 *gm->input_rate_ptr = (f64)(input_packets - last_input_packets) / dt;
93 last_input_packets = input_packets;
96 return 0; /* not so much */
99 VLIB_REGISTER_NODE (gmon_process_node,static) = {
100 .function = gmon_process,
101 .type = VLIB_NODE_TYPE_PROCESS,
102 .name = "gmon-process",
105 static clib_error_t *
106 gmon_init (vlib_main_t *vm)
108 gmon_main_t *gm = &gmon_main;
109 api_main_t * am = &api_main;
114 gm->svmdb_client = svmdb_map_chroot(am->root_path);
116 /* Find or create, set to zero */
118 svmdb_local_set_vec_variable(gm->svmdb_client,
120 (char *)v, sizeof (*v));
123 svmdb_local_set_vec_variable(gm->svmdb_client,
125 (char *)v, sizeof (*v));
129 svmdb_local_set_vec_variable(gm->svmdb_client,
131 (char *)swp, sizeof (*swp));
134 /* the value cell will never move, so acquire a reference to it */
135 gm->vector_rate_ptr =
136 svmdb_local_get_variable_reference (gm->svmdb_client,
140 svmdb_local_get_variable_reference (gm->svmdb_client,
144 svmdb_local_get_variable_reference (gm->svmdb_client,
150 VLIB_INIT_FUNCTION (gmon_init);
152 static clib_error_t *gmon_exit (vlib_main_t *vm)
154 gmon_main_t *gm = &gmon_main;
156 if (gm->vector_rate_ptr) {
157 *gm->vector_rate_ptr = 0.0;
158 *gm->vpef_pid_ptr = 0;
159 *gm->input_rate_ptr = 0.0;
160 svmdb_unmap (gm->svmdb_client);
164 VLIB_MAIN_LOOP_EXIT_FUNCTION (gmon_exit);