aboutsummaryrefslogtreecommitdiffstats
path: root/epan
diff options
context:
space:
mode:
authorEvan Huus <eapache@gmail.com>2014-06-30 19:46:58 -0400
committerAnders Broman <a.broman58@gmail.com>2014-07-01 04:21:14 +0000
commita452d16f2c27fc44a41f14d05acca8e94b1c71d8 (patch)
tree085907efa4a91520b08443bebeead97f201f3764 /epan
parent659d0efc928e102d8ca0390a374cddcbad7d8797 (diff)
Optimize epan_new/init_dissection
As Anders correctly pointed out in I7d8f84b2e, constantly resetting state will turn init_dissection into a bit of a hot path. Especially as we will already bear the overhead of switching files, we don't want to fall any further behind than we have to. This change includes three unrelated optimizations that reduce the cost of init_dissection by about 40% as measured by callgrind: - only initialize ares/ADNS if that preference is enabled (this of course only applies if you specify -n to tshark or otherwise disable the preference) - use memcpy instead of a loop in sigcomp UDVM init - use memcpy instead of a loop in bootp dissector The only remaining obvious hot spot in this path is reassembly_table_init since it is called by so many dissectors. Suggestions (perhaps to get rid of the GPtrArray) welcome. Oh, and one other change to use g_strerror instead of strerror as insisted upon by the API pre-commit hook. Change-Id: I18a74f2b64b25498116079bd4e7fc2b335c7703a Reviewed-on: https://code.wireshark.org/review/2738 Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'epan')
-rw-r--r--epan/addr_resolv.c48
-rw-r--r--epan/dissectors/packet-bootp.c7
-rw-r--r--epan/sigcomp_state_hdlr.c29
3 files changed, 41 insertions, 43 deletions
diff --git a/epan/addr_resolv.c b/epan/addr_resolv.c
index 595b50fe80..fbfc7295de 100644
--- a/epan/addr_resolv.c
+++ b/epan/addr_resolv.c
@@ -2393,7 +2393,7 @@ host_name_lookup_process(void) {
nfds = ares_fds(ghba_chan, &rfds, &wfds);
if (nfds > 0) {
if (select(nfds, &rfds, &wfds, NULL, &tv) == -1) { /* call to select() failed */
- fprintf(stderr, "Warning: call to select() failed, error is %s\n", strerror(errno));
+ fprintf(stderr, "Warning: call to select() failed, error is %s\n", g_strerror(errno));
return nro;
}
ares_process(ghba_chan, &rfds, &wfds);
@@ -2688,15 +2688,17 @@ host_name_lookup_init(void)
}
g_free(hostspath);
#ifdef HAVE_C_ARES
+ if (gbl_resolv_flags.concurrent_dns) {
#ifdef CARES_HAVE_ARES_LIBRARY_INIT
- if (ares_library_init(ARES_LIB_INIT_ALL) == ARES_SUCCESS) {
+ if (ares_library_init(ARES_LIB_INIT_ALL) == ARES_SUCCESS) {
#endif
- if (ares_init(&ghba_chan) == ARES_SUCCESS && ares_init(&ghbn_chan) == ARES_SUCCESS) {
- async_dns_initialized = TRUE;
- }
+ if (ares_init(&ghba_chan) == ARES_SUCCESS && ares_init(&ghbn_chan) == ARES_SUCCESS) {
+ async_dns_initialized = TRUE;
+ }
#ifdef CARES_HAVE_ARES_LIBRARY_INIT
- }
+ }
#endif
+ }
#else
#ifdef HAVE_GNU_ADNS
/*
@@ -2732,21 +2734,23 @@ host_name_lookup_init(void)
}
#endif /* _WIN32 */
- /* XXX - Any flags we should be using? */
- /* XXX - We could provide config settings for DNS servers, and
- pass them to ADNS with adns_init_strcfg */
- if (adns_init(&ads, adns_if_none, 0 /*0=>stderr*/) != 0) {
- /*
- * XXX - should we report the error? I'm assuming that some crashes
- * reported on a Windows machine with TCP/IP not configured are due
- * to "adns_init()" failing (due to the lack of TCP/IP) and leaving
- * ADNS in a state where it crashes due to that. We'll still try
- * doing name resolution anyway.
- */
- return;
+ if (gbl_resolv_flags.concurrent_dns) {
+ /* XXX - Any flags we should be using? */
+ /* XXX - We could provide config settings for DNS servers, and
+ pass them to ADNS with adns_init_strcfg */
+ if (adns_init(&ads, adns_if_none, 0 /*0=>stderr*/) != 0) {
+ /*
+ * XXX - should we report the error? I'm assuming that some crashes
+ * reported on a Windows machine with TCP/IP not configured are due
+ * to "adns_init()" failing (due to the lack of TCP/IP) and leaving
+ * ADNS in a state where it crashes due to that. We'll still try
+ * doing name resolution anyway.
+ */
+ return;
+ }
+ async_dns_initialized = TRUE;
+ async_dns_in_flight = 0;
}
- async_dns_initialized = TRUE;
- async_dns_in_flight = 0;
#endif /* HAVE_GNU_ADNS */
#endif /* HAVE_C_ARES */
@@ -3221,7 +3225,7 @@ get_host_ipaddr(const char *host, guint32 *addrp)
if (nfds > 0) {
tvp = ares_timeout(ghbn_chan, &tv, &tv);
if (select(nfds, &rfds, &wfds, NULL, tvp) == -1) { /* call to select() failed */
- fprintf(stderr, "Warning: call to select() failed, error is %s\n", strerror(errno));
+ fprintf(stderr, "Warning: call to select() failed, error is %s\n", g_strerror(errno));
return FALSE;
}
ares_process(ghbn_chan, &rfds, &wfds);
@@ -3308,7 +3312,7 @@ get_host_ipaddr6(const char *host, struct e_in6_addr *addrp)
if (nfds > 0) {
tvp = ares_timeout(ghbn_chan, &tv, &tv);
if (select(nfds, &rfds, &wfds, NULL, tvp) == -1) { /* call to select() failed */
- fprintf(stderr, "Warning: call to select() failed, error is %s\n", strerror(errno));
+ fprintf(stderr, "Warning: call to select() failed, error is %s\n", g_strerror(errno));
return FALSE;
}
ares_process(ghbn_chan, &rfds, &wfds);
diff --git a/epan/dissectors/packet-bootp.c b/epan/dissectors/packet-bootp.c
index 2825f37b89..631ca43b0e 100644
--- a/epan/dissectors/packet-bootp.c
+++ b/epan/dissectors/packet-bootp.c
@@ -5383,12 +5383,7 @@ bootp_init_protocol(void)
guint i;
/* first copy default_bootp_opt[] to bootp_opt[]. This resets all values to default */
- for(i=0; i<BOOTP_OPT_NUM; i++)
- {
- bootp_opt[i].text = default_bootp_opt[i].text;
- bootp_opt[i].ftype = default_bootp_opt[i].ftype;
- bootp_opt[i].phf = default_bootp_opt[i].phf;
- }
+ memcpy(bootp_opt, default_bootp_opt, sizeof(bootp_opt));
/* Now apply the custom options */
for (i = 0; i < num_bootp_records_uat; i++)
diff --git a/epan/sigcomp_state_hdlr.c b/epan/sigcomp_state_hdlr.c
index cdb8782eae..fdc6ae3ef4 100644
--- a/epan/sigcomp_state_hdlr.c
+++ b/epan/sigcomp_state_hdlr.c
@@ -610,7 +610,6 @@ void
sigcomp_init_udvm(void){
gchar *partial_state_str;
- guint i;
guint8 *sip_sdp_buff, *presence_buff;
/* Destroy any existing memory chunks / hashes. */
@@ -636,15 +635,7 @@ sigcomp_init_udvm(void){
memset(sip_sdp_buff, 0, 8);
sip_sdp_buff[0] = SIP_SDP_STATE_LENGTH >> 8;
sip_sdp_buff[1] = SIP_SDP_STATE_LENGTH & 0xff;
- i = 0;
- while ( i < SIP_SDP_STATE_LENGTH ){
- sip_sdp_buff[i+8] = sip_sdp_static_dictionaty_for_sigcomp[i];
- /* Debug
- * g_warning(" Loading 0x%x at address %u",sip_sdp_buff[i] , i);
- */
- i++;
-
- }
+ memcpy(sip_sdp_buff+8, sip_sdp_static_dictionaty_for_sigcomp, SIP_SDP_STATE_LENGTH);
g_hash_table_insert(state_buffer_table, g_strdup(partial_state_str), sip_sdp_buff);
/* Debug
@@ -659,11 +650,7 @@ sigcomp_init_udvm(void){
memset(presence_buff, 0, 8);
presence_buff[0] = PRESENCE_STATE_LENGTH >> 8;
presence_buff[1] = PRESENCE_STATE_LENGTH & 0xff;
- i = 0;
- while ( i < PRESENCE_STATE_LENGTH ){
- presence_buff[i+8] = presence_static_dictionary_for_sigcomp[i];
- i++;
- }
+ memcpy(presence_buff+8, presence_static_dictionary_for_sigcomp, PRESENCE_STATE_LENGTH);
g_hash_table_insert(state_buffer_table, g_strdup(partial_state_str), presence_buff);
}
@@ -879,3 +866,15 @@ void udvm_state_free(guint8 buff[],guint16 p_id_start,guint16 p_id_length){
}
#endif
+/*
+ * Editor modelines - http://www.wireshark.org/tools/modelines.html
+ *
+ * Local variables:
+ * c-basic-offset: 8
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * End:
+ *
+ * vi: set shiftwidth=8 tabstop=8 noexpandtab:
+ * :indentSize=8:tabSize=8:noTabs=false:
+ */