sq epan/dissectors/pidl/rcg/rcg.cnf
[wireshark-sm.git] / epan / timestats.c
blob69ed5f342c362b2270d10d908732c1cb40a9b81c
1 /* timestats.c
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
12 #include "config.h"
14 #include "timestats.h"
16 /* Initialize a timestat_t struct */
17 void
18 time_stat_init(timestat_t *stats)
20 stats->num = 0;
21 stats->min_num = 0;
22 stats->max_num = 0;
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 */
30 void
31 time_stat_update(timestat_t *stats, const nstime_t *delta, packet_info *pinfo)
33 if(stats->num==0){
34 stats->max=*delta;
35 stats->max_num=pinfo->num;
36 stats->min=*delta;
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) ) ){
43 stats->min=*delta;
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) ) ){
50 stats->max=*delta;
51 stats->max_num=pinfo->num;
54 nstime_add(&stats->tot, delta);
56 stats->num++;
60 * get_average - function
62 * function to calculate the average
63 * returns the average as a double , time base is milli seconds
66 double get_average(const nstime_t *sum, uint32_t num)
68 double average;
70 if(num > 0) {
71 average = (double)sum->secs*1000 + (double)sum->nsecs/1000000;
72 average /= num;
74 else {
75 average = 0;
77 return average;
81 * Editor modelines - https://www.wireshark.org/tools/modelines.html
83 * Local variables:
84 * c-basic-offset: 8
85 * tab-width: 8
86 * indent-tabs-mode: t
87 * End:
89 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
90 * :indentSize=8:tabSize=8:noTabs=false: