X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvlib%2Fnode_cli.c;h=bf18702d582cc32052bf1c282f088bb260130f83;hb=62d9fda8e474f87459c6e24d13b09f7bfec146f3;hp=062854af5bcb66074ab3ad681e09b171cdf3d1c5;hpb=4d1a866aff6ceb03025990b6e60b42faf09ef486;p=vpp.git diff --git a/src/vlib/node_cli.c b/src/vlib/node_cli.c index 062854af5bc..bf18702d582 100644 --- a/src/vlib/node_cli.c +++ b/src/vlib/node_cli.c @@ -37,6 +37,9 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include +#include +#include #include #include @@ -88,6 +91,81 @@ VLIB_CLI_COMMAND (show_node_graph_command, static) = { }; /* *INDENT-ON* */ +static clib_error_t * +show_node_graphviz (vlib_main_t * vm, + unformat_input_t * input, vlib_cli_command_t * cmd) +{ + clib_error_t *error = 0; + vlib_node_main_t *nm = &vm->node_main; + u8 *chroot_filename = 0; + int fd; + vlib_node_t **nodes = 0; + uword i, j; + + if (!unformat_user (input, unformat_vlib_tmpfile, &chroot_filename)) + { + fd = -1; + } + else + { + fd = + open ((char *) chroot_filename, O_CREAT | O_TRUNC | O_WRONLY, 0664); + } + +#define format__(vm__, fd__, ...) \ + if ((fd) < 0) \ + { \ + vlib_cli_output((vm__), ## __VA_ARGS__); \ + } \ + else \ + { \ + fdformat((fd__), ## __VA_ARGS__); \ + } + + format__ (vm, fd, "%s", "digraph {\n"); + + nodes = vec_dup (nm->nodes); + vec_sort_with_function (nodes, node_cmp); + + for (i = 0; i < vec_len (nodes); i++) + { + for (j = 0; j < vec_len (nodes[i]->next_nodes); j++) + { + vlib_node_t *x; + + if (nodes[i]->next_nodes[j] == VLIB_INVALID_NODE_INDEX) + continue; + + x = vec_elt (nm->nodes, nodes[i]->next_nodes[j]); + format__ (vm, fd, " \"%v\" -> \"%v\"\n", nodes[i]->name, x->name); + } + } + + format__ (vm, fd, "%s", "}"); + + if (fd >= 0) + { + vlib_cli_output (vm, + "vlib graph dumped into `%s'. Run eg. `fdp -Tsvg -O %s'.", + chroot_filename, chroot_filename); + } + + vec_free (nodes); + vec_free (chroot_filename); + vec_free (nodes); + if (fd >= 0) + close (fd); + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (show_node_graphviz_command, static) = { + .path = "show vlib graphviz", + .short_help = "Dump packet processing node graph as a graphviz dotfile", + .function = show_node_graphviz, +}; +/* *INDENT-ON* */ + static u8 * format_vlib_node_state (u8 * s, va_list * va) { @@ -148,8 +226,6 @@ format_vlib_node_stats (u8 * s, va_list * va) f64 maxc, maxcn; u32 maxn; u32 indent; - u64 pmc_ticks; - f64 pmc_ticks_per_packet; if (!n) { @@ -163,9 +239,6 @@ format_vlib_node_stats (u8 * s, va_list * va) "%=30s%=12s%=16s%=16s%=16s%=16s%=16s", "Name", "State", "Calls", "Vectors", "Suspends", "Clocks", "Vectors/Call"); - if (vm->perf_counter_id) - s = format (s, "%=16s", "Perf Ticks"); - return s; } @@ -182,13 +255,6 @@ format_vlib_node_stats (u8 * s, va_list * va) else maxcn = 0.0; - pmc_ticks = n->stats_total.perf_counter_ticks - - n->stats_last_clear.perf_counter_ticks; - if (p > 0) - pmc_ticks_per_packet = (f64) pmc_ticks / (f64) p; - else - pmc_ticks_per_packet = 0.0; - /* Clocks per packet, per call or per suspend. */ x = 0; if (p > 0) @@ -221,9 +287,6 @@ format_vlib_node_stats (u8 * s, va_list * va) s = format (s, "%-30v%=12U%16Ld%16Ld%16Ld%16.2e%16.2f", ns, format_vlib_node_state, vm, n, c, p, d, x, v); - if (pmc_ticks_per_packet > 0.0) - s = format (s, "%16.2e", pmc_ticks_per_packet); - if (ns != n->name) vec_free (ns); @@ -236,6 +299,13 @@ format_vlib_node_stats (u8 * s, va_list * va) return s; } +f64 vlib_get_stat_segment_update_rate (void) __attribute__ ((weak)); +f64 +vlib_get_stat_segment_update_rate (void) +{ + return 1e70; +} + static clib_error_t * show_node_runtime (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) @@ -245,8 +315,7 @@ show_node_runtime (vlib_main_t * vm, f64 time_now; u32 node_index; vlib_node_t ***node_dups = 0; - f64 *vectors_per_main_loop = 0; - f64 *last_vector_length_per_node = 0; + f64 *internal_node_vector_rates = 0; time_now = vlib_time_now (vm); @@ -266,6 +335,7 @@ show_node_runtime (vlib_main_t * vm, u64 n_internal_vectors, n_internal_calls; u64 n_clocks, l, v, c, d; int brief = 1; + int summary = 0; int max = 0; vlib_main_t **stat_vms = 0, *stat_vm; @@ -276,6 +346,9 @@ show_node_runtime (vlib_main_t * vm, brief = 0; if (unformat (input, "max") || unformat (input, "m")) max = 1; + if (unformat (input, "summary") || unformat (input, "sum") + || unformat (input, "su")) + summary = 1; for (i = 0; i < vec_len (vlib_mains); i++) { @@ -304,10 +377,8 @@ show_node_runtime (vlib_main_t * vm, nodes = vec_dup (nm->nodes); vec_add1 (node_dups, nodes); - vec_add1 (vectors_per_main_loop, - vlib_last_vectors_per_main_loop_as_f64 (stat_vm)); - vec_add1 (last_vector_length_per_node, - vlib_last_vector_length_per_node (stat_vm)); + vec_add1 (internal_node_vector_rates, + vlib_internal_node_vector_rate (stat_vm)); } vlib_worker_thread_barrier_release (vm); @@ -371,39 +442,38 @@ show_node_runtime (vlib_main_t * vm, dt = time_now - nm->time_last_runtime_stats_clear; vlib_cli_output (vm, - "Time %.1f, average vectors/node %.2f, last %d main loops %.2f per node %.2f" - "\n vector rates in %.4e, out %.4e, drop %.4e, punt %.4e", + "Time %.1f, %f sec internal node vector rate %.2f \n" + " vector rates in %.4e, out %.4e, drop %.4e, punt %.4e", dt, - (n_internal_calls > 0 - ? (f64) n_internal_vectors / (f64) n_internal_calls - : 0), - 1 << VLIB_LOG2_MAIN_LOOPS_PER_STATS_UPDATE, - vectors_per_main_loop[j], - last_vector_length_per_node[j], + vlib_get_stat_segment_update_rate (), + internal_node_vector_rates[j], (f64) n_input / dt, (f64) n_output / dt, (f64) n_drop / dt, (f64) n_punt / dt); - vlib_cli_output (vm, "%U", format_vlib_node_stats, stat_vm, 0, max); - for (i = 0; i < vec_len (nodes); i++) + if (summary == 0) { - c = - nodes[i]->stats_total.calls - - nodes[i]->stats_last_clear.calls; - d = - nodes[i]->stats_total.suspends - - nodes[i]->stats_last_clear.suspends; - if (c || d || !brief) + vlib_cli_output (vm, "%U", format_vlib_node_stats, stat_vm, + 0, max); + for (i = 0; i < vec_len (nodes); i++) { - vlib_cli_output (vm, "%U", format_vlib_node_stats, stat_vm, - nodes[i], max); + c = + nodes[i]->stats_total.calls - + nodes[i]->stats_last_clear.calls; + d = + nodes[i]->stats_total.suspends - + nodes[i]->stats_last_clear.suspends; + if (c || d || !brief) + { + vlib_cli_output (vm, "%U", format_vlib_node_stats, + stat_vm, nodes[i], max); + } } } vec_free (nodes); } vec_free (stat_vms); vec_free (node_dups); - vec_free (vectors_per_main_loop); - vec_free (last_vector_length_per_node); + vec_free (internal_node_vector_rates); } return 0; @@ -499,6 +569,9 @@ show_node (vlib_main_t * vm, unformat_input_t * input, else error = clib_error_return (0, "unknown input '%U'", format_unformat_error, line_input); + + if (error) + break; } unformat_free (line_input); @@ -533,7 +606,7 @@ show_node (vlib_main_t * vm, unformat_input_t * input, if (n->sibling_of) s = format (s, ", sibling-of %s", n->sibling_of); - vlib_cli_output (vm, "node %s, type %s, state %U, index %d%v\n", + vlib_cli_output (vm, "node %v, type %s, state %U, index %d%v\n", n->name, type_str, format_vlib_node_state, vm, n, n->index, s); vec_reset_length (s);