Skip to content

Commit a40ae7a

Browse files
committed
util/xdp_sample: Calculate average PPS from elapsed time
Instead of counting the number of rounds in the polling loop, actually calculate the total runtime in seconds and compute the average PPS from that. Also print the duration as part of the end-of-run statistics. Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
1 parent 65d3155 commit a40ae7a

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lib/util/xdp_sample.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ size_t sample_map_count[NUM_MAP];
154154
enum log_level sample_log_level;
155155
struct sample_output sample_out;
156156
unsigned long sample_interval;
157+
__u64 sample_start_time;
157158
bool sample_err_exp;
158159
int sample_xdp_cnt;
159160
int sample_n_cpus;
@@ -1339,23 +1340,26 @@ int __sample_init(int mask, int ifindex_from, int ifindex_to)
13391340

13401341
static void sample_summary_print(void)
13411342
{
1342-
double num = sample_out.rx_cnt.num;
1343+
__u64 start = sample_start_time;
1344+
__u64 now = gettime();
1345+
double dur_s = ((double)now - start) / NANOSEC_PER_SEC;
13431346

1347+
print_always(" Duration : %.1fs\n", dur_s);
13441348
if (sample_out.totals.rx) {
13451349
double pkts = sample_out.totals.rx;
13461350

13471351
print_always(" Packets received : %'-10" PRIu64 "\n",
13481352
(uint64_t)sample_out.totals.rx);
13491353
print_always(" Average packets/s : %'-10.0f\n",
1350-
round(pkts / num));
1354+
round(pkts / dur_s));
13511355
}
13521356
if (sample_out.totals.redir) {
13531357
double pkts = sample_out.totals.redir;
13541358

13551359
print_always(" Packets redirected : %'-10" PRIu64 "\n",
13561360
sample_out.totals.redir);
13571361
print_always(" Average redir/s : %'-10.0f\n",
1358-
round(pkts / num));
1362+
round(pkts / dur_s));
13591363
}
13601364
if (sample_out.totals.drop)
13611365
print_always(" Rx dropped : %'-10" PRIu64 "\n",
@@ -1372,7 +1376,7 @@ static void sample_summary_print(void)
13721376
print_always(" Packets transmitted : %'-10" PRIu64 "\n",
13731377
sample_out.totals.xmit);
13741378
print_always(" Average transmit/s : %'-10.0f\n",
1375-
round(pkts / num));
1379+
round(pkts / dur_s));
13761380
}
13771381
}
13781382

@@ -1439,7 +1443,6 @@ static void sample_summary_update(struct sample_output *out)
14391443
sample_out.totals.drop_xmit += out->totals.drop_xmit;
14401444
sample_out.totals.err += out->totals.err;
14411445
sample_out.totals.xmit += out->totals.xmit;
1442-
sample_out.rx_cnt.num++;
14431446
}
14441447

14451448
static void sample_stats_print(int mask, struct stats_record *cur,
@@ -1585,6 +1588,8 @@ int sample_run(unsigned int interval, void (*post_cb)(void *), void *ctx)
15851588
if (!prev)
15861589
goto end_rec;
15871590

1591+
sample_start_time = gettime();
1592+
15881593
ret = sample_stats_collect(rec);
15891594
if (ret < 0)
15901595
goto end_rec_prev;

0 commit comments

Comments
 (0)