Print more useful results
authorAlex Pyrgiotis <apyrgio@grnet.gr>
Thu, 21 Feb 2013 10:34:35 +0000 (12:34 +0200)
committerFilippos Giannakos <philipgian@grnet.gr>
Mon, 11 Mar 2013 09:52:31 +0000 (11:52 +0200)
xseg/peers/user/bench-utils.c
xseg/peers/user/bench-xseg.c
xseg/peers/user/bench-xseg.h

index 71ed9e0..ea3d8fe 100644 (file)
@@ -46,6 +46,8 @@
 #include <signal.h>
 #include <bench-xseg.h>
 
+#include <math.h>
+
 struct timespec delay = {0, 4000000};
 
 /*
@@ -81,6 +83,14 @@ uint64_t str2num(char *str)
        return num;
 }
 
+/*
+ * Converts struct timespec to double (units in nanoseconds)
+ */
+static double timespec2double(struct timespec num)
+{
+       return (double) (num.tv_sec * pow(10, 9) + num.tv_nsec);
+}
+
 int read_insanity(char *insanity)
 {
        if (strcmp(insanity, "sane") == 0)
@@ -116,26 +126,66 @@ int read_pattern(char *pattern)
        return -1;
 }
 
-void print_res(struct tm_result res, char *type)
+/*
+ * Seperates a double number in seconds, msec, usec, nsec
+ * Expects a number in nanoseconds (e.g. a number from timespec2double)
+ */
+static struct tm_result separate_by_order(double num)
+{
+       struct tm_result res;
+
+       //The format we expect is the following:
+       //
+       //              |-s-|-ms-|-us-|-ns|
+       //num =  123 456  789  012 . 000000000000
+       res.s = num / pow(10,9);
+       num = fmod(num, pow(10,9));
+       res.ms = num / pow(10,6);
+       num = fmod(num, pow(10,6));
+       res.us = num / 1000;
+       res.ns = fmod(num, 1000);
+
+       return res;
+}
+
+void print_stats(struct bench *prefs)
 {
+       uint64_t remaining;
+
        printf("\n");
-       printf("      %s\n", type);
-       printf("================================\n");
-       printf("       |-s-||-ms-|-us-|-ns-|\n");
-       printf("Time:   %3lu. %03lu  %03lu  %03lu\n",
-                       res.s, res.ms, res.us, res.ns);
+       printf("Requests total:     %10lu\n", prefs->max_requests);
+       printf("Requests submitted: %10lu\n", prefs->sub_tm->completed);
+       printf("Requests received:  %10lu\n", prefs->rec_tm->completed);
+       printf("\n");
+
+       remaining = prefs->max_requests - prefs->rec_tm->completed;
+       if (remaining)
+               printf("Requests remaining: %10lu\n", remaining);
+       else
+               printf("All requests have been served.\n");
 }
 
-/*
- * Seperates a timespec struct in seconds, msec, usec, nsec
- */
-void separate_by_order(struct timespec src, struct tm_result *res)
+void print_res(struct bench *prefs, struct timer *tm, char *type)
 {
-       res->ns = src.tv_nsec % 1000;
-       src.tv_nsec /= 1000;
-       res->us = src.tv_nsec % 1000;
-       res->ms = src.tv_nsec / 1000;
-       res->s = src.tv_sec;
+       struct tm_result res;
+       double sum;
+
+       sum = timespec2double(tm->sum);
+       res = separate_by_order(sum);
+
+       printf("\n");
+       printf("              %s\n", type);
+       printf("=======================================\n");
+       printf("             |-s-||-ms-|-us-|-ns-|\n");
+       printf("Total time:   %3u. %03u  %03u  %03u\n",
+                       res.s, res.ms, res.us, res.ns);
+
+       res = separate_by_order(sum / prefs->rec_tm->completed);
+
+       printf("Mean Time:    %3u. %03u  %03u  %03u\n",
+                       res.s, res.ms, res.us, res.ns);
+
+       //TODO: Add std
 }
 
 void create_target(struct bench *prefs, struct xseg_request *req,
index 32bd26e..cffa7c4 100644 (file)
@@ -538,13 +538,12 @@ void custom_peer_finalize(struct peerd *peer)
 {
        struct bench *prefs = peer->priv;
        //TODO: Measure mean time, standard variation
-       struct tm_result total; //mean, std;
 
        if (!prefs->total_tm->completed)
                timer_stop(prefs, prefs->total_tm, NULL);
 
-       separate_by_order(prefs->total_tm->sum, &total);
-       print_res(total, "Total Time");
+       print_stats(prefs);
+       print_res(prefs, prefs->total_tm, "Total Requests");
        return;
 }
 
index 89ea037..de38f92 100644 (file)
@@ -101,15 +101,15 @@ struct timer {
        struct timespec sum;
        struct timespec2 sum_sq;
        struct timespec start_time;
-       uint32_t completed;
-       unsigned int insanity;
+       uint64_t completed;
+       int insanity;
 };
 
 struct tm_result {
-       unsigned long s;
-       unsigned long ms;
-       unsigned long us;
-       unsigned long ns;
+       unsigned int s;
+       unsigned int ms;
+       unsigned int us;
+       unsigned int ns;
 };
 
 /* FILLME
@@ -130,15 +130,15 @@ int init_timer(struct timer **tm, int insanity);
 uint64_t str2num(char *str);
 int read_op(char *op);
 int read_pattern(char *pattern);
-void print_res(struct tm_result res, char *type);
-void separate_by_order(struct timespec src, struct tm_result *res);
+int read_insanity(char *insanity);
+void print_res(struct bench *prefs, struct timer *tm, char *type);
+void print_stats(struct bench *prefs);
 void create_target(struct bench *prefs, struct xseg_request *req,
                uint64_t new);
 void create_chunk(struct bench *prefs, struct xseg_request *req,
                uint64_t new);
 uint64_t determine_next(struct bench *prefs);
 void create_id();
-int read_insanity(char *insanity);
 
 /**************\
  * LFSR stuff *