]> rtime.felk.cvut.cz Git - frescor/fwp.git/commitdiff
Unsucessfull attempt to measure send and sendback delays.
authorMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 18 Jan 2008 17:12:40 +0000 (18:12 +0100)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 18 Jan 2008 17:12:40 +0000 (18:12 +0100)
wme_test/wclient.c

index 9d723a76d81b4e898f4bfe7f2ca30db5ea29dd01..75ef7d31e2d2f1873589ad7b67b059dbedffce10 100644 (file)
@@ -237,6 +237,21 @@ void timespec_sub (struct timespec *diff, const struct timespec *left,
        }
 }
 
+static inline long long timespec_sub_usec(const struct timespec *left,
+                                         const struct timespec *right)
+{
+       struct timespec result;
+       timespec_sub(&result, left, right);
+       return result.tv_sec * SEC_TO_USEC +
+               result.tv_nsec / USEC_TO_NSEC;
+}
+
+static inline long long timespec2usec(const struct timespec *ts)
+{
+       return ts->tv_sec * SEC_TO_USEC + ts->tv_nsec / USEC_TO_NSEC;
+}
+
+
 int create_ac_socket(unsigned int ac) 
 {
        int sockfd;
@@ -291,9 +306,9 @@ void* receiver(void* queue)
        struct  sockaddr_in rem_addr;
        int     mlen, ret;
        unsigned int ac, rem_addr_length; 
-       unsigned long int trans_time_usec;
-       unsigned long int min_trans_time;
-       struct timespec   send_timestamp,recv_timestamp, trans_time, time_from_reset;
+       long long int trans_time_usec, client_to_server_usec, server_to_client_usec;
+       long long int min_trans_time;
+       struct timespec send_timestamp, server_timestamp, recv_timestamp;
        fd_set fdset;
        
        min_trans_time = ~0;
@@ -312,7 +327,7 @@ void* receiver(void* queue)
                        perror("receiver select");
                        goto out;
                }
-               mlen = recvfrom(ac_sockfd[ac], &msg, sizeof(msg), 0,    \
+               mlen = recvfrom(ac_sockfd[ac], &msg, sizeof(msg), 0,
                                (struct sockaddr*)&rem_addr, &rem_addr_length);
                if (mlen < 0) {
                        perror("Chyba pri prijimani pozadavku");
@@ -320,17 +335,20 @@ void* receiver(void* queue)
                }       
                clock_gettime(CLOCK_MONOTONIC,&recv_timestamp);
                send_timestamp = msg.send_timestamp;
+               server_timestamp = msg.sendback_timestamp;
 
                /* Check whether this message was sent after reset_statistics() */
-               timespec_sub(&time_from_reset, &send_timestamp, &reset_timestamp);
-               if (time_from_reset.tv_sec < 0) {
-                       printf("ted\n");
+               
+               if (timespec_sub_usec(&send_timestamp, &reset_timestamp) < 0) {
                        continue; /* If so, don't count it */
                }
-               timespec_sub(&trans_time,&recv_timestamp ,&send_timestamp);
-               trans_time_usec = (trans_time.tv_sec * SEC_TO_USEC + \
-                                        trans_time.tv_nsec / USEC_TO_NSEC) /2;
-         
+
+               trans_time_usec = timespec_sub_usec(&recv_timestamp ,&send_timestamp);
+               client_to_server_usec = timespec_sub_usec(&server_timestamp, &send_timestamp);
+               server_to_client_usec = timespec_sub_usec(&recv_timestamp, &server_timestamp);
+
+               trans_time_usec /= 2;
+
                if (trans_time_usec < MAX_DELAY_US)
                        delay_stats[ac][trans_time_usec/opt_granularity_usec]++;