aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilip Balister <philip@opensdr.com>2011-06-12 18:00:03 -0700
committerroot <root@usrp-e1xx.local>2011-06-12 18:01:22 -0700
commitf914195053060d4274ea4f9b11589b7e4ef47e40 (patch)
tree1ab42976e7b4522589590bbc15311c6bc51fcb5c
parente625e890f5f341e4e93bec46a5279a96523a7b24 (diff)
downloaduhd-f914195053060d4274ea4f9b11589b7e4ef47e40.tar.gz
uhd-f914195053060d4274ea4f9b11589b7e4ef47e40.tar.bz2
uhd-f914195053060d4274ea4f9b11589b7e4ef47e40.zip
usrp-e-loopback : Fix transfer rate calculation.
Calculation now uses fractional seconds, not integer seconds.
-rw-r--r--host/usrp_e_utils/usrp-e-loopback.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/host/usrp_e_utils/usrp-e-loopback.c b/host/usrp_e_utils/usrp-e-loopback.c
index 0bd3d3100..762e55ac8 100644
--- a/host/usrp_e_utils/usrp-e-loopback.c
+++ b/host/usrp_e_utils/usrp-e-loopback.c
@@ -51,12 +51,27 @@ static int calc_checksum(struct pkt *p)
return sum;
}
+static struct timeval delta_time(struct timeval f, struct timeval s)
+{
+ struct timeval d;
+
+ if (f.tv_usec > s.tv_usec) {
+ d.tv_usec = f.tv_usec - s.tv_usec;
+ d.tv_sec = f.tv_sec - s.tv_sec;
+ } else {
+ d.tv_usec = f.tv_usec - s.tv_usec + 1e6;
+ d.tv_sec = f.tv_sec - s.tv_sec - 1;
+ }
+
+ return d;
+}
+
static void *read_thread(void *threadid)
{
int cnt, prev_seq_num, pkt_count, seq_num_failure;
struct pkt *p;
- unsigned long bytes_transfered, elapsed_seconds;
- struct timeval start_time, finish_time;
+ unsigned long bytes_transfered;
+ struct timeval start_time;
int rb_read;
printf("Greetings from the reading thread!\n");
@@ -125,11 +140,15 @@ static void *read_thread(void *threadid)
bytes_transfered += cnt;
if (bytes_transfered > (100 * 1000000)) {
+ struct timeval finish_time, d_time;
+ float elapsed_seconds;
+
gettimeofday(&finish_time, NULL);
- elapsed_seconds = finish_time.tv_sec - start_time.tv_sec;
+ d_time = delta_time(finish_time, start_time);
+ elapsed_seconds = (float)d_time.tv_sec + ((float)d_time.tv_usec * 1e-6f);
printf("RX data transfer rate = %f K Samples/second\n",
- (float) bytes_transfered / (float) elapsed_seconds / 4000);
+ (float) bytes_transfered / elapsed_seconds / 4000.0f);
start_time = finish_time;