summaryrefslogtreecommitdiffstats
path: root/src/scripts/host-stack
AgeCommit message (Collapse)AuthorFilesLines
2019-11-05misc: Fix python scripts shebang lineRenato Botelho do Couto1-1/+1
Type: fix Since CentOS 8, RPM build script doesn't accept '#!/usr/bin/env python' as a valid shebang line. It requires scripts to explicitly chose between python2 or python3. Change all to use python3 as suggested by Paul Vinciguerra. Depends-On: https://gerrit.fd.io/r/23170 Signed-off-by: Renato Botelho do Couto <renato@netgate.com> Change-Id: Ie72af9f60fd0609e07f05b70f8d96e738b2754d1
2019-06-12tcp: add cc stats plotting toolsFlorin Coras2-0/+231
Type: feature cc_plot.py can plot cc stats collected via elogs from tcp connections. To enable the collection of cc stats, tcp must be compiled with TCP_DEBUG_CC_STAT turned on. Once the tests have been carried out, and elogs have been saved with "ev save log <file>", the logs can be converted to txt format with the convert_evt script. The resulting file can be used as input to the cc_plots script. Change-Id: I16df2993fa09cab9ad35f91825eab7df4da6428b Signed-off-by: Florin Coras <fcoras@cisco.com>
06 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513
/*
 * Copyright (c) 2020 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <vnet/vnet.h>
#include <perfmon/perfmon.h>
#include <vppinfra/format_table.h>

uword
unformat_perfmon_bundle_name (unformat_input_t *input, va_list *args)
{
  perfmon_main_t *pm = &perfmon_main;
  perfmon_bundle_t **b = va_arg (*args, perfmon_bundle_t **);
  uword *p;
  u8 *str = 0;

  if (unformat (input, "%s", &str) == 0)
    return 0;

  p = hash_get_mem (pm->bundle_by_name, str);

  if (p)
    b[0] = (perfmon_bundle_t *) p[0];

  vec_free (str);
  return p ? 1 : 0;
}

uword
unformat_perfmon_active_type (unformat_input_t *input, va_list *args)
{
  perfmon_bundle_t *b = va_arg (*args, perfmon_bundle_t *);
  perfmon_bundle_type_t *bundle_type = va_arg (*args, perfmon_bundle_type_t *);
  char *str = 0;

  char *_str_types[PERFMON_BUNDLE_TYPE_MAX];

#define _(type, pstr) _str_types[type] = (char *) pstr;

  foreach_perfmon_bundle_type
#undef _

    if (!b) return 0;

  if (unformat (input, "%s", &str) == 0)
    return 0;

  for (int i = PERFMON_BUNDLE_TYPE_NODE; i < PERFMON_BUNDLE_TYPE_MAX; i++)
    {
      /* match the name and confirm it is available on this cpu */
      if (strncmp (str, _str_types[i], strlen (_str_types[i])) == 0 &&
	  (b->type_flags & 1 << i))
	{
	  *bundle_type = i;
	  break;
	}
    }

  vec_free (str);
  return bundle_type ? 1 : 0;
}

uword
unformat_perfmon_source_name (unformat_input_t *input, va_list *args)
{
  perfmon_main_t *pm = &perfmon_main;
  perfmon_source_t **b = va_arg (*args, perfmon_source_t **);
  uword *p;
  u8 *str = 0;

  if (unformat (input, "%s", &str) == 0)
    return 0;

  p = hash_get_mem (pm->source_by_name, str);

  if (p)
    b[0] = (perfmon_source_t *) p[0];

  vec_free (str);
  return p ? 1 : 0;
}

u8 *
format_perfmon_bundle (u8 *s, va_list *args)
{
  perfmon_bundle_t *b = va_arg (*args, perfmon_bundle_t *);
  int verbose = va_arg (*args, int);

  int vl = 0;

  u8 *_bundle_type = 0;
  const char *bundle_type[PERFMON_BUNDLE_TYPE_MAX];
#define _(type, pstr) bundle_type[type] = (const char *) pstr;

  foreach_perfmon_bundle_type
#undef _

    if (b == 0) return format (s, "%-20s%-20s%-20s%s", "Name", "Type(s)",
			       "Source", "Description");

  if (verbose)
    {
      s = format (s, "name: %s\n", b->name);
      s = format (s, "description: %s\n", b->description);
      s = format (s, "source: %s\n", b->src->name);
      for (int i = 0; i < b->n_events; i++)
	{
	  perfmon_event_t *e = b->src->events + b->events[i];
	  s = format (s, "event %u: %s\n", i, e->name);
	}
    }
  else
    {
      s = format (s, "%-20s", b->name);
      for (int i = PERFMON_BUNDLE_TYPE_NODE; i < PERFMON_BUNDLE_TYPE_MAX; i++)
	{
	  /* check the type is available on this uarch*/
	  if (b->type_flags & 1 << i)
	    _bundle_type = format (_bundle_type, "%s,", bundle_type[i]);
	}
      /* remove any stray commas */
      if ((vl = vec_len (_bundle_type)))
	_bundle_type[vl - 1] = 0;

      s =
	format (s, "%-20s%-20s%s", _bundle_type, b->src->name, b->description);
    }

  vec_free (_bundle_type);

  return s;
}

static int
bundle_name_sort_cmp (void *a1, void *a2)
{
  perfmon_bundle_t **n1 = a1;
  perfmon_bundle_t **n2 = a2;

  return clib_strcmp ((char *) (*n1)->name, (char *) (*n2)->name);
}

static clib_error_t *
show_perfmon_bundle_command_fn (vlib_main_t *vm, unformat_input_t *input,
				vlib_cli_command_t *cmd)
{
  perfmon_main_t *pm = &perfmon_main;
  unformat_input_t _line_input, *line_input = &_line_input;
  perfmon_bundle_t *b = 0, **vb = 0;
  int verbose = 0;

  if (unformat_user (input, unformat_line_input, line_input))
    {
      while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
	{
	  if (unformat (line_input, "verbose"))
	    verbose = 1;
	  else if (unformat (line_input, "%U", unformat_perfmon_bundle_name,
			     &b))
	    vec_add (vb, &b, 1);
	  else
	    return clib_error_return (0, "unknown input `%U'",
				      format_unformat_error, line_input);
	}
      unformat_free (line_input);
    }

  if (vb == 0)
    {
      char *key;
      hash_foreach_mem (key, b, pm->bundle_by_name, vec_add (vb, &b, 1););
    }
  else
    verbose = 1;

  if (verbose == 0)
    vlib_cli_output (vm, "%U\n", format_perfmon_bundle, 0, 0);

  vec_sort_with_function (vb, bundle_name_sort_cmp);

  for (int i = 0; i < vec_len (vb); i++)
    /* bundle type will be unknown if no cpu_supports matched */
    if (vb[i]->type_flags)
      vlib_cli_output (vm, "%U\n", format_perfmon_bundle, vb[i], verbose);

  vec_free (vb);
  return 0;
}

VLIB_CLI_COMMAND (show_perfmon_bundle_command, static) = {
  .path = "show perfmon bundle",
  .short_help = "show perfmon bundle [<bundle-name>] [verbose]",
  .function = show_perfmon_bundle_command_fn,
  .is_mp_safe = 1,
};

u8 *
format_perfmon_source (u8 *s, va_list *args)
{
  perfmon_source_t *src = va_arg (*args, perfmon_source_t *);
  int verbose = va_arg (*args, int);

  if (src == 0)
    return format (s, "%-20s%-9s %s", "Name", "NumEvents", "Description");

  if (verbose)
    {
      s = format (s, "name:        %s\n", src->name);
      s = format (s, "description: %s\n", src->description);
      s = format (s, "Events:\n");
      for (int i = 0; i < src->n_events; i++)
	{
	  perfmon_event_t *e = src->events + i;
	  s = format (s, "  %s", e->name);
	  if (src->format_config)
	    s = format (s, " (%U)\n", src->format_config, e->config);
	  else
	    s = format (s, " (0x%x)\n", e->config);
	  if (e->description)
	    s = format (s, "    %s\n", e->description);
	}

      if (src->instances_by_type)
	{
	  s = format (s, "Instances:\n");
	  for (int i = 0; i < vec_len (src->instances_by_type); i++)
	    {
	      perfmon_instance_type_t *it;
	      it = vec_elt_at_index (src->instances_by_type, i);
	      if (vec_len (it->instances) == 0)
		continue;
	      s = format (s, "  %s:\n   ", it->name);
	      for (int j = 0; j < vec_len (it->instances); j++)
		{
		  perfmon_instance_t *in = vec_elt_at_index (it->instances, j);
		  s = format (s, " %s", in->name);
		}
	      s = format (s, "\n");
	    }
	}
    }
  else
    s = format (s, "%-20s%9u %s", src->name, src->n_events, src->description);

  return s;
}

static clib_error_t *
show_perfmon_source_command_fn (vlib_main_t *vm, unformat_input_t *input,
				vlib_cli_command_t *cmd)
{
  perfmon_main_t *pm = &perfmon_main;
  unformat_input_t _line_input, *line_input = &_line_input;
  perfmon_source_t *s = 0, **vs = 0;
  int verbose = 0;

  if (unformat_user (input, unformat_line_input, line_input))
    {
      while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
	{
	  if (unformat (line_input, "verbose"))
	    verbose = 1;
	  else if (unformat (line_input, "%U", unformat_perfmon_source_name,
			     &s))
	    vec_add (vs, &s, 1);
	  else
	    return clib_error_return (0, "unknown input `%U'",
				      format_unformat_error, line_input);
	}
      unformat_free (line_input);
    }

  if (vs == 0)
    {
      char *key;
      hash_foreach_mem (key, s, pm->source_by_name, vec_add (vs, &s, 1););
    }
  else
    verbose = 1;

  if (verbose == 0)
    vlib_cli_output (vm, "%U\n", format_perfmon_source, 0, 0);

  for (int i = 0; i < vec_len (vs); i++)
    vlib_cli_output (vm, "%U\n", format_perfmon_source, vs[i], verbose);

  vec_free (vs);
  return 0;
}

VLIB_CLI_COMMAND (show_perfmon_source_command, static) = {
  .path = "show perfmon source",
  .short_help = "show perfmon source [<source-name>] [verbose]",
  .function = show_perfmon_source_command_fn,
  .is_mp_safe = 1,
};

static clib_error_t *
show_perfmon_active_bundle_command_fn (vlib_main_t *vm,
				       unformat_input_t *input,
				       vlib_cli_command_t *cmd)
{
  perfmon_main_t *pm = &perfmon_main;

  vlib_cli_output (vm, "%U\n", format_perfmon_bundle, pm->active_bundle, 1);
  return 0;
}

VLIB_CLI_COMMAND (show_perfmon_active_bundle_command, static) = {
  .path = "show perfmon active-bundle",
  .short_help = "show perfmon active-bundle",
  .function = show_perfmon_active_bundle_command_fn,
  .is_mp_safe = 1,
};

static clib_error_t *
show_perfmon_stats_command_fn (vlib_main_t *vm, unformat_input_t *input,
			       vlib_cli_command_t *cmd)
{
  perfmon_main_t *pm = &perfmon_main;
  perfmon_bundle_t *b = pm->active_bundle;
  clib_error_t *err = 0;
  table_t table = {}, *t = &table;
  u32 n_instances;
  perfmon_reading_t *r, *readings = 0;
  perfmon_instance_type_t *it = pm->active_instance_type;
  perfmon_instance_t *in;
  u8 *s = 0;
  int n_row = 0;

  if (b == 0)
    return clib_error_return (0, "no bundle selected");

  n_instances = vec_len (it->instances);
  vec_validate (readings, n_instances - 1);

  /*Only perform read() for THREAD or SYSTEM bundles*/
  for (int i = 0;
       i < n_instances && b->active_type != PERFMON_BUNDLE_TYPE_NODE; i++)
    {
      in = vec_elt_at_index (it->instances, i);
      r = vec_elt_at_index (readings, i);

      if (read (pm->group_fds[i], r, (b->n_events + 3) * sizeof (u64)) == -1)
	{
	  err = clib_error_return_unix (0, "read");
	  goto done;
	}
    }

  table_format_title (t, "%s", b->description);

  table_add_header_col (t, 0);
  table_add_header_row (t, 0);

  if (b->column_headers)
    {
      char **hdr = b->column_headers;
      while (hdr[0])
	table_format_cell (t, -1, n_row++, "%s", hdr++[0]);
    }

  int col = 0;
  for (int i = 0; i < n_instances; i++)
    {
      in = vec_elt_at_index (it->instances, i);
      r = vec_elt_at_index (readings, i);
      table_format_cell (t, col, -1, "%s", in->name, b->active_type);
      if (b->active_type == PERFMON_BUNDLE_TYPE_NODE)
	{
	  perfmon_thread_runtime_t *tr;
	  tr = vec_elt_at_index (pm->thread_runtimes, i);
	  for (int j = 0; j < tr->n_nodes; j++)
	    if (tr->node_stats[j].n_calls)
	      {
		perfmon_node_stats_t ns;
		table_format_cell (t, ++col, -1, "%U", format_vlib_node_name,
				   vm, j, b->active_type);
		table_set_cell_align (t, col, -1, TTAA_RIGHT);
		table_set_cell_fg_color (t, col, -1, TTAC_CYAN);
		clib_memcpy_fast (&ns, tr->node_stats + j, sizeof (ns));

		for (int j = 0; j < n_row; j++)
		  table_format_cell (t, col, j, "%U", b->format_fn, &ns, j,
				     b->active_type);
	      }
	}
      else
	{
	  for (int j = 0; j < n_row; j++)
	    table_format_cell (t, i, j, "%U", b->format_fn, r, j,
			       b->active_type);
	}
      col++;
    }

  vlib_cli_output (vm, "%U\n", format_table, t);
  table_free (t);

  if (b->footer)
    vlib_cli_output (vm, "\n%s\n", b->footer);

done:
  vec_free (readings);
  vec_free (s);
  return err;
}

VLIB_CLI_COMMAND (show_perfmon_stats_command, static) = {
  .path = "show perfmon statistics",
  .short_help = "show perfmon statistics [raw]",
  .function = show_perfmon_stats_command_fn,
  .is_mp_safe = 1,
};

static clib_error_t *
perfmon_reset_command_fn (vlib_main_t *vm, unformat_input_t *input,
			  vlib_cli_command_t *cmd)
{
  perfmon_reset (vm);
  return 0;
}

VLIB_CLI_COMMAND (perfmon_reset_command, static) = {
  .path = "perfmon reset",
  .short_help = "perfmon reset",
  .function = perfmon_reset_command_fn,
  .is_mp_safe = 1,
};

static clib_error_t *
perfmon_start_command_fn (vlib_main_t *vm, unformat_input_t *input,
			  vlib_cli_command_t *cmd)
{
  perfmon_main_t *pm = &perfmon_main;
  unformat_input_t _line_input, *line_input = &_line_input;
  perfmon_bundle_t *b = 0;
  perfmon_bundle_type_t bundle_type = PERFMON_BUNDLE_TYPE_UNKNOWN;

  if (pm->is_running)
    return clib_error_return (0, "please stop first");

  if (unformat_user (input, unformat_line_input, line_input) == 0)
    return clib_error_return (0, "please specify bundle name");

  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
    {
      if (unformat (line_input, "bundle %U", unformat_perfmon_bundle_name, &b))
	;
      else if (unformat (line_input, "type %U", unformat_perfmon_active_type,
			 b, &bundle_type))
	;
      else
	return clib_error_return (0, "unknown input '%U'",
				  format_unformat_error, line_input);
    }
  unformat_free (line_input);

  if (b == 0)
    return clib_error_return (0, "please specify bundle name");

  /* if there is more than one valid mode */
  if (count_set_bits (b->type_flags) > 1)
    {
      /* what did the user indicate */
      if (!bundle_type)
	return clib_error_return (0, "please specify a valid type");
    }
  else /* otherwise just use the default  */
    {
      if (bundle_type && !(b->type_flags & bundle_type))
	return clib_error_return (0, "please specify a valid type");

      bundle_type =
	(perfmon_bundle_type_t) count_trailing_zeros (b->type_flags);
    }

  b->active_type = bundle_type;

  return perfmon_start (vm, b);
}

VLIB_CLI_COMMAND (perfmon_start_command, static) = {
  .path = "perfmon start",
  .short_help = "perfmon start bundle [<bundle-name>] type [<node|thread>]",
  .function = perfmon_start_command_fn,
  .is_mp_safe = 1,
};

static clib_error_t *
perfmon_stop_command_fn (vlib_main_t *vm, unformat_input_t *input,
			 vlib_cli_command_t *cmd)
{
  return perfmon_stop (vm);
}

VLIB_CLI_COMMAND (perfmon_stop_command, static) = {
  .path = "perfmon stop",
  .short_help = "perfmon stop",
  .function = perfmon_stop_command_fn,
  .is_mp_safe = 1,
};