Skip to content

Commit 81b7802

Browse files
committed
iio_readdev/iio_writedev: Refresh benchmark values at ~10 Hz
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 <[email protected]>
1 parent 1b88be0 commit 81b7802

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

tests/iio_readdev.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ int main(int argc, char **argv)
198198
unsigned int i, nb_channels;
199199
unsigned int nb_active_channels = 0;
200200
unsigned int buffer_size = SAMPLES_PER_READ;
201+
unsigned int refill_per_benchmark = REFILL_PER_BENCHMARK;
201202
int c;
202203
struct iio_device *dev;
203204
ssize_t sample_size;
@@ -400,15 +401,20 @@ int main(int argc, char **argv)
400401
after = get_time_us();
401402
total += after - before;
402403

403-
if (++i == REFILL_PER_BENCHMARK) {
404+
if (++i == refill_per_benchmark) {
404405
rate = buffer_size * sample_size *
405-
REFILL_PER_BENCHMARK * 1000000ull / total;
406+
refill_per_benchmark * 1000000ull / total;
406407
mib = rate > 1048576;
407408

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

413+
/* Print every 100ms more or less */
414+
refill_per_benchmark = refill_per_benchmark * 100000 / total;
415+
if (refill_per_benchmark < REFILL_PER_BENCHMARK)
416+
refill_per_benchmark = REFILL_PER_BENCHMARK;
417+
412418
i = 0;
413419
total = 0;
414420
}

tests/iio_writedev.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ int main(int argc, char **argv)
209209
unsigned int i, nb_channels;
210210
unsigned int nb_active_channels = 0;
211211
unsigned int buffer_size = SAMPLES_PER_READ;
212+
unsigned int refill_per_benchmark = REFILL_PER_BENCHMARK;
212213
int c;
213214
struct iio_device *dev;
214215
ssize_t sample_size;
@@ -445,15 +446,20 @@ int main(int argc, char **argv)
445446
after = get_time_us();
446447
total += after - before;
447448

448-
if (++i == REFILL_PER_BENCHMARK) {
449+
if (++i == refill_per_benchmark) {
449450
rate = buffer_size * sample_size *
450-
REFILL_PER_BENCHMARK * 1000000ull / total;
451+
refill_per_benchmark * 1000000ull / total;
451452
mib = rate > 1048576;
452453

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

458+
/* Print every 100ms more or less */
459+
refill_per_benchmark = refill_per_benchmark * 100000 / total;
460+
if (refill_per_benchmark < REFILL_PER_BENCHMARK)
461+
refill_per_benchmark = REFILL_PER_BENCHMARK;
462+
457463
i = 0;
458464
total = 0;
459465
}

0 commit comments

Comments
 (0)