Skip to content

Commit

Permalink
iio_readdev/iio_writedev: Refresh benchmark values at ~10 Hz
Browse files Browse the repository at this point in the history
Dynamically compute the number of times a buffer has to be refilled or
pushed to average a refresh rate for the benchmark of 10 Hz (one print
every 100ms).

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
  • Loading branch information
pcercuei committed Jan 11, 2022
1 parent 1b88be0 commit 81b7802
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions tests/iio_readdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ int main(int argc, char **argv)
unsigned int i, nb_channels;
unsigned int nb_active_channels = 0;
unsigned int buffer_size = SAMPLES_PER_READ;
unsigned int refill_per_benchmark = REFILL_PER_BENCHMARK;
int c;
struct iio_device *dev;
ssize_t sample_size;
Expand Down Expand Up @@ -400,15 +401,20 @@ int main(int argc, char **argv)
after = get_time_us();
total += after - before;

if (++i == REFILL_PER_BENCHMARK) {
if (++i == refill_per_benchmark) {
rate = buffer_size * sample_size *
REFILL_PER_BENCHMARK * 1000000ull / total;
refill_per_benchmark * 1000000ull / total;
mib = rate > 1048576;

fprintf(stderr, "\33[2K\rThroughput: %" PRIu64 " %ciB/s",
rate / (1024 * (mib ? 1024 : 1)),
mib ? 'M' : 'K');

/* Print every 100ms more or less */
refill_per_benchmark = refill_per_benchmark * 100000 / total;
if (refill_per_benchmark < REFILL_PER_BENCHMARK)
refill_per_benchmark = REFILL_PER_BENCHMARK;

i = 0;
total = 0;
}
Expand Down
10 changes: 8 additions & 2 deletions tests/iio_writedev.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ int main(int argc, char **argv)
unsigned int i, nb_channels;
unsigned int nb_active_channels = 0;
unsigned int buffer_size = SAMPLES_PER_READ;
unsigned int refill_per_benchmark = REFILL_PER_BENCHMARK;
int c;
struct iio_device *dev;
ssize_t sample_size;
Expand Down Expand Up @@ -445,15 +446,20 @@ int main(int argc, char **argv)
after = get_time_us();
total += after - before;

if (++i == REFILL_PER_BENCHMARK) {
if (++i == refill_per_benchmark) {
rate = buffer_size * sample_size *
REFILL_PER_BENCHMARK * 1000000ull / total;
refill_per_benchmark * 1000000ull / total;
mib = rate > 1048576;

fprintf(stderr, "\33[2K\rThroughput: %" PRIu64 " %ciB/s",
rate / (1024 * (mib ? 1024 : 1)),
mib ? 'M' : 'K');

/* Print every 100ms more or less */
refill_per_benchmark = refill_per_benchmark * 100000 / total;
if (refill_per_benchmark < REFILL_PER_BENCHMARK)
refill_per_benchmark = REFILL_PER_BENCHMARK;

i = 0;
total = 0;
}
Expand Down

0 comments on commit 81b7802

Please sign in to comment.