Skip to content

Commit

Permalink
Improve throughput by reducing calls to stats
Browse files Browse the repository at this point in the history
  • Loading branch information
LocutusOfBorg authored and Alexander Koeppe committed Mar 6, 2018
1 parent e5241d8 commit ddaf8b8
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 15 deletions.
1 change: 1 addition & 0 deletions include/ec_globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct ec_conf {
int connection_buffer;
int connect_timeout;
int sampling_rate;
int packet_update_count;
int close_on_eof;
int aggressive_dissectors;
int skip_forwarded;
Expand Down
1 change: 1 addition & 0 deletions share/etter.conf.v4
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ connect_timeout = 5 # seconds

[stats]
sampling_rate = 50 # number of packets
packet_update_count = 50 # number of packets

[misc]
close_on_eof = 1 # boolean value
Expand Down
1 change: 1 addition & 0 deletions share/etter.conf.v6
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ connect_timeout = 5 # seconds

[stats]
sampling_rate = 50 # number of packets
packet_update_count = 50 # number of packets

[misc]
close_on_eof = 1 # boolean value
Expand Down
3 changes: 2 additions & 1 deletion src/ec_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ static struct conf_entry connections[] = {

static struct conf_entry stats[] = {
{ "sampling_rate", NULL },
{ "packet_update_count", NULL },
{ NULL, NULL },
};

Expand Down Expand Up @@ -183,12 +184,12 @@ static void init_structures(void)
set_pointer(mitm, "ndp_poison_equal_mac", &GBL_CONF->ndp_poison_equal_mac);
set_pointer(mitm, "icmp6_probe_delay", &GBL_CONF->icmp6_probe_delay);
#endif

set_pointer(connections, "connection_timeout", &GBL_CONF->connection_timeout);
set_pointer(connections, "connection_idle", &GBL_CONF->connection_idle);
set_pointer(connections, "connection_buffer", &GBL_CONF->connection_buffer);
set_pointer(connections, "connect_timeout", &GBL_CONF->connect_timeout);
set_pointer(stats, "sampling_rate", &GBL_CONF->sampling_rate);
set_pointer(stats, "packet_update_count", &GBL_CONF->packet_update_count);
set_pointer(misc, "close_on_eof", &GBL_CONF->close_on_eof);
set_pointer(misc, "store_profiles", &GBL_CONF->store_profiles);
set_pointer(misc, "aggressive_dissectors", &GBL_CONF->aggressive_dissectors);
Expand Down
22 changes: 15 additions & 7 deletions src/ec_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

/* globals */

static int count = 0;
static struct dec_entry *protocols_table;
static unsigned protocols_num;
static bool table_sorted = false;
Expand Down Expand Up @@ -86,9 +87,13 @@ void ec_decode(u_char *param, const struct pcap_pkthdr *pkthdr, const u_char *pk

CANCELLATION_POINT();

/* start the timer for the stats */
stats_half_start(&GBL_STATS->bh);

count++;
if(count = 1)
{
/* start the timer for the stats */
stats_half_start(&GBL_STATS->bh);
}

/* XXX -- remove this */
#if 0
if (!GBL_OPTIONS->quiet)
Expand Down Expand Up @@ -233,10 +238,13 @@ void ec_decode(u_char *param, const struct pcap_pkthdr *pkthdr, const u_char *pk

/* free the structure */
packet_destroy_object(&po);

/* calculate the stats */
stats_half_end(&GBL_STATS->bh, pkthdr->caplen);

if(count == GBL_CONF->packet_update_count)
{
/* calculate the stats */
stats_half_end(&GBL_STATS->bh, pkthdr->caplen);
count = 0;
}

CANCELLATION_POINT();

return;
Expand Down
24 changes: 17 additions & 7 deletions src/ec_dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include <ec_stats.h>
#include <ec_sleep.h>

/* globals */
static int count = 0;

/* this is the PO queue from bottom to top half */
struct po_queue_entry {
Expand Down Expand Up @@ -97,10 +99,14 @@ EC_THREAD_FUNC(top_half)
ec_usleep(1); // 1µs
continue;
}

/* start the counter for the TopHalf */
stats_half_start(&GBL_STATS->th);


count++;
if(count = 1)
{
/* start the counter for the TopHalf */
stats_half_start(&GBL_STATS->th);
}

/* remove the packet form the queue */
STAILQ_REMOVE_HEAD(&po_queue, e, next);

Expand Down Expand Up @@ -140,9 +146,13 @@ EC_THREAD_FUNC(top_half)
packet_destroy_object(e->po);
SAFE_FREE(e->po);
SAFE_FREE(e);

/* start the counter for the TopHalf */
stats_half_end(&GBL_STATS->th, pck_len);

if(count == GBL_CONF->packet_update_count)
{
/* start the counter for the TopHalf */
stats_half_end(&GBL_STATS->th, pck_len);
count = 0;
}
}

return NULL;
Expand Down

0 comments on commit ddaf8b8

Please sign in to comment.