]> rtime.felk.cvut.cz Git - frescor/fwp.git/commitdiff
Added -g (granularity) option.
authorMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 5 Dec 2007 09:19:03 +0000 (10:19 +0100)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 5 Dec 2007 09:19:03 +0000 (10:19 +0100)
wme_test/wclient.c

index 7d2216b5e1da3f2c82ccdfda042d6ded6750a471..30bf3fdb39e6e626f9751b179e9257d06c388e84 100644 (file)
 #include <semaphore.h>
 
 #define MAX_SENDENDPOINTS  10 
+#define MIN_GRANULARITY 100
 
 unsigned opt_packet_size = 800;
 unsigned opt_period_usec = 10*MSEC_TO_USEC;
 unsigned opt_jitter = 0;
 char    *opt_output = "delay_stats";
 unsigned opt_count_sec = 0;
+int opt_granularity_usec = MIN_GRANULARITY;
 
 int ac_sockfd[AC_NUM];
 
@@ -50,9 +52,8 @@ union msg_buff {
 
 /* maximal traffic delay in ms - 10 s*/
 #define MAX_DELAY_US 10000000
-#define GRANULARITY 100
 
-unsigned delay_stats[AC_NUM][MAX_DELAY_US/GRANULARITY];
+unsigned delay_stats[AC_NUM][MAX_DELAY_US/MIN_GRANULARITY];
 
 /*struct ac_stats[AC_NUM] {
    unsigned long int min_trans_time;
@@ -104,7 +105,7 @@ void stopper()
 void save_results()
 {
        int ac, i, maxi;
-       const int mini = 3000/GRANULARITY;
+       const int mini = 3000/opt_granularity_usec;
        bool allzeros;
        unsigned sum[AC_NUM];
        double val;
@@ -112,7 +113,7 @@ void save_results()
        fprintf(stderr, "\nWriting data to %s...\n", logfname);
 
        allzeros = true;
-       for (maxi = MAX_DELAY_US/GRANULARITY - 1; maxi >= 0; maxi--) {
+       for (maxi = MAX_DELAY_US/opt_granularity_usec - 1; maxi >= 0; maxi--) {
                for (ac = 0; ac < AC_NUM; ac++) {
                        if (delay_stats[ac][maxi] != 0) allzeros = false;
                }
@@ -129,7 +130,7 @@ void save_results()
        }
 
        for ( i = 0 ; i < maxi; i++) {
-               fprintf(logfd,"\n%f", i*GRANULARITY/1000.0);
+               fprintf(logfd,"\n%f", i*opt_granularity_usec/1000.0);
                for (ac = 0; ac < AC_NUM; ac++) { 
                        if (sum[ac])
                                val = (double)delay_stats[ac][i]*100.0 / sum[ac];
@@ -236,7 +237,7 @@ void* receiver(void* queue)
                                         trans_time.tv_nsec / USEC_TO_NSEC) /2;
          
                if (trans_time_usec < MAX_DELAY_US)
-                       delay_stats[ac][trans_time_usec/GRANULARITY]++;
+                       delay_stats[ac][trans_time_usec/opt_granularity_usec]++;
 
                receivers[ac].received++;
        
@@ -351,11 +352,18 @@ int main(int argc, char *argv[])
        char opt;
 
 
-       while ((opt = getopt(argc, argv, "c:j:o:s:")) != -1) {
+       while ((opt = getopt(argc, argv, "c:g:j:o:s:")) != -1) {
                switch (opt) {
                        case 'c':
                                opt_count_sec = atoi(optarg);
                                break;
+                       case 'g':
+                               opt_granularity_usec = atoi(optarg);
+                               if (opt_granularity_usec < MIN_GRANULARITY) {
+                                       fprintf(stderr, "Granulatiry too small (min %d)!\n", MIN_GRANULARITY);
+                                       exit(1);
+                               }
+                               break;
                        case 'j':
                                opt_jitter = atoi(optarg);
                                break;
@@ -369,6 +377,7 @@ int main(int argc, char *argv[])
                                fprintf(stderr, "Usage: %s [ options ] server_addr\n\n", argv[0]);
                                fprintf(stderr, "Options:\n");
                                fprintf(stderr, "    -c  count (number of seconds to run)");
+                               fprintf(stderr, "    -g  histogram granularity [usec]");
                                fprintf(stderr, "    -j  send jitter (0-100) [%%]\n");
                                fprintf(stderr, "    -o  output filename (.dat will be appended)");
                                fprintf(stderr, "    -s  size of data payload in packets [bytes]\n");