From a441793cba1e5cb7567e08990e82bfb94f6764df Mon Sep 17 00:00:00 2001 From: Jeff Morriss Date: Tue, 25 Jun 2013 22:02:20 +0000 Subject: Move a couple of time-related modules into wsutil. A bunch of files didn't really need to include these header files so remove the include line rather than changing it. svn path=/trunk/; revision=50154 --- CMakeLists.txt | 1 - Makefile.common | 3 - asn1/cmp/packet-cmp-template.c | 1 - asn1/goose/packet-goose-template.c | 1 - asn1/mms/packet-mms-template.c | 1 - asn1/sv/packet-sv-template.c | 1 - editcap.c | 2 +- epan/CMakeLists.txt | 1 - epan/Makefile.common | 2 - epan/column.c | 1 - epan/dissectors/packet-cmp.c | 13 ++- epan/dissectors/packet-goose.c | 11 +- epan/dissectors/packet-iscsi.c | 1 - epan/dissectors/packet-mms.c | 11 +- epan/dissectors/packet-sv.c | 11 +- epan/frame_data.h | 2 +- epan/ftypes/ftypes.h | 2 +- epan/nstime.c | 202 ----------------------------------- epan/nstime.h | 115 -------------------- epan/proto.h | 2 +- epan/to_str.h | 2 +- epan/wslua/init_wslua.c | 1 - epan/wslua/wslua.h | 2 +- tap-megaco-common.c | 2 +- timestats.c | 92 ---------------- timestats.h | 54 ---------- ui/cli/tap-afpstat.c | 2 +- ui/cli/tap-camelsrt.c | 2 +- ui/cli/tap-comparestat.c | 2 +- ui/cli/tap-diameter-avp.c | 1 - ui/cli/tap-funnel.c | 1 - ui/cli/tap-h225rassrt.c | 2 +- ui/cli/tap-megacostat.c | 2 +- ui/cli/tap-mgcpstat.c | 2 +- ui/cli/tap-radiusstat.c | 2 +- ui/cli/tap-smbstat.c | 2 +- ui/cli/tap-sv.c | 1 - ui/gtk/afp_stat.c | 1 - ui/gtk/camel_counter.c | 1 - ui/gtk/camel_srt.c | 1 - ui/gtk/compare_stat.c | 3 +- ui/gtk/conversations_table.c | 1 - ui/gtk/diameter_stat.c | 1 - ui/gtk/fc_stat.c | 1 - ui/gtk/filter_expression_save_dlg.c | 1 - ui/gtk/funnel_stat.c | 1 - ui/gtk/gtp_stat.c | 1 - ui/gtk/h225_ras_srt.c | 2 +- ui/gtk/ldap_stat.c | 1 - ui/gtk/megaco_stat.c | 2 +- ui/gtk/mgcp_stat.c | 2 +- ui/gtk/ncp_stat.c | 1 - ui/gtk/packet_list_store.c | 1 - ui/gtk/radius_stat.c | 2 +- ui/gtk/service_response_time_table.h | 4 +- ui/gtk/smb2_stat.c | 1 - ui/gtk/smb_stat.c | 1 - ui/qt/capture_file_dialog.cpp | 2 +- ui/qt/packet_list_model.cpp | 2 +- ui/time_shift.h | 2 +- wsutil/CMakeLists.txt | 2 + wsutil/Makefile.common | 4 + wsutil/nstime.c | 202 +++++++++++++++++++++++++++++++++++ wsutil/nstime.h | 115 ++++++++++++++++++++ wsutil/timestats.c | 92 ++++++++++++++++ wsutil/timestats.h | 54 ++++++++++ 66 files changed, 515 insertions(+), 545 deletions(-) delete mode 100644 epan/nstime.c delete mode 100644 epan/nstime.h delete mode 100644 timestats.c delete mode 100644 timestats.h create mode 100644 wsutil/nstime.c create mode 100644 wsutil/nstime.h create mode 100644 wsutil/timestats.c create mode 100644 wsutil/timestats.h diff --git a/CMakeLists.txt b/CMakeLists.txt index b1b0316005..42b22fc746 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -659,7 +659,6 @@ set(WIRESHARK_COMMON_SRC ps.c svnversion.h sync_pipe_write.c - timestats.c tap-megaco-common.c tap-rtp-common.c version_info.c diff --git a/Makefile.common b/Makefile.common index 635e8c4ff0..6e3b3572c6 100644 --- a/Makefile.common +++ b/Makefile.common @@ -56,7 +56,6 @@ SHARK_COMMON_SRC = \ print.c \ ps.c \ sync_pipe_write.c \ - timestats.c \ tap-megaco-common.c \ tap-rtp-common.c \ version_info.c @@ -81,7 +80,6 @@ SHARK_COMMON_INCLUDES = \ ps.h \ register.h \ tempfile.h \ - timestats.h \ tap-megaco-common.h \ tap-rtp-common.h \ version_info.h \ @@ -176,7 +174,6 @@ mergecap_SOURCES = \ editcap_SOURCES = \ editcap.c \ epan/crypt/md5.c \ - epan/nstime.c \ $(WTAP_PLUGIN_SOURCES) # reordercap specifics diff --git a/asn1/cmp/packet-cmp-template.c b/asn1/cmp/packet-cmp-template.c index 857290b7d8..2281da2298 100644 --- a/asn1/cmp/packet-cmp-template.c +++ b/asn1/cmp/packet-cmp-template.c @@ -41,7 +41,6 @@ #include "packet-tcp.h" #include "packet-http.h" #include -#include #define PNAME "Certificate Management Protocol" #define PSNAME "CMP" diff --git a/asn1/goose/packet-goose-template.c b/asn1/goose/packet-goose-template.c index 0577d5f6ab..c65a9b1d9f 100644 --- a/asn1/goose/packet-goose-template.c +++ b/asn1/goose/packet-goose-template.c @@ -30,7 +30,6 @@ #include #include #include -#include #include "packet-ber.h" #include "packet-acse.h" diff --git a/asn1/mms/packet-mms-template.c b/asn1/mms/packet-mms-template.c index 64753b2718..421cf8dcbb 100644 --- a/asn1/mms/packet-mms-template.c +++ b/asn1/mms/packet-mms-template.c @@ -30,7 +30,6 @@ #include #include #include -#include #include "packet-ber.h" #include "packet-acse.h" diff --git a/asn1/sv/packet-sv-template.c b/asn1/sv/packet-sv-template.c index 5ad3a71e9f..e225eadfbe 100644 --- a/asn1/sv/packet-sv-template.c +++ b/asn1/sv/packet-sv-template.c @@ -30,7 +30,6 @@ #include #include #include -#include #include #include diff --git a/editcap.c b/editcap.c index 3332d5df6a..a0a4dfc227 100644 --- a/editcap.c +++ b/editcap.c @@ -89,7 +89,7 @@ #include "epan/plugins.h" #include "epan/report_err.h" #include "epan/filesystem.h" -#include "epan/nstime.h" +#include "wsutil/nstime.h" #undef WS_BUILD_DLL #define RESET_SYMBOL_EXPORT diff --git a/epan/CMakeLists.txt b/epan/CMakeLists.txt index 7eacdf14f0..b11ceaf361 100644 --- a/epan/CMakeLists.txt +++ b/epan/CMakeLists.txt @@ -1448,7 +1448,6 @@ set(LIBWIRESHARK_FILES ipproto.c ipv4.c next_tvb.c - nstime.c oids.c osi-utils.c packet.c diff --git a/epan/Makefile.common b/epan/Makefile.common index c2f797f561..473b870e49 100644 --- a/epan/Makefile.common +++ b/epan/Makefile.common @@ -65,7 +65,6 @@ LIBWIRESHARK_SRC = \ ipproto.c \ ipv4.c \ next_tvb.c \ - nstime.c \ oids.c \ osi-utils.c \ packet.c \ @@ -203,7 +202,6 @@ LIBWIRESHARK_INCLUDES = \ llcsaps.h \ next_tvb.h \ nlpid.h \ - nstime.h \ oids.h \ osi-utils.h \ oui.h \ diff --git a/epan/column.c b/epan/column.c index 231f1c5459..e25252b54c 100644 --- a/epan/column.c +++ b/epan/column.c @@ -35,7 +35,6 @@ #include #include -#include #include #include #include diff --git a/epan/dissectors/packet-cmp.c b/epan/dissectors/packet-cmp.c index 99770656ba..b5823b443a 100644 --- a/epan/dissectors/packet-cmp.c +++ b/epan/dissectors/packet-cmp.c @@ -49,7 +49,6 @@ #include "packet-tcp.h" #include "packet-http.h" #include -#include #define PNAME "Certificate Management Protocol" #define PSNAME "CMP" @@ -237,7 +236,7 @@ static int hf_cmp_PKIFailureInfo_systemFailure = -1; static int hf_cmp_PKIFailureInfo_duplicateCertReq = -1; /*--- End of included file: packet-cmp-hf.c ---*/ -#line 70 "../../asn1/cmp/packet-cmp-template.c" +#line 69 "../../asn1/cmp/packet-cmp-template.c" /* Initialize the subtree pointers */ static gint ett_cmp = -1; @@ -293,7 +292,7 @@ static gint ett_cmp_PollRepContent = -1; static gint ett_cmp_PollRepContent_item = -1; /*--- End of included file: packet-cmp-ett.c ---*/ -#line 74 "../../asn1/cmp/packet-cmp-template.c" +#line 73 "../../asn1/cmp/packet-cmp-template.c" /*--- Included file: packet-cmp-fn.c ---*/ #line 1 "../../asn1/cmp/packet-cmp-fn.c" @@ -1453,7 +1452,7 @@ static void dissect_SuppLangTagsValue_PDU(tvbuff_t *tvb _U_, packet_info *pinfo /*--- End of included file: packet-cmp-fn.c ---*/ -#line 75 "../../asn1/cmp/packet-cmp-template.c" +#line 74 "../../asn1/cmp/packet-cmp-template.c" static int dissect_cmp_pdu(tvbuff_t *tvb, proto_tree *tree, asn1_ctx_t *actx) @@ -2343,7 +2342,7 @@ void proto_register_cmp(void) { NULL, HFILL }}, /*--- End of included file: packet-cmp-hfarr.c ---*/ -#line 332 "../../asn1/cmp/packet-cmp-template.c" +#line 331 "../../asn1/cmp/packet-cmp-template.c" }; /* List of subtrees */ @@ -2401,7 +2400,7 @@ void proto_register_cmp(void) { &ett_cmp_PollRepContent_item, /*--- End of included file: packet-cmp-ettarr.c ---*/ -#line 338 "../../asn1/cmp/packet-cmp-template.c" +#line 337 "../../asn1/cmp/packet-cmp-template.c" }; module_t *cmp_module; @@ -2495,7 +2494,7 @@ void proto_reg_handoff_cmp(void) { /*--- End of included file: packet-cmp-dis-tab.c ---*/ -#line 410 "../../asn1/cmp/packet-cmp-template.c" +#line 409 "../../asn1/cmp/packet-cmp-template.c" inited = TRUE; } diff --git a/epan/dissectors/packet-goose.c b/epan/dissectors/packet-goose.c index a17e644ce3..7cd1c67eda 100644 --- a/epan/dissectors/packet-goose.c +++ b/epan/dissectors/packet-goose.c @@ -38,7 +38,6 @@ #include #include #include -#include #include "packet-ber.h" #include "packet-acse.h" @@ -120,7 +119,7 @@ static int hf_goose_mMSString = -1; /* MMSString */ static int hf_goose_utc_time = -1; /* UtcTime */ /*--- End of included file: packet-goose-hf.c ---*/ -#line 52 "../../asn1/goose/packet-goose-template.c" +#line 51 "../../asn1/goose/packet-goose-template.c" /* Initialize the subtree pointers */ static int ett_goose = -1; @@ -147,7 +146,7 @@ static gint ett_goose_SEQUENCE_OF_Data = -1; static gint ett_goose_Data = -1; /*--- End of included file: packet-goose-ett.c ---*/ -#line 57 "../../asn1/goose/packet-goose-template.c" +#line 56 "../../asn1/goose/packet-goose-template.c" /*--- Included file: packet-goose-fn.c ---*/ @@ -715,7 +714,7 @@ dissect_goose_GOOSEpdu(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset /*--- End of included file: packet-goose-fn.c ---*/ -#line 59 "../../asn1/goose/packet-goose-template.c" +#line 58 "../../asn1/goose/packet-goose-template.c" /* * Dissect GOOSE PDUs inside a PPDU. @@ -1024,7 +1023,7 @@ void proto_register_goose(void) { "UtcTime", HFILL }}, /*--- End of included file: packet-goose-hfarr.c ---*/ -#line 127 "../../asn1/goose/packet-goose-template.c" +#line 126 "../../asn1/goose/packet-goose-template.c" }; /* List of subtrees */ @@ -1052,7 +1051,7 @@ void proto_register_goose(void) { &ett_goose_Data, /*--- End of included file: packet-goose-ettarr.c ---*/ -#line 133 "../../asn1/goose/packet-goose-template.c" +#line 132 "../../asn1/goose/packet-goose-template.c" }; static ei_register_info ei[] = { diff --git a/epan/dissectors/packet-iscsi.c b/epan/dissectors/packet-iscsi.c index 5c01507896..c38b9432e0 100644 --- a/epan/dissectors/packet-iscsi.c +++ b/epan/dissectors/packet-iscsi.c @@ -44,7 +44,6 @@ #include #include #include "packet-scsi.h" -#include #include #include #include diff --git a/epan/dissectors/packet-mms.c b/epan/dissectors/packet-mms.c index 97e12b6332..df18a337be 100644 --- a/epan/dissectors/packet-mms.c +++ b/epan/dissectors/packet-mms.c @@ -38,7 +38,6 @@ #include #include #include -#include #include "packet-ber.h" #include "packet-acse.h" @@ -723,7 +722,7 @@ static int hf_mms_Transitions_idle_to_active = -1; static int hf_mms_Transitions_any_to_deleted = -1; /*--- End of included file: packet-mms-hf.c ---*/ -#line 47 "../../asn1/mms/packet-mms-template.c" +#line 46 "../../asn1/mms/packet-mms-template.c" /* Initialize the subtree pointers */ static gint ett_mms = -1; @@ -940,7 +939,7 @@ static gint ett_mms_DirectoryEntry = -1; static gint ett_mms_FileAttributes = -1; /*--- End of included file: packet-mms-ett.c ---*/ -#line 51 "../../asn1/mms/packet-mms-template.c" +#line 50 "../../asn1/mms/packet-mms-template.c" static expert_field ei_mms_mal_timeofday_encoding = EI_INIT; static expert_field ei_mms_mal_utctime_encoding = EI_INIT; @@ -7053,7 +7052,7 @@ dissect_mms_MMSpdu(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, /*--- End of included file: packet-mms-fn.c ---*/ -#line 56 "../../asn1/mms/packet-mms-template.c" +#line 55 "../../asn1/mms/packet-mms-template.c" /* * Dissect MMS PDUs inside a PPDU. @@ -9761,7 +9760,7 @@ void proto_register_mms(void) { NULL, HFILL }}, /*--- End of included file: packet-mms-hfarr.c ---*/ -#line 95 "../../asn1/mms/packet-mms-template.c" +#line 94 "../../asn1/mms/packet-mms-template.c" }; /* List of subtrees */ @@ -9980,7 +9979,7 @@ void proto_register_mms(void) { &ett_mms_FileAttributes, /*--- End of included file: packet-mms-ettarr.c ---*/ -#line 101 "../../asn1/mms/packet-mms-template.c" +#line 100 "../../asn1/mms/packet-mms-template.c" }; static ei_register_info ei[] = { diff --git a/epan/dissectors/packet-sv.c b/epan/dissectors/packet-sv.c index d25e4d00b9..41428bbcee 100644 --- a/epan/dissectors/packet-sv.c +++ b/epan/dissectors/packet-sv.c @@ -38,7 +38,6 @@ #include #include #include -#include #include #include @@ -127,7 +126,7 @@ static int hf_sv_seqData = -1; /* Data */ static int hf_sv_smpMod = -1; /* T_smpMod */ /*--- End of included file: packet-sv-hf.c ---*/ -#line 105 "../../asn1/sv/packet-sv-template.c" +#line 104 "../../asn1/sv/packet-sv-template.c" /* Initialize the subtree pointers */ static int ett_sv = -1; @@ -143,7 +142,7 @@ static gint ett_sv_SEQUENCE_OF_ASDU = -1; static gint ett_sv_ASDU = -1; /*--- End of included file: packet-sv-ett.c ---*/ -#line 112 "../../asn1/sv/packet-sv-template.c" +#line 111 "../../asn1/sv/packet-sv-template.c" static expert_field ei_sv_mal_utctime = EI_INIT; @@ -450,7 +449,7 @@ dissect_sv_SampledValues(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offse /*--- End of included file: packet-sv-fn.c ---*/ -#line 195 "../../asn1/sv/packet-sv-template.c" +#line 194 "../../asn1/sv/packet-sv-template.c" /* * Dissect SV PDUs inside a PPDU. @@ -624,7 +623,7 @@ void proto_register_sv(void) { NULL, HFILL }}, /*--- End of included file: packet-sv-hfarr.c ---*/ -#line 312 "../../asn1/sv/packet-sv-template.c" +#line 311 "../../asn1/sv/packet-sv-template.c" }; /* List of subtrees */ @@ -641,7 +640,7 @@ void proto_register_sv(void) { &ett_sv_ASDU, /*--- End of included file: packet-sv-ettarr.c ---*/ -#line 320 "../../asn1/sv/packet-sv-template.c" +#line 319 "../../asn1/sv/packet-sv-template.c" }; static ei_register_info ei[] = { diff --git a/epan/frame_data.h b/epan/frame_data.h index 050fa28c37..2efdb39ab4 100644 --- a/epan/frame_data.h +++ b/epan/frame_data.h @@ -27,7 +27,7 @@ #include #include -#include +#include #include "ws_symbol_export.h" #define PINFO_FD_NUM(pinfo) ((pinfo)->fd->num) diff --git a/epan/ftypes/ftypes.h b/epan/ftypes/ftypes.h index bdf969ba84..82bbe25097 100644 --- a/epan/ftypes/ftypes.h +++ b/epan/ftypes/ftypes.h @@ -165,7 +165,7 @@ ftype_can_matches(enum ftenum ftype); #include #include -#include +#include #include typedef struct _fvalue_t { diff --git a/epan/nstime.c b/epan/nstime.c deleted file mode 100644 index e88818856a..0000000000 --- a/epan/nstime.c +++ /dev/null @@ -1,202 +0,0 @@ -/* nstime.c - * Routines for manipulating nstime_t structures - * - * Copyright (c) 2005 MX Telecom Ltd. - * - * $Id$ - * - * Wireshark - Network traffic analyzer - * By Gerald Combs - * Copyright 1998 Gerald Combs - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - -#include -#include "nstime.h" - -/* this is #defined so that we can clearly see that we have the right number of - zeros, rather than as a guard against the number of nanoseconds in a second - changing ;) */ -#define NS_PER_S 1000000000 - -/* set the given nstime_t to zero */ -void nstime_set_zero(nstime_t *nstime) -{ - nstime->secs = 0; - nstime->nsecs = 0; -} - -/* is the given nstime_t currently zero? */ -gboolean nstime_is_zero(nstime_t *nstime) -{ - if(nstime->secs == 0 && nstime->nsecs == 0) { - return TRUE; - } else { - return FALSE; - } -} - -/* set the given nstime_t to (0,maxint) to mark it as "unset" - * That way we can find the first frame even when a timestamp - * is zero (fix for bug 1056) - */ -void nstime_set_unset(nstime_t *nstime) -{ - nstime->secs = 0; - nstime->nsecs = G_MAXINT; -} - -/* is the given nstime_t currently (0,maxint)? */ -gboolean nstime_is_unset(nstime_t *nstime) -{ - if(nstime->secs == 0 && nstime->nsecs == G_MAXINT) { - return TRUE; - } else { - return FALSE; - } -} - - -/** funcion: nstime_copy - * - * a = b - */ -void nstime_copy(nstime_t *a, const nstime_t *b) -{ - a->secs = b->secs; - a->nsecs = b->nsecs; -} - -/* - * function: nstime_delta - * delta = b - a - */ - -void nstime_delta(nstime_t *delta, const nstime_t *b, const nstime_t *a ) -{ - if (b->secs == a->secs) { - /* The seconds part of b is the same as the seconds part of a, so if - the nanoseconds part of the first time is less than the nanoseconds - part of a, b is before a. The nanoseconds part of the delta should - just be the difference between the nanoseconds part of b and the - nanoseconds part of a; don't adjust the seconds part of the delta, - as it's OK if the nanoseconds part is negative, and an overflow - can never result. */ - delta->secs = 0; - delta->nsecs = b->nsecs - a->nsecs; - } else if (b->secs <= a->secs) { - /* The seconds part of b is less than the seconds part of a, so b is - before a. - - Both the "seconds" and "nanoseconds" value of the delta - should have the same sign, so if the difference between the - nanoseconds values would be *positive*, subtract 1,000,000,000 - from it, and add one to the seconds value. */ - delta->secs = b->secs - a->secs; - delta->nsecs = b->nsecs - a->nsecs; - if(delta->nsecs > 0) { - delta->nsecs -= NS_PER_S; - delta->secs ++; - } - } else { - delta->secs = b->secs - a->secs; - delta->nsecs = b->nsecs - a->nsecs; - if(delta->nsecs < 0) { - delta->nsecs += NS_PER_S; - delta->secs --; - } - } -} - -/* - * function: nstime_sum - * sum = a + b - */ - -void nstime_sum(nstime_t *sum, const nstime_t *a, const nstime_t *b) -{ - sum->secs = a->secs + b->secs; - sum->nsecs = a->nsecs + b->nsecs; - if(sum->nsecs>=NS_PER_S || (sum->nsecs>0 && sum->secs<0)){ - sum->nsecs-=NS_PER_S; - sum->secs++; - } else if(sum->nsecs<=-NS_PER_S || (sum->nsecs<0 && sum->secs>0)) { - sum->nsecs+=NS_PER_S; - sum->secs--; - } -} - -/* - * function: nstime_cmp - * - * a > b : > 0 - * a = b : 0 - * a < b : < 0 - */ - -int nstime_cmp (const nstime_t *a, const nstime_t *b ) -{ - if (a->secs == b->secs) { - return a->nsecs - b->nsecs; - } else { - return (int) (a->secs - b->secs); - } -} - -/* - * function: nstime_to_msec - * converts nstime to double, time base is milli seconds - */ - -double nstime_to_msec(const nstime_t *nstime) -{ - return ((double)nstime->secs*1000 + (double)nstime->nsecs/1000000); -} - -/* - * function: nstime_to_sec - * converts nstime to double, time base is seconds - */ - -double nstime_to_sec(const nstime_t *nstime) -{ - return ((double)nstime->secs + (double)nstime->nsecs/1000000000); -} - -/* - * function: wtap_nstime_to_sec - * converts wtap_nstime to double, time base is seconds - */ - -double wtap_nstime_to_sec(const struct wtap_nstime *nstime) -{ - return ((double)nstime->secs + (double)nstime->nsecs/1000000000); -} - -/* - * Editor modelines - * - * Local Variables: - * c-basic-offset: 4 - * tab-width: 8 - * indent-tabs-mode: nil - * End: - * - * ex: set shiftwidth=4 tabstop=8 expandtab: - * :indentSize=4:tabSize=8:noTabs=true: - */ - diff --git a/epan/nstime.h b/epan/nstime.h deleted file mode 100644 index 01fd469b62..0000000000 --- a/epan/nstime.h +++ /dev/null @@ -1,115 +0,0 @@ -/* nstime.h - * Definition of data structure to hold time values with nanosecond resolution - * - * $Id$ - * - * Wireshark - Network traffic analyzer - * By Gerald Combs - * Copyright 1998 Gerald Combs - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef __NSTIME_H__ -#define __NSTIME_H__ - -#include - -#include -#include "ws_symbol_export.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/** @file - * Definition of data structure to hold time values with nanosecond resolution - */ - -/** data structure to hold time values with nanosecond resolution*/ -typedef struct { - time_t secs; - int nsecs; -} nstime_t; - -/* functions */ - -/** set the given nstime_t to zero */ -WS_DLL_PUBLIC void nstime_set_zero(nstime_t *nstime); - -/** is the given nstime_t currently zero? */ -WS_DLL_PUBLIC gboolean nstime_is_zero(nstime_t *nstime); - -/** set the given nstime_t to (0,maxint) to mark it as "unset" - * That way we can find the first frame even when a timestamp - * is zero (fix for bug 1056) - */ -WS_DLL_PUBLIC void nstime_set_unset(nstime_t *nstime); - -/* is the given nstime_t currently (0,maxint)? */ -WS_DLL_PUBLIC gboolean nstime_is_unset(nstime_t *nstime); - -/** duplicate the current time - * - * a = b - */ -WS_DLL_PUBLIC void nstime_copy(nstime_t *a, const nstime_t *b); - -/** calculate the delta between two times (can be negative!) - * - * delta = b-a - * - * Note that it is acceptable for two or more of the arguments to point at the - * same structure. - */ -WS_DLL_PUBLIC void nstime_delta(nstime_t *delta, const nstime_t *b, const nstime_t *a ); - -/** calculate the sum of two times - * - * sum = a+b - * - * Note that it is acceptable for two or more of the arguments to point at the - * same structure. - */ -WS_DLL_PUBLIC void nstime_sum(nstime_t *sum, const nstime_t *b, const nstime_t *a ); - -/** sum += a */ -#define nstime_add(sum, a) nstime_sum(sum, sum, a) - -/** sum -= a */ -#define nstime_subtract(sum, a) nstime_delta(sum, sum, a) - -/** compare two times are return a value similar to memcmp() or strcmp(). - * - * a > b : > 0 - * a = b : 0 - * a < b : < 0 - */ -WS_DLL_PUBLIC int nstime_cmp (const nstime_t *a, const nstime_t *b ); - -/** converts nstime to double, time base is milli seconds */ -WS_DLL_PUBLIC double nstime_to_msec(const nstime_t *nstime); - -/** converts nstime to double, time base is seconds */ -WS_DLL_PUBLIC double nstime_to_sec(const nstime_t *nstime); - -/** converts wtap_nstime to double, time base is seconds */ -WS_DLL_PUBLIC double wtap_nstime_to_sec(const struct wtap_nstime *nstime); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* __NSTIME_H__ */ diff --git a/epan/proto.h b/epan/proto.h index a05d43fe9d..e82747f9c8 100644 --- a/epan/proto.h +++ b/epan/proto.h @@ -46,7 +46,7 @@ #include #include "ipv4.h" -#include "nstime.h" +#include "wsutil/nstime.h" #include "time_fmt.h" #include "tvbuff.h" #include "ftypes/ftypes.h" diff --git a/epan/to_str.h b/epan/to_str.h index a353304a3d..3e2f137ab9 100644 --- a/epan/to_str.h +++ b/epan/to_str.h @@ -27,7 +27,7 @@ #include -#include "nstime.h" +#include "wsutil/nstime.h" #include "time_fmt.h" #include #include "ws_symbol_export.h" diff --git a/epan/wslua/init_wslua.c b/epan/wslua/init_wslua.c index ad23c1ecb0..577dab9fe5 100644 --- a/epan/wslua/init_wslua.c +++ b/epan/wslua/init_wslua.c @@ -30,7 +30,6 @@ #include "wslua.h" #include -#include #include #include #include diff --git a/epan/wslua/wslua.h b/epan/wslua/wslua.h index eaf93b9adb..d761c4830a 100644 --- a/epan/wslua/wslua.h +++ b/epan/wslua/wslua.h @@ -51,7 +51,7 @@ #include #include #include -#include +#include #include "declare_wslua.h" diff --git a/tap-megaco-common.c b/tap-megaco-common.c index f2688bbc5e..d4a033a0d4 100644 --- a/tap-megaco-common.c +++ b/tap-megaco-common.c @@ -35,7 +35,7 @@ #include #include "epan/gcp.h" -#include "../timestats.h" +#include "wsutil/timestats.h" #include "../file.h" #include "../globals.h" #include "../stat_menu.h" diff --git a/timestats.c b/timestats.c deleted file mode 100644 index 9803999b91..0000000000 --- a/timestats.c +++ /dev/null @@ -1,92 +0,0 @@ -/* timestats.c - * routines for time statistics - * Copyrigth 2003 Lars Roland - * - * $Id$ - * - * Wireshark - Network traffic analyzer - * By Gerald Combs - * Copyright 1998 Gerald Combs - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include "config.h" - -#include "timestats.h" - -/* Initialize a timestat_t struct */ -void -time_stat_init(timestat_t *stats) -{ - stats->num = 0; - stats->min_num = 0; - stats->max_num = 0; - nstime_set_zero(&stats->min); - nstime_set_zero(&stats->max); - nstime_set_zero(&stats->tot); - stats->variance = 0.0; -} - -/* 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=*delta; - stats->max_num=pinfo->fd->num; - stats->min=*delta; - stats->min_num=pinfo->fd->num; - } - - if( (delta->secsmin.secs) - ||( (delta->secs==stats->min.secs) - &&(delta->nsecsmin.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=*delta; - stats->max_num=pinfo->fd->num; - } - - nstime_add(&stats->tot, delta); - - stats->num++; -} - -/* - * get_average - function - * - * function to calculate the average - * returns the average as a gdouble , time base is milli seconds - */ - -gdouble get_average(const nstime_t *sum, guint32 num) -{ - gdouble average; - - if(num > 0) { - average = (double)sum->secs*1000 + (double)sum->nsecs/1000000; - average /= num; - } - else { - average = 0; - } - return average; -} diff --git a/timestats.h b/timestats.h deleted file mode 100644 index b67ea3f8be..0000000000 --- a/timestats.h +++ /dev/null @@ -1,54 +0,0 @@ -/* timestats.h - * Routines and definitions for time statistics - * Copyrigth 2003 Lars Roland - * - * $Id$ - * - * Wireshark - Network traffic analyzer - * By Gerald Combs - * Copyright 1998 Gerald Combs - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef _time_stat -#define _time_stat - -#include -#include "epan/packet_info.h" -#include "epan/nstime.h" - - /* Summary of time statistics*/ -typedef struct _timestat_t { - guint32 num; /* number of samples */ - guint32 min_num; /* frame number of minimum */ - guint32 max_num; /* frame number of maximum */ - nstime_t min; - nstime_t max; - nstime_t tot; - gdouble variance; -} timestat_t; - -/* functions */ - -/* 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 diff --git a/ui/cli/tap-afpstat.c b/ui/cli/tap-afpstat.c index 088030574e..8c5929d5c0 100644 --- a/ui/cli/tap-afpstat.c +++ b/ui/cli/tap-afpstat.c @@ -33,7 +33,7 @@ #include #include #include -#include "timestats.h" +#include "wsutil/timestats.h" /* used to keep track of the statistics for an entire program interface */ typedef struct _afpstat_t { diff --git a/ui/cli/tap-camelsrt.c b/ui/cli/tap-camelsrt.c index f241a72960..df27e857e0 100644 --- a/ui/cli/tap-camelsrt.c +++ b/ui/cli/tap-camelsrt.c @@ -35,7 +35,7 @@ #include "epan/asn1.h" #include "epan/dissectors/packet-camel.h" #include "epan/camel-persistentdata.h" -#include "timestats.h" +#include "wsutil/timestats.h" #include "epan/stat_cmd_args.h" diff --git a/ui/cli/tap-comparestat.c b/ui/cli/tap-comparestat.c index 6f55926e6c..de5e2ecbe0 100644 --- a/ui/cli/tap-comparestat.c +++ b/ui/cli/tap-comparestat.c @@ -45,7 +45,7 @@ #include #include #include -#include "timestats.h" +#include "wsutil/timestats.h" /* For checksum */ diff --git a/ui/cli/tap-diameter-avp.c b/ui/cli/tap-diameter-avp.c index f3b5777bdc..ce773bfccb 100644 --- a/ui/cli/tap-diameter-avp.c +++ b/ui/cli/tap-diameter-avp.c @@ -46,7 +46,6 @@ #include #include #include "epan/value_string.h" -#include "epan/nstime.h" #include "epan/ftypes/ftypes.h" #include "epan/to_str.h" #include "epan/dissectors/packet-diameter.h" diff --git a/ui/cli/tap-funnel.c b/ui/cli/tap-funnel.c index 38d26a5f16..acbc89cbd4 100644 --- a/ui/cli/tap-funnel.c +++ b/ui/cli/tap-funnel.c @@ -30,7 +30,6 @@ #include #include -#include #include #include diff --git a/ui/cli/tap-h225rassrt.c b/ui/cli/tap-h225rassrt.c index 5bb62e97f4..155b368dea 100644 --- a/ui/cli/tap-h225rassrt.c +++ b/ui/cli/tap-h225rassrt.c @@ -34,7 +34,7 @@ #include #include "epan/value_string.h" #include -#include "timestats.h" +#include "wsutil/timestats.h" /* following values represent the size of their valuestring arrays */ #define NUM_RAS_STATS 7 diff --git a/ui/cli/tap-megacostat.c b/ui/cli/tap-megacostat.c index b15f5673e2..9570b1b7b7 100644 --- a/ui/cli/tap-megacostat.c +++ b/ui/cli/tap-megacostat.c @@ -34,7 +34,7 @@ #include #include "epan/value_string.h" #include "epan/gcp.h" -#include "timestats.h" +#include "wsutil/timestats.h" #include #include "tap-megaco-common.h" diff --git a/ui/cli/tap-mgcpstat.c b/ui/cli/tap-mgcpstat.c index 4858142721..9ea2129fa9 100644 --- a/ui/cli/tap-mgcpstat.c +++ b/ui/cli/tap-mgcpstat.c @@ -32,7 +32,7 @@ #include #include "epan/value_string.h" #include "epan/dissectors/packet-mgcp.h" -#include "timestats.h" +#include "wsutil/timestats.h" #define NUM_TIMESTATS 11 diff --git a/ui/cli/tap-radiusstat.c b/ui/cli/tap-radiusstat.c index 852c89d0c8..67522b8b46 100644 --- a/ui/cli/tap-radiusstat.c +++ b/ui/cli/tap-radiusstat.c @@ -32,7 +32,7 @@ #include #include "epan/value_string.h" #include -#include "timestats.h" +#include "wsutil/timestats.h" typedef enum _radius_category { RADIUS_CAT_OVERALL = 0, diff --git a/ui/cli/tap-smbstat.c b/ui/cli/tap-smbstat.c index 99d65ddc23..153a086208 100644 --- a/ui/cli/tap-smbstat.c +++ b/ui/cli/tap-smbstat.c @@ -32,7 +32,7 @@ #include #include "epan/value_string.h" #include -#include "timestats.h" +#include "wsutil/timestats.h" #define MICROSECS_PER_SEC 1000000 #define NANOSECS_PER_SEC 1000000000 diff --git a/ui/cli/tap-sv.c b/ui/cli/tap-sv.c index 8ef6acb0ff..ccd705a445 100644 --- a/ui/cli/tap-sv.c +++ b/ui/cli/tap-sv.c @@ -32,7 +32,6 @@ #include #include #include -#include #include static int diff --git a/ui/gtk/afp_stat.c b/ui/gtk/afp_stat.c index 56af2e4b11..61258ea2d4 100644 --- a/ui/gtk/afp_stat.c +++ b/ui/gtk/afp_stat.c @@ -35,7 +35,6 @@ #include #include -#include "../timestats.h" #include "../file.h" #include "../stat_menu.h" diff --git a/ui/gtk/camel_counter.c b/ui/gtk/camel_counter.c index f2f2621283..53e334abfd 100644 --- a/ui/gtk/camel_counter.c +++ b/ui/gtk/camel_counter.c @@ -38,7 +38,6 @@ #include #include "../stat_menu.h" -#include "../timestats.h" #include "ui/simple_dialog.h" diff --git a/ui/gtk/camel_srt.c b/ui/gtk/camel_srt.c index b52cc2c904..d9d396d8de 100644 --- a/ui/gtk/camel_srt.c +++ b/ui/gtk/camel_srt.c @@ -36,7 +36,6 @@ #include #include -#include "../timestats.h" #include "../file.h" #include "../stat_menu.h" diff --git a/ui/gtk/compare_stat.c b/ui/gtk/compare_stat.c index e07ee96eaa..c6f483e5c6 100644 --- a/ui/gtk/compare_stat.c +++ b/ui/gtk/compare_stat.c @@ -51,11 +51,10 @@ #include #include #include -#include #include #include "../stat_menu.h" -#include "../timestats.h" +#include "wsutil/timestats.h" #include "ui/simple_dialog.h" diff --git a/ui/gtk/conversations_table.c b/ui/gtk/conversations_table.c index e17d62e7f8..4cb5ef57f6 100644 --- a/ui/gtk/conversations_table.c +++ b/ui/gtk/conversations_table.c @@ -35,7 +35,6 @@ #include #include #include -#include #include "../globals.h" diff --git a/ui/gtk/diameter_stat.c b/ui/gtk/diameter_stat.c index a5887c3577..c0cd20f452 100644 --- a/ui/gtk/diameter_stat.c +++ b/ui/gtk/diameter_stat.c @@ -36,7 +36,6 @@ #include #include -#include "../timestats.h" #include "../file.h" #include "../stat_menu.h" diff --git a/ui/gtk/fc_stat.c b/ui/gtk/fc_stat.c index 85d64227db..45d5443886 100644 --- a/ui/gtk/fc_stat.c +++ b/ui/gtk/fc_stat.c @@ -36,7 +36,6 @@ #include #include -#include "../timestats.h" #include "ui/simple_dialog.h" #include "../file.h" #include "../stat_menu.h" diff --git a/ui/gtk/filter_expression_save_dlg.c b/ui/gtk/filter_expression_save_dlg.c index adc4aed15d..f9525835f9 100644 --- a/ui/gtk/filter_expression_save_dlg.c +++ b/ui/gtk/filter_expression_save_dlg.c @@ -33,7 +33,6 @@ #include #include -#include #include #include #include diff --git a/ui/gtk/funnel_stat.c b/ui/gtk/funnel_stat.c index 4af421486b..11583fa0a2 100644 --- a/ui/gtk/funnel_stat.c +++ b/ui/gtk/funnel_stat.c @@ -46,7 +46,6 @@ #include #include -#include "../timestats.h" #include "../file.h" #include "../stat_menu.h" #include "ui/progress_dlg.h" diff --git a/ui/gtk/gtp_stat.c b/ui/gtk/gtp_stat.c index 908a8a95f8..17e6a15cc9 100644 --- a/ui/gtk/gtp_stat.c +++ b/ui/gtk/gtp_stat.c @@ -35,7 +35,6 @@ #include #include -#include "../timestats.h" #include "ui/simple_dialog.h" #include "../file.h" #include "../stat_menu.h" diff --git a/ui/gtk/h225_ras_srt.c b/ui/gtk/h225_ras_srt.c index bd12ac71d2..9b4b8b551c 100644 --- a/ui/gtk/h225_ras_srt.c +++ b/ui/gtk/h225_ras_srt.c @@ -36,7 +36,7 @@ #include #include -#include "../timestats.h" +#include "wsutil/timestats.h" #include "ui/simple_dialog.h" #include "../file.h" #include "../stat_menu.h" diff --git a/ui/gtk/ldap_stat.c b/ui/gtk/ldap_stat.c index e34255211e..c2f9a6f0ce 100644 --- a/ui/gtk/ldap_stat.c +++ b/ui/gtk/ldap_stat.c @@ -34,7 +34,6 @@ #include #include -#include "../timestats.h" #include "ui/simple_dialog.h" #include "../file.h" #include "../stat_menu.h" diff --git a/ui/gtk/megaco_stat.c b/ui/gtk/megaco_stat.c index 5f0b0bab7d..55cc7ead6f 100644 --- a/ui/gtk/megaco_stat.c +++ b/ui/gtk/megaco_stat.c @@ -38,7 +38,7 @@ #include "epan/gcp.h" #include -#include "../timestats.h" +#include "wsutil/timestats.h" #include "ui/simple_dialog.h" #include "../file.h" #include "../stat_menu.h" diff --git a/ui/gtk/mgcp_stat.c b/ui/gtk/mgcp_stat.c index aea8739278..80d20ec958 100644 --- a/ui/gtk/mgcp_stat.c +++ b/ui/gtk/mgcp_stat.c @@ -35,7 +35,7 @@ #include #include "epan/dissectors/packet-mgcp.h" -#include "../timestats.h" +#include "wsutil/timestats.h" #include "ui/simple_dialog.h" #include "../file.h" #include "../stat_menu.h" diff --git a/ui/gtk/ncp_stat.c b/ui/gtk/ncp_stat.c index 6ab3b91242..3a8a9f2b53 100644 --- a/ui/gtk/ncp_stat.c +++ b/ui/gtk/ncp_stat.c @@ -34,7 +34,6 @@ #include #include -#include "../timestats.h" #include "ui/simple_dialog.h" #include "../file.h" #include "../stat_menu.h" diff --git a/ui/gtk/packet_list_store.c b/ui/gtk/packet_list_store.c index d91fdd6033..c1e9a4c29c 100644 --- a/ui/gtk/packet_list_store.c +++ b/ui/gtk/packet_list_store.c @@ -45,7 +45,6 @@ #include #include #include -#include #include "color.h" #include "color_filters.h" diff --git a/ui/gtk/radius_stat.c b/ui/gtk/radius_stat.c index cd73e76795..595a027f72 100644 --- a/ui/gtk/radius_stat.c +++ b/ui/gtk/radius_stat.c @@ -35,7 +35,7 @@ #include #include -#include "../timestats.h" +#include "wsutil/timestats.h" #include "ui/simple_dialog.h" #include "../file.h" #include "../stat_menu.h" diff --git a/ui/gtk/service_response_time_table.h b/ui/gtk/service_response_time_table.h index 3907ac5de1..761ebd813a 100644 --- a/ui/gtk/service_response_time_table.h +++ b/ui/gtk/service_response_time_table.h @@ -28,8 +28,8 @@ #define __SERVICE_RESPONSE_TIME_TABLE_H__ #include -#include "epan/nstime.h" -#include "../timestats.h" +#include "wsutil/nstime.h" +#include "wsutil/timestats.h" /** @file * Helper routines common to all service response time statistics tap. diff --git a/ui/gtk/smb2_stat.c b/ui/gtk/smb2_stat.c index b875bd57d7..c3b0a5108e 100644 --- a/ui/gtk/smb2_stat.c +++ b/ui/gtk/smb2_stat.c @@ -34,7 +34,6 @@ #include #include -#include "../timestats.h" #include "ui/simple_dialog.h" #include "../file.h" #include "../globals.h" diff --git a/ui/gtk/smb_stat.c b/ui/gtk/smb_stat.c index 8d81688727..33c730bc68 100644 --- a/ui/gtk/smb_stat.c +++ b/ui/gtk/smb_stat.c @@ -34,7 +34,6 @@ #include #include -#include "../timestats.h" #include "ui/simple_dialog.h" #include "../file.h" #include "../globals.h" diff --git a/ui/qt/capture_file_dialog.cpp b/ui/qt/capture_file_dialog.cpp index 63f986e2a8..1136b62991 100644 --- a/ui/qt/capture_file_dialog.cpp +++ b/ui/qt/capture_file_dialog.cpp @@ -37,7 +37,7 @@ #include "../../epan/addr_resolv.h" #include "../../epan/prefs.h" #include "../../epan/filesystem.h" -#include "../../epan/nstime.h" +#include "../../wsutil/nstime.h" #include diff --git a/ui/qt/packet_list_model.cpp b/ui/qt/packet_list_model.cpp index 96953f2938..d34a35bb37 100644 --- a/ui/qt/packet_list_model.cpp +++ b/ui/qt/packet_list_model.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include "color.h" diff --git a/ui/time_shift.h b/ui/time_shift.h index bedc353bf4..d1bbebde92 100644 --- a/ui/time_shift.h +++ b/ui/time_shift.h @@ -26,7 +26,7 @@ #define __TIME_SHIFT_H__ #include "cfile.h" -#include +#include #ifdef __cplusplus extern "C" { diff --git a/wsutil/CMakeLists.txt b/wsutil/CMakeLists.txt index 94a2183082..97da38cbc5 100644 --- a/wsutil/CMakeLists.txt +++ b/wsutil/CMakeLists.txt @@ -47,8 +47,10 @@ set(WSUTIL_FILES crc11.c crcdrm.c mpeg-audio.c + nstime.c privileges.c str_util.c + timestats.c type_util.c ${WSUTIL_PLATFORM_FILES} ) diff --git a/wsutil/Makefile.common b/wsutil/Makefile.common index 570dbe60da..712c6c8448 100644 --- a/wsutil/Makefile.common +++ b/wsutil/Makefile.common @@ -41,8 +41,10 @@ LIBWSUTIL_SRC = \ crc32.c \ crcdrm.c \ mpeg-audio.c \ + nstime.c \ privileges.c \ str_util.c \ + timestats.c \ type_util.c # Header files that are not generated from other files @@ -58,6 +60,8 @@ LIBWSUTIL_INCLUDES = \ crc32.h \ crcdrm.h \ mpeg-audio.h \ + nstime.h \ privileges.h \ str_util.h \ + timestats.h \ type_util.h diff --git a/wsutil/nstime.c b/wsutil/nstime.c new file mode 100644 index 0000000000..e88818856a --- /dev/null +++ b/wsutil/nstime.c @@ -0,0 +1,202 @@ +/* nstime.c + * Routines for manipulating nstime_t structures + * + * Copyright (c) 2005 MX Telecom Ltd. + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#include +#include "nstime.h" + +/* this is #defined so that we can clearly see that we have the right number of + zeros, rather than as a guard against the number of nanoseconds in a second + changing ;) */ +#define NS_PER_S 1000000000 + +/* set the given nstime_t to zero */ +void nstime_set_zero(nstime_t *nstime) +{ + nstime->secs = 0; + nstime->nsecs = 0; +} + +/* is the given nstime_t currently zero? */ +gboolean nstime_is_zero(nstime_t *nstime) +{ + if(nstime->secs == 0 && nstime->nsecs == 0) { + return TRUE; + } else { + return FALSE; + } +} + +/* set the given nstime_t to (0,maxint) to mark it as "unset" + * That way we can find the first frame even when a timestamp + * is zero (fix for bug 1056) + */ +void nstime_set_unset(nstime_t *nstime) +{ + nstime->secs = 0; + nstime->nsecs = G_MAXINT; +} + +/* is the given nstime_t currently (0,maxint)? */ +gboolean nstime_is_unset(nstime_t *nstime) +{ + if(nstime->secs == 0 && nstime->nsecs == G_MAXINT) { + return TRUE; + } else { + return FALSE; + } +} + + +/** funcion: nstime_copy + * + * a = b + */ +void nstime_copy(nstime_t *a, const nstime_t *b) +{ + a->secs = b->secs; + a->nsecs = b->nsecs; +} + +/* + * function: nstime_delta + * delta = b - a + */ + +void nstime_delta(nstime_t *delta, const nstime_t *b, const nstime_t *a ) +{ + if (b->secs == a->secs) { + /* The seconds part of b is the same as the seconds part of a, so if + the nanoseconds part of the first time is less than the nanoseconds + part of a, b is before a. The nanoseconds part of the delta should + just be the difference between the nanoseconds part of b and the + nanoseconds part of a; don't adjust the seconds part of the delta, + as it's OK if the nanoseconds part is negative, and an overflow + can never result. */ + delta->secs = 0; + delta->nsecs = b->nsecs - a->nsecs; + } else if (b->secs <= a->secs) { + /* The seconds part of b is less than the seconds part of a, so b is + before a. + + Both the "seconds" and "nanoseconds" value of the delta + should have the same sign, so if the difference between the + nanoseconds values would be *positive*, subtract 1,000,000,000 + from it, and add one to the seconds value. */ + delta->secs = b->secs - a->secs; + delta->nsecs = b->nsecs - a->nsecs; + if(delta->nsecs > 0) { + delta->nsecs -= NS_PER_S; + delta->secs ++; + } + } else { + delta->secs = b->secs - a->secs; + delta->nsecs = b->nsecs - a->nsecs; + if(delta->nsecs < 0) { + delta->nsecs += NS_PER_S; + delta->secs --; + } + } +} + +/* + * function: nstime_sum + * sum = a + b + */ + +void nstime_sum(nstime_t *sum, const nstime_t *a, const nstime_t *b) +{ + sum->secs = a->secs + b->secs; + sum->nsecs = a->nsecs + b->nsecs; + if(sum->nsecs>=NS_PER_S || (sum->nsecs>0 && sum->secs<0)){ + sum->nsecs-=NS_PER_S; + sum->secs++; + } else if(sum->nsecs<=-NS_PER_S || (sum->nsecs<0 && sum->secs>0)) { + sum->nsecs+=NS_PER_S; + sum->secs--; + } +} + +/* + * function: nstime_cmp + * + * a > b : > 0 + * a = b : 0 + * a < b : < 0 + */ + +int nstime_cmp (const nstime_t *a, const nstime_t *b ) +{ + if (a->secs == b->secs) { + return a->nsecs - b->nsecs; + } else { + return (int) (a->secs - b->secs); + } +} + +/* + * function: nstime_to_msec + * converts nstime to double, time base is milli seconds + */ + +double nstime_to_msec(const nstime_t *nstime) +{ + return ((double)nstime->secs*1000 + (double)nstime->nsecs/1000000); +} + +/* + * function: nstime_to_sec + * converts nstime to double, time base is seconds + */ + +double nstime_to_sec(const nstime_t *nstime) +{ + return ((double)nstime->secs + (double)nstime->nsecs/1000000000); +} + +/* + * function: wtap_nstime_to_sec + * converts wtap_nstime to double, time base is seconds + */ + +double wtap_nstime_to_sec(const struct wtap_nstime *nstime) +{ + return ((double)nstime->secs + (double)nstime->nsecs/1000000000); +} + +/* + * Editor modelines + * + * Local Variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ + diff --git a/wsutil/nstime.h b/wsutil/nstime.h new file mode 100644 index 0000000000..01fd469b62 --- /dev/null +++ b/wsutil/nstime.h @@ -0,0 +1,115 @@ +/* nstime.h + * Definition of data structure to hold time values with nanosecond resolution + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __NSTIME_H__ +#define __NSTIME_H__ + +#include + +#include +#include "ws_symbol_export.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** @file + * Definition of data structure to hold time values with nanosecond resolution + */ + +/** data structure to hold time values with nanosecond resolution*/ +typedef struct { + time_t secs; + int nsecs; +} nstime_t; + +/* functions */ + +/** set the given nstime_t to zero */ +WS_DLL_PUBLIC void nstime_set_zero(nstime_t *nstime); + +/** is the given nstime_t currently zero? */ +WS_DLL_PUBLIC gboolean nstime_is_zero(nstime_t *nstime); + +/** set the given nstime_t to (0,maxint) to mark it as "unset" + * That way we can find the first frame even when a timestamp + * is zero (fix for bug 1056) + */ +WS_DLL_PUBLIC void nstime_set_unset(nstime_t *nstime); + +/* is the given nstime_t currently (0,maxint)? */ +WS_DLL_PUBLIC gboolean nstime_is_unset(nstime_t *nstime); + +/** duplicate the current time + * + * a = b + */ +WS_DLL_PUBLIC void nstime_copy(nstime_t *a, const nstime_t *b); + +/** calculate the delta between two times (can be negative!) + * + * delta = b-a + * + * Note that it is acceptable for two or more of the arguments to point at the + * same structure. + */ +WS_DLL_PUBLIC void nstime_delta(nstime_t *delta, const nstime_t *b, const nstime_t *a ); + +/** calculate the sum of two times + * + * sum = a+b + * + * Note that it is acceptable for two or more of the arguments to point at the + * same structure. + */ +WS_DLL_PUBLIC void nstime_sum(nstime_t *sum, const nstime_t *b, const nstime_t *a ); + +/** sum += a */ +#define nstime_add(sum, a) nstime_sum(sum, sum, a) + +/** sum -= a */ +#define nstime_subtract(sum, a) nstime_delta(sum, sum, a) + +/** compare two times are return a value similar to memcmp() or strcmp(). + * + * a > b : > 0 + * a = b : 0 + * a < b : < 0 + */ +WS_DLL_PUBLIC int nstime_cmp (const nstime_t *a, const nstime_t *b ); + +/** converts nstime to double, time base is milli seconds */ +WS_DLL_PUBLIC double nstime_to_msec(const nstime_t *nstime); + +/** converts nstime to double, time base is seconds */ +WS_DLL_PUBLIC double nstime_to_sec(const nstime_t *nstime); + +/** converts wtap_nstime to double, time base is seconds */ +WS_DLL_PUBLIC double wtap_nstime_to_sec(const struct wtap_nstime *nstime); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __NSTIME_H__ */ diff --git a/wsutil/timestats.c b/wsutil/timestats.c new file mode 100644 index 0000000000..9803999b91 --- /dev/null +++ b/wsutil/timestats.c @@ -0,0 +1,92 @@ +/* timestats.c + * routines for time statistics + * Copyrigth 2003 Lars Roland + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "config.h" + +#include "timestats.h" + +/* Initialize a timestat_t struct */ +void +time_stat_init(timestat_t *stats) +{ + stats->num = 0; + stats->min_num = 0; + stats->max_num = 0; + nstime_set_zero(&stats->min); + nstime_set_zero(&stats->max); + nstime_set_zero(&stats->tot); + stats->variance = 0.0; +} + +/* 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=*delta; + stats->max_num=pinfo->fd->num; + stats->min=*delta; + stats->min_num=pinfo->fd->num; + } + + if( (delta->secsmin.secs) + ||( (delta->secs==stats->min.secs) + &&(delta->nsecsmin.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=*delta; + stats->max_num=pinfo->fd->num; + } + + nstime_add(&stats->tot, delta); + + stats->num++; +} + +/* + * get_average - function + * + * function to calculate the average + * returns the average as a gdouble , time base is milli seconds + */ + +gdouble get_average(const nstime_t *sum, guint32 num) +{ + gdouble average; + + if(num > 0) { + average = (double)sum->secs*1000 + (double)sum->nsecs/1000000; + average /= num; + } + else { + average = 0; + } + return average; +} diff --git a/wsutil/timestats.h b/wsutil/timestats.h new file mode 100644 index 0000000000..81e6d97042 --- /dev/null +++ b/wsutil/timestats.h @@ -0,0 +1,54 @@ +/* timestats.h + * Routines and definitions for time statistics + * Copyrigth 2003 Lars Roland + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef _time_stat +#define _time_stat + +#include +#include "epan/packet_info.h" +#include "nstime.h" + + /* Summary of time statistics*/ +typedef struct _timestat_t { + guint32 num; /* number of samples */ + guint32 min_num; /* frame number of minimum */ + guint32 max_num; /* frame number of maximum */ + nstime_t min; + nstime_t max; + nstime_t tot; + gdouble variance; +} timestat_t; + +/* functions */ + +/* Initialize a timestat_t struct */ +WS_DLL_PUBLIC void time_stat_init(timestat_t *stats); + +/* Update a timestat_t struct with a new sample */ +WS_DLL_PUBLIC void time_stat_update(timestat_t *stats, const nstime_t *delta, packet_info *pinfo); + +WS_DLL_PUBLIC gdouble get_average(const nstime_t *sum, guint32 num); + +#endif -- cgit v1.2.3