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:
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 * node_cli.c: node CLI
18 * Copyright (c) 2008 Eliot Dresselhaus
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:
28 * The above copyright notice and this permission notice shall be
29 * included in all copies or substantial portions of the Software.
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.
40 #include <sys/types.h>
43 #include <vlib/vlib.h>
44 #include <vlib/threads.h>
45 #include <vlib/stats/stats.h>
49 node_cmp (void *a1, void *a2)
51 vlib_node_t **n1 = a1;
52 vlib_node_t **n2 = a2;
54 return vec_cmp (n1[0]->name, n2[0]->name);
58 show_node_graph (vlib_main_t * vm,
59 unformat_input_t * input, vlib_cli_command_t * cmd)
61 vlib_node_main_t *nm = &vm->node_main;
65 vlib_cli_output (vm, "%U\n", format_vlib_node_graph, nm, 0);
67 if (unformat (input, "%U", unformat_vlib_node, vm, &node_index))
69 n = vlib_get_node (vm, node_index);
70 vlib_cli_output (vm, "%U\n", format_vlib_node_graph, nm, n);
74 vlib_node_t **nodes = vec_dup (nm->nodes);
77 vec_sort_with_function (nodes, node_cmp);
79 for (i = 0; i < vec_len (nodes); i++)
80 vlib_cli_output (vm, "%U\n\n", format_vlib_node_graph, nm, nodes[i]);
89 VLIB_CLI_COMMAND (show_node_graph_command, static) = {
90 .path = "show vlib graph",
91 .short_help = "Show packet processing node graph",
92 .function = show_node_graph,
97 show_node_graphviz (vlib_main_t * vm,
98 unformat_input_t * input, vlib_cli_command_t * cmd)
100 clib_error_t *error = 0;
101 vlib_node_main_t *nm = &vm->node_main;
102 vlib_node_t **nodes = nm->nodes;
103 u8 *chroot_filename = 0;
107 unformat_input_t _line_input, *line_input = &_line_input;
108 u8 filter = 0, calls_filter = 0, vectors_filter = 0, both = 0;
111 /* Get a line of input. */
112 if (unformat_user (input, unformat_line_input, line_input))
114 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
116 if (unformat (line_input, "filter"))
118 else if (unformat (line_input, "calls") && filter)
120 else if (unformat (line_input, "vectors") && filter)
122 else if (unformat (line_input, "file %U", unformat_vlib_tmpfile,
125 fd = open ((char *) chroot_filename,
126 O_CREAT | O_TRUNC | O_WRONLY, 0664);
129 return clib_error_return (0, "unknown input `%U'",
130 format_unformat_error, input);
132 unformat_free (line_input);
135 /*both is set to true if calls_filter and vectors_filter are, or neither */
136 both = filter & (!(calls_filter ^ vectors_filter));
138 #define format__(vm__, fd__, ...) \
141 vlib_cli_output((vm__), ## __VA_ARGS__); \
145 fdformat((fd__), ## __VA_ARGS__); \
148 format__ (vm, fd, "%s", "digraph {\n");
150 clib_bitmap_alloc (active, vec_len (nodes));
151 clib_bitmap_set_region (active, 0, 1, vec_len (nodes));
154 /*Adding the legend to the dot file*/
155 format__ (vm, fd, "%s",
156 " rankdir=\"LR\"\n nodesep=2\n subgraph cluster_legend {\n "
157 " label=\"Legend\"\n style=\"solid\"\n labelloc = b\n "
158 " subgraph cluster_colors {\n label=\"Packets/Call\"\n "
159 " style=\"solid\"\n labelloc = b\n");
160 format__ (vm, fd, "%s",
161 " 0 [label=\"No packet\", fixedsize=true shape=circle "
162 "width=2 fontsize=17]\n"
163 " 1 [label=\"1-32\", fillcolor=1 style=filled "
164 "colorscheme=ylorrd8 fixedsize=true shape=circle width=2 "
166 " 2 [label=\"33-64\", fillcolor=2 style=filled "
167 "colorscheme=ylorrd8 fixedsize=true shape=circle width=2 "
169 " 3 [label=\"65-96\", fillcolor=3 style=filled "
170 "colorscheme=ylorrd8 fixedsize=true shape=circle width=2 "
172 " 4 [label=\"97-128\", fillcolor=4 style=filled "
173 "colorscheme=ylorrd8 fixedsize=true shape=circle width=2 "
175 " 5 [label=\"129-160\", fillcolor=5 style=filled "
176 "colorscheme=ylorrd8 fixedsize=true shape=circle width=2 "
178 " 6 [label=\"161-192\", fillcolor=6 style=filled "
179 "colorscheme=ylorrd8 fixedsize=true shape=circle width=2 "
181 " 7 [label=\"193-224\", fillcolor=7 style=filled "
182 "colorscheme=ylorrd8 fixedsize=true shape=circle width=2 "
184 " 8 [label=\"224+\", fillcolor=8 style=filled "
185 "colorscheme=ylorrd8 fixedsize=true shape=circle width=2 "
187 format__ (vm, fd, "%s",
188 " 0 -> 1 -> 2 -> 3 -> 4 [style=\"invis\",weight =100]\n "
189 " 5 -> 6 -> 7 -> 8 [style=\"invis\",weight =100]\n }\n "
190 " subgraph cluster_size {\n label=\"Cycles/Packet\"\n "
191 " style=\"solid\"\n labelloc = b\n");
194 " a[label=\"0\",fixedsize=true shape=circle width=1] \n"
195 " b[label=\"10\",fixedsize=true shape=circle width=2 "
197 " c[label=\"100\",fixedsize=true shape=circle width=3 "
199 " d[label=\"1000\",fixedsize=true shape=circle width=4 "
201 " a -> b -> c -> d [style=\"invis\",weight =100]\n }\n }\n");
203 vlib_worker_thread_barrier_sync (vm);
204 for (j = 0; j < vec_len (nm->nodes); j++)
208 vlib_node_sync_stats (vm, n);
211 /* Updating the stats for multithreaded use cases.
212 * We need to dup the nodes to sum the stats from all threads.*/
213 nodes = vec_dup (nm->nodes);
214 for (i = 1; i < vlib_get_n_threads (); i++)
216 vlib_node_main_t *nm_clone;
217 vlib_main_t *vm_clone;
218 vlib_node_runtime_t *rt;
221 vm_clone = vlib_get_main_by_index (i);
222 nm_clone = &vm_clone->node_main;
224 for (j = 0; j < vec_len (nm_clone->nodes); j++)
226 n = nm_clone->nodes[j];
228 rt = vlib_node_get_runtime (vm_clone, n->index);
229 /* Sync the stats directly in the duplicated node.*/
230 vlib_node_runtime_sync_stats_node (nodes[j], rt, 0, 0, 0);
233 vlib_worker_thread_barrier_release (vm);
235 for (i = 0; i < vec_len (nodes); i++)
238 c = nodes[i]->stats_total.calls - nodes[i]->stats_last_clear.calls;
240 nodes[i]->stats_total.vectors - nodes[i]->stats_last_clear.vectors;
241 l = nodes[i]->stats_total.clocks - nodes[i]->stats_last_clear.clocks;
243 if ((both && c > 0 && p > 0) || (calls_filter && c > 0) ||
244 (vectors_filter && p > 0))
246 format__ (vm, fd, " \"%v\" [shape=circle", nodes[i]->name);
247 /*Changing the size and the font of nodes that receive packets*/
250 f64 x = (f64) l / (f64) p;
251 f64 size_ratio = (1 + log10 (x + 1));
252 format__ (vm, fd, " width=%.2f fontsize=%.2f fixedsize=true",
253 size_ratio, 11 + 3 * size_ratio);
254 /*Coloring nodes that are indeed called*/
257 u64 color = ((p - 1) / (32 * c)) + 1;
258 color = clib_min (color, 8);
261 " fillcolor=%u style=filled colorscheme=ylorrd8",
265 format__ (vm, fd, "]\n");
269 clib_bitmap_set (active, i, 0);
274 clib_bitmap_foreach (i, active)
276 for (j = 0; j < vec_len (nodes[i]->next_nodes); j++)
278 if (nodes[i]->next_nodes[j] == VLIB_INVALID_NODE_INDEX)
281 if (!filter || clib_bitmap_get (active, nodes[i]->next_nodes[j]))
283 format__ (vm, fd, " \"%v\" -> \"%v\"\n", nodes[i]->name,
284 nodes[nodes[i]->next_nodes[j]]->name);
289 format__ (vm, fd, "}\n");
293 /*Dumping all the nodes saturates dot capacities to render a directed
294 * graph. In this case, prefer using he fdp command to generate an
295 * undirected graph. */
296 const char *soft = filter ? "dot" : "fdp";
298 vm, "vlib graph dumped into `%s'. Run eg. `%s -Tsvg -O %s'.",
299 chroot_filename, soft, chroot_filename);
302 clib_bitmap_free (active);
303 vec_free (chroot_filename);
312 * Dump dot files data to draw a graph of all the nodes.
313 * If the argument 'filter' is provided, only the active nodes (since the last
314 * "clear run" command) are selected and they are scaled and colored according
315 * to their utilization. You can choose to filter nodes that are called,
316 * nodes that receive vectors or both (default).
317 * The 'file' option allows to save data in a temp file.
322 * show vlib graphviz filter file tmpfile
323 * show vlib graphviz filter calls file tmpfile
325 * @cliexcmd{show vlib graphviz [filter][calls][vectors][file <filename>]}
328 VLIB_CLI_COMMAND (show_node_graphviz_command, static) = {
329 .path = "show vlib graphviz",
330 .short_help = "Dump packet processing node graph as a graphviz dotfile",
331 .function = show_node_graphviz,
337 format_vlib_node_state (u8 * s, va_list * va)
339 vlib_main_t *vm = va_arg (*va, vlib_main_t *);
340 vlib_node_t *n = va_arg (*va, vlib_node_t *);
344 if (n->type == VLIB_NODE_TYPE_PROCESS)
346 vlib_process_t *p = vlib_get_process_from_node (vm, n);
348 switch (p->flags & (VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_CLOCK
349 | VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_EVENT))
352 if (!(p->flags & VLIB_PROCESS_IS_RUNNING))
356 case VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_CLOCK:
360 case VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_EVENT:
361 state = "event wait";
364 case (VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_EVENT | VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_CLOCK):
370 else if (n->type != VLIB_NODE_TYPE_INTERNAL)
373 if (n->state == VLIB_NODE_STATE_DISABLED)
375 else if (n->state == VLIB_NODE_STATE_INTERRUPT)
376 state = "interrupt wait";
379 return format (s, "%s", state);
383 format_vlib_node_stats (u8 * s, va_list * va)
385 vlib_main_t *vm = va_arg (*va, vlib_main_t *);
386 vlib_node_t *n = va_arg (*va, vlib_node_t *);
387 int max = va_arg (*va, int);
401 "%=30s%=17s%=16s%=16s%=16s%=16s",
402 "Name", "Max Node Clocks", "Vectors at Max",
403 "Max Clocks", "Avg Clocks", "Avg Vectors/Call");
406 "%=30s%=12s%=16s%=16s%=16s%=16s%=16s",
407 "Name", "State", "Calls", "Vectors", "Suspends",
408 "Clocks", "Vectors/Call");
412 indent = format_get_indent (s);
414 l = n->stats_total.clocks - n->stats_last_clear.clocks;
415 c = n->stats_total.calls - n->stats_last_clear.calls;
416 p = n->stats_total.vectors - n->stats_last_clear.vectors;
417 d = n->stats_total.suspends - n->stats_last_clear.suspends;
418 maxc = (f64) n->stats_total.max_clock;
419 maxn = n->stats_total.max_clock_n;
420 if (n->stats_total.max_clock_n)
421 maxcn = (f64) n->stats_total.max_clock / (f64) maxn;
425 /* Clocks per packet, per call or per suspend. */
428 x = (f64) l / (f64) p;
430 x = (f64) l / (f64) c;
432 x = (f64) l / (f64) d;
435 v = (double) p / (double) c;
439 if (n->type == VLIB_NODE_TYPE_PROCESS)
441 vlib_process_t *p = vlib_get_process_from_node (vm, n);
443 /* Show processes with events pending. This helps spot bugs where events are not
445 if (!clib_bitmap_is_zero (p->non_empty_event_type_bitmap))
446 misc_info = format (misc_info, "events pending, ");
451 s = format (s, "%-30v%=17.2e%=16d%=16.2e%=16.2e%=16.2e",
452 ns, maxc, maxn, maxcn, x, v);
454 s = format (s, "%-30v%=12U%16Ld%16Ld%16Ld%16.2e%16.2f", ns,
455 format_vlib_node_state, vm, n, c, p, d, x, v);
462 s = format (s, "\n%U%v", format_white_space, indent + 4, misc_info);
463 vec_free (misc_info);
469 static clib_error_t *
470 show_node_runtime (vlib_main_t * vm,
471 unformat_input_t * input, vlib_cli_command_t * cmd)
473 vlib_node_main_t *nm = &vm->node_main;
477 vlib_node_t ***node_dups = 0;
478 f64 *internal_node_vector_rates = 0;
480 time_now = vlib_time_now (vm);
482 if (unformat (input, "%U", unformat_vlib_node, vm, &node_index))
484 n = vlib_get_node (vm, node_index);
485 vlib_node_sync_stats (vm, n);
486 vlib_cli_output (vm, "%U\n", format_vlib_node_stats, vm, 0, 0);
487 vlib_cli_output (vm, "%U\n", format_vlib_node_stats, vm, n, 0);
494 u64 n_input, n_output, n_drop, n_punt;
495 u64 n_clocks, l, v, c, d;
499 vlib_main_t **stat_vms = 0, *stat_vm;
501 /* Suppress nodes with zero calls since last clear */
502 if (unformat (input, "brief") || unformat (input, "b"))
504 if (unformat (input, "verbose") || unformat (input, "v"))
506 if (unformat (input, "max") || unformat (input, "m"))
508 if (unformat (input, "summary") || unformat (input, "sum")
509 || unformat (input, "su"))
512 for (i = 0; i < vlib_get_n_threads (); i++)
514 stat_vm = vlib_get_main_by_index (i);
516 vec_add1 (stat_vms, stat_vm);
520 * Barrier sync across stats scraping.
521 * Otherwise, the counts will be grossly inaccurate.
523 vlib_worker_thread_barrier_sync (vm);
525 for (j = 0; j < vec_len (stat_vms); j++)
527 stat_vm = stat_vms[j];
528 nm = &stat_vm->node_main;
530 for (i = 0; i < vec_len (nm->nodes); i++)
533 vlib_node_sync_stats (stat_vm, n);
536 nodes = vec_dup (nm->nodes);
538 vec_add1 (node_dups, nodes);
539 vec_add1 (internal_node_vector_rates,
540 vlib_internal_node_vector_rate (stat_vm));
542 vlib_worker_thread_barrier_release (vm);
545 for (j = 0; j < vec_len (stat_vms); j++)
547 stat_vm = stat_vms[j];
548 nodes = node_dups[j];
550 vec_sort_with_function (nodes, node_cmp);
552 n_input = n_output = n_drop = n_punt = n_clocks = 0;
553 for (i = 0; i < vec_len (nodes); i++)
557 l = n->stats_total.clocks - n->stats_last_clear.clocks;
560 v = n->stats_total.vectors - n->stats_last_clear.vectors;
567 case VLIB_NODE_TYPE_INTERNAL:
568 n_output += (n->flags & VLIB_NODE_FLAG_IS_OUTPUT) ? v : 0;
569 n_drop += (n->flags & VLIB_NODE_FLAG_IS_DROP) ? v : 0;
570 n_punt += (n->flags & VLIB_NODE_FLAG_IS_PUNT) ? v : 0;
571 if (n->flags & VLIB_NODE_FLAG_IS_HANDOFF)
575 case VLIB_NODE_TYPE_INPUT:
581 if (vlib_get_n_threads () > 1)
583 vlib_worker_thread_t *w = vlib_worker_threads + j;
585 vlib_cli_output (vm, "---------------");
588 vlib_cli_output (vm, "Thread %d %s (lcore %u)", j, w->name,
591 vlib_cli_output (vm, "Thread %d %s", j, w->name);
594 dt = time_now - nm->time_last_runtime_stats_clear;
597 "Time %.1f, %f sec internal node vector rate %.2f loops/sec %.2f\n"
598 " vector rates in %.4e, out %.4e, drop %.4e, punt %.4e",
599 dt, vlib_stats_get_segment_update_rate (),
600 internal_node_vector_rates[j], stat_vm->loops_per_second,
601 (f64) n_input / dt, (f64) n_output / dt, (f64) n_drop / dt,
606 vlib_cli_output (vm, "%U", format_vlib_node_stats, stat_vm,
608 for (i = 0; i < vec_len (nodes); i++)
611 nodes[i]->stats_total.calls -
612 nodes[i]->stats_last_clear.calls;
614 nodes[i]->stats_total.suspends -
615 nodes[i]->stats_last_clear.suspends;
616 if (c || d || !brief)
618 vlib_cli_output (vm, "%U", format_vlib_node_stats,
619 stat_vm, nodes[i], max);
626 vec_free (node_dups);
627 vec_free (internal_node_vector_rates);
634 VLIB_CLI_COMMAND (show_node_runtime_command, static) = {
635 .path = "show runtime",
636 .short_help = "Show packet processing runtime",
637 .function = show_node_runtime,
642 static clib_error_t *
643 clear_node_runtime (vlib_main_t * vm,
644 unformat_input_t * input, vlib_cli_command_t * cmd)
646 vlib_node_main_t *nm;
649 vlib_main_t **stat_vms = 0, *stat_vm;
650 vlib_node_runtime_t *r;
652 for (i = 0; i < vlib_get_n_threads (); i++)
654 stat_vm = vlib_get_main_by_index (i);
656 vec_add1 (stat_vms, stat_vm);
659 vlib_worker_thread_barrier_sync (vm);
661 for (j = 0; j < vec_len (stat_vms); j++)
663 stat_vm = stat_vms[j];
664 nm = &stat_vm->node_main;
666 for (i = 0; i < vec_len (nm->nodes); i++)
669 vlib_node_sync_stats (stat_vm, n);
670 n->stats_last_clear = n->stats_total;
672 r = vlib_node_get_runtime (stat_vm, n->index);
675 /* Note: input/output rates computed using vlib_global_main */
676 nm->time_last_runtime_stats_clear = vlib_time_now (vm);
679 vlib_stats_set_timestamp (STAT_COUNTER_LAST_STATS_CLEAR,
680 vm->node_main.time_last_runtime_stats_clear);
681 vlib_worker_thread_barrier_release (vm);
689 VLIB_CLI_COMMAND (clear_node_runtime_command, static) = {
690 .path = "clear runtime",
691 .short_help = "Clear packet processing runtime statistics",
692 .function = clear_node_runtime,
696 static clib_error_t *
697 show_node (vlib_main_t * vm, unformat_input_t * input,
698 vlib_cli_command_t * cmd)
700 unformat_input_t _line_input, *line_input = &_line_input;
701 clib_error_t *error = 0;
702 vlib_node_main_t *nm = &vm->node_main;
705 u32 i, node_index = ~0, verbose = 0;
707 u8 valid_node_name = 0;
710 if (!unformat_user (input, unformat_line_input, line_input))
713 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
715 if (unformat (line_input, "index %u", &node_index))
717 else if (unformat (line_input, "verbose"))
720 if (unformat (line_input, "%U", unformat_vlib_node, vm, &node_index))
722 else if (!valid_node_name)
723 error = clib_error_return (0, "unknown node name: '%U'",
724 format_unformat_error, line_input);
726 error = clib_error_return (0, "unknown input '%U'",
727 format_unformat_error, line_input);
733 unformat_free (line_input);
738 if (node_index >= vec_len (vm->node_main.nodes))
739 return clib_error_return (0, "please specify valid node");
741 n = vlib_get_node (vm, node_index);
742 vlib_node_sync_stats (vm, n);
746 case VLIB_NODE_TYPE_INTERNAL:
747 type_str = "internal";
749 case VLIB_NODE_TYPE_INPUT:
752 case VLIB_NODE_TYPE_PRE_INPUT:
753 type_str = "pre-input";
755 case VLIB_NODE_TYPE_PROCESS:
756 type_str = "process";
759 type_str = "unknown";
763 s = format (s, ", sibling-of %s", n->sibling_of);
765 vlib_cli_output (vm, "node %v, type %s, state %U, index %d%v\n",
766 n->name, type_str, format_vlib_node_state, vm, n,
768 vec_reset_length (s);
770 if (n->node_fn_registrations)
772 vlib_node_fn_registration_t *fnr = n->node_fn_registrations;
773 vlib_node_fn_variant_t *v;
776 v = vec_elt_at_index (vm->node_main.variants, fnr->march_variant);
777 if (vec_len (s) == 0)
778 s = format (s, "\n %-15s %=8s %6s %s", "Name", "Priority",
779 "Active", "Description");
780 s = format (s, "\n %-15s %8d %=6s %s", v->suffix, v->priority,
781 fnr->function == n->function ? "yes" : "", v->desc);
782 fnr = fnr->next_registration;
786 s = format (s, "\n default only");
787 vlib_cli_output (vm, " node function variants:%v\n", s);
788 vec_reset_length (s);
790 for (i = 0; i < vec_len (n->next_nodes); i++)
793 if (n->next_nodes[i] == VLIB_INVALID_NODE_INDEX)
796 pn = vec_elt (nm->nodes, n->next_nodes[i]);
798 if (vec_len (s) == 0)
799 s = format (s, "\n %10s %10s %=30s %8s",
800 "next-index", "node-index", "Node", "Vectors");
802 s = format (s, "\n %=10u %=10u %=30v %=8llu", i, n->next_nodes[i],
803 pn->name, vec_elt (n->n_vectors_by_next_node, i));
806 if (vec_len (s) == 0)
807 s = format (s, "\n none");
808 vlib_cli_output (vm, "\n next nodes:%v\n", s);
809 vec_reset_length (s);
811 if (n->type == VLIB_NODE_TYPE_INTERNAL)
815 clib_bitmap_foreach (i, n->prev_node_bitmap) {
816 vlib_node_t *pn = vlib_get_node (vm, i);
818 s = format (s, "\n ");
819 s2 = format (s2, "%v (%u)", pn->name, i);
820 s = format (s, "%-35v", s2);
821 vec_reset_length (s2);
825 if (vec_len (s) == 0)
826 s = format (s, "\n none");
827 vlib_cli_output (vm, "\n known previous nodes:%v\n", s);
828 vec_reset_length (s);
835 s = format (s, "\n%8s %=12s %=12s %=12s %=12s %=12s\n", "Thread", "Calls",
836 "Clocks", "Vectors", "Max Clock", "Max Vectors");
837 for (i = 0; i < vlib_get_n_threads (); i++)
839 n = vlib_get_node (vlib_get_main_by_index (i), node_index);
840 vlib_node_sync_stats (vlib_get_main_by_index (i), n);
842 cl = n->stats_total.clocks - n->stats_last_clear.clocks;
843 ca = n->stats_total.calls - n->stats_last_clear.calls;
844 v = n->stats_total.vectors - n->stats_last_clear.vectors;
846 s = format (s, "%=8u %=12lu %=12lu %=12lu %=12u %=12u\n", i, ca, cl, v,
847 n->stats_total.max_clock, n->stats_total.max_clock_n);
850 vlib_cli_output (vm, "%v", s);
859 VLIB_CLI_COMMAND (show_node_command, static) = {
861 .short_help = "show node [index] <node-name | node-index>",
862 .function = show_node,
865 static clib_error_t *
866 set_node_fn(vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
868 unformat_input_t _line_input, *line_input = &_line_input;
869 u32 node_index, march_variant;
871 clib_error_t *err = 0;
873 if (!unformat_user (input, unformat_line_input, line_input))
876 if (!unformat (line_input, "%U", unformat_vlib_node, vm, &node_index))
878 err = clib_error_return (0, "please specify valid node name");
882 if (!unformat (line_input, "%U", unformat_vlib_node_variant, &march_variant))
884 err = clib_error_return (0, "please specify node function variant");
888 n = vlib_get_node (vm, node_index);
890 if (n->node_fn_registrations == 0)
892 err = clib_error_return (0, "node doesn't have function variants");
896 if (vlib_node_set_march_variant (vm, node_index, march_variant))
898 vlib_node_fn_variant_t *v;
899 v = vec_elt_at_index (vm->node_main.variants, march_variant);
900 err = clib_error_return (0, "node function variant '%s' not found",
907 unformat_free (line_input);
912 VLIB_CLI_COMMAND (set_node_fn_command, static) = {
913 .path = "set node function",
914 .short_help = "set node function <node-name> <variant-name>",
915 .function = set_node_fn,
919 /* Dummy function to get us linked in. */
921 vlib_node_cli_reference (void)
926 * fd.io coding-style-patch-verification: ON
929 * eval: (c-set-style "gnu")