[dpdk-dev,v2,3/5] testpmd: show throughput in port stats

Message ID 1464751663-135211-4-git-send-email-zhihong.wang@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers

Commit Message

Zhihong Wang June 1, 2016, 3:27 a.m. UTC
  This patch adds throughput numbers (in the period since last use of this
command) in port statistics display for "show port stats (port_id|all)".


Signed-off-by: Zhihong Wang <zhihong.wang@intel.com>
---
 app/test-pmd/config.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
  

Comments

De Lara Guarch, Pablo June 7, 2016, 10:02 a.m. UTC | #1
> -----Original Message-----
> From: Wang, Zhihong
> Sent: Wednesday, June 01, 2016 4:28 AM
> To: dev@dpdk.org
> Cc: Ananyev, Konstantin; Richardson, Bruce; De Lara Guarch, Pablo;
> thomas.monjalon@6wind.com; Wang, Zhihong
> Subject: [PATCH v2 3/5] testpmd: show throughput in port stats
> 
> This patch adds throughput numbers (in the period since last use of this
> command) in port statistics display for "show port stats (port_id|all)".
> 
> 
> Signed-off-by: Zhihong Wang <zhihong.wang@intel.com>
> ---
>  app/test-pmd/config.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
> index c611649..f487b87 100644
> --- a/app/test-pmd/config.c
> +++ b/app/test-pmd/config.c
> @@ -92,6 +92,7 @@
>  #include <rte_ether.h>
>  #include <rte_ethdev.h>
>  #include <rte_string_fns.h>
> +#include <rte_cycles.h>
> 
>  #include "testpmd.h"
> 
> @@ -150,6 +151,10 @@ print_ethaddr(const char *name, struct ether_addr
> *eth_addr)
>  void
>  nic_stats_display(portid_t port_id)
>  {
> +	static uint64_t sum_rx[RTE_MAX_ETHPORTS];
> +	static uint64_t sum_tx[RTE_MAX_ETHPORTS];
> +	static uint64_t cycles[RTE_MAX_ETHPORTS];
> +	uint64_t pkt_rx, pkt_tx, cycle;

Could you rename some of these variables to something more specific?
Like:
pkt_rx -> diff_rx_pkts
sum_rx -> prev_rx_pkts
cycle -> diff_cycles
cycles -> prev_cycles



>  	struct rte_eth_stats stats;
>  	struct rte_port *port = &ports[port_id];
>  	uint8_t i;
> @@ -209,6 +214,21 @@ nic_stats_display(portid_t port_id)
>  		}
>  	}
> 
> +	cycle = cycles[port_id];
> +	cycles[port_id] = rte_rdtsc();
> +	if (cycle > 0)
> +		cycle = cycles[port_id] - cycle;
> +
> +	pkt_rx = stats.ipackets - sum_rx[port_id];
> +	pkt_tx = stats.opackets - sum_tx[port_id];
> +	sum_rx[port_id] = stats.ipackets;
> +	sum_tx[port_id] = stats.opackets;
> +	printf("\n  Throughput (since last show)\n");
> +	printf("  RX-pps: %12"PRIu64"\n"
> +			"  TX-pps: %12"PRIu64"\n",
> +			cycle > 0 ? pkt_rx * rte_get_tsc_hz() / cycle : 0,
> +			cycle > 0 ? pkt_tx * rte_get_tsc_hz() / cycle : 0);
> +
>  	printf("  %s############################%s\n",
>  	       nic_stats_border, nic_stats_border);
>  }
> --
> 2.5.0
  
Zhihong Wang June 8, 2016, 1:31 a.m. UTC | #2
> -----Original Message-----
> From: De Lara Guarch, Pablo
> Sent: Tuesday, June 7, 2016 6:03 PM
> To: Wang, Zhihong <zhihong.wang@intel.com>; dev@dpdk.org
> Cc: Ananyev, Konstantin <konstantin.ananyev@intel.com>; Richardson, Bruce
> <bruce.richardson@intel.com>; thomas.monjalon@6wind.com
> Subject: RE: [PATCH v2 3/5] testpmd: show throughput in port stats
> 
> 
> 
> > -----Original Message-----
> > From: Wang, Zhihong
> > Sent: Wednesday, June 01, 2016 4:28 AM
> > To: dev@dpdk.org
> > Cc: Ananyev, Konstantin; Richardson, Bruce; De Lara Guarch, Pablo;
> > thomas.monjalon@6wind.com; Wang, Zhihong
> > Subject: [PATCH v2 3/5] testpmd: show throughput in port stats
> >
> > This patch adds throughput numbers (in the period since last use of this
> > command) in port statistics display for "show port stats (port_id|all)".
> >
> >
> > Signed-off-by: Zhihong Wang <zhihong.wang@intel.com>
> > ---
> >  app/test-pmd/config.c | 20 ++++++++++++++++++++
> >  1 file changed, 20 insertions(+)
> >
> > diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
> > index c611649..f487b87 100644
> > --- a/app/test-pmd/config.c
> > +++ b/app/test-pmd/config.c
> > @@ -92,6 +92,7 @@
> >  #include <rte_ether.h>
> >  #include <rte_ethdev.h>
> >  #include <rte_string_fns.h>
> > +#include <rte_cycles.h>
> >
> >  #include "testpmd.h"
> >
> > @@ -150,6 +151,10 @@ print_ethaddr(const char *name, struct ether_addr
> > *eth_addr)
> >  void
> >  nic_stats_display(portid_t port_id)
> >  {
> > +	static uint64_t sum_rx[RTE_MAX_ETHPORTS];
> > +	static uint64_t sum_tx[RTE_MAX_ETHPORTS];
> > +	static uint64_t cycles[RTE_MAX_ETHPORTS];
> > +	uint64_t pkt_rx, pkt_tx, cycle;
> 
> Could you rename some of these variables to something more specific?

Thanks for the suggestion! Will rename them.

> Like:
> pkt_rx -> diff_rx_pkts
> sum_rx -> prev_rx_pkts
> cycle -> diff_cycles
> cycles -> prev_cycles
> 
> 
> 
> >  	struct rte_eth_stats stats;
> >  	struct rte_port *port = &ports[port_id];
> >  	uint8_t i;
> > @@ -209,6 +214,21 @@ nic_stats_display(portid_t port_id)
> >  		}
> >  	}
> >
> > +	cycle = cycles[port_id];
> > +	cycles[port_id] = rte_rdtsc();
> > +	if (cycle > 0)
> > +		cycle = cycles[port_id] - cycle;
> > +
> > +	pkt_rx = stats.ipackets - sum_rx[port_id];
> > +	pkt_tx = stats.opackets - sum_tx[port_id];
> > +	sum_rx[port_id] = stats.ipackets;
> > +	sum_tx[port_id] = stats.opackets;
> > +	printf("\n  Throughput (since last show)\n");
> > +	printf("  RX-pps: %12"PRIu64"\n"
> > +			"  TX-pps: %12"PRIu64"\n",
> > +			cycle > 0 ? pkt_rx * rte_get_tsc_hz() / cycle : 0,
> > +			cycle > 0 ? pkt_tx * rte_get_tsc_hz() / cycle : 0);
> > +
> >  	printf("  %s############################%s\n",
> >  	       nic_stats_border, nic_stats_border);
> >  }
> > --
> > 2.5.0
  

Patch

diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index c611649..f487b87 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -92,6 +92,7 @@ 
 #include <rte_ether.h>
 #include <rte_ethdev.h>
 #include <rte_string_fns.h>
+#include <rte_cycles.h>
 
 #include "testpmd.h"
 
@@ -150,6 +151,10 @@  print_ethaddr(const char *name, struct ether_addr *eth_addr)
 void
 nic_stats_display(portid_t port_id)
 {
+	static uint64_t sum_rx[RTE_MAX_ETHPORTS];
+	static uint64_t sum_tx[RTE_MAX_ETHPORTS];
+	static uint64_t cycles[RTE_MAX_ETHPORTS];
+	uint64_t pkt_rx, pkt_tx, cycle;
 	struct rte_eth_stats stats;
 	struct rte_port *port = &ports[port_id];
 	uint8_t i;
@@ -209,6 +214,21 @@  nic_stats_display(portid_t port_id)
 		}
 	}
 
+	cycle = cycles[port_id];
+	cycles[port_id] = rte_rdtsc();
+	if (cycle > 0)
+		cycle = cycles[port_id] - cycle;
+
+	pkt_rx = stats.ipackets - sum_rx[port_id];
+	pkt_tx = stats.opackets - sum_tx[port_id];
+	sum_rx[port_id] = stats.ipackets;
+	sum_tx[port_id] = stats.opackets;
+	printf("\n  Throughput (since last show)\n");
+	printf("  RX-pps: %12"PRIu64"\n"
+			"  TX-pps: %12"PRIu64"\n",
+			cycle > 0 ? pkt_rx * rte_get_tsc_hz() / cycle : 0,
+			cycle > 0 ? pkt_tx * rte_get_tsc_hz() / cycle : 0);
+
 	printf("  %s############################%s\n",
 	       nic_stats_border, nic_stats_border);
 }