Take yet more care not to be dividing by zero when calculating the bit
authorMartin Mathieson <martin.r.mathieson@googlemail.com>
Fri, 6 Jul 2012 01:52:09 +0000 (01:52 -0000)
committerMartin Mathieson <martin.r.mathieson@googlemail.com>
Fri, 6 Jul 2012 01:52:09 +0000 (01:52 -0000)
rate of the channel/UE. Times four...

svn path=/trunk/; revision=43578

ui/cli/tap-macltestat.c
ui/cli/tap-rlcltestat.c
ui/gtk/mac_lte_stat_dlg.c
ui/gtk/rlc_lte_stat_dlg.c

index af230da51f13ecc54b268277929114f76e58a6d8..cf2df41e09ef9e90a0e1df6a699c088ff5c35a80 100644 (file)
@@ -395,9 +395,16 @@ mac_lte_stat_packet(void *phs, packet_info *pinfo, epan_dissect_t *edt _U_,
 /* Calculate and return a bandwidth figure, in Mbs */
 static float calculate_bw(nstime_t *start_time, nstime_t *stop_time, guint32 bytes)
 {
+    /* Can only calculate bandwidth if have time delta */
     if (memcmp(start_time, stop_time, sizeof(nstime_t)) != 0) {
         float elapsed_ms = (((float)stop_time->secs - (float)start_time->secs) * 1000) +
                            (((float)stop_time->nsecs - (float)start_time->nsecs) / 1000000);
+
+        /* Only really meaningful if have a few frames spread over time...
+           For now at least avoid dividing by something very close to 0.0 */
+        if (elapsed_ms < 2.0) {
+           return 0.0;
+        }
         return ((bytes * 8) / elapsed_ms) / 1000;
     }
     else {
@@ -406,6 +413,7 @@ static float calculate_bw(nstime_t *start_time, nstime_t *stop_time, guint32 byt
 }
 
 
+
 /* Output the accumulated stats */
 static void
 mac_lte_stat_draw(void *phs)
index 085e51ea89b2dcc5dab35b19c29ff81797365519..ab334dd18bcd5592a1d3bde1acfb79f51b66cf8e 100644 (file)
@@ -284,9 +284,16 @@ rlc_lte_stat_packet(void *phs, packet_info *pinfo, epan_dissect_t *edt _U_,
 /* Calculate and return a bandwidth figure, in Mbs */
 static float calculate_bw(nstime_t *start_time, nstime_t *stop_time, guint32 bytes)
 {
+    /* Can only calculate bandwidth if have time delta */
     if (memcmp(start_time, stop_time, sizeof(nstime_t)) != 0) {
         float elapsed_ms = (((float)stop_time->secs - (float)start_time->secs) * 1000) +
                            (((float)stop_time->nsecs - (float)start_time->nsecs) / 1000000);
+
+        /* Only really meaningful if have a few frames spread over time...
+           For now at least avoid dividing by something very close to 0.0 */
+        if (elapsed_ms < 2.0) {
+           return 0.0;
+        }
         return ((bytes * 8) / elapsed_ms) / 1000;
     }
     else {
@@ -296,7 +303,6 @@ static float calculate_bw(nstime_t *start_time, nstime_t *stop_time, guint32 byt
 
 
 
-
 /* (Re)draw RLC stats */
 static void
 rlc_lte_stat_draw(void *phs)
index a7ebc6eea99d012e13358aa7f8d412f89af5c84d..35381b1266b3a265887737800c0acbe32a141f16 100644 (file)
@@ -23,7 +23,6 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -625,9 +624,16 @@ static void mac_lte_ue_details(mac_lte_ep_t *mac_stat_ep, mac_lte_stat_t *hs)
 /* Calculate and return a bandwidth figure, in Mbs */
 static float calculate_bw(nstime_t *start_time, nstime_t *stop_time, guint32 bytes)
 {
+    /* Can only calculate bandwidth if have time delta */
     if (memcmp(start_time, stop_time, sizeof(nstime_t)) != 0) {
         float elapsed_ms = (((float)stop_time->secs - (float)start_time->secs) * 1000) +
                            (((float)stop_time->nsecs - (float)start_time->nsecs) / 1000000);
+
+        /* Only really meaningful if have a few frames spread over time...
+           For now at least avoid dividing by something very close to 0.0 */
+        if (elapsed_ms < 2.0) {
+           return 0.0;
+        }
         return ((bytes * 8) / elapsed_ms) / 1000;
     }
     else {
index 943a5a560fbe3c746a7a1ab165916a75457d9f8a..f08abb8d2b2863ba2772057899c94921f8bc812f 100644 (file)
@@ -574,9 +574,16 @@ static void invalidate_channel_iters(rlc_lte_stat_t *hs)
 /* Calculate and return a bandwidth figure, in Mbs */
 static float calculate_bw(nstime_t *start_time, nstime_t *stop_time, guint32 bytes)
 {
+    /* Can only calculate bandwidth if have time delta */
     if (memcmp(start_time, stop_time, sizeof(nstime_t)) != 0) {
         float elapsed_ms = (((float)stop_time->secs - (float)start_time->secs) * 1000) +
                            (((float)stop_time->nsecs - (float)start_time->nsecs) / 1000000);
+
+        /* Only really meaningful if have a few frames spread over time...
+           For now at least avoid dividing by something very close to 0.0 */
+        if (elapsed_ms < 2.0) {
+           return 0.0;
+        }
         return ((bytes * 8) / elapsed_ms) / 1000;
     }
     else {
@@ -585,7 +592,6 @@ static float calculate_bw(nstime_t *start_time, nstime_t *stop_time, guint32 byt
 }
 
 
-
 /* Draw the channels table according to the current UE selection */
 static void rlc_lte_channels(rlc_lte_ep_t *rlc_stat_ep, rlc_lte_stat_t *hs)
 {