FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
cli.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 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 #include <vnet/vnet.h>
17 #include <perfmon/perfmon.h>
18 #include <vppinfra/format_table.h>
19 
20 uword
22 {
24  perfmon_bundle_t **b = va_arg (*args, perfmon_bundle_t **);
25  uword *p;
26  u8 *str = 0;
27 
28  if (unformat (input, "%s", &str) == 0)
29  return 0;
30 
31  p = hash_get_mem (pm->bundle_by_name, str);
32 
33  if (p)
34  b[0] = (perfmon_bundle_t *) p[0];
35 
36  vec_free (str);
37  return p ? 1 : 0;
38 }
39 
40 uword
42 {
44  perfmon_source_t **b = va_arg (*args, perfmon_source_t **);
45  uword *p;
46  u8 *str = 0;
47 
48  if (unformat (input, "%s", &str) == 0)
49  return 0;
50 
51  p = hash_get_mem (pm->source_by_name, str);
52 
53  if (p)
54  b[0] = (perfmon_source_t *) p[0];
55 
56  vec_free (str);
57  return p ? 1 : 0;
58 }
59 
60 u8 *
61 format_perfmon_bundle (u8 *s, va_list *args)
62 {
63  perfmon_bundle_t *b = va_arg (*args, perfmon_bundle_t *);
64  int verbose = va_arg (*args, int);
65 
66  const char *bundle_type[] = {
67  [PERFMON_BUNDLE_TYPE_NODE] = "node",
68  [PERFMON_BUNDLE_TYPE_THREAD] = "thread",
69  [PERFMON_BUNDLE_TYPE_SYSTEM] = "system",
70  };
71 
72  if (b == 0)
73  return format (s, "%-20s%-10s%-20s%s", "Name", "Type", "Source",
74  "Description");
75 
76  if (verbose)
77  {
78  s = format (s, "name: %s\n", b->name);
79  s = format (s, "description: %s\n", b->description);
80  s = format (s, "source: %s\n", b->src->name);
81  for (int i = 0; i < b->n_events; i++)
82  {
83  perfmon_event_t *e = b->src->events + b->events[i];
84  s = format (s, "event %u: %s\n", i, e->name);
85  }
86  }
87  else
88  s = format (s, "%-20s%-10s%-20s%s", b->name, bundle_type[b->type],
89  b->src->name, b->description);
90 
91  return s;
92 }
93 
94 static int
95 bundle_name_sort_cmp (void *a1, void *a2)
96 {
97  perfmon_bundle_t **n1 = a1;
98  perfmon_bundle_t **n2 = a2;
99 
100  return clib_strcmp ((char *) (*n1)->name, (char *) (*n2)->name);
101 }
102 
103 static clib_error_t *
105  vlib_cli_command_t *cmd)
106 {
108  unformat_input_t _line_input, *line_input = &_line_input;
109  perfmon_bundle_t *b = 0, **vb = 0;
110  int verbose = 0;
111 
112  if (unformat_user (input, unformat_line_input, line_input))
113  {
114  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
115  {
116  if (unformat (line_input, "verbose"))
117  verbose = 1;
118  else if (unformat (line_input, "%U", unformat_perfmon_bundle_name,
119  &b))
120  vec_add (vb, &b, 1);
121  else
122  return clib_error_return (0, "unknown input `%U'",
123  format_unformat_error, line_input);
124  }
125  unformat_free (line_input);
126  }
127 
128  if (vb == 0)
129  {
130  char *key;
131  hash_foreach_mem (key, b, pm->bundle_by_name, vec_add (vb, &b, 1););
132  }
133  else
134  verbose = 1;
135 
136  if (verbose == 0)
137  vlib_cli_output (vm, "%U\n", format_perfmon_bundle, 0, 0);
138 
140 
141  for (int i = 0; i < vec_len (vb); i++)
142  /* bundle type will be unknown if no cpu_supports matched */
144  vlib_cli_output (vm, "%U\n", format_perfmon_bundle, vb[i], verbose);
145 
146  vec_free (vb);
147  return 0;
148 }
149 
151  .path = "show perfmon bundle",
152  .short_help = "show perfmon bundle [<bundle-name>] [verbose]",
153  .function = show_perfmon_bundle_command_fn,
154  .is_mp_safe = 1,
155 };
156 
157 u8 *
158 format_perfmon_source (u8 *s, va_list *args)
159 {
160  perfmon_source_t *src = va_arg (*args, perfmon_source_t *);
161  int verbose = va_arg (*args, int);
162 
163  if (src == 0)
164  return format (s, "%-20s%-9s %s", "Name", "NumEvents", "Description");
165 
166  if (verbose)
167  {
168  s = format (s, "name: %s\n", src->name);
169  s = format (s, "description: %s\n", src->description);
170  s = format (s, "Events:\n");
171  for (int i = 0; i < src->n_events; i++)
172  {
173  perfmon_event_t *e = src->events + i;
174  s = format (s, " %s", e->name);
175  if (src->format_config)
176  s = format (s, " (%U)\n", src->format_config, e->config);
177  else
178  s = format (s, " (0x%x)\n", e->config);
179  if (e->description)
180  s = format (s, " %s\n", e->description);
181  }
182 
183  if (src->instances_by_type)
184  {
185  s = format (s, "Instances:\n");
186  for (int i = 0; i < vec_len (src->instances_by_type); i++)
187  {
189  it = vec_elt_at_index (src->instances_by_type, i);
190  if (vec_len (it->instances) == 0)
191  continue;
192  s = format (s, " %s:\n ", it->name);
193  for (int j = 0; j < vec_len (it->instances); j++)
194  {
195  perfmon_instance_t *in = vec_elt_at_index (it->instances, j);
196  s = format (s, " %s", in->name);
197  }
198  s = format (s, "\n");
199  }
200  }
201  }
202  else
203  s = format (s, "%-20s%9u %s", src->name, src->n_events, src->description);
204 
205  return s;
206 }
207 
208 static clib_error_t *
210  vlib_cli_command_t *cmd)
211 {
213  unformat_input_t _line_input, *line_input = &_line_input;
214  perfmon_source_t *s = 0, **vs = 0;
215  int verbose = 0;
216 
217  if (unformat_user (input, unformat_line_input, line_input))
218  {
219  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
220  {
221  if (unformat (line_input, "verbose"))
222  verbose = 1;
223  else if (unformat (line_input, "%U", unformat_perfmon_source_name,
224  &s))
225  vec_add (vs, &s, 1);
226  else
227  return clib_error_return (0, "unknown input `%U'",
228  format_unformat_error, line_input);
229  }
230  unformat_free (line_input);
231  }
232 
233  if (vs == 0)
234  {
235  char *key;
236  hash_foreach_mem (key, s, pm->source_by_name, vec_add (vs, &s, 1););
237  }
238  else
239  verbose = 1;
240 
241  if (verbose == 0)
242  vlib_cli_output (vm, "%U\n", format_perfmon_source, 0, 0);
243 
244  for (int i = 0; i < vec_len (vs); i++)
245  vlib_cli_output (vm, "%U\n", format_perfmon_source, vs[i], verbose);
246 
247  vec_free (vs);
248  return 0;
249 }
250 
252  .path = "show perfmon source",
253  .short_help = "show perfmon source [<source-name>] [verbose]",
254  .function = show_perfmon_source_command_fn,
255  .is_mp_safe = 1,
256 };
257 
258 static clib_error_t *
260  unformat_input_t *input,
261  vlib_cli_command_t *cmd)
262 {
264 
266  return 0;
267 }
268 
270  .path = "show perfmon active-bundle",
271  .short_help = "show perfmon active-bundle",
273  .is_mp_safe = 1,
274 };
275 
276 static clib_error_t *
278  vlib_cli_command_t *cmd)
279 {
282  clib_error_t *err = 0;
283  table_t table = {}, *t = &table;
284  u32 n_instances;
285  perfmon_reading_t *r, *readings = 0;
287  perfmon_instance_t *in;
288  u8 *s = 0;
289  int n_row = 0;
290 
291  if (b == 0)
292  return clib_error_return (0, "no bundle selected");
293 
294  n_instances = vec_len (it->instances);
295  vec_validate (readings, n_instances - 1);
296 
297  /*Only perform read() for THREAD or SYSTEM bundles*/
298  for (int i = 0; i < n_instances && b->type != PERFMON_BUNDLE_TYPE_NODE; i++)
299  {
300  in = vec_elt_at_index (it->instances, i);
301  r = vec_elt_at_index (readings, i);
302 
303  if (read (pm->group_fds[i], r, (b->n_events + 3) * sizeof (u64)) == -1)
304  {
305  err = clib_error_return_unix (0, "read");
306  goto done;
307  }
308  }
309 
310  table_format_title (t, "%s", b->description);
311 
312  table_add_header_col (t, 0);
313  table_add_header_row (t, 0);
314 
315  if (b->column_headers)
316  {
317  char **hdr = b->column_headers;
318  while (hdr[0])
319  table_format_cell (t, -1, n_row++, "%s", hdr++[0]);
320  }
321 
322  int col = 0;
323  for (int i = 0; i < n_instances; i++)
324  {
325  in = vec_elt_at_index (it->instances, i);
326  r = vec_elt_at_index (readings, i);
327  table_format_cell (t, col, -1, "%s", in->name, b->type);
328  if (b->type == PERFMON_BUNDLE_TYPE_NODE)
329  {
331  tr = vec_elt_at_index (pm->thread_runtimes, i);
332  for (int j = 0; j < tr->n_nodes; j++)
333  if (tr->node_stats[j].n_calls)
334  {
336  table_format_cell (t, ++col, -1, "%U", format_vlib_node_name,
337  vm, j, b->type);
338  table_set_cell_align (t, col, -1, TTAA_RIGHT);
339  table_set_cell_fg_color (t, col, -1, TTAC_CYAN);
340  clib_memcpy_fast (&ns, tr->node_stats + j, sizeof (ns));
341 
342  for (int j = 0; j < n_row; j++)
343  table_format_cell (t, col, j, "%U", b->format_fn, &ns, j,
344  b->type);
345  }
346  }
347  else
348  {
349  for (int j = 0; j < n_row; j++)
350  table_format_cell (t, i, j, "%U", b->format_fn, r, j, b->type);
351  }
352  col++;
353  }
354 
355  vlib_cli_output (vm, "%U\n", format_table, t);
356  table_free (t);
357 
358  if (b->footer)
359  vlib_cli_output (vm, "\n%s\n", b->footer);
360 
361 done:
362  vec_free (readings);
363  vec_free (s);
364  return err;
365 }
366 
368  .path = "show perfmon statistics",
369  .short_help = "show perfmon statistics [raw]",
370  .function = show_perfmon_stats_command_fn,
371  .is_mp_safe = 1,
372 };
373 
374 static clib_error_t *
376  vlib_cli_command_t *cmd)
377 {
378  perfmon_reset (vm);
379  return 0;
380 }
381 
383  .path = "perfmon reset",
384  .short_help = "perfmon reset",
385  .function = perfmon_reset_command_fn,
386  .is_mp_safe = 1,
387 };
388 
389 static clib_error_t *
391  vlib_cli_command_t *cmd)
392 {
394  unformat_input_t _line_input, *line_input = &_line_input;
395  perfmon_bundle_t *b = 0;
396 
397  if (pm->is_running)
398  return clib_error_return (0, "please stop first");
399 
400  if (unformat_user (input, unformat_line_input, line_input) == 0)
401  return clib_error_return (0, "please specify bundle name");
402 
403  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
404  {
405  if (unformat (line_input, "bundle %U", unformat_perfmon_bundle_name, &b))
406  ;
407  else
408  return clib_error_return (0, "unknown input '%U'",
409  format_unformat_error, line_input);
410  }
411  unformat_free (line_input);
412 
413  if (b == 0)
414  return clib_error_return (0, "please specify bundle name");
415 
416  return perfmon_start (vm, b);
417 }
418 
420  .path = "perfmon start",
421  .short_help = "perfmon start bundle [<bundle-name>]",
422  .function = perfmon_start_command_fn,
423  .is_mp_safe = 1,
424 };
425 
426 static clib_error_t *
428  vlib_cli_command_t *cmd)
429 {
430  return perfmon_stop (vm);
431 }
432 
434  .path = "perfmon stop",
435  .short_help = "perfmon stop",
436  .function = perfmon_stop_command_fn,
437  .is_mp_safe = 1,
438 };
perfmon_node_stats_t
Definition: perfmon.h:140
perfmon_event_t::config
u64 config
Definition: perfmon.h:53
table_add_header_row
void table_add_header_row(table_t *t, int n_strings,...)
Definition: format_table.c:269
vec_add
#define vec_add(V, E, N)
Add N elements to end of vector V (no header, unspecified alignment)
Definition: vec.h:688
PERFMON_BUNDLE_TYPE_NODE
@ PERFMON_BUNDLE_TYPE_NODE
Definition: perfmon.h:31
unformat_user
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
perfmon_reading_t
Definition: perfmon.h:132
perfmon_reset_command
static vlib_cli_command_t perfmon_reset_command
(constructor) VLIB_CLI_COMMAND (perfmon_reset_command)
Definition: cli.c:382
table_free
void table_free(table_t *t)
Definition: format_table.c:232
perfmon_reset
void perfmon_reset(vlib_main_t *vm)
Definition: perfmon.c:45
perfmon_main_t::active_bundle
perfmon_bundle_t * active_bundle
Definition: perfmon.h:171
unformat_line_input
unformat_function_t unformat_line_input
Definition: format.h:275
perfmon_event_t
Definition: perfmon.h:44
perfmon_main_t
Definition: perfmon.h:164
perfmon_instance_type_t
Definition: perfmon.h:66
perfmon_node_stats_t::n_calls
u64 n_calls
Definition: perfmon.h:143
perfmon_thread_runtime_t::n_nodes
u16 n_nodes
Definition: perfmon.h:158
show_perfmon_source_command
static vlib_cli_command_t show_perfmon_source_command
(constructor) VLIB_CLI_COMMAND (show_perfmon_source_command)
Definition: cli.c:251
perfmon_main
perfmon_main_t perfmon_main
Definition: perfmon.c:27
TTAC_CYAN
@ TTAC_CYAN
Definition: format_table.h:47
clib_error_return
#define clib_error_return(e, args...)
Definition: error.h:99
vlib_cli_command_t::path
char * path
Definition: cli.h:96
format_table.h
PERFMON_BUNDLE_TYPE_UNKNOWN
@ PERFMON_BUNDLE_TYPE_UNKNOWN
Definition: perfmon.h:30
perfmon_bundle
Definition: perfmon.h:105
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
format_perfmon_source
u8 * format_perfmon_source(u8 *s, va_list *args)
Definition: cli.c:158
clib_strcmp
#define clib_strcmp(s1, s2)
Definition: string.h:823
unformat_input_t
struct _unformat_input_t unformat_input_t
r
vnet_hw_if_output_node_runtime_t * r
Definition: interface_output.c:1089
perfmon_main_t::active_instance_type
perfmon_instance_type_t * active_instance_type
Definition: perfmon.h:177
clib_memcpy_fast
static_always_inline void * clib_memcpy_fast(void *restrict dst, const void *restrict src, size_t n)
Definition: string.h:92
perfmon_main_t::thread_runtimes
perfmon_thread_runtime_t * thread_runtimes
Definition: perfmon.h:166
perfmon_main_t::source_by_name
uword * source_by_name
Definition: perfmon.h:170
key
typedef key
Definition: ipsec_types.api:91
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
unformat_free
static void unformat_free(unformat_input_t *i)
Definition: format.h:155
perfmon_source
Definition: perfmon.h:82
table_set_cell_fg_color
void table_set_cell_fg_color(table_t *t, int c, int r, table_text_attr_color_t v)
Definition: format_table.c:216
show_perfmon_source_command_fn
static clib_error_t * show_perfmon_source_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:209
PERFMON_BUNDLE_TYPE_THREAD
@ PERFMON_BUNDLE_TYPE_THREAD
Definition: perfmon.h:32
vec_elt_at_index
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
Definition: vec_bootstrap.h:203
bundle_name_sort_cmp
static int bundle_name_sort_cmp(void *a1, void *a2)
Definition: cli.c:95
unformat_check_input
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:163
perfmon_stop_command_fn
static clib_error_t * perfmon_stop_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:427
table_set_cell_align
void table_set_cell_align(table_t *t, int c, int r, table_text_attr_align_t a)
Definition: format_table.c:209
uword
u64 uword
Definition: types.h:112
format_table
__clib_export format_function_t format_table
Definition: format_table.h:95
PERFMON_BUNDLE_TYPE_SYSTEM
@ PERFMON_BUNDLE_TYPE_SYSTEM
Definition: perfmon.h:33
show_perfmon_stats_command_fn
static clib_error_t * show_perfmon_stats_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:277
format_unformat_error
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
vec_validate
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment)
Definition: vec.h:523
VLIB_CLI_COMMAND
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:163
src
vl_api_address_t src
Definition: gre.api:54
it
save_rewrite_length must be aligned so that reass doesn t overwrite it
Definition: buffer.h:425
vlib_cli_output
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:716
show_perfmon_stats_command
static vlib_cli_command_t show_perfmon_stats_command
(constructor) VLIB_CLI_COMMAND (show_perfmon_stats_command)
Definition: cli.c:367
perfmon_instance_t
Definition: perfmon.h:58
format_perfmon_bundle
u8 * format_perfmon_bundle(u8 *s, va_list *args)
Definition: cli.c:61
perfmon_reset_command_fn
static clib_error_t * perfmon_reset_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:375
TTAA_RIGHT
@ TTAA_RIGHT
Definition: format_table.h:55
vb
vnet_buffer_opaque_t * vb(void *vb_arg)
Definition: gdb_funcs.c:336
table_format_cell
void table_format_cell(table_t *t, int c, int r, char *fmt,...)
Definition: format_table.c:192
show_perfmon_active_bundle_command
static vlib_cli_command_t show_perfmon_active_bundle_command
(constructor) VLIB_CLI_COMMAND (show_perfmon_active_bundle_command)
Definition: cli.c:269
hash_get_mem
#define hash_get_mem(h, key)
Definition: hash.h:269
perfmon_start_command_fn
static clib_error_t * perfmon_start_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:390
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
perfmon_main_t::group_fds
int * group_fds
Definition: perfmon.h:174
perfmon_start_command
static vlib_cli_command_t perfmon_start_command
(constructor) VLIB_CLI_COMMAND (perfmon_start_command)
Definition: cli.c:419
format_vlib_node_name
format_function_t format_vlib_node_name
Definition: node_funcs.h:1235
table_t
Definition: format_table.h:80
u64
unsigned long u64
Definition: types.h:89
format
description fragment has unexpected format
Definition: map.api:433
perfmon_main_t::bundle_by_name
uword * bundle_by_name
Definition: perfmon.h:168
u32
unsigned int u32
Definition: types.h:88
perfmon_main_t::is_running
int is_running
Definition: perfmon.h:172
perfmon_instance_t::name
char * name
Definition: perfmon.h:63
clib_error_return_unix
#define clib_error_return_unix(e, args...)
Definition: error.h:102
perfmon_event_t::name
char * name
Definition: perfmon.h:54
perfmon_thread_runtime_t
Definition: perfmon.h:155
vec_sort_with_function
#define vec_sort_with_function(vec, f)
Sort a vector using the supplied element comparison function.
Definition: vec.h:1097
vlib_main_t
Definition: main.h:102
show_perfmon_bundle_command
static vlib_cli_command_t show_perfmon_bundle_command
(constructor) VLIB_CLI_COMMAND (show_perfmon_bundle_command)
Definition: cli.c:150
b
vlib_buffer_t ** b
Definition: nat44_ei_out2in.c:717
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
table_format_title
void table_format_title(table_t *t, char *fmt,...)
Definition: format_table.c:169
perfmon_thread_runtime_t::node_stats
perfmon_node_stats_t * node_stats
Definition: perfmon.h:159
perfmon_event_t::description
char * description
Definition: perfmon.h:55
i
int i
Definition: flowhash_template.h:376
perfmon_stop
clib_error_t * perfmon_stop(vlib_main_t *vm)
Definition: perfmon.c:262
unformat_perfmon_bundle_name
uword unformat_perfmon_bundle_name(unformat_input_t *input, va_list *args)
Definition: cli.c:21
show_perfmon_active_bundle_command_fn
static clib_error_t * show_perfmon_active_bundle_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:259
perfmon_start
clib_error_t * perfmon_start(vlib_main_t *vm, perfmon_bundle_t *b)
Definition: perfmon.c:216
vnet.h
vlib_cli_command_t
Definition: cli.h:92
show_perfmon_bundle_command_fn
static clib_error_t * show_perfmon_bundle_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:104
unformat_perfmon_source_name
uword unformat_perfmon_source_name(unformat_input_t *input, va_list *args)
Definition: cli.c:41
hash_foreach_mem
#define hash_foreach_mem(key_var, value_var, h, body)
Definition: hash.h:460
table_add_header_col
void table_add_header_col(table_t *t, int n_strings,...)
Definition: format_table.c:247
perfmon_stop_command
static vlib_cli_command_t perfmon_stop_command
(constructor) VLIB_CLI_COMMAND (perfmon_stop_command)
Definition: cli.c:433
type
vl_api_fib_path_type_t type
Definition: fib_types.api:123
UNFORMAT_END_OF_INPUT
#define UNFORMAT_END_OF_INPUT
Definition: format.h:137