Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 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 | * node_cli.c: node CLI |
| 17 | * |
| 18 | * Copyright (c) 2008 Eliot Dresselhaus |
| 19 | * |
| 20 | * Permission is hereby granted, free of charge, to any person obtaining |
| 21 | * a copy of this software and associated documentation files (the |
| 22 | * "Software"), to deal in the Software without restriction, including |
| 23 | * without limitation the rights to use, copy, modify, merge, publish, |
| 24 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 25 | * permit persons to whom the Software is furnished to do so, subject to |
| 26 | * the following conditions: |
| 27 | * |
| 28 | * The above copyright notice and this permission notice shall be |
| 29 | * included in all copies or substantial portions of the Software. |
| 30 | * |
| 31 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 32 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 33 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 34 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 35 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 36 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 37 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 38 | */ |
| 39 | |
| 40 | #include <vlib/vlib.h> |
| 41 | #include <vlib/threads.h> |
| 42 | |
Matus Fabian | d2dc3df | 2015-12-14 10:31:33 -0500 | [diff] [blame] | 43 | static int |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 44 | node_cmp (void *a1, void *a2) |
Matus Fabian | d2dc3df | 2015-12-14 10:31:33 -0500 | [diff] [blame] | 45 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 46 | vlib_node_t **n1 = a1; |
| 47 | vlib_node_t **n2 = a2; |
Matus Fabian | d2dc3df | 2015-12-14 10:31:33 -0500 | [diff] [blame] | 48 | |
| 49 | return vec_cmp (n1[0]->name, n2[0]->name); |
| 50 | } |
| 51 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 52 | static clib_error_t * |
| 53 | show_node_graph (vlib_main_t * vm, |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 54 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 55 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 56 | vlib_node_main_t *nm = &vm->node_main; |
| 57 | vlib_node_t *n; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 58 | u32 node_index; |
| 59 | |
| 60 | vlib_cli_output (vm, "%U\n", format_vlib_node_graph, nm, 0); |
| 61 | |
| 62 | if (unformat (input, "%U", unformat_vlib_node, vm, &node_index)) |
| 63 | { |
| 64 | n = vlib_get_node (vm, node_index); |
| 65 | vlib_cli_output (vm, "%U\n", format_vlib_node_graph, nm, n); |
| 66 | } |
| 67 | else |
| 68 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 69 | vlib_node_t **nodes = vec_dup (nm->nodes); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 70 | uword i; |
| 71 | |
Matus Fabian | d2dc3df | 2015-12-14 10:31:33 -0500 | [diff] [blame] | 72 | vec_sort_with_function (nodes, node_cmp); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 73 | |
| 74 | for (i = 0; i < vec_len (nodes); i++) |
| 75 | vlib_cli_output (vm, "%U\n\n", format_vlib_node_graph, nm, nodes[i]); |
| 76 | |
| 77 | vec_free (nodes); |
| 78 | } |
| 79 | |
| 80 | return 0; |
| 81 | } |
| 82 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 83 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 84 | VLIB_CLI_COMMAND (show_node_graph_command, static) = { |
| 85 | .path = "show vlib graph", |
| 86 | .short_help = "Show packet processing node graph", |
| 87 | .function = show_node_graph, |
| 88 | }; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 89 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 90 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 91 | static u8 * |
| 92 | format_vlib_node_stats (u8 * s, va_list * va) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 93 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 94 | vlib_main_t *vm = va_arg (*va, vlib_main_t *); |
| 95 | vlib_node_t *n = va_arg (*va, vlib_node_t *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 96 | int max = va_arg (*va, int); |
| 97 | f64 v; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 98 | char *state; |
| 99 | u8 *ns; |
| 100 | u8 *misc_info = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 101 | u64 c, p, l, d; |
| 102 | f64 x; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 103 | f64 maxc, maxcn; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 104 | u32 maxn; |
| 105 | uword indent; |
| 106 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 107 | if (!n) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 108 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 109 | if (max) |
| 110 | return format (s, |
| 111 | "%=30s%=17s%=16s%=16s%=16s%=16s", |
| 112 | "Name", "Max Node Clocks", "Vectors at Max", |
| 113 | "Max Clocks", "Avg Clocks", "Avg Vectors/Call"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 114 | else |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 115 | return format (s, |
| 116 | "%=30s%=12s%=16s%=16s%=16s%=16s%=16s", |
| 117 | "Name", "State", "Calls", "Vectors", "Suspends", |
| 118 | "Clocks", "Vectors/Call"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | indent = format_get_indent (s); |
| 122 | |
| 123 | l = n->stats_total.clocks - n->stats_last_clear.clocks; |
| 124 | c = n->stats_total.calls - n->stats_last_clear.calls; |
| 125 | p = n->stats_total.vectors - n->stats_last_clear.vectors; |
| 126 | d = n->stats_total.suspends - n->stats_last_clear.suspends; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 127 | maxc = (f64) n->stats_total.max_clock; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 128 | maxn = n->stats_total.max_clock_n; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 129 | if (n->stats_total.max_clock_n) |
| 130 | maxcn = (f64) n->stats_total.max_clock / (f64) maxn; |
| 131 | else |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 132 | maxcn = 0.0; |
| 133 | |
| 134 | /* Clocks per packet, per call or per suspend. */ |
| 135 | x = 0; |
| 136 | if (p > 0) |
| 137 | x = (f64) l / (f64) p; |
| 138 | else if (c > 0) |
| 139 | x = (f64) l / (f64) c; |
| 140 | else if (d > 0) |
| 141 | x = (f64) l / (f64) d; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 142 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 143 | if (c > 0) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 144 | v = (double) p / (double) c; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 145 | else |
| 146 | v = 0; |
| 147 | |
| 148 | state = "active"; |
| 149 | if (n->type == VLIB_NODE_TYPE_PROCESS) |
| 150 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 151 | vlib_process_t *p = vlib_get_process_from_node (vm, n); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 152 | |
| 153 | /* Show processes with events pending. This helps spot bugs where events are not |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 154 | being handled. */ |
| 155 | if (!clib_bitmap_is_zero (p->non_empty_event_type_bitmap)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 156 | misc_info = format (misc_info, "events pending, "); |
| 157 | |
| 158 | switch (p->flags & (VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_CLOCK |
| 159 | | VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_EVENT)) |
| 160 | { |
| 161 | default: |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 162 | if (!(p->flags & VLIB_PROCESS_IS_RUNNING)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 163 | state = "done"; |
| 164 | break; |
| 165 | |
| 166 | case VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_CLOCK: |
| 167 | state = "time wait"; |
| 168 | break; |
| 169 | |
| 170 | case VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_EVENT: |
| 171 | state = "event wait"; |
| 172 | break; |
| 173 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 174 | case (VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_EVENT | VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_CLOCK): |
| 175 | state = |
| 176 | "any wait"; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 177 | break; |
| 178 | } |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 179 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 180 | else if (n->type != VLIB_NODE_TYPE_INTERNAL) |
| 181 | { |
| 182 | state = "polling"; |
| 183 | if (n->state == VLIB_NODE_STATE_DISABLED) |
| 184 | state = "disabled"; |
| 185 | else if (n->state == VLIB_NODE_STATE_INTERRUPT) |
| 186 | state = "interrupt wait"; |
| 187 | } |
| 188 | |
| 189 | ns = n->name; |
| 190 | |
| 191 | if (max) |
| 192 | s = format (s, "%-30v%=17.2e%=16d%=16.2e%=16.2e%=16.2e", |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 193 | ns, maxc, maxn, maxcn, x, v); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 194 | else |
| 195 | s = format (s, "%-30v%=12s%16Ld%16Ld%16Ld%16.2e%16.2f", ns, state, |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 196 | c, p, d, x, v); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 197 | |
| 198 | if (ns != n->name) |
| 199 | vec_free (ns); |
| 200 | |
| 201 | if (misc_info) |
| 202 | { |
| 203 | s = format (s, "\n%U%v", format_white_space, indent + 4, misc_info); |
| 204 | vec_free (misc_info); |
| 205 | } |
| 206 | |
| 207 | return s; |
| 208 | } |
| 209 | |
| 210 | static clib_error_t * |
| 211 | show_node_runtime (vlib_main_t * vm, |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 212 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 213 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 214 | vlib_node_main_t *nm = &vm->node_main; |
| 215 | vlib_node_t *n; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 216 | f64 time_now; |
| 217 | u32 node_index; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 218 | vlib_node_t ***node_dups = 0; |
| 219 | f64 *vectors_per_main_loop = 0; |
| 220 | f64 *last_vector_length_per_node = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 221 | |
| 222 | time_now = vlib_time_now (vm); |
| 223 | |
| 224 | if (unformat (input, "%U", unformat_vlib_node, vm, &node_index)) |
| 225 | { |
| 226 | n = vlib_get_node (vm, node_index); |
| 227 | vlib_node_sync_stats (vm, n); |
| 228 | vlib_cli_output (vm, "%U\n", format_vlib_node_stats, vm, 0, 0); |
| 229 | vlib_cli_output (vm, "%U\n", format_vlib_node_stats, vm, n, 0); |
| 230 | } |
| 231 | else |
| 232 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 233 | vlib_node_t **nodes; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 234 | uword i, j; |
| 235 | f64 dt; |
| 236 | u64 n_input, n_output, n_drop, n_punt; |
| 237 | u64 n_internal_vectors, n_internal_calls; |
| 238 | u64 n_clocks, l, v, c, d; |
| 239 | int brief = 1; |
| 240 | int max = 0; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 241 | vlib_main_t **stat_vms = 0, *stat_vm; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 242 | |
| 243 | /* Suppress nodes with zero calls since last clear */ |
| 244 | if (unformat (input, "brief") || unformat (input, "b")) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 245 | brief = 1; |
| 246 | if (unformat (input, "verbose") || unformat (input, "v")) |
| 247 | brief = 0; |
| 248 | if (unformat (input, "max") || unformat (input, "m")) |
| 249 | max = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 250 | |
Dave Barach | 80f54e2 | 2017-03-08 19:08:56 -0500 | [diff] [blame] | 251 | for (i = 0; i < vec_len (vlib_mains); i++) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 252 | { |
Dave Barach | 80f54e2 | 2017-03-08 19:08:56 -0500 | [diff] [blame] | 253 | stat_vm = vlib_mains[i]; |
| 254 | if (stat_vm) |
| 255 | vec_add1 (stat_vms, stat_vm); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 256 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 257 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 258 | /* |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 259 | * Barrier sync across stats scraping. |
| 260 | * Otherwise, the counts will be grossly inaccurate. |
| 261 | */ |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 262 | vlib_worker_thread_barrier_sync (vm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 263 | |
| 264 | for (j = 0; j < vec_len (stat_vms); j++) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 265 | { |
| 266 | stat_vm = stat_vms[j]; |
| 267 | nm = &stat_vm->node_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 268 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 269 | for (i = 0; i < vec_len (nm->nodes); i++) |
| 270 | { |
| 271 | n = nm->nodes[i]; |
| 272 | vlib_node_sync_stats (stat_vm, n); |
| 273 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 274 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 275 | nodes = vec_dup (nm->nodes); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 276 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 277 | vec_add1 (node_dups, nodes); |
| 278 | vec_add1 (vectors_per_main_loop, |
| 279 | vlib_last_vectors_per_main_loop_as_f64 (stat_vm)); |
| 280 | vec_add1 (last_vector_length_per_node, |
| 281 | vlib_last_vector_length_per_node (stat_vm)); |
| 282 | } |
| 283 | vlib_worker_thread_barrier_release (vm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 284 | |
| 285 | |
| 286 | for (j = 0; j < vec_len (stat_vms); j++) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 287 | { |
| 288 | stat_vm = stat_vms[j]; |
| 289 | nodes = node_dups[j]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 290 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 291 | vec_sort_with_function (nodes, node_cmp); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 292 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 293 | n_input = n_output = n_drop = n_punt = n_clocks = 0; |
| 294 | n_internal_vectors = n_internal_calls = 0; |
| 295 | for (i = 0; i < vec_len (nodes); i++) |
| 296 | { |
| 297 | n = nodes[i]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 298 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 299 | l = n->stats_total.clocks - n->stats_last_clear.clocks; |
| 300 | n_clocks += l; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 301 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 302 | v = n->stats_total.vectors - n->stats_last_clear.vectors; |
| 303 | c = n->stats_total.calls - n->stats_last_clear.calls; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 304 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 305 | switch (n->type) |
| 306 | { |
| 307 | default: |
| 308 | continue; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 309 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 310 | case VLIB_NODE_TYPE_INTERNAL: |
| 311 | n_output += (n->flags & VLIB_NODE_FLAG_IS_OUTPUT) ? v : 0; |
| 312 | n_drop += (n->flags & VLIB_NODE_FLAG_IS_DROP) ? v : 0; |
| 313 | n_punt += (n->flags & VLIB_NODE_FLAG_IS_PUNT) ? v : 0; |
| 314 | if (!(n->flags & VLIB_NODE_FLAG_IS_OUTPUT)) |
| 315 | { |
| 316 | n_internal_vectors += v; |
| 317 | n_internal_calls += c; |
| 318 | } |
| 319 | if (n->flags & VLIB_NODE_FLAG_IS_HANDOFF) |
| 320 | n_input += v; |
| 321 | break; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 322 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 323 | case VLIB_NODE_TYPE_INPUT: |
| 324 | n_input += v; |
| 325 | break; |
| 326 | } |
| 327 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 328 | |
Dave Barach | 80f54e2 | 2017-03-08 19:08:56 -0500 | [diff] [blame] | 329 | if (vec_len (vlib_mains) > 1) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 330 | { |
| 331 | vlib_worker_thread_t *w = vlib_worker_threads + j; |
| 332 | if (j > 0) |
| 333 | vlib_cli_output (vm, "---------------"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 334 | |
Pavel Kotucek | 9876520 | 2016-10-07 08:37:28 +0200 | [diff] [blame] | 335 | if (w->lcore_id > -1) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 336 | vlib_cli_output (vm, "Thread %d %s (lcore %u)", j, w->name, |
Pavel Kotucek | 9876520 | 2016-10-07 08:37:28 +0200 | [diff] [blame] | 337 | w->lcore_id); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 338 | else |
| 339 | vlib_cli_output (vm, "Thread %d %s", j, w->name); |
| 340 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 341 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 342 | dt = time_now - nm->time_last_runtime_stats_clear; |
| 343 | vlib_cli_output |
| 344 | (vm, |
| 345 | "Time %.1f, average vectors/node %.2f, last %d main loops %.2f per node %.2f" |
| 346 | "\n vector rates in %.4e, out %.4e, drop %.4e, punt %.4e", |
| 347 | dt, |
| 348 | (n_internal_calls > 0 |
| 349 | ? (f64) n_internal_vectors / (f64) n_internal_calls |
| 350 | : 0), |
| 351 | 1 << VLIB_LOG2_MAIN_LOOPS_PER_STATS_UPDATE, |
| 352 | vectors_per_main_loop[j], |
| 353 | last_vector_length_per_node[j], |
| 354 | (f64) n_input / dt, |
| 355 | (f64) n_output / dt, (f64) n_drop / dt, (f64) n_punt / dt); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 356 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 357 | vlib_cli_output (vm, "%U", format_vlib_node_stats, stat_vm, 0, max); |
| 358 | for (i = 0; i < vec_len (nodes); i++) |
| 359 | { |
| 360 | c = |
| 361 | nodes[i]->stats_total.calls - |
| 362 | nodes[i]->stats_last_clear.calls; |
| 363 | d = |
| 364 | nodes[i]->stats_total.suspends - |
| 365 | nodes[i]->stats_last_clear.suspends; |
| 366 | if (c || d || !brief) |
| 367 | { |
| 368 | vlib_cli_output (vm, "%U", format_vlib_node_stats, stat_vm, |
| 369 | nodes[i], max); |
| 370 | } |
| 371 | } |
| 372 | vec_free (nodes); |
| 373 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 374 | vec_free (stat_vms); |
| 375 | vec_free (node_dups); |
| 376 | vec_free (vectors_per_main_loop); |
| 377 | vec_free (last_vector_length_per_node); |
| 378 | } |
| 379 | |
| 380 | return 0; |
| 381 | } |
| 382 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 383 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 384 | VLIB_CLI_COMMAND (show_node_runtime_command, static) = { |
| 385 | .path = "show runtime", |
| 386 | .short_help = "Show packet processing runtime", |
| 387 | .function = show_node_runtime, |
| 388 | .is_mp_safe = 1, |
| 389 | }; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 390 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 391 | |
| 392 | static clib_error_t * |
| 393 | clear_node_runtime (vlib_main_t * vm, |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 394 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 395 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 396 | vlib_node_main_t *nm; |
| 397 | vlib_node_t *n; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 398 | int i, j; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 399 | vlib_main_t **stat_vms = 0, *stat_vm; |
| 400 | vlib_node_runtime_t *r; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 401 | |
Dave Barach | 80f54e2 | 2017-03-08 19:08:56 -0500 | [diff] [blame] | 402 | for (i = 0; i < vec_len (vlib_mains); i++) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 403 | { |
Dave Barach | 80f54e2 | 2017-03-08 19:08:56 -0500 | [diff] [blame] | 404 | stat_vm = vlib_mains[i]; |
| 405 | if (stat_vm) |
| 406 | vec_add1 (stat_vms, stat_vm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 407 | } |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 408 | |
| 409 | vlib_worker_thread_barrier_sync (vm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 410 | |
| 411 | for (j = 0; j < vec_len (stat_vms); j++) |
| 412 | { |
| 413 | stat_vm = stat_vms[j]; |
| 414 | nm = &stat_vm->node_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 415 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 416 | for (i = 0; i < vec_len (nm->nodes); i++) |
| 417 | { |
| 418 | n = nm->nodes[i]; |
| 419 | vlib_node_sync_stats (stat_vm, n); |
| 420 | n->stats_last_clear = n->stats_total; |
| 421 | |
| 422 | r = vlib_node_get_runtime (stat_vm, n->index); |
| 423 | r->max_clock = 0; |
| 424 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 425 | /* Note: input/output rates computed using vlib_global_main */ |
| 426 | nm->time_last_runtime_stats_clear = vlib_time_now (vm); |
| 427 | } |
| 428 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 429 | vlib_worker_thread_barrier_release (vm); |
| 430 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 431 | vec_free (stat_vms); |
| 432 | |
| 433 | return 0; |
| 434 | } |
| 435 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 436 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 437 | VLIB_CLI_COMMAND (clear_node_runtime_command, static) = { |
| 438 | .path = "clear runtime", |
| 439 | .short_help = "Clear packet processing runtime statistics", |
| 440 | .function = clear_node_runtime, |
| 441 | }; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 442 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 443 | |
| 444 | /* Dummy function to get us linked in. */ |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 445 | void |
| 446 | vlib_node_cli_reference (void) |
| 447 | { |
| 448 | } |
| 449 | |
| 450 | /* |
| 451 | * fd.io coding-style-patch-verification: ON |
| 452 | * |
| 453 | * Local Variables: |
| 454 | * eval: (c-set-style "gnu") |
| 455 | * End: |
| 456 | */ |