summaryrefslogtreecommitdiffstats
path: root/docs/glossary
diff options
context:
space:
mode:
authorOnong Tayeng <otayeng@cisco.com>2017-12-14 14:54:05 +0530
committerGerrit Code Review <gerrit@opnfv.org>2017-12-14 14:42:07 +0000
commite80027a4d1b9ddd734b7fb9ae42533d30896afcb (patch)
treec588c19e229a2b5eea588e205a0f98bd0e301ea2 /docs/glossary
parent07f70501c7d0ebad9f149ff01bbfb7189d102133 (diff)
Update git submodules
* Update docs/submodules/fds from branch 'master' - Doc update for Euphrates 5.1 Change-Id: I59bae774ef06e970eb2baf2910bdda8572c99d50 Signed-off-by: Onong Tayeng <otayeng@cisco.com>
Diffstat (limited to 'docs/glossary')
0 files changed, 0 insertions, 0 deletions
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 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939
/*
// Copyright (c) 2010-2017 Intel Corporation
//
// 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 <string.h>
#include <stddef.h>

#include "stats_parser.h"
#include "log.h"
#include "stats.h"
#include "parse_utils.h"
#include "handle_lat.h"
#include "prox_port_cfg.h"
#include "stats_port.h"
#include "stats_mempool.h"
#include "stats_ring.h"
#include "stats_l4gen.h"
#include "stats_latency.h"
#include "stats_global.h"
#include "stats_prio_task.h"
#include "stats_irq.h"

struct stats_path_str {
	const char *str;
	uint64_t (*func)(int argc, const char *argv[]);
};

static int args_to_core_task(const char *core_str, const char *task_str, uint32_t *lcore_id, uint32_t *task_id)
{
	if (parse_list_set(lcore_id, core_str, 1) != 1)
		return -1;
	*task_id = atoi(task_str);

	return 0;
}

static uint64_t sp_task_idle_cycles(int argc, const char *argv[])
{
	struct task_stats_sample *last;
	uint32_t c, t;

	if (args_to_core_task(argv[0], argv[1], &c, &t))
		return -1;
	return stats_get_task_stats_sample(c, t, 1)->tsc;
}

static uint64_t sp_task_rx_packets(int argc, const char *argv[])
{
	struct task_stats_sample *last;
	uint32_t c, t;

	if (args_to_core_task(argv[0], argv[1], &c, &t))
		return -1;
	return stats_get_task_stats_sample(c, t, 1)->rx_pkt_count;
}

static uint64_t sp_task_tx_packets(int argc, const char *argv[])
{
	struct task_stats_sample *last;
	uint32_t c, t;

	if (args_to_core_task(argv[0], argv[1], &c, &t))
		return -1;
	return stats_get_task_stats_sample(c, t, 1)->tx_pkt_count;
}

static uint64_t sp_task_drop_tx_fail(int argc, const char *argv[])
{
	struct task_stats_sample *last;
	uint32_t c, t;

	if (args_to_core_task(argv[0], argv[1], &c, &t))
		return -1;
	return stats_get_task_stats_sample(c, t, 1)->drop_tx_fail;
}

static uint64_t sp_task_drop_tx_fail_prio(int argc, const char *argv[])
{
	struct task_stats_sample *last;
	uint32_t c, t;

	if (args_to_core_task(argv[0], argv[1], &c, &t))
		return -1;
	if (stats_get_prio_task_stats_sample_by_core_task(c, t, 1))
		return stats_get_prio_task_stats_sample_by_core_task(c, t, 1)->drop_tx_fail_prio[atoi(argv[2])];
	else
		return -1;
}

static uint64_t sp_task_rx_prio(int argc, const char *argv[])
{
	struct task_stats_sample *last;
	uint32_t c, t;

	if (args_to_core_task(argv[0], argv[1], &c, &t))
		return -1;
	return stats_get_prio_task_stats_sample_by_core_task(c, t, 1)->rx_prio[atoi(argv[2])];
}

static uint64_t sp_task_max_irq(int argc, const char *argv[])
{
	struct task_stats_sample *last;
	uint32_t c, t;

	if (args_to_core_task(argv[0], argv[1], &c, &t))
		return -1;
	return get_max_irq_stats_by_core_task(c, t);
}

static uint64_t sp_task_irq(int argc, const char *argv[])
{
	struct task_stats_sample *last;
	uint32_t c, t;

	if (args_to_core_task(argv[0], argv[1], &c, &t))
		return -1;
	return get_irq_stats_by_core_task(c, t, atoi(argv[2]));
}

static uint64_t sp_task_drop_discard(int argc, const char *argv[])
{
	struct task_stats_sample *last;
	uint32_t c, t;

	if (args_to_core_task(argv[0], argv[1], &c, &t))
		return -1;
	return stats_get_task_stats_sample(c, t, 1)->drop_discard;
}

static uint64_t sp_task_drop_handled(int argc, const char *argv[])
{
	struct task_stats_sample *last;
	uint32_t c, t;

	if (args_to_core_task(argv[0], argv[1], &c, &t))
		return -1;
	return stats_get_task_stats_sample(c, t, 1)->drop_handled;
}

static uint64_t sp_task_rx_non_dp(int argc, const char *argv[])
{
	struct task_stats_sample *last;
	uint32_t c, t;
	if (args_to_core_task(argv[0], argv[1], &c, &t))
		return -1;
	return stats_get_task_stats_sample(c, t, 1)->rx_non_dp;
}

static uint64_t sp_task_tx_non_dp(int argc, const char *argv[])
{
	struct task_stats_sample *last;
	uint32_t c, t;
	if (args_to_core_task(argv[0], argv[1], &c, &t))
		return -1;
	return stats_get_task_stats_sample(c, t, 1)->tx_non_dp;
}
static uint64_t sp_task_rx_bytes(int argc, const char *argv[])
{
	return -1;
}

static uint64_t sp_task_tx_bytes(int argc, const char *argv[])
{
	return -1;
}

static uint64_t sp_task_tsc(int argc, const char *argv[])
{
	struct task_stats_sample *last;
	uint32_t c, t;

	if (args_to_core_task(argv[0], argv[1], &c, &t))
		return -1;
	return stats_get_task_stats_sample(c, t, 1)->tsc;
}

static uint64_t sp_l4gen_created(int argc, const char *argv[])
{
	struct l4_stats_sample *clast = NULL;

	if (atoi(argv[0]) >= stats_get_n_l4gen())
		return -1;
	clast = stats_get_l4_stats_sample(atoi(argv[0]), 1);
	return clast->stats.tcp_created + clast->stats.udp_created;
}

static uint64_t sp_l4gen_finished(int argc, const char *argv[])
{
	struct l4_stats_sample *clast = NULL;

	if (atoi(argv[0]) >= stats_get_n_l4gen())
		return -1;
	clast = stats_get_l4_stats_sample(atoi(argv[0]), 1);
	return clast->stats.tcp_finished_retransmit + clast->stats.tcp_finished_no_retransmit +
		clast->stats.udp_finished + clast->stats.udp_expired + clast->stats.tcp_expired;
}

static uint64_t sp_l4gen_expire_tcp(int argc, const char *argv[])
{
	struct l4_stats_sample *clast = NULL;

	if (atoi(argv[0]) >= stats_get_n_l4gen())
		return -1;
	clast = stats_get_l4_stats_sample(atoi(argv[0]), 1);
	return 	clast->stats.tcp_expired;
}

static uint64_t sp_l4gen_expire_udp(int argc, const char *argv[])
{
	struct l4_stats_sample *clast = NULL;

	if (atoi(argv[0]) >= stats_get_n_l4gen())
		return -1;
	clast = stats_get_l4_stats_sample(atoi(argv[0]), 1);
	return clast->stats.udp_expired;
}

static uint64_t sp_l4gen_retx(int argc, const char *argv[])
{
	struct l4_stats_sample *clast = NULL;

	if (atoi(argv[0]) >= stats_get_n_l4gen())
		return -1;
	clast = stats_get_l4_stats_sample(atoi(argv[0]), 1);
	return clast->stats.tcp_retransmits;
}

static uint64_t sp_l4gen_tsc(int argc, const char *argv[])
{
	struct l4_stats_sample *clast = NULL;

	if (atoi(argv[0]) >= stats_get_n_l4gen())
		return -1;
	clast = stats_get_l4_stats_sample(atoi(argv[0]), 1);
	return clast->tsc;
}

static uint64_t sp_l4gen_torndown_no_retx(int argc, const char *argv[])
{
	struct l4_stats_sample *clast = NULL;

	if (atoi(argv[0]) >= stats_get_n_l4gen())
		return -1;
	clast = stats_get_l4_stats_sample(atoi(argv[0]), 1);
	return clast->stats.tcp_finished_no_retransmit;
}

static uint64_t sp_l4gen_torndown_retx(int argc, const char *argv[])
{
	struct l4_stats_sample *clast = NULL;

	if (atoi(argv[0]) >= stats_get_n_l4gen())
		return -1;
	clast = stats_get_l4_stats_sample(atoi(argv[0]), 1);
	return clast->stats.tcp_finished_retransmit;
}

static uint64_t sp_l4gen_torndown_udp(int argc, const char *argv[])
{
	struct l4_stats_sample *clast = NULL;

	if (atoi(argv[0]) >= stats_get_n_l4gen())
		return -1;
	clast = stats_get_l4_stats_sample(atoi(argv[0]), 1);
	return clast->stats.udp_finished;
}

static uint64_t sp_l4gen_created_tcp(int argc, const char *argv[])
{
	struct l4_stats_sample *clast = NULL;

	if (atoi(argv[0]) >= stats_get_n_l4gen())
		return -1;
	clast = stats_get_l4_stats_sample(atoi(argv[0]), 1);
	return clast->stats.tcp_created;

}

static uint64_t sp_l4gen_created_udp(int argc, const char *argv[])
{
	struct l4_stats_sample *clast = NULL;

	if (atoi(argv[0]) >= stats_get_n_l4gen())
		return -1;
	clast = stats_get_l4_stats_sample(atoi(argv[0]), 1);
	return clast->stats.udp_created;
}

static uint64_t sp_l4gen_created_all(int argc, const char *argv[])
{
	struct l4_stats_sample *clast = NULL;

	if (atoi(argv[0]) >= stats_get_n_l4gen())
		return -1;
	clast = stats_get_l4_stats_sample(atoi(argv[0]), 1);
	return clast->stats.tcp_created + clast->stats.udp_created;
}

static uint64_t sp_l4gen_created_bundles(int argc, const char *argv[])
{
	struct l4_stats_sample *clast = NULL;

	if (atoi(argv[0]) >= stats_get_n_l4gen())
		return -1;
	clast = stats_get_l4_stats_sample(atoi(argv[0]), 1);
	return clast->stats.bundles_created;
}

static uint64_t sp_latency_min(int argc, const char *argv[])
{
	struct stats_latency *lat_test = NULL;

	if (atoi(argv[0]) >= stats_get_n_latency())
		return -1;
	lat_test = stats_latency_get(atoi(argv[0]));

	if (!lat_test->tot_packets)
		return -1;

	struct time_unit tu = lat_test->min.time;
	return time_unit_to_usec(&tu);
}

static uint64_t sp_mem_used(int argc, const char *argv[])
{
	struct mempool_stats *ms;

	if (atoi(argv[0]) > stats_get_n_mempools())
		return -1;
	ms = stats_get_mempool_stats(atoi(argv[0]));
	return ms->size - ms->free;
}

static uint64_t sp_mem_free(int argc, const char *argv[])
{
	struct mempool_stats *ms;

	if (atoi(argv[0]) > stats_get_n_mempools())
		return -1;
	ms = stats_get_mempool_stats(atoi(argv[0]));
	return ms->free;
}

static uint64_t sp_mem_size(int argc, const char *argv[])
{
	struct mempool_stats *ms;

	if (atoi(argv[0]) > stats_get_n_mempools())
		return -1;
	ms = stats_get_mempool_stats(atoi(argv[0]));
	return ms->size;
}

static uint64_t sp_port_no_mbufs(int argc, const char *argv[])
{
	uint32_t port_id = atoi(argv[0]);
	struct port_stats_sample *ps;

	if (port_id > PROX_MAX_PORTS || !prox_port_cfg[port_id].active)
		return -1;
	ps = stats_get_port_stats_sample(port_id, 1);
	return ps->no_mbufs;
}

static uint64_t sp_port_ierrors(int argc, const char *argv[])
{
	uint32_t port_id = atoi(argv[0]);
	struct port_stats_sample *ps;

	if (port_id > PROX_MAX_PORTS || !prox_port_cfg[port_id].active)
		return -1;
	ps = stats_get_port_stats_sample(port_id, 1);
	return ps->ierrors;
}

static uint64_t sp_port_imissed(int argc, const char *argv[])
{
	uint32_t port_id = atoi(argv[0]);
	struct port_stats_sample *ps;

	if (port_id > PROX_MAX_PORTS || !prox_port_cfg[port_id].active)
		return -1;
	ps = stats_get_port_stats_sample(port_id, 1);
	return ps->imissed;
}

static uint64_t sp_port_oerrors(int argc, const char *argv[])
{
	uint32_t port_id = atoi(argv[0]);
	struct port_stats_sample *ps;

	if (port_id > PROX_MAX_PORTS || !prox_port_cfg[port_id].active)
		return -1;
	ps = stats_get_port_stats_sample(port_id, 1);
	return ps->oerrors;
}

static uint64_t sp_port_rx_packets(int argc, const char *argv[])
{
	uint32_t port_id = atoi(argv[0]);
	struct port_stats_sample *ps;

	if (port_id > PROX_MAX_PORTS || !prox_port_cfg[port_id].active)
		return -1;
	ps = stats_get_port_stats_sample(port_id, 1);
	return ps->rx_tot;
}

static uint64_t sp_port_tx_packets(int argc, const char *argv[])
{
	uint32_t port_id = atoi(argv[0]);
	struct port_stats_sample *ps;

	if (port_id > PROX_MAX_PORTS || !prox_port_cfg[port_id].active)
		return -1;
	ps = stats_get_port_stats_sample(port_id, 1);
	return ps->tx_tot;
}

static uint64_t sp_port_rx_bytes(int argc, const char *argv[])
{
	uint32_t port_id = atoi(argv[0]);
	struct port_stats_sample *ps;

	if (port_id > PROX_MAX_PORTS || !prox_port_cfg[port_id].active)
		return -1;
	ps = stats_get_port_stats_sample(port_id, 1);
	return ps->rx_bytes;
}

static uint64_t sp_port_tx_bytes(int argc, const char *argv[])
{
	uint32_t port_id = atoi(argv[0]);
	struct port_stats_sample *ps;

	if (port_id > PROX_MAX_PORTS || !prox_port_cfg[port_id].active)
		return -1;
	ps = stats_get_port_stats_sample(port_id, 1);
	return ps->tx_bytes;
}

static uint64_t sp_port_tx_packets_64(int argc, const char *argv[])
{
	uint32_t port_id = atoi(argv[0]);
	struct port_stats_sample *ps;

	if (port_id > PROX_MAX_PORTS || !prox_port_cfg[port_id].active)
		return -1;
	ps = stats_get_port_stats_sample(port_id, 1);
	return ps->tx_pkt_size[PKT_SIZE_64];
}

static uint64_t sp_port_tx_packets_65_127(int argc, const char *argv[])
{
	uint32_t port_id = atoi(argv[0]);
	struct port_stats_sample *ps;

	if (port_id > PROX_MAX_PORTS || !prox_port_cfg[port_id].active)
		return -1;
	ps = stats_get_port_stats_sample(port_id, 1);
	return ps->tx_pkt_size[PKT_SIZE_65];
}

static uint64_t sp_port_tx_packets_128_255(int argc, const char *argv[])
{
	uint32_t port_id = atoi(argv[0]);
	struct port_stats_sample *ps;

	if (port_id > PROX_MAX_PORTS || !prox_port_cfg[port_id].active)
		return -1;
	ps = stats_get_port_stats_sample(port_id, 1);
	return ps->tx_pkt_size[PKT_SIZE_128];
}

static uint64_t sp_port_tx_packets_256_511(int argc, const char *argv[])
{
	uint32_t port_id = atoi(argv[0]);
	struct port_stats_sample *ps;

	if (port_id > PROX_MAX_PORTS || !prox_port_cfg[port_id].active)
		return -1;
	ps = stats_get_port_stats_sample(port_id, 1);
	return ps->tx_pkt_size[PKT_SIZE_256];
}

static uint64_t sp_port_tx_packets_512_1023(int argc, const char *argv[])
{
	uint32_t port_id = atoi(argv[0]);
	struct port_stats_sample *ps;

	if (port_id > PROX_MAX_PORTS || !prox_port_cfg[port_id].active)
		return -1;
	ps = stats_get_port_stats_sample(port_id, 1);
	return ps->tx_pkt_size[PKT_SIZE_512];
}

static uint64_t sp_port_tx_packets_1024_1522(int argc, const char *argv[])
{
	uint32_t port_id = atoi(argv[0]);
	struct port_stats_sample *ps;

	if (port_id > PROX_MAX_PORTS || !prox_port_cfg[port_id].active)
		return -1;
	ps = stats_get_port_stats_sample(port_id, 1);
	return ps->tx_pkt_size[PKT_SIZE_1024];
}

static uint64_t sp_port_tx_packets_1523_max(int argc, const char *argv[])
{
	uint32_t port_id = atoi(argv[0]);
	struct port_stats_sample *ps;

	if (port_id > PROX_MAX_PORTS || !prox_port_cfg[port_id].active)
		return -1;
	ps = stats_get_port_stats_sample(port_id, 1);
	return ps->tx_pkt_size[PKT_SIZE_1522];
}

static uint64_t sp_port_tsc(int argc, const char *argv[])
{
	uint32_t port_id = atoi(argv[0]);
	struct port_stats_sample *ps;

	if (port_id > PROX_MAX_PORTS || !prox_port_cfg[port_id].active)
		return -1;
	ps = stats_get_port_stats_sample(port_id, 1);
	return ps->tsc;
}

static uint64_t sp_latency_max(int argc, const char *argv[])
{
	struct stats_latency *lat_test = NULL;

	if (atoi(argv[0]) >= stats_get_n_latency())
		return -1;
	lat_test = stats_latency_get(atoi(argv[0]));

	if (!lat_test->tot_packets)
		return -1;

	struct time_unit tu = lat_test->max.time;
	return time_unit_to_usec(&tu);
}

static uint64_t sp_latency_avg(int argc, const char *argv[])
{
	struct stats_latency *lat_test = NULL;

	if (atoi(argv[0]) >= stats_get_n_latency())
		return -1;
	lat_test = stats_latency_get(atoi(argv[0]));

	if (!lat_test->tot_packets)
		return -1;

	struct time_unit tu = lat_test->avg.time;
	return time_unit_to_usec(&tu);
}

static uint64_t sp_latency_lost(int argc, const char *argv[])
{
	struct stats_latency *lat_test = NULL;

	if (atoi(argv[0]) >= stats_get_n_latency())
		return -1;
	lat_test = stats_latency_get(atoi(argv[0]));

	if (!lat_test->tot_packets)
		return -1;

	return lat_test->lost_packets;
}

static uint64_t sp_latency_tot_lost(int argc, const char *argv[])
{
	struct stats_latency *lat_test = NULL;

	if (atoi(argv[0]) >= stats_get_n_latency())
		return -1;
	lat_test = stats_latency_tot_get(atoi(argv[0]));

	if (!lat_test->tot_packets)
		return -1;

	return lat_test->lost_packets;
}

static uint64_t sp_latency_total(int argc, const char *argv[])
{
	struct stats_latency *lat_test = NULL;

	if (atoi(argv[0]) >= stats_get_n_latency())
		return -1;
	lat_test = stats_latency_get(atoi(argv[0]));

	if (!lat_test->tot_all_packets)
		return -1;

	return lat_test->tot_all_packets;
}

static uint64_t sp_latency_used(int argc, const char *argv[])
{
	struct stats_latency *lat_test = NULL;

	if (atoi(argv[0]) >= stats_get_n_latency())
		return -1;
	lat_test = stats_latency_get(atoi(argv[0]));

	if (!lat_test->tot_all_packets)
		return -1;

	return lat_test->tot_packets;
}

static uint64_t sp_latency_tot_total(int argc, const char *argv[])
{
	struct stats_latency *lat_test = NULL;

	if (atoi(argv[0]) >= stats_get_n_latency())
		return -1;
	lat_test = stats_latency_tot_get(atoi(argv[0]));

	if (!lat_test->tot_all_packets)
		return -1;

	return lat_test->tot_all_packets;
}

static uint64_t sp_latency_tot_used(int argc, const char *argv[])
{
	struct stats_latency *lat_test = NULL;

	if (atoi(argv[0]) >= stats_get_n_latency())
		return -1;
	lat_test = stats_latency_tot_get(atoi(argv[0]));

	if (!lat_test->tot_all_packets)
		return -1;

	return lat_test->tot_packets;
}

static uint64_t sp_latency_tot_min(int argc, const char *argv[])
{
	struct stats_latency *lat_test = NULL;

	if (atoi(argv[0]) >= stats_get_n_latency())
		return -1;
	lat_test = stats_latency_tot_get(atoi(argv[0]));

	if (!lat_test->tot_packets)
		return -1;

	struct time_unit tu = lat_test->min.time;
	return time_unit_to_usec(&tu);
}

static uint64_t sp_latency_tot_max(int argc, const char *argv[])
{
	struct stats_latency *lat_test = NULL;

	if (atoi(argv[0]) >= stats_get_n_latency())
		return -1;
	lat_test = stats_latency_tot_get(atoi(argv[0]));

	if (!lat_test->tot_packets)
		return -1;

	struct time_unit tu = lat_test->max.time;
	return time_unit_to_usec(&tu);
}

static uint64_t sp_latency_tot_avg(int argc, const char *argv[])
{
	struct stats_latency *lat_test = NULL;

	if (atoi(argv[0]) >= stats_get_n_latency())
		return -1;
	lat_test = stats_latency_tot_get(atoi(argv[0]));

	if (!lat_test->tot_packets)
		return -1;

	struct time_unit tu = lat_test->avg.time;
	return time_unit_to_usec(&tu);
}

static uint64_t sp_latency_stddev(int argc, const char *argv[])
{
	struct stats_latency *lat_test = NULL;

	if (atoi(argv[0]) >= stats_get_n_latency())
		return -1;
	lat_test = stats_latency_get(atoi(argv[0]));

	if (!lat_test->tot_packets)
		return -1;

	struct time_unit tu = lat_test->stddev.time;
	return time_unit_to_usec(&tu);
}

static uint64_t sp_ring_used(int argc, const char *argv[])
{
	struct ring_stats *rs = NULL;

	if (atoi(argv[0]) >= stats_get_n_rings())
		return -1;
	rs = stats_get_ring_stats(atoi(argv[0]));
	return rs->size - rs->free;
}

static uint64_t sp_ring_free(int argc, const char *argv[])
{
	struct ring_stats *rs = NULL;

	if (atoi(argv[0]) >= stats_get_n_rings())
		return -1;
	rs = stats_get_ring_stats(atoi(argv[0]));
	return rs->free;
}

static uint64_t sp_ring_size(int argc, const char *argv[])
{
	struct ring_stats *rs = NULL;

	if (atoi(argv[0]) >= stats_get_n_rings())
		return -1;
	rs = stats_get_ring_stats(atoi(argv[0]));
	return rs->size;
}

static uint64_t sp_global_host_rx_packets(int argc, const char *argv[])
{
	return stats_get_global_stats(1)->host_rx_packets;
}

static uint64_t sp_global_host_tx_packets(int argc, const char *argv[])
{
	return stats_get_global_stats(1)->host_tx_packets;
}

static uint64_t sp_global_nics_rx_packets(int argc, const char *argv[])
{
	return stats_get_global_stats(1)->nics_rx_packets;
}

static uint64_t sp_global_nics_tx_packets(int argc, const char *argv[])
{
	return stats_get_global_stats(1)->nics_tx_packets;
}

static uint64_t sp_global_nics_ierrors(int argc, const char *argv[])
{
	return stats_get_global_stats(1)->nics_ierrors;
}

static uint64_t sp_global_nics_imissed(int argc, const char *argv[])
{
	return stats_get_global_stats(1)->nics_imissed;
}

static uint64_t sp_global_tsc(int argc, const char *argv[])
{
	return stats_get_global_stats(1)->tsc;
}

static uint64_t sp_hz(int argc, const char *argv[])
{
	return rte_get_tsc_hz();
}

struct stats_path_str stats_paths[] = {
	{"hz", sp_hz},

	{"global.host.rx.packets", sp_global_host_rx_packets},
	{"global.host.tx.packets", sp_global_host_tx_packets},
	{"global.nics.rx.packets", sp_global_nics_rx_packets},
	{"global.nics.tx.packets", sp_global_nics_tx_packets},
	{"global.nics.ierrrors", sp_global_nics_ierrors},
	{"global.nics.imissed", sp_global_nics_imissed},
	{"global.tsc", sp_global_tsc},

	{"task.core(#).task(#).idle_cycles", sp_task_idle_cycles},
	{"task.core(#).task(#).rx.packets", sp_task_rx_packets},
	{"task.core(#).task(#).tx.packets", sp_task_tx_packets},
	{"task.core(#).task(#).drop.tx_fail", sp_task_drop_tx_fail},
	{"task.core(#).task(#).drop.discard", sp_task_drop_discard},
	{"task.core(#).task(#).drop.handled", sp_task_drop_handled},
	{"task.core(#).task(#).rx.bytes", sp_task_rx_bytes},
	{"task.core(#).task(#).tx.bytes", sp_task_tx_bytes},
	{"task.core(#).task(#).tsc", sp_task_tsc},
	{"task.core(#).task(#).drop.tx_fail_prio(#)", sp_task_drop_tx_fail_prio},
	{"task.core(#).task(#).rx_prio(#)", sp_task_rx_prio},
	{"task.core(#).task(#).max_irq", sp_task_max_irq},
	{"task.core(#).task(#).irq(#)", sp_task_irq},
	{"task.core(#).task(#).rx_non_dp", sp_task_rx_non_dp},
	{"task.core(#).task(#).tx_non_dp", sp_task_tx_non_dp},

	{"port(#).no_mbufs", sp_port_no_mbufs},
	{"port(#).ierrors", sp_port_ierrors},
	{"port(#).imissed", sp_port_imissed},
	{"port(#).oerrors", sp_port_oerrors},
	{"port(#).rx.packets", sp_port_rx_packets},
	{"port(#).tx.packets", sp_port_tx_packets},
	{"port(#).rx.bytes", sp_port_rx_bytes},
	{"port(#).tx.bytes", sp_port_tx_bytes},
	{"port(#).tx.packets_64", sp_port_tx_packets_64},
	{"port(#).tx.packets_65_127", sp_port_tx_packets_65_127},
	{"port(#).tx.packets_128_255", sp_port_tx_packets_128_255},
	{"port(#).tx.packets_256_511", sp_port_tx_packets_256_511},
	{"port(#).tx.packets_512_1023", sp_port_tx_packets_512_1023},
	{"port(#).tx.packets_1024_1522", sp_port_tx_packets_1024_1522},
	{"port(#).tx.packets_1523_max", sp_port_tx_packets_1523_max},
	{"port(#).tsc", sp_port_tsc},

	{"mem(#).used", sp_mem_used},
	{"mem(#).free", sp_mem_free},
	{"mem(#).size", sp_mem_size},

	{"latency(#).min", sp_latency_min},
	{"latency(#).max", sp_latency_max},
	{"latency(#).avg", sp_latency_avg},
	{"latency(#).lost", sp_latency_lost},
	{"latency(#).used", sp_latency_used},
	{"latency(#).total", sp_latency_total},
	{"latency(#).tot.min", sp_latency_tot_min},
	{"latency(#).tot.max", sp_latency_tot_max},
	{"latency(#).tot.avg", sp_latency_tot_avg},
	{"latency(#).tot.lost", sp_latency_tot_lost},
	{"latency(#).tot.used", sp_latency_tot_used},
	{"latency(#).tot.total", sp_latency_tot_total},
	{"latency(#).stddev", sp_latency_stddev},

	{"ring(#).used", sp_ring_used},
	{"ring(#).free", sp_ring_free},
	{"ring(#).size", sp_ring_size},

	{"l4gen(#).created.tcp", sp_l4gen_created_tcp},
	{"l4gen(#).created.udp", sp_l4gen_created_udp},
	{"l4gen(#).created.all", sp_l4gen_created_all},
	{"l4gen(#).created.bundles", sp_l4gen_created_bundles},
	{"l4gen(#).torndown.no_retx", sp_l4gen_torndown_no_retx},
	{"l4gen(#).torndown.retx", sp_l4gen_torndown_retx},
	{"l4gen(#).torndown.udp", sp_l4gen_torndown_udp},
	{"l4gen(#).expired.tcp", sp_l4gen_expire_tcp},
	{"l4gen(#).expired.udp", sp_l4gen_expire_udp},
	{"l4gen(#).created", sp_l4gen_created},
	{"l4gen(#).finished", sp_l4gen_finished},
	{"l4gen(#).retx", sp_l4gen_retx},
	{"l4gen(#).tsc", sp_l4gen_tsc},
};

static int stats_parser_extract_args(char *stats_path, size_t *argc, char **argv)
{
	size_t len = strlen(stats_path);
	size_t j = 0;
	size_t k = 0;
	int state = 0;

	for (size_t i = 0; i < len; ++i) {
		switch (state) {
		case 0:
			if (stats_path[i] == '(') {
				state = 1;
				k = 0;
			}
			else if (stats_path[i] == ')')
				return -1;
			stats_path[j] = stats_path[i];
			j++;
			break;
		case 1:
			if (stats_path[i] == ')') {
				state = 0;
				stats_path[j] = '#';
				j++;
				stats_path[j] = ')';
				j++;
				(*argc)++;
			}
			else {
				argv[*argc][k++] = stats_path[i];
			}
			break;
		}
	}
	if (state == 1)
		return -1;
	stats_path[j] = 0;
	return 0;
}

uint64_t stats_parser_get(const char *stats_path)
{
	size_t stats_path_len;

	char stats_path_cpy[128];

	strncpy(stats_path_cpy, stats_path, sizeof(stats_path_cpy));
	stats_path_len = strlen(stats_path);

	size_t max_argc = 16;
	size_t argc = 0;
	char argv_data[16][16] = {{0}};
	char *argv[16];
	const char *argv_c[16];

	for (size_t i = 0; i < 16; ++i) {
		argv[i] = argv_data[i];
		argv_c[i] = argv_data[i];
	}

	if (stats_parser_extract_args(stats_path_cpy, &argc, argv))
		return -1;

	for (size_t i = 0; i < sizeof(stats_paths)/sizeof(stats_paths[0]); ++i) {
		if (strcmp(stats_paths[i].str, stats_path_cpy) == 0) {
			if (stats_paths[i].func == NULL)
				return -1;
			return stats_paths[i].func(argc, argv_c);
		}
	}

	return -1;
}