hsa: vcl test client incremental stats 71/32171/6
authorFlorin Coras <fcoras@cisco.com>
Fri, 30 Apr 2021 04:28:03 +0000 (21:28 -0700)
committerDave Barach <openvpp@barachs.net>
Fri, 30 Apr 2021 14:39:39 +0000 (14:39 +0000)
Add option to print per second tx stats

Type: improvement

Signed-off-by: Florin Coras <fcoras@cisco.com>
Change-Id: I7f226a6521da13ab29de65a441f73d4e56fb57cf

src/plugins/hs_apps/vcl/vcl_test.h
src/plugins/hs_apps/vcl/vcl_test_client.c

index d475ec3..f1e6bc4 100644 (file)
@@ -136,6 +136,7 @@ typedef struct vcl_test_session
   char *rxbuf;
   vcl_test_cfg_t cfg;
   vcl_test_stats_t stats;
+  vcl_test_stats_t old_stats;
   int session_index;
   vppcom_endpt_t endpt;
   uint8_t ip[16];
@@ -396,6 +397,37 @@ vcl_test_stats_dump (char *header, vcl_test_stats_t * stats,
   printf (VCL_TEST_SEPARATOR_STRING);
 }
 
+static inline double
+vcl_test_time_diff (struct timespec *old, struct timespec *new)
+{
+  uint64_t sec, nsec;
+  if ((new->tv_nsec - old->tv_nsec) < 0)
+    {
+      sec = new->tv_sec - old->tv_sec - 1;
+      nsec = new->tv_nsec - old->tv_nsec + 1e9;
+    }
+  else
+    {
+      sec = new->tv_sec - old->tv_sec;
+      nsec = new->tv_nsec - old->tv_nsec;
+    }
+  return (double) sec + (1e-9 * nsec);
+}
+
+static inline void
+vcl_test_stats_dump_inc (vcl_test_stats_t *old, vcl_test_stats_t *new)
+{
+  double duration, rate;
+  uint64_t total_bytes;
+
+  duration = vcl_test_time_diff (&old->stop, &new->stop);
+
+  total_bytes = new->tx_bytes - old->tx_bytes;
+  rate = (double) total_bytes * 8 / duration / 1e9;
+  printf ("Sent %lu Mbytes in %.2lf seconds %.2lf Gbps\n",
+         (uint64_t) (total_bytes / 1e6), duration, rate);
+}
+
 static inline int
 vcl_comp_tspec (struct timespec *a, struct timespec *b)
 {
index 1f2c47d..d16d62c 100644 (file)
@@ -48,6 +48,7 @@ typedef struct
   uint8_t dump_cfg;
   vcl_test_t post_test;
   uint8_t proto;
+  uint8_t incremental_stats;
   uint32_t n_workers;
   volatile int active_workers;
   volatile int test_running;
@@ -172,15 +173,19 @@ vtc_worker_test_setup (vcl_test_client_worker_t * wrk)
 {
   vcl_test_cfg_t *cfg = &wrk->cfg;
   vcl_test_session_t *ts;
+  struct timespec now;
   uint32_t sidx;
   int i, j;
 
   FD_ZERO (&wrk->wr_fdset);
   FD_ZERO (&wrk->rd_fdset);
 
+  clock_gettime (CLOCK_REALTIME, &now);
+
   for (i = 0; i < cfg->num_test_sessions; i++)
     {
       ts = &wrk->sessions[i];
+      ts->old_stats.stop = now;
 
       switch (cfg->test)
        {
@@ -288,6 +293,21 @@ vtc_worker_sessions_exit (vcl_test_client_worker_t * wrk)
   wrk->n_sessions = 0;
 }
 
+static void
+vtc_inc_stats_check (vcl_test_session_t *ts)
+{
+  /* Avoid checking time too often because of syscall cost */
+  if (ts->stats.tx_bytes - ts->old_stats.tx_bytes < 1 << 20)
+    return;
+
+  clock_gettime (CLOCK_REALTIME, &ts->stats.stop);
+  if (vcl_test_time_diff (&ts->old_stats.stop, &ts->stats.stop) > 1)
+    {
+      vcl_test_stats_dump_inc (&ts->old_stats, &ts->stats);
+      ts->old_stats = ts->stats;
+    }
+}
+
 static void *
 vtc_worker_loop (void *arg)
 {
@@ -353,6 +373,8 @@ vtc_worker_loop (void *arg)
                         ts->fd);
                  goto exit;
                }
+             if (vcm->incremental_stats)
+               vtc_inc_stats_check (ts);
            }
          if ((!check_rx && ts->stats.tx_bytes >= ts->cfg.total_bytes)
              || (check_rx && ts->stats.rx_bytes >= ts->cfg.total_bytes))
@@ -642,27 +664,29 @@ parse_input ()
 void
 print_usage_and_exit (void)
 {
-  fprintf (stderr,
-          "vcl_test_client [OPTIONS] <ipaddr> <port>\n"
-          "  OPTIONS\n"
-          "  -h               Print this message and exit.\n"
-          "  -6               Use IPv6\n"
-          "  -c               Print test config before test.\n"
-          "  -w <dir>         Write test results to <dir>.\n"
-          "  -X               Exit after running test.\n"
-          "  -p <proto>       Use <proto> transport layer\n"
-          "  -D               Use UDP transport layer\n"
-          "  -L               Use TLS transport layer\n"
-          "  -E               Run Echo test.\n"
-          "  -N <num-writes>  Test Cfg: number of writes.\n"
-          "  -R <rxbuf-size>  Test Cfg: rx buffer size.\n"
-          "  -T <txbuf-size>  Test Cfg: tx buffer size.\n"
-          "  -U               Run Uni-directional test.\n"
-          "  -B               Run Bi-directional test.\n"
-          "  -V               Verbose mode.\n"
-          "  -I <N>           Use N sessions.\n"
-          "  -s <N>           Use N sessions.\n"
-          "  -q <n>           QUIC : use N Ssessions on top of n Qsessions\n");
+  fprintf (
+    stderr,
+    "vcl_test_client [OPTIONS] <ipaddr> <port>\n"
+    "  OPTIONS\n"
+    "  -h               Print this message and exit.\n"
+    "  -6               Use IPv6\n"
+    "  -c               Print test config before test.\n"
+    "  -w <dir>         Write test results to <dir>.\n"
+    "  -X               Exit after running test.\n"
+    "  -p <proto>       Use <proto> transport layer\n"
+    "  -D               Use UDP transport layer\n"
+    "  -L               Use TLS transport layer\n"
+    "  -E               Run Echo test.\n"
+    "  -N <num-writes>  Test Cfg: number of writes.\n"
+    "  -R <rxbuf-size>  Test Cfg: rx buffer size.\n"
+    "  -T <txbuf-size>  Test Cfg: tx buffer size.\n"
+    "  -U               Run Uni-directional test.\n"
+    "  -B               Run Bi-directional test.\n"
+    "  -V               Verbose mode.\n"
+    "  -I <N>           Use N sessions.\n"
+    "  -s <N>           Use N sessions.\n"
+    "  -S              Print incremental stats per session.\n"
+    "  -q <n>           QUIC : use N Ssessions on top of n Qsessions\n");
   exit (1);
 }
 
@@ -673,7 +697,7 @@ vtc_process_opts (vcl_test_client_main_t * vcm, int argc, char **argv)
   int c, v;
 
   opterr = 0;
-  while ((c = getopt (argc, argv, "chnp:w:XE:I:N:R:T:UBV6DLs:q:")) != -1)
+  while ((c = getopt (argc, argv, "chnp:w:XE:I:N:R:T:UBV6DLs:q:S")) != -1)
     switch (c)
       {
       case 'c':
@@ -828,6 +852,10 @@ vtc_process_opts (vcl_test_client_main_t * vcm, int argc, char **argv)
        vcm->proto = VPPCOM_PROTO_TLS;
        break;
 
+      case 'S':
+       vcm->incremental_stats = 1;
+       break;
+
       case '?':
        switch (optopt)
          {