[TOOLS] add -c option to vstat to read the ib port counters
authorsleybo <sleybo@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Tue, 16 May 2006 07:54:47 +0000 (07:54 +0000)
committersleybo <sleybo@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Tue, 16 May 2006 07:54:47 +0000 (07:54 +0000)
git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@353 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

tools/vstat/user/vstat_main.c

index 1d0eaf8..5ba8d67 100644 (file)
@@ -219,12 +219,63 @@ void vstat_print_ca_attr(int idx,  ib_ca_attr_t* ca_attr, BOOLEAN fullPrint){
 }\r
 /* Internal Functions */\r
 \r
+void vstat_get_counters(ib_ca_handle_t h_ca,uint8_t port_num)\r
+{\r
+       ib_mad_t                        *mad_in = NULL;\r
+       ib_mad_t                        *mad_out = NULL;\r
+       ib_port_counters_t      *port_counters;\r
+       ib_api_status_t         ib_status = IB_SUCCESS;\r
+       int i;\r
+       \r
+       mad_out = (ib_mad_t*)cl_zalloc(256);\r
+       CL_ASSERT(mad_out);\r
+\r
+       mad_in = (ib_mad_t*)cl_zalloc(256);\r
+       CL_ASSERT(mad_in);\r
+\r
 \r
+       mad_in->attr_id = IB_MAD_ATTR_PORT_CNTRS;\r
+       mad_in->method = IB_MAD_METHOD_GET;\r
+       mad_in->base_ver = 1;\r
+       mad_in->class_ver =1;\r
+       mad_in->mgmt_class = IB_MCLASS_PERF;\r
+\r
+       port_counters = (ib_port_counters_t*)(((ib_gmp_t*)mad_in)->data);\r
+\r
+       port_counters->port_select= port_num;\r
+       port_counters->counter_select= 0xff;\r
+\r
+       ib_status = ib_local_mad(h_ca ,port_num ,mad_in ,mad_out);\r
+       if(ib_status != IB_SUCCESS)\r
+       {\r
+               printf("ib_local_mad failed with status = %d\n", ib_status);\r
+               return;\r
+       }\r
+       \r
+       port_counters = (ib_port_counters_t*)(((ib_gmp_t*)mad_out)->data);\r
+\r
+       printf("\nport counters for port %d\n",port_num);\r
+       printf("\tlink_error_recovery_counter\t0x%x \n",port_counters->link_error_recovery_counter);\r
+       printf("\tlink_down_counter\t0x%x \n",port_counters->link_down_counter);\r
+       printf("\tport_rcv_errors\t\t0x%x \n",CL_NTOH16(port_counters->port_rcv_errors));\r
+       printf("\tport_rcv_remote_physical_errors\t0x%x \n",CL_NTOH16(port_counters->port_rcv_remote_physical_errors));\r
+       printf("\tport_rcv_switch_relay_errors\t0x%x \n",CL_NTOH16(port_counters->port_rcv_switch_relay_errors));\r
+       printf("\tport_xmit_discard\t\t0x%x \n",CL_NTOH16(port_counters->port_xmit_discard));\r
+       printf("\tport_xmit_constraint_errors\t0x%x \n",port_counters->port_xmit_constraint_errors);\r
+       printf("\tport_rcv_constraint_errors\t0x%x \n",port_counters->port_rcv_constraint_errors);\r
+       printf("\tvl15_dropped\t\t\t0x%x \n",CL_NTOH16(port_counters->vl15_dropped));\r
+       printf("\tport_rcv_data\t\t\t0x%x \n",CL_NTOH32(port_counters->port_rcv_data));\r
+       printf("\tport_xmit_data\t\t\t0x%x \n",CL_NTOH32(port_counters->port_xmit_data));\r
+       printf("\tport_rcv_pkts\t\t\t0x%x \n",CL_NTOH32(port_counters->port_rcv_pkts));\r
+       printf("\tport_xmit_pkts\t\t\t0x%x \n\n",CL_NTOH32(port_counters->port_xmit_pkts));\r
+       \r
+}\r
 \r
 ib_api_status_t\r
 vstat_ca_attr(\r
        boolean_t modify_attr,\r
-       BOOLEAN fullPrint\r
+       BOOLEAN fullPrint,\r
+       BOOLEAN getCounters\r
        )\r
 {\r
        ib_al_handle_t          h_al = NULL;\r
@@ -237,9 +288,7 @@ vstat_ca_attr(
        ib_ca_handle_t  h_ca = NULL;\r
        uint32_t                        bsize;\r
        ib_port_attr_mod_t port_attr_mod;\r
-\r
-\r
-\r
+       uint8_t                 port_idx;\r
 \r
        while(1)\r
        {\r
@@ -344,11 +393,17 @@ vstat_ca_attr(
                                goto Cleanup2;\r
                        }\r
 \r
-                       /* Print_ca_attributes */\r
-\r
-                       vstat_print_ca_attr((int)i, vstat_ca_attr, fullPrint);\r
 \r
+                       \r
 \r
+                       vstat_print_ca_attr((int)i, vstat_ca_attr, fullPrint);\r
+                       if(getCounters)\r
+                       {\r
+                               for(port_idx =0; port_idx< vstat_ca_attr->num_ports;port_idx++){\r
+                                       vstat_get_counters(h_ca ,port_idx+1);\r
+                               }\r
+                       }\r
+                       \r
                        /* Free the memory */\r
                        cl_free(vstat_ca_attr);\r
                        vstat_ca_attr = NULL;\r
@@ -398,18 +453,23 @@ main(
 {\r
        ib_api_status_t ib_status;\r
        BOOLEAN fullPrint = FALSE;\r
+       BOOLEAN getCounters = FALSE;\r
        if(argc>1){\r
                int i = 2;\r
                while(i<=argc){\r
                        if(!_stricmp(argv[i-1], "-v")){\r
                                fullPrint = TRUE;\r
                                i+=1;\r
+                       }else if(!_stricmp(argv[i-1], "-c")){\r
+                               getCounters = TRUE;\r
+                               i+=1;\r
                        }else{\r
                                i+=2;\r
                        }\r
                }\r
        }\r
-       ib_status = vstat_ca_attr(FALSE, fullPrint);\r
+       ib_status = vstat_ca_attr(FALSE, fullPrint,getCounters);\r
+\r
        return 0;\r
 }\r
 \r