2 * Copyright (c) 2016 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>
43 #include <vnet/api_errno.h>
48 volatile int signal_received;
51 unix_signal_handler (int signum, siginfo_t * si, ucontext_t * uc)
63 setup_signal_handlers (void)
68 for (i = 1; i < 32; i++)
70 memset (&sa, 0, sizeof (sa));
71 sa.sa_sigaction = (void *) unix_signal_handler;
72 sa.sa_flags = SA_SIGINFO;
76 /* these signals take the default action */
84 /* ignore SIGPIPE, SIGCHLD */
87 sa.sa_sigaction = (void *) SIG_IGN;
90 /* catch and handle all other signals */
95 if (sigaction (i, &sa, 0) < 0)
96 return clib_unix_warning (0, "sigaction %U", format_signal, i);
101 main (int argc, char **argv)
103 unformat_input_t input;
104 char *chroot_path = 0;
107 f64 *vector_ratep, *rx_ratep, *sig_error_ratep;
110 unformat_init_command_line (&input, argv);
112 while (unformat_check_input (&input) != UNFORMAT_END_OF_INPUT)
114 if (unformat (&input, "chroot %s", &chroot_path_u8))
116 chroot_path = (char *) chroot_path_u8;
118 else if (unformat (&input, "interval %d", &interval))
123 "usage: vpp_get_metrics [chroot <path>] [interval <nn>]\n");
128 setup_signal_handlers ();
130 c = svmdb_map_chroot (chroot_path);
133 svmdb_local_get_variable_reference (c, SVMDB_NAMESPACE_VEC, "vpp_pid");
135 svmdb_local_get_variable_reference (c, SVMDB_NAMESPACE_VEC,
138 svmdb_local_get_variable_reference (c, SVMDB_NAMESPACE_VEC,
141 svmdb_local_get_variable_reference (c, SVMDB_NAMESPACE_VEC,
142 "vpp_sig_error_rate");
145 * Make sure vpp is actually running. Otherwise, there's every
146 * chance that the database region will be wiped out by the
147 * process monitor script
150 if (vpp_pidp == 0 || vector_ratep == 0 || rx_ratep == 0
151 || sig_error_ratep == 0)
153 fformat (stdout, "vpp not running\n");
159 /* Once vpp exits, the svm db region will be recreated... */
160 if (*vpp_pidp == 0 || kill (*vpp_pidp, 0) < 0)
162 fformat (stdout, "vpp not running\n");
166 "%d: vpp_vector_rate=%.2f, vpp_input_rate=%f, vpp_sig_error_rate=%f\n",
167 *vpp_pidp, *vector_ratep, *rx_ratep, *sig_error_ratep);
181 * fd.io coding-style-patch-verification: ON
184 * eval: (c-set-style "gnu")