src/tools/rxperf/rxperf.c: Fix misleading indentation
[openafs.git] / src / tools / rxperf / rxperf.c
index 3367fd2..8d90b1b 100644 (file)
@@ -118,16 +118,25 @@ start_timer(void)
  */
 
 static void
-end_and_print_timer(char *str)
+end_and_print_timer(char *str, long long bytes)
 {
     long long start_l, stop_l;
+    double kbps;
 
     timer_check--;
     assert(timer_check == 0);
     gettimeofday(&timer_stop, NULL);
     start_l = timer_start.tv_sec * 1000000 + timer_start.tv_usec;
     stop_l = timer_stop.tv_sec * 1000000 + timer_stop.tv_usec;
-    printf("%s:\t%8llu msec\n", str, (stop_l - start_l) / 1000);
+    printf("%s:\t%8llu msec", str, (stop_l - start_l) / 1000);
+
+    kbps = bytes * 8000.0 / (stop_l - start_l);
+    if (kbps > 1000000.0)
+        printf("\t[%.4g Gbit/s]\n", kbps/1000000.0);
+    else if (kbps > 1000.0)
+        printf("\t[%.4g Mbit/s]\n", kbps/1000.0);
+    else
+        printf("\t[%.4g kbit/s]\n", kbps);
 }
 
 /*
@@ -692,8 +701,7 @@ do_client(const char *server, short port, char *filename, afs_int32 command,
     void *status;
 #endif
 
-    params = malloc(sizeof(struct client_data));
-    memset(params, 0, sizeof(struct client_data));
+    params = calloc(1, sizeof(struct client_data));
 
 #ifdef AFS_NT40_ENV
     if (afs_winsockInit() < 0) {
@@ -793,7 +801,17 @@ do_client(const char *server, short port, char *filename, afs_int32 command,
         pthread_join(thread[i], &status);
 #endif
 
-    end_and_print_timer(stamp);
+    switch (command) {
+    case RX_PERF_RPC:
+        end_and_print_timer(stamp, (long long)threads*times*(sendbytes+readbytes));
+        break;
+    case RX_PERF_RECV:
+    case RX_PERF_SEND:
+    case RX_PERF_FILE:
+        end_and_print_timer(stamp, (long long)threads*times*bytes);
+        break;
+    }
+
     DBFPRINT(("done for good\n"));
 
     if (dumpstats) {
@@ -908,9 +926,9 @@ rxperf_server(int argc, char **argv)
            hotthreads = 1;
            break;
        case 'm':
-         maxmtu = strtol(optarg, &ptr, 0);
-         if (ptr && *ptr != '\0')
-           errx(1, "can't resolve rx maxmtu to use");
+           maxmtu = strtol(optarg, &ptr, 0);
+           if (ptr && *ptr != '\0')
+               errx(1, "can't resolve rx maxmtu to use");
            break;
        case 'u':
            udpbufsz = strtol(optarg, &ptr, 0) * 1024;
@@ -1080,9 +1098,9 @@ rxperf_client(int argc, char **argv)
          nojumbo=1;
          break;
        case 'm':
-         maxmtu = strtol(optarg, &ptr, 0);
-         if (ptr && *ptr != '\0')
-           errx(1, "can't resolve rx maxmtu to use");
+           maxmtu = strtol(optarg, &ptr, 0);
+           if (ptr && *ptr != '\0')
+               errx(1, "can't resolve rx maxmtu to use");
            break;
        case 'u':
            udpbufsz = strtol(optarg, &ptr, 0) * 1024;