Skip to content

Commit

Permalink
appneta#269 print per-loop stats with --stats=0 (appneta#288)
Browse files Browse the repository at this point in the history
  • Loading branch information
fklassen authored Feb 27, 2017
1 parent 5bdca6d commit b6196bc
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/common/flows.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ static inline flow_entry_type_t hash_put_data(flow_hash_table_t *fht, const uint
res = FLOW_ENTRY_INVALID;
}

dbgx(2, "flow type=%d\n", (int)res);
dbgx(2, "flow type=%d", (int)res);
return res;
}

Expand Down Expand Up @@ -321,7 +321,7 @@ flow_hash_table_t *flow_hash_table_init(size_t n)
{
flow_hash_table_t *fht;
if (!is_power_of_2(n))
errx(-1, "invalid table size: %zu\n", n);
errx(-1, "invalid table size: %zu", n);

fht = safe_malloc(sizeof(*fht));
fht->num_buckets = n;
Expand Down
6 changes: 3 additions & 3 deletions src/common/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ packet_stats(const tcpreplay_stats_t *stats)
}

if (diff_us >= 1000000)
printf("Actual: " COUNTER_SPEC " packets (" COUNTER_SPEC " bytes) sent in %zd.%02zd seconds.\n",
stats->pkts_sent, stats->bytes_sent, (ssize_t)diff.tv_sec, (ssize_t)(diff.tv_usec / (100 * 1000)));
printf("Actual: " COUNTER_SPEC " packets (" COUNTER_SPEC " bytes) sent in %zd.%02zd seconds\n",
stats->pkts_sent, stats->bytes_sent, (ssize_t)diff.tv_sec, (ssize_t)(diff.tv_usec / (10 * 1000)));
else
printf("Actual: " COUNTER_SPEC " packets (" COUNTER_SPEC " bytes) sent in %zd.%06zd seconds.\n",
printf("Actual: " COUNTER_SPEC " packets (" COUNTER_SPEC " bytes) sent in %zd.%06zd seconds\n",
stats->pkts_sent, stats->bytes_sent, (ssize_t)diff.tv_sec, (ssize_t)diff.tv_usec);


Expand Down
4 changes: 2 additions & 2 deletions src/tcpedit/tcpedit.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ tcpedit_init(tcpedit_t **tcpedit_ex, int dlt)
tcpedit->runtime.dlt1 = dlt;
tcpedit->runtime.dlt2 = dlt;

dbgx(1, "Input file (1) datalink type is %s\n",
dbgx(1, "Input file (1) datalink type is %s",
pcap_datalink_val_to_name(dlt));

#ifdef FORCE_ALIGN
Expand Down Expand Up @@ -494,7 +494,7 @@ tcpedit_close(tcpedit_t *tcpedit)

assert(tcpedit);
dbgx(1, "tcpedit processed " COUNTER_SPEC " bytes in " COUNTER_SPEC
" packets.\n", tcpedit->runtime.total_bytes,
" packets.", tcpedit->runtime.total_bytes,
tcpedit->runtime.pkts_edited);

/* free buffer if required */
Expand Down
26 changes: 22 additions & 4 deletions src/tcpreplay_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ tcpreplay_init()
/* set the default MTU size */
ctx->options->mtu = DEFAULT_MTU;

/* disable periodic statistics */
ctx->options->stats = -1;

/* disable limit send */
ctx->options->limit_send = -1;

Expand Down Expand Up @@ -1149,7 +1152,7 @@ tcpreplay_prepare(tcpreplay_t *ctx)
int
tcpreplay_replay(tcpreplay_t *ctx)
{
int rcode;
int rcode, loop, total_loops;

assert(ctx);

Expand All @@ -1172,21 +1175,36 @@ tcpreplay_replay(tcpreplay_t *ctx)
return -1;
}


ctx->running = true;
total_loops = ctx->options->loop;
loop = 0;

/* main loop, when not looping forever (or until abort) */
if (ctx->options->loop > 0) {
while (ctx->options->loop-- && !ctx->abort) { /* limited loop */
if (ctx->options->stats == 0)
printf("Loop %d of %d...\n", ++loop, total_loops);
if ((rcode = tcpr_replay_index(ctx)) < 0)
return rcode;
if (ctx->options->loop > 0 && !ctx->abort && ctx->options->loopdelay_ms > 0)
usleep(ctx->options->loopdelay_ms * 1000);
if (ctx->options->loop > 0) {
if (!ctx->abort && ctx->options->loopdelay_ms > 0) {
usleep(ctx->options->loopdelay_ms * 1000);
gettimeofday(&ctx->stats.end_time, NULL);
}

if (ctx->options->stats == 0)
packet_stats(&ctx->stats);
}
}
} else {
while (!ctx->abort) { /* loop forever unless user aborts */
if (ctx->options->stats == 0)
printf("Loop %d...\n", ++loop);
if ((rcode = tcpr_replay_index(ctx)) < 0)
return rcode;

if (ctx->options->stats == 0 && !ctx->abort)
packet_stats(&ctx->stats);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/tcpreplay_opts.def
Original file line number Diff line number Diff line change
Expand Up @@ -596,10 +596,10 @@ EOText;
flag = {
name = stats;
arg-type = number;
arg-range = "1->";
descrip = "Print statistics every X seconds";
arg-range = "0->";
descrip = "Print statistics every X seconds, or every loop if '0'";
doc = <<- EOText
Note that this is very much a "best effort" and long delays between
Note that timed delays are a "best effort" and long delays between
sending packets may cause equally long delays between printing statistics.
EOText;
};
Expand Down

0 comments on commit b6196bc

Please sign in to comment.