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 * SPDX-License-Identifier: GPL-2.0-or-later
14 #include "timestats.h"
16 /* Initialize a timestat_t struct */
18 time_stat_init(timestat_t *stats)
23 nstime_set_zero(&stats->min);
24 nstime_set_zero(&stats->max);
25 nstime_set_zero(&stats->tot);
26 stats->variance = 0.0;
29 /* Update a timestat_t struct with a new sample */
31 time_stat_update(timestat_t *stats, const nstime_t *delta, packet_info *pinfo)
35 stats->max_num=pinfo->num;
37 stats->min_num=pinfo->num;
40 if( (delta->secs<stats->min.secs)
41 ||( (delta->secs==stats->min.secs)
42 &&(delta->nsecs<stats->min.nsecs) ) ){
44 stats->min_num=pinfo->num;
47 if( (delta->secs>stats->max.secs)
48 ||( (delta->secs==stats->max.secs)
49 &&(delta->nsecs>stats->max.nsecs) ) ){
51 stats->max_num=pinfo->num;
54 nstime_add(&stats->tot, delta);
60 * get_average - function
62 * function to calculate the average
63 * returns the average as a gdouble , time base is milli seconds
66 gdouble get_average(const nstime_t *sum, guint32 num)
71 average = (double)sum->secs*1000 + (double)sum->nsecs/1000000;
81 * Editor modelines - http://www.wireshark.org/tools/modelines.html
89 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
90 * :indentSize=8:tabSize=8:noTabs=false: