2 * routines for time statistics
3 * Copyright 2003 Lars Roland
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include "timestats.h"
28 /* Initialize a timestat_t struct */
30 time_stat_init(timestat_t *stats)
35 nstime_set_zero(&stats->min);
36 nstime_set_zero(&stats->max);
37 nstime_set_zero(&stats->tot);
38 stats->variance = 0.0;
41 /* Update a timestat_t struct with a new sample */
43 time_stat_update(timestat_t *stats, const nstime_t *delta, packet_info *pinfo)
47 stats->max_num=pinfo->num;
49 stats->min_num=pinfo->num;
52 if( (delta->secs<stats->min.secs)
53 ||( (delta->secs==stats->min.secs)
54 &&(delta->nsecs<stats->min.nsecs) ) ){
56 stats->min_num=pinfo->num;
59 if( (delta->secs>stats->max.secs)
60 ||( (delta->secs==stats->max.secs)
61 &&(delta->nsecs>stats->max.nsecs) ) ){
63 stats->max_num=pinfo->num;
66 nstime_add(&stats->tot, delta);
72 * get_average - function
74 * function to calculate the average
75 * returns the average as a gdouble , time base is milli seconds
78 gdouble get_average(const nstime_t *sum, guint32 num)
83 average = (double)sum->secs*1000 + (double)sum->nsecs/1000000;
93 * Editor modelines - http://www.wireshark.org/tools/modelines.html
101 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
102 * :indentSize=8:tabSize=8:noTabs=false: