aboutsummaryrefslogtreecommitdiffstats
path: root/writecap
diff options
context:
space:
mode:
authorAndersBroman <anders.broman@ericsson.com>2017-02-23 09:27:50 +0100
committerAnders Broman <a.broman58@gmail.com>2017-02-24 04:42:31 +0000
commitbd9afdddfe45b4c9c6e966df7264d12cdfd85f42 (patch)
treeaf651f903c1a8dc985774367fc70a2f0750554a4 /writecap
parentd347a608c9b55628d00e17dc029170876ae496dd (diff)
Reduce number of fwrite when writing pcap-ng EPB.
According to callgrind with the patch dumping 3000 pakets the number of calls to write_to_file is reduced from 11541 to 9000 reducing the number of lr from 4 681 518 to 4 314 101. If the buffer holding the packet was guaranteed to be padded to 32 bit boundary the code could be simplified and if there was space "in front" for the packet header it would be even better. Change-Id: Ie991c05fa9d831ee4d703bd47b8123f2b1f83277 Reviewed-on: https://code.wireshark.org/review/20256 Petri-Dish: Anders Broman <a.broman58@gmail.com> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'writecap')
-rw-r--r--writecap/pcapio.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/writecap/pcapio.c b/writecap/pcapio.c
index ce2a90d0c1..1336f735c3 100644
--- a/writecap/pcapio.c
+++ b/writecap/pcapio.c
@@ -516,6 +516,9 @@ pcapng_write_enhanced_packet_block(FILE* pfile,
guint64 timestamp;
guint32 options_length;
const guint32 padding = 0;
+ guint8 buff[8];
+ guint8 i;
+ guint8 pad_len = 0;
block_total_length = (guint32)(sizeof(struct epb) +
ADD_PADDING(caplen) +
@@ -543,8 +546,28 @@ pcapng_write_enhanced_packet_block(FILE* pfile,
return FALSE;
if (!write_to_file(pfile, pd, caplen, bytes_written, err))
return FALSE;
- if (caplen % 4) {
- if (!write_to_file(pfile, (const guint8*)&padding, 4 - caplen % 4, bytes_written, err))
+ /* Use more efficient write in case of no "extras" */
+ if(caplen % 4) {
+ pad_len = 4 - (caplen % 4);
+ }
+ if(!comment && flags == 0 && options_length==0){
+ /* Put padding in the buffer */
+ for (i = 0; i < pad_len; i++) {
+ buff[i] = 0;
+ }
+ /* Write the total length */
+ buff[i] = (block_total_length & 0x000000ff);
+ i++;
+ buff[i] = (block_total_length & 0x0000ff00) >> 8;
+ i++;
+ buff[i] = (block_total_length & 0x00ff0000) >> 16;
+ i++;
+ buff[i] = (block_total_length & 0xff000000) >> 24;
+ i++;
+ return write_to_file(pfile, (const guint8*)&buff, i, bytes_written, err);
+ }
+ if (pad_len) {
+ if (!write_to_file(pfile, (const guint8*)&padding, pad_len, bytes_written, err))
return FALSE;
}
if (!pcapng_write_string_option(pfile, OPT_COMMENT, comment,