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]);
88 VLIB_CLI_COMMAND (show_node_graph_command, static) = {
89 .path = "show vlib graph",
90 .short_help = "Show packet processing node graph",
91 .function = show_node_graph,
95 show_node_graphviz (vlib_main_t * vm,
96 unformat_input_t * input, vlib_cli_command_t * cmd)
98 clib_error_t *error = 0;
99 vlib_node_main_t *nm = &vm->node_main;
100 vlib_node_t **nodes = nm->nodes;
101 u8 *chroot_filename = 0;
105 unformat_input_t _line_input, *line_input = &_line_input;
106 u8 filter = 0, calls_filter = 0, vectors_filter = 0, both = 0;
109 /* Get a line of input. */
110 if (unformat_user (input, unformat_line_input, line_input))
112 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
114 if (unformat (line_input, "filter"))
116 else if (unformat (line_input, "calls") && filter)
118 else if (unformat (line_input, "vectors") && filter)
120 else if (unformat (line_input, "file %U", unformat_vlib_tmpfile,
123 fd = open ((char *) chroot_filename,
124 O_CREAT | O_TRUNC | O_WRONLY, 0664);
127 return clib_error_return (0, "unknown input `%U'",
128 format_unformat_error, input);
130 unformat_free (line_input);
133 /*both is set to true if calls_filter and vectors_filter are, or neither */
134 both = filter & (!(calls_filter ^ vectors_filter));
136 #define format__(vm__, fd__, ...) \
139 vlib_cli_output((vm__), ## __VA_ARGS__); \
143 fdformat((fd__), ## __VA_ARGS__); \
146 format__ (vm, fd, "%s", "digraph {\n");
148 clib_bitmap_alloc (active, vec_len (nodes));
149 clib_bitmap_set_region (active, 0, 1, vec_len (nodes));
152 /*Adding the legend to the dot file*/
153 format__ (vm, fd, "%s",
154 " rankdir=\"LR\"\n nodesep=2\n subgraph cluster_legend {\n "
155 " label=\"Legend\"\n style=\"solid\"\n labelloc = b\n "
156 " subgraph cluster_colors {\n label=\"Packets/Call\"\n "
157 " style=\"solid\"\n labelloc = b\n");
158 format__ (vm, fd, "%s",
159 " 0 [label=\"No packet\", fixedsize=true shape=circle "
160 "width=2 fontsize=17]\n"
161 " 1 [label=\"1-32\", fillcolor=1 style=filled "
162 "colorscheme=ylorrd8 fixedsize=true shape=circle width=2 "
164 " 2 [label=\"33-64\", fillcolor=2 style=filled "
165 "colorscheme=ylorrd8 fixedsize=true shape=circle width=2 "
167 " 3 [label=\"65-96\", fillcolor=3 style=filled "
168 "colorscheme=ylorrd8 fixedsize=true shape=circle width=2 "
170 " 4 [label=\"97-128\", fillcolor=4 style=filled "
171 "colorscheme=ylorrd8 fixedsize=true shape=circle width=2 "
173 " 5 [label=\"129-160\", fillcolor=5 style=filled "
174 "colorscheme=ylorrd8 fixedsize=true shape=circle width=2 "
176 " 6 [label=\"161-192\", fillcolor=6 style=filled "
177 "colorscheme=ylorrd8 fixedsize=true shape=circle width=2 "
179 " 7 [label=\"193-224\", fillcolor=7 style=filled "
180 "colorscheme=ylorrd8 fixedsize=true shape=circle width=2 "
182 " 8 [label=\"224+\", fillcolor=8 style=filled "
183 "colorscheme=ylorrd8 fixedsize=true shape=circle width=2 "
185 format__ (vm, fd, "%s",
186 " 0 -> 1 -> 2 -> 3 -> 4 [style=\"invis\",weight =100]\n "
187 " 5 -> 6 -> 7 -> 8 [style=\"invis\",weight =100]\n }\n "
188 " subgraph cluster_size {\n label=\"Cycles/Packet\"\n "
189 " style=\"solid\"\n labelloc = b\n");
192 " a[label=\"0\",fixedsize=true shape=circle width=1] \n"
193 " b[label=\"10\",fixedsize=true shape=circle width=2 "
195 " c[label=\"100\",fixedsize=true shape=circle width=3 "
197 " d[label=\"1000\",fixedsize=true shape=circle width=4 "
199 " a -> b -> c -> d [style=\"invis\",weight =100]\n }\n }\n");
201 vlib_worker_thread_barrier_sync (vm);
202 for (j = 0; j < vec_len (nm->nodes); j++)
206 vlib_node_sync_stats (vm, n);
209 /* Updating the stats for multithreaded use cases.
210 * We need to dup the nodes to sum the stats from all threads.*/
211 nodes = vec_dup (nm->nodes);
212 for (i = 1; i < vlib_get_n_threads (); i++)
214 vlib_node_main_t *nm_clone;
215 vlib_main_t *vm_clone;
216 vlib_node_runtime_t *rt;
219 vm_clone = vlib_get_main_by_index (i);
220 nm_clone = &vm_clone->node_main;
222 for (j = 0; j < vec_len (nm_clone->nodes); j++)
224 n = nm_clone->nodes[j];
226 rt = vlib_node_get_runtime (vm_clone, n->index);
227 /* Sync the stats directly in the duplicated node.*/
228 vlib_node_runtime_sync_stats_node (nodes[j], rt, 0, 0, 0);
231 vlib_worker_thread_barrier_release (vm);
233 for (i = 0; i < vec_len (nodes); i++)
236 c = nodes[i]->stats_total.calls - nodes[i]->stats_last_clear.calls;
238 nodes[i]->stats_total.vectors - nodes[i]->stats_last_clear.vectors;
239 l = nodes[i]->stats_total.clocks - nodes[i]->stats_last_clear.clocks;
241 if ((both && c > 0 && p > 0) || (calls_filter && c > 0) ||
242 (vectors_filter && p > 0))
244 format__ (vm, fd, " \"%v\" [shape=circle", nodes[i]->name);
245 /*Changing the size and the font of nodes that receive packets*/
248 f64 x = (f64) l / (f64) p;
249 f64 size_ratio = (1 + log10 (x + 1));
250 format__ (vm, fd, " width=%.2f fontsize=%.2f fixedsize=true",
251 size_ratio, 11 + 3 * size_ratio);
252 /*Coloring nodes that are indeed called*/
255 u64 color = ((p - 1) / (32 * c)) + 1;
256 color = clib_min (color, 8);
259 " fillcolor=%u style=filled colorscheme=ylorrd8",
263 format__ (vm, fd, "]\n");
267 clib_bitmap_set (active, i, 0);
272 clib_bitmap_foreach (i, active)
274 for (j = 0; j < vec_len (nodes[i]->next_nodes); j++)
276 if (nodes[i]->next_nodes[j] == VLIB_INVALID_NODE_INDEX)
279 if (!filter || clib_bitmap_get (active, nodes[i]->next_nodes[j]))
281 format__ (vm, fd, " \"%v\" -> \"%v\"\n", nodes[i]->name,
282 nodes[nodes[i]->next_nodes[j]]->name);
287 format__ (vm, fd, "}\n");
291 /*Dumping all the nodes saturates dot capacities to render a directed
292 * graph. In this case, prefer using he fdp command to generate an
293 * undirected graph. */
294 const char *soft = filter ? "dot" : "fdp";
296 vm, "vlib graph dumped into `%s'. Run eg. `%s -Tsvg -O %s'.",
297 chroot_filename, soft, chroot_filename);
300 clib_bitmap_free (active);
301 vec_free (chroot_filename);
310 * Dump dot files data to draw a graph of all the nodes.
311 * If the argument 'filter' is provided, only the active nodes (since the last
312 * "clear run" command) are selected and they are scaled and colored according
313 * to their utilization. You can choose to filter nodes that are called,
314 * nodes that receive vectors or both (default).
315 * The 'file' option allows to save data in a temp file.
320 * show vlib graphviz filter file tmpfile
321 * show vlib graphviz filter calls file tmpfile
323 * @cliexcmd{show vlib graphviz [filter][calls][vectors][file <filename>]}
325 VLIB_CLI_COMMAND (show_node_graphviz_command, static) = {
326 .path = "show vlib graphviz",
327 .short_help = "Dump packet processing node graph as a graphviz dotfile",
328 .function = show_node_graphviz,
333 format_vlib_node_state (u8 * s, va_list * va)
335 vlib_main_t *vm = va_arg (*va, vlib_main_t *);
336 vlib_node_t *n = va_arg (*va, vlib_node_t *);
340 if (n->type == VLIB_NODE_TYPE_PROCESS)
342 vlib_process_t *p = vlib_get_process_from_node (vm, n);
344 switch (p->flags & (VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_CLOCK
345 | VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_EVENT))
348 if (!(p->flags & VLIB_PROCESS_IS_RUNNING))
352 case VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_CLOCK:
356 case VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_EVENT:
357 state = "event wait";
360 case (VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_EVENT | VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_CLOCK):
366 else if (n->type != VLIB_NODE_TYPE_INTERNAL)
369 if (n->state == VLIB_NODE_STATE_DISABLED)
371 else if (n->state == VLIB_NODE_STATE_INTERRUPT)
372 state = "interrupt wait";
375 return format (s, "%s", state);
379 format_vlib_node_stats (u8 * s, va_list * va)
381 vlib_main_t *vm = va_arg (*va, vlib_main_t *);
382 vlib_node_t *n = va_arg (*va, vlib_node_t *);
383 int max = va_arg (*va, int);
397 "%=30s%=17s%=16s%=16s%=16s%=16s",
398 "Name", "Max Node Clocks", "Vectors at Max",
399 "Max Clocks", "Avg Clocks", "Avg Vectors/Call");
402 "%=30s%=12s%=16s%=16s%=16s%=16s%=16s",
403 "Name", "State", "Calls", "Vectors", "Suspends",
404 "Clocks", "Vectors/Call");
408 indent = format_get_indent (s);
410 l = n->stats_total.clocks - n->stats_last_clear.clocks;
411 c = n->stats_total.calls - n->stats_last_clear.calls;
412 p = n->stats_total.vectors - n->stats_last_clear.vectors;
413 d = n->stats_total.suspends - n->stats_last_clear.suspends;
414 maxc = (f64) n->stats_total.max_clock;
415 maxn = n->stats_total.max_clock_n;
416 if (n->stats_total.max_clock_n)
417 maxcn = (f64) n->stats_total.max_clock / (f64) maxn;
421 /* Clocks per packet, per call or per suspend. */
424 x = (f64) l / (f64) p;
426 x = (f64) l / (f64) c;
428 x = (f64) l / (f64) d;
431 v = (double) p / (double) c;
435 if (n->type == VLIB_NODE_TYPE_PROCESS)
437 vlib_process_t *p = vlib_get_process_from_node (vm, n);
439 /* Show processes with events pending. This helps spot bugs where events are not
441 if (!clib_bitmap_is_zero (p->non_empty_event_type_bitmap))
442 misc_info = format (misc_info, "events pending, ");
447 s = format (s, "%-30v%=17.2e%=16d%=16.2e%=16.2e%=16.2e",
448 ns, maxc, maxn, maxcn, x, v);
450 s = format (s, "%-30v%=12U%16Ld%16Ld%16Ld%16.2e%16.2f", ns,
451 format_vlib_node_state, vm, n, c, p, d, x, v);
458 s = format (s, "\n%U%v", format_white_space, indent + 4, misc_info);
459 vec_free (misc_info);
465 static clib_error_t *
466 show_node_runtime (vlib_main_t * vm,
467 unformat_input_t * input, vlib_cli_command_t * cmd)
469 vlib_node_main_t *nm = &vm->node_main;
473 vlib_node_t ***node_dups = 0;
474 f64 *internal_node_vector_rates = 0;
476 time_now = vlib_time_now (vm);
478 if (unformat (input, "%U", unformat_vlib_node, vm, &node_index))
480 n = vlib_get_node (vm, node_index);
481 vlib_node_sync_stats (vm, n);
482 vlib_cli_output (vm, "%U\n", format_vlib_node_stats, vm, 0, 0);
483 vlib_cli_output (vm, "%U\n", format_vlib_node_stats, vm, n, 0);
490 u64 n_input, n_output, n_drop, n_punt;
491 u64 n_clocks, l, v, c, d;
495 vlib_main_t **stat_vms = 0, *stat_vm;
497 /* Suppress nodes with zero calls since last clear */
498 if (unformat (input, "brief") || unformat (input, "b"))
500 if (unformat (input, "verbose") || unformat (input, "v"))
502 if (unformat (input, "max") || unformat (input, "m"))
504 if (unformat (input, "summary") || unformat (input, "sum")
505 || unformat (input, "su"))
508 for (i = 0; i < vlib_get_n_threads (); i++)
510 stat_vm = vlib_get_main_by_index (i);
512 vec_add1 (stat_vms, stat_vm);
516 * Barrier sync across stats scraping.
517 * Otherwise, the counts will be grossly inaccurate.
519 vlib_worker_thread_barrier_sync (vm);
521 for (j = 0; j < vec_len (stat_vms); j++)
523 stat_vm = stat_vms[j];
524 nm = &stat_vm->node_main;
526 for (i = 0; i < vec_len (nm->nodes); i++)
529 vlib_node_sync_stats (stat_vm, n);
532 nodes = vec_dup (nm->nodes);
534 vec_add1 (node_dups, nodes);
535 vec_add1 (internal_node_vector_rates,
536 vlib_internal_node_vector_rate (stat_vm));
538 vlib_worker_thread_barrier_release (vm);
541 for (j = 0; j < vec_len (stat_vms); j++)
543 stat_vm = stat_vms[j];
544 nodes = node_dups[j];
546 vec_sort_with_function (nodes, node_cmp);
548 n_input = n_output = n_drop = n_punt = n_clocks = 0;
549 for (i = 0; i < vec_len (nodes); i++)
553 l = n->stats_total.clocks - n->stats_last_clear.clocks;
556 v = n->stats_total.vectors - n->stats_last_clear.vectors;
563 case VLIB_NODE_TYPE_INTERNAL:
564 n_output += (n->flags & VLIB_NODE_FLAG_IS_OUTPUT) ? v : 0;
565 n_drop += (n->flags & VLIB_NODE_FLAG_IS_DROP) ? v : 0;
566 n_punt += (n->flags & VLIB_NODE_FLAG_IS_PUNT) ? v : 0;
567 if (n->flags & VLIB_NODE_FLAG_IS_HANDOFF)
571 case VLIB_NODE_TYPE_INPUT:
577 if (vlib_get_n_threads () > 1)
579 vlib_worker_thread_t *w = vlib_worker_threads + j;
581 vlib_cli_output (vm, "---------------");
584 vlib_cli_output (vm, "Thread %d %s (lcore %u)", j, w->name,
587 vlib_cli_output (vm, "Thread %d %s", j, w->name);
590 dt = time_now - nm->time_last_runtime_stats_clear;
593 "Time %.1f, %f sec internal node vector rate %.2f loops/sec %.2f\n"
594 " vector rates in %.4e, out %.4e, drop %.4e, punt %.4e",
595 dt, vlib_stats_get_segment_update_rate (),
596 internal_node_vector_rates[j], stat_vm->loops_per_second,
597 (f64) n_input / dt, (f64) n_output / dt, (f64) n_drop / dt,
602 vlib_cli_output (vm, "%U", format_vlib_node_stats, stat_vm,
604 for (i = 0; i < vec_len (nodes); i++)
607 nodes[i]->stats_total.calls -
608 nodes[i]->stats_last_clear.calls;
610 nodes[i]->stats_total.suspends -
611 nodes[i]->stats_last_clear.suspends;
612 if (c || d || !brief)
614 vlib_cli_output (vm, "%U", format_vlib_node_stats,
615 stat_vm, nodes[i], max);
622 vec_free (node_dups);
623 vec_free (internal_node_vector_rates);
629 VLIB_CLI_COMMAND (show_node_runtime_command, static) = {
630 .path = "show runtime",
631 .short_help = "Show packet processing runtime",
632 .function = show_node_runtime,
636 static clib_error_t *
637 clear_node_runtime (vlib_main_t * vm,
638 unformat_input_t * input, vlib_cli_command_t * cmd)
640 vlib_node_main_t *nm;
643 vlib_main_t **stat_vms = 0, *stat_vm;
644 vlib_node_runtime_t *r;
646 for (i = 0; i < vlib_get_n_threads (); i++)
648 stat_vm = vlib_get_main_by_index (i);
650 vec_add1 (stat_vms, stat_vm);
653 vlib_worker_thread_barrier_sync (vm);
655 for (j = 0; j < vec_len (stat_vms); j++)
657 stat_vm = stat_vms[j];
658 nm = &stat_vm->node_main;
660 for (i = 0; i < vec_len (nm->nodes); i++)
663 vlib_node_sync_stats (stat_vm, n);
664 n->stats_last_clear = n->stats_total;
666 r = vlib_node_get_runtime (stat_vm, n->index);
669 /* Note: input/output rates computed using vlib_global_main */
670 nm->time_last_runtime_stats_clear = vlib_time_now (vm);
673 vlib_stats_set_timestamp (STAT_COUNTER_LAST_STATS_CLEAR,
674 vm->node_main.time_last_runtime_stats_clear);
675 vlib_worker_thread_barrier_release (vm);
682 VLIB_CLI_COMMAND (clear_node_runtime_command, static) = {
683 .path = "clear runtime",
684 .short_help = "Clear packet processing runtime statistics",
685 .function = clear_node_runtime,
688 static clib_error_t *
689 show_node (vlib_main_t * vm, unformat_input_t * input,
690 vlib_cli_command_t * cmd)
692 unformat_input_t _line_input, *line_input = &_line_input;
693 clib_error_t *error = 0;
694 vlib_node_main_t *nm = &vm->node_main;
697 u32 i, node_index = ~0, verbose = 0;
699 u8 valid_node_name = 0;
702 if (!unformat_user (input, unformat_line_input, line_input))
705 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
707 if (unformat (line_input, "index %u", &node_index))
709 else if (unformat (line_input, "verbose"))
712 if (unformat (line_input, "%U", unformat_vlib_node, vm, &node_index))
714 else if (!valid_node_name)
715 error = clib_error_return (0, "unknown node name: '%U'",
716 format_unformat_error, line_input);
718 error = clib_error_return (0, "unknown input '%U'",
719 format_unformat_error, line_input);
725 unformat_free (line_input);
730 if (node_index >= vec_len (vm->node_main.nodes))
731 return clib_error_return (0, "please specify valid node");
733 n = vlib_get_node (vm, node_index);
734 vlib_node_sync_stats (vm, n);
738 case VLIB_NODE_TYPE_INTERNAL:
739 type_str = "internal";
741 case VLIB_NODE_TYPE_INPUT:
744 case VLIB_NODE_TYPE_PRE_INPUT:
745 type_str = "pre-input";
747 case VLIB_NODE_TYPE_PROCESS:
748 type_str = "process";
751 type_str = "unknown";
755 s = format (s, ", sibling-of %s", n->sibling_of);
757 vlib_cli_output (vm, "node %v, type %s, state %U, index %d%v\n",
758 n->name, type_str, format_vlib_node_state, vm, n,
760 vec_reset_length (s);
762 if (n->node_fn_registrations)
764 vlib_node_fn_registration_t *fnr = n->node_fn_registrations;
765 vlib_node_fn_variant_t *v;
768 v = vec_elt_at_index (vm->node_main.variants, fnr->march_variant);
769 if (vec_len (s) == 0)
770 s = format (s, "\n %-15s %=8s %6s %s", "Name", "Priority",
771 "Active", "Description");
772 s = format (s, "\n %-15s %8d %=6s %s", v->suffix, v->priority,
773 fnr->function == n->function ? "yes" : "", v->desc);
774 fnr = fnr->next_registration;
778 s = format (s, "\n default only");
779 vlib_cli_output (vm, " node function variants:%v\n", s);
780 vec_reset_length (s);
782 for (i = 0; i < vec_len (n->next_nodes); i++)
785 if (n->next_nodes[i] == VLIB_INVALID_NODE_INDEX)
788 pn = vec_elt (nm->nodes, n->next_nodes[i]);
790 if (vec_len (s) == 0)
791 s = format (s, "\n %10s %10s %=30s %8s",
792 "next-index", "node-index", "Node", "Vectors");
794 s = format (s, "\n %=10u %=10u %=30v %=8llu", i, n->next_nodes[i],
795 pn->name, vec_elt (n->n_vectors_by_next_node, i));
798 if (vec_len (s) == 0)
799 s = format (s, "\n none");
800 vlib_cli_output (vm, "\n next nodes:%v\n", s);
801 vec_reset_length (s);
803 if (n->type == VLIB_NODE_TYPE_INTERNAL)
806 clib_bitmap_foreach (i, n->prev_node_bitmap) {
807 vlib_node_t *pn = vlib_get_node (vm, i);
809 s = format (s, "\n ");
810 s2 = format (s2, "%v (%u)", pn->name, i);
811 s = format (s, "%-35v", s2);
812 vec_reset_length (s2);
815 if (vec_len (s) == 0)
816 s = format (s, "\n none");
817 vlib_cli_output (vm, "\n known previous nodes:%v\n", s);
818 vec_reset_length (s);
825 s = format (s, "\n%8s %=12s %=12s %=12s %=12s %=12s\n", "Thread", "Calls",
826 "Clocks", "Vectors", "Max Clock", "Max Vectors");
827 for (i = 0; i < vlib_get_n_threads (); i++)
829 n = vlib_get_node (vlib_get_main_by_index (i), node_index);
830 vlib_node_sync_stats (vlib_get_main_by_index (i), n);
832 cl = n->stats_total.clocks - n->stats_last_clear.clocks;
833 ca = n->stats_total.calls - n->stats_last_clear.calls;
834 v = n->stats_total.vectors - n->stats_last_clear.vectors;
836 s = format (s, "%=8u %=12lu %=12lu %=12lu %=12u %=12u\n", i, ca, cl, v,
837 n->stats_total.max_clock, n->stats_total.max_clock_n);
840 vlib_cli_output (vm, "%v", s);
848 VLIB_CLI_COMMAND (show_node_command, static) = {
850 .short_help = "show node [index] <node-name | node-index>",
851 .function = show_node,
854 static clib_error_t *
855 set_node_fn(vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
857 unformat_input_t _line_input, *line_input = &_line_input;
858 u32 node_index, march_variant;
860 clib_error_t *err = 0;
862 if (!unformat_user (input, unformat_line_input, line_input))
865 if (!unformat (line_input, "%U", unformat_vlib_node, vm, &node_index))
867 err = clib_error_return (0, "please specify valid node name");
871 if (!unformat (line_input, "%U", unformat_vlib_node_variant, &march_variant))
873 err = clib_error_return (0, "please specify node function variant");
877 n = vlib_get_node (vm, node_index);
879 if (n->node_fn_registrations == 0)
881 err = clib_error_return (0, "node doesn't have function variants");
885 if (vlib_node_set_march_variant (vm, node_index, march_variant))
887 vlib_node_fn_variant_t *v;
888 v = vec_elt_at_index (vm->node_main.variants, march_variant);
889 err = clib_error_return (0, "node function variant '%s' not found",
896 unformat_free (line_input);
900 VLIB_CLI_COMMAND (set_node_fn_command, static) = {
901 .path = "set node function",
902 .short_help = "set node function <node-name> <variant-name>",
903 .function = set_node_fn,
906 /* Dummy function to get us linked in. */
908 vlib_node_cli_reference (void)
913 * fd.io coding-style-patch-verification: ON
916 * eval: (c-set-style "gnu")