From 86ea8b88f3b721e1001f898ed05d8ba5f1ecf20e Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Mon, 22 Aug 2005 07:12:20 +0000 Subject: [PATCH] Add a "time_stat_init()" routine to initialize the fields of a "timestat_t". Move "nstime_to_msec()" to "epan/nstime.c", as it has nothing to do with a "timestat_t". Use structure assignment when possible. Fix the "addtime()" macro and use it in "time_stat_update()". Use "timestat_t"s, and the routines to manipulate them, in the service response time table code. svn path=/trunk/; revision=15509 --- epan/libethereal.def | 1 + epan/nstime.c | 11 ++++ epan/nstime.h | 5 +- gtk/service_response_time_table.c | 91 +++++++++++-------------------- gtk/service_response_time_table.h | 6 +- timestats.c | 42 ++++++-------- timestats.h | 6 +- 7 files changed, 70 insertions(+), 92 deletions(-) diff --git a/epan/libethereal.def b/epan/libethereal.def index 4ecb0deb24..6221d736e3 100644 --- a/epan/libethereal.def +++ b/epan/libethereal.def @@ -351,6 +351,7 @@ mtp3_addr_to_str_buf mtp3_service_indicator_code_short_vals DATA new_create_dissector_handle new_register_dissector +nstime_to_msec nt_cmd_vals DATA num_tap_filters DATA num_tree_types DATA diff --git a/epan/nstime.c b/epan/nstime.c index 6944329794..b5089bb97c 100644 --- a/epan/nstime.c +++ b/epan/nstime.c @@ -90,3 +90,14 @@ void get_timesum(nstime_t *sum, const nstime_t *a, const nstime_t *b) sum->secs--; } } + +/* + * function: nstime_to_msec + * converts nstime to double, time base is milli seconds + */ + +double nstime_to_msec(const nstime_t *time) +{ + return ((double)time->secs*1000 + (double)time->nsecs/1000000); +} + diff --git a/epan/nstime.h b/epan/nstime.h index af6a8c7e10..25c10d6bef 100644 --- a/epan/nstime.h +++ b/epan/nstime.h @@ -53,6 +53,9 @@ extern void get_timedelta(nstime_t *delta, const nstime_t *b, const nstime_t *a extern void get_timesum(nstime_t *sum, const nstime_t *b, const nstime_t *a ); /* sum += a */ -#define addtime(sum, a) get_timesum(sum, sum, b) +#define addtime(sum, a) get_timesum(sum, sum, a) + +/* converts nstime to double, time base is milli seconds*/ +extern double nstime_to_msec(const nstime_t *time); #endif /* __NSTIME_H__ */ diff --git a/gtk/service_response_time_table.c b/gtk/service_response_time_table.c index f81a7aebdc..1f7abb8cec 100644 --- a/gtk/service_response_time_table.c +++ b/gtk/service_response_time_table.c @@ -408,13 +408,13 @@ init_srt_table(srt_stat_table *rst, int num_procs, GtkWidget *vbox, const char * rst->num_procs=num_procs; rst->procedures=g_malloc(sizeof(srt_procedure_t)*num_procs); for(i=0;iprocedures[i].num=0; - rst->procedures[i].min.secs=0; - rst->procedures[i].min.nsecs=0; - rst->procedures[i].max.secs=0; - rst->procedures[i].max.nsecs=0; - rst->procedures[i].tot.secs=0; - rst->procedures[i].tot.nsecs=0; + rst->procedures[i].stats.num=0; + rst->procedures[i].stats.min.secs=0; + rst->procedures[i].stats.min.nsecs=0; + rst->procedures[i].stats.max.secs=0; + rst->procedures[i].stats.max.nsecs=0; + rst->procedures[i].stats.tot.secs=0; + rst->procedures[i].stats.tot.nsecs=0; for(j=0;j<6;j++){ rst->procedures[i].entries[j]=NULL; } @@ -436,13 +436,13 @@ init_srt_table_row(srt_stat_table *rst, int index, const char *procedure) rst->num_procs=index+1; rst->procedures=g_realloc(rst->procedures, sizeof(srt_procedure_t)*(rst->num_procs)); for(i=old_num_procs;inum_procs;i++){ - rst->procedures[i].num=0; - rst->procedures[i].min.secs=0; - rst->procedures[i].min.nsecs=0; - rst->procedures[i].max.secs=0; - rst->procedures[i].max.nsecs=0; - rst->procedures[i].tot.secs=0; - rst->procedures[i].tot.nsecs=0; + rst->procedures[i].stats.num=0; + rst->procedures[i].stats.min.secs=0; + rst->procedures[i].stats.min.nsecs=0; + rst->procedures[i].stats.max.secs=0; + rst->procedures[i].stats.max.nsecs=0; + rst->procedures[i].stats.tot.secs=0; + rst->procedures[i].stats.tot.nsecs=0; for(j=0;j<6;j++){ rst->procedures[i].entries[j]=NULL; } @@ -467,33 +467,6 @@ add_srt_table_data(srt_stat_table *rst, int index, const nstime_t *req_time, pac rp=&rst->procedures[index]; - /* calculate time delta between request and reply */ - t.secs=pinfo->fd->abs_secs; - t.nsecs=pinfo->fd->abs_usecs*1000; - get_timedelta(&delta, &t, req_time); - - if(rp->num==0){ - rp->max=delta; - } - - if(rp->num==0){ - rp->min=delta; - } - - if( (delta.secsmin.secs) - ||( (delta.secs==rp->min.secs) - &&(delta.nsecsmin.nsecs) ) ){ - rp->min=delta; - } - - if( (delta.secs>rp->max.secs) - ||( (delta.secs==rp->max.secs) - &&(delta.nsecs>rp->max.nsecs) ) ){ - rp->max=delta; - } - - get_timesum(&rp->tot, &rp->tot, &delta); - /* * If the count of calls for this procedure is currently zero, it's * going to become non-zero, so add a row for it (we don't want @@ -504,11 +477,17 @@ add_srt_table_data(srt_stat_table *rst, int index, const nstime_t *req_time, pac * (Yes, this means that the rows aren't in order by anything * interesting. That's why we have the table sorted by a column.) */ - if (rp->num==0){ + if (rp->stats.num==0){ row=gtk_clist_append(rst->table, rst->procedures[index].entries); gtk_clist_set_row_data(rst->table, row, (gpointer) index); } - rp->num++; + + /* calculate time delta between request and reply */ + t.secs=pinfo->fd->abs_secs; + t.nsecs=pinfo->fd->abs_usecs*1000; + get_timedelta(&delta, &t, req_time); + + time_stat_update(&rp->stats, &delta, pinfo); } void @@ -520,34 +499,34 @@ draw_srt_table_data(srt_stat_table *rst) for(i=0;inum_procs;i++){ /* ignore procedures with no calls (they don't have CList rows) */ - if(rst->procedures[i].num==0){ + if(rst->procedures[i].stats.num==0){ continue; } /* scale it to units of 10us.*/ /* for long captures with a large tot time, this can overflow on 32bit */ - td=(int)rst->procedures[i].tot.secs; - td=td*100000+(int)rst->procedures[i].tot.nsecs/10000; - td/=rst->procedures[i].num; + 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; j=gtk_clist_find_row_from_data(rst->table, (gpointer)i); - strp=g_strdup_printf("%d", rst->procedures[i].num); + strp=g_strdup_printf("%d", rst->procedures[i].stats.num); gtk_clist_set_text(rst->table, j, 2, strp); g_free(rst->procedures[i].entries[2]); rst->procedures[i].entries[2]=strp; strp=g_strdup_printf("%3d.%05d", - (int)rst->procedures[i].min.secs, - rst->procedures[i].min.nsecs/10000); + (int)rst->procedures[i].stats.min.secs, + rst->procedures[i].stats.min.nsecs/10000); gtk_clist_set_text(rst->table, j, 3, strp); g_free(rst->procedures[i].entries[3]); rst->procedures[i].entries[3]=strp; strp=g_strdup_printf("%3d.%05d", - (int)rst->procedures[i].max.secs, - rst->procedures[i].max.nsecs/10000); + (int)rst->procedures[i].stats.max.secs, + rst->procedures[i].stats.max.nsecs/10000); gtk_clist_set_text(rst->table, j, 4, strp); g_free(rst->procedures[i].entries[4]); rst->procedures[i].entries[4]=strp; @@ -569,13 +548,7 @@ reset_srt_table_data(srt_stat_table *rst) int i; for(i=0;inum_procs;i++){ - rst->procedures[i].num=0; - rst->procedures[i].min.secs=0; - rst->procedures[i].min.nsecs=0; - rst->procedures[i].max.secs=0; - rst->procedures[i].max.nsecs=0; - rst->procedures[i].tot.secs=0; - rst->procedures[i].tot.nsecs=0; + time_stat_init(&rst->procedures[i].stats); } } diff --git a/gtk/service_response_time_table.h b/gtk/service_response_time_table.h index ed15620ba5..c62afa2b5e 100644 --- a/gtk/service_response_time_table.h +++ b/gtk/service_response_time_table.h @@ -26,6 +26,7 @@ #include #include "epan/nstime.h" +#include "../timestats.h" /** @file * Helper routines common to all service response time statistics tap. @@ -34,10 +35,7 @@ /** Procedure data */ typedef struct _srt_procedure_t { char *entries[6]; /**< column entries */ - int num; /**< number of calls seen */ - nstime_t min; /**< minimum srt */ - nstime_t max; /**< maximum srt */ - nstime_t tot; /**< average srt */ + timestat_t stats; /**< stats */ } srt_procedure_t; /** Statistics table */ diff --git a/timestats.c b/timestats.c index 18c1c6f58b..ed5cd5a86f 100644 --- a/timestats.c +++ b/timestats.c @@ -25,55 +25,45 @@ #include "timestats.h" -/* - * function: nstime_to_msec - * converts nstime to gdouble, time base is milli seconds - */ - -gdouble nstime_to_msec(const nstime_t *time) +/* Initialize a timestat_t struct */ +void +time_stat_init(timestat_t *stats) { - return ((double)time->secs*1000 + (double)time->nsecs/1000000); + stats->num = 0; + stats->min.secs = 0; + stats->min.nsecs = 0; + stats->max.secs = 0; + stats->max.nsecs = 0; + stats->tot.secs = 0; + stats->tot.nsecs = 0; } -/* A Function to update a timestat_t struct with a new sample*/ - +/* Update a timestat_t struct with a new sample */ void time_stat_update(timestat_t *stats, const nstime_t *delta, packet_info *pinfo) { if(stats->num==0){ - stats->max.secs=delta->secs; - stats->max.nsecs=delta->nsecs; + stats->max=*delta; stats->max_num=pinfo->fd->num; - } - - if(stats->num==0){ - stats->min.secs=delta->secs; - stats->min.nsecs=delta->nsecs; + stats->min=*delta; stats->min_num=pinfo->fd->num; } if( (delta->secsmin.secs) ||( (delta->secs==stats->min.secs) &&(delta->nsecsmin.nsecs) ) ){ - stats->min.secs=delta->secs; - stats->min.nsecs=delta->nsecs; + stats->min=*delta; stats->min_num=pinfo->fd->num; } if( (delta->secs>stats->max.secs) ||( (delta->secs==stats->max.secs) &&(delta->nsecs>stats->max.nsecs) ) ){ - stats->max.secs=delta->secs; - stats->max.nsecs=delta->nsecs; + stats->max=*delta; stats->max_num=pinfo->fd->num; } - stats->tot.secs += delta->secs; - stats->tot.nsecs += delta->nsecs; - if(stats->tot.nsecs>1000000000){ - stats->tot.nsecs-=1000000000; - stats->tot.secs++; - } + addtime(&stats->tot, delta); stats->num++; } diff --git a/timestats.h b/timestats.h index 4a6417f6ba..90fbd61883 100644 --- a/timestats.h +++ b/timestats.h @@ -43,10 +43,12 @@ typedef struct _timestat_t { /* functions */ -/* converts nstime to gdouble, time base is milli seconds*/ -extern gdouble nstime_to_msec(const nstime_t *time); +/* Initialize a timestat_t struct */ +extern void time_stat_init(timestat_t *stats); +/* Update a timestat_t struct with a new sample */ extern void time_stat_update(timestat_t *stats, const nstime_t *delta, packet_info *pinfo); + extern gdouble get_average(const nstime_t *sum, guint32 num); #endif