From Cal Turney: Need 6 dec places of SRT precision in WS SRT dialogs and the values...
authorwmeier <wmeier@f5534014-38df-0310-8fa8-9805f1628bb7>
Thu, 5 Aug 2010 22:14:16 +0000 (22:14 +0000)
committerwmeier <wmeier@f5534014-38df-0310-8fa8-9805f1628bb7>
Thu, 5 Aug 2010 22:14:16 +0000 (22:14 +0000)
From me:
 -Slight revision of the patch to prevent overflows
   when time_t is 32 bits (eg: on 32 bit Linux);
 -Other minor changes.

See: https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=4956

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@33721 f5534014-38df-0310-8fa8-9805f1628bb7

AUTHORS
gtk/rpc_progs.c
gtk/service_response_time_table.c

diff --git a/AUTHORS b/AUTHORS
index 186018bc1d8256c40e14bfaa9ed04c95276e52f9..eec9c5ea5147ed2f94fb6e92ba5253ccf8d13c12 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -3106,6 +3106,7 @@ Håkon Nessjøen          <haakon.nessjoen@gmail.com> {
        Digium TDMoE protocol dissector
 }
 
+
 and by:
 
 Pavel Roskin            <proski [AT] gnu.org>
@@ -3284,6 +3285,7 @@ Chuck Kristofek           <chuck.kristofek [AT] ngc.com>
 Markus Renz            <Markus.Renz [AT] hirschmann.de>
 Toshihiro Kataoka      <kataoka.toshihiro [AT] gmail.com>
 Petr Lautrbach         <plautrba [AT] redhat.com>
+Cal Turney             <turney_cal [AT] emc.com>
 
 Dan Lasley <dlasley[AT]promus.com> gave permission for his
 dumpit() hex-dump routine to be used.
index 90abd1fa99d761e98e1ec465398f2a9e67e1cb24..f2ba52eb8b4be9ecf0247fa88b882317f32b82da 100644 (file)
@@ -51,6 +51,7 @@
 #include "gtk/dlg_utils.h"
 #include "gtk/main.h"
 
+#define NANOSECS_PER_SEC 1000000000
 
 static GtkWidget *win=NULL;
 static GtkWidget *table=NULL;
@@ -249,8 +250,8 @@ rpcprogs_packet(void *dummy _U_, packet_info *pinfo, epan_dissect_t *edt _U_, co
 
        rp->tot.secs += delta.secs;
        rp->tot.nsecs += delta.nsecs;
-       if(rp->tot.nsecs>1000000000){
-               rp->tot.nsecs-=1000000000;
+       if(rp->tot.nsecs>NANOSECS_PER_SEC){
+               rp->tot.nsecs-=NANOSECS_PER_SEC;
                rp->tot.secs++;
        }
        rp->num++;
@@ -264,22 +265,21 @@ rpcprogs_draw(void *dummy _U_)
 {
        rpc_program_t *rp;
        int i;
-#ifdef G_HAVE_UINT64
        guint64 td;
-#else
-       guint32 td;
-#endif
 
        for(rp=prog_list,i=1;rp;rp=rp->next,i++){
-               /* scale it to units of 10us.*/
-               /* for long captures with a large tot time, this can overflow on 32bit */
-               td=(int)rp->tot.secs;
-               td=td*100000+(int)rp->tot.nsecs/10000;
-               if(rp->num){
-                       td/=rp->num;
-               } else {
+               /* Ignore procedures with no calls */
+               if(rp->num==0){
                        td=0;
+                       continue;
                }
+               /* Scale the average SRT in units of 1us and round to the nearest us.
+                  tot.secs is a time_t which may be 32 or 64 bits (or even floating)
+                   depending on the platform.  After casting tot.secs to a 64 bits int, it
+                   would take a capture with a duration of over 136 *years* to 
+                   overflow the secs portion of td. */
+               td = ((guint64)(rp->tot.secs))*NANOSECS_PER_SEC + rp->tot.nsecs;
+               td = ((td / rp->num) + 500) / 1000; 
 
                g_snprintf(rp->sprogram, sizeof(rp->sprogram), "%s",rpc_prog_name(rp->program));
                gtk_label_set_text(GTK_LABEL(rp->wprogram), rp->sprogram);
@@ -290,13 +290,13 @@ rpcprogs_draw(void *dummy _U_)
                g_snprintf(rp->snum, sizeof(rp->snum), "%d",rp->num);
                gtk_label_set_text(GTK_LABEL(rp->wnum), rp->snum);
 
-               g_snprintf(rp->smin, sizeof(rp->smin), "%3d.%05d",(int)rp->min.secs,(int)rp->min.nsecs/10000);
+               g_snprintf(rp->smin, sizeof(rp->smin), "%3d.%06d",(int)rp->min.secs, (rp->min.nsecs+500)/1000);
                gtk_label_set_text(GTK_LABEL(rp->wmin), rp->smin);
 
-               g_snprintf(rp->smax, sizeof(rp->smax), "%3d.%05d",(int)rp->max.secs,(int)rp->max.nsecs/10000);
+               g_snprintf(rp->smax, sizeof(rp->smax), "%3d.%06d",(int)rp->max.secs, (rp->max.nsecs+500)/1000);
                gtk_label_set_text(GTK_LABEL(rp->wmax), rp->smax);
 
-               g_snprintf(rp->savg, sizeof(rp->savg), "%3d.%05d",(int)td/100000,(int)td%100000);
+               g_snprintf(rp->savg, sizeof(rp->savg), "%3d.%06d",(int)(td/1000000),(int)(td%1000000));
                gtk_label_set_text(GTK_LABEL(rp->wavg), rp->savg);
 
        }
index 1d6c61a3eaa0fb9161771787500b3877d5a0855d..a794f8158bc6ab307a89c3a815377530dfefc03a 100644 (file)
@@ -39,6 +39,8 @@
 #include "gtk/filter_utils.h"
 #include "gtk/gui_utils.h"
 
+#define NANOSECS_PER_SEC 1000000000
+
 enum
 {
    INDEX_COLUMN,
@@ -190,7 +192,7 @@ srt_time_func (GtkTreeViewColumn *column _U_,
             g_object_set(renderer, "text", "", NULL);
             return;
         }
-        str = g_strdup_printf("%3d.%05d", (int)data->secs, data->nsecs/10000);
+        str = g_strdup_printf("%3d.%06d", (int)data->secs, (data->nsecs+500)/1000);
         g_object_set(renderer, "text", str, NULL);
         g_free(str);
 }
@@ -207,8 +209,8 @@ srt_avg_func (GtkTreeViewColumn *column _U_,
      gint data_column = GPOINTER_TO_INT(user_data);
 
      gtk_tree_model_get(model, iter, data_column, &td, -1);
-     str=g_strdup_printf("%3" G_GINT64_MODIFIER "d.%05" G_GINT64_MODIFIER "d",
-                   td/100000, td%100000);
+     str=g_strdup_printf("%3d.%06d",
+                   (int)(td/1000000), (int)(td%1000000));
         g_object_set(renderer, "text", str, NULL);
         g_free(str);
 }
@@ -412,12 +414,14 @@ draw_srt_table_data(srt_stat_table *rst)
                if(rst->procedures[i].stats.num==0){
                        continue;
                }
+               /* Scale the average SRT in units of 1us and round to the nearest us.
+                  tot.secs is a time_t which may be 32 or 64 bits (or even floating)
+                   depending uon the platform.  After casting tot.secs to 64 bits, it
+                   would take a capture with a duration of over 136 *years* to 
+                   overflow the secs portion of td. */
+               td = ((guint64)(rst->procedures[i].stats.tot.secs))*NANOSECS_PER_SEC + rst->procedures[i].stats.tot.nsecs;
+               td = ((td / rst->procedures[i].stats.num) + 500) / 1000;
 
-               /* scale it to units of 10us.*/
-               /* for long captures with a large tot time, this can overflow on 32bit */
-               td=(int)rst->procedures[i].stats.tot.secs;
-               td=td*100000+(int)rst->procedures[i].stats.tot.nsecs/10000;
-               td/=rst->procedures[i].stats.num;
                gtk_list_store_set(store, &rst->procedures[i].iter,
                                   CALLS_COLUMN,     rst->procedures[i].stats.num,
                                   MIN_SRT_COLUMN,   &rst->procedures[i].stats.min,