diff options
author | Guy Harris <guy@alum.mit.edu> | 2005-08-22 07:12:20 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2005-08-22 07:12:20 +0000 |
commit | 86ea8b88f3b721e1001f898ed05d8ba5f1ecf20e (patch) | |
tree | df3523ea31c067e87cc28e452eaa70b33a565774 /timestats.c | |
parent | 6d52a0369a6d155b62433fc60230f574ad98492f (diff) |
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
Diffstat (limited to 'timestats.c')
-rw-r--r-- | timestats.c | 42 |
1 files changed, 16 insertions, 26 deletions
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->secs<stats->min.secs) ||( (delta->secs==stats->min.secs) &&(delta->nsecs<stats->min.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++; } |