openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

stat.c (3535B)


      1 /*
      2  * 
      3  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      4  * 
      5  * Copyright 2007-2019 Broadcom Inc. All rights reserved.
      6  *
      7  * File:        stat.c
      8  * Purpose:	BCMX diagnostic stat command
      9  */
     10 
     11 #ifdef	INCLUDE_BCMX
     12 
     13 #include <bcm/types.h>
     14 #include <bcm/error.h>
     15 #include <bcm/stat.h>
     16 #include <bcmx/stat.h>
     17 #include <bcmx/lplist.h>
     18 
     19 #include <appl/diag/parse.h>
     20 #include <appl/diag/shell.h>
     21 #include <appl/diag/system.h>
     22 #include "bcmx.h"
     23 
     24 char bcmx_cmd_stat_usage[] =
     25 	"\n"
     26 	"\tstat init\n"
     27 	"\tstat show [all] <user-port-list>\n"
     28 	"\tstat clear [<user-port-list>]\n";
     29 
     30 cmd_result_t
     31 bcmx_cmd_stat(int unit, args_t *args)
     32 {
     33     char		*cmd, *subcmd, *s;
     34     int			rv, all, count;
     35     bcmx_lport_t	lport;
     36     bcmx_lplist_t	lplist;
     37     bcm_stat_val_t	stype;
     38     uint64		sval;
     39     char		*sname;
     40     char        *_stat_names[] = BCM_STAT_NAME_INITIALIZER;
     41 
     42     cmd = ARG_CMD(args);
     43     subcmd = ARG_GET(args);
     44     if (subcmd == NULL) {
     45 	subcmd = "show";
     46     }
     47 
     48     if (sal_strcasecmp(subcmd, "init") == 0) {
     49 	rv = bcmx_stat_init();
     50 	if (rv < 0) {
     51 	    sal_printf("%s: ERROR: %s failed: %s\n",
     52 		       cmd, subcmd, bcm_errmsg(rv));
     53 	    return CMD_FAIL;
     54 	}
     55 	return CMD_OK;
     56     }
     57 
     58     if (sal_strcasecmp(subcmd, "show") == 0) {
     59 	all = 0;
     60 	s = ARG_GET(args);
     61 	if (s != NULL && sal_strcasecmp(s, "all") == 0) {
     62 	    all = 1;
     63 	    s = ARG_GET(args);
     64 	}
     65 	if (s == NULL) {
     66 	    s = "*";
     67 	}
     68 	if (bcmx_lplist_init(&lplist, 0, 0) < 0) {
     69 	    sal_printf("%s: ERROR: could not init port list\n", cmd);
     70 	    return CMD_FAIL;
     71 	}
     72         if (bcmx_lplist_parse(&lplist, s) < 0) {
     73             sal_printf("%s: ERROR: could not parse port list: %s\n",
     74                          cmd, s);
     75             return CMD_FAIL;
     76         }
     77 
     78 	BCMX_LPLIST_ITER(lplist, lport, count) {
     79         sal_printf("%s: Statistics for port %s\n",
     80                    cmd, bcmx_lport_to_uport_str(lport));
     81 
     82 	    for (stype = (bcm_stat_val_t)0; stype < snmpValCount; stype++) {
     83 		sname = _stat_names[stype];
     84 		rv = bcmx_stat_get(lport, stype, &sval);
     85 		if (rv < 0) {
     86 		    sal_printf("\t%18s\t%s (stat %d): %s\n",
     87 			       "-", sname, stype, bcm_errmsg(rv));
     88 		    continue;
     89 		}
     90 		if (all == 0 && COMPILER_64_IS_ZERO(sval)) {
     91 		    continue;
     92 		}
     93 		if (COMPILER_64_HI(sval) == 0) {
     94 		    sal_printf("\t%18u\t%s (stat %d)\n",
     95 			       COMPILER_64_LO(sval), sname, stype);
     96 		} else {
     97 		    sal_printf("\t0x%08x%08x\t%s (stat %d)\n",
     98 			       COMPILER_64_HI(sval),
     99 			       COMPILER_64_LO(sval),
    100 			       sname, stype);
    101 		}
    102 
    103 	    }
    104 	}
    105         bcmx_lplist_free(&lplist);
    106 	return CMD_OK;
    107     }
    108 
    109     if (sal_strcasecmp(subcmd, "clear") == 0) {
    110 	s = ARG_GET(args);
    111 	if (s == NULL) {
    112 	    s = "*";
    113 	}
    114 	if (bcmx_lplist_init(&lplist, 0, 0) < 0) {
    115 	    sal_printf("%s: ERROR: could not init port list\n", cmd);
    116 	    return CMD_FAIL;
    117 	}
    118         if (bcmx_lplist_parse(&lplist, s) < 0) {
    119             sal_printf("%s: ERROR: could not parse port list: %s\n",
    120                          cmd, s);
    121             return CMD_FAIL;
    122         }
    123 
    124 	BCMX_LPLIST_ITER(lplist, lport, count) {
    125 	    rv = bcmx_stat_clear(lport);
    126 	    if (rv < 0) {
    127             sal_printf("%s: ERROR: %s on port %s failed: %s\n",
    128                        cmd, subcmd,
    129                        bcmx_lport_to_uport_str(lport), bcm_errmsg(rv));
    130             return CMD_FAIL;
    131 	    }
    132 	}
    133         bcmx_lplist_free(&lplist);
    134 	return CMD_OK;
    135     }
    136 
    137     sal_printf("%s: unknown subcommand '%s'\n", ARG_CMD(args), subcmd);
    138     return CMD_USAGE;
    139 }
    140 
    141 #endif	/* INCLUDE_BCMX */