diff options
author | Vadim Yanitskiy <axilirator@gmail.com> | 2017-09-04 04:18:06 +0700 |
---|---|---|
committer | Vadim Yanitskiy <axilirator@gmail.com> | 2017-12-31 12:20:59 +0100 |
commit | cda8995ac8a17cc1d579f73519fd5b0f2429675a (patch) | |
tree | 351dc406ecab00db2e22938e8ce86a2f499e7431 /src | |
parent | 72218e7da04783222f04492d939268ac40585027 (diff) |
benchmark: add functions to get cycle and frame count
To simplify the benchrarking process via the library API, this
change introduces two new functions, which are intended to
provide total cycle and frame count.
Diffstat (limited to 'src')
-rw-r--r-- | src/benchmark.c | 36 | ||||
-rw-r--r-- | src/main.c | 40 |
2 files changed, 57 insertions, 19 deletions
diff --git a/src/benchmark.c b/src/benchmark.c index 8896a3b..e9637b1 100644 --- a/src/benchmark.c +++ b/src/benchmark.c @@ -43,6 +43,42 @@ int osmo_gapk_bench_enable(enum osmo_gapk_codec_type codec) return 0; } +unsigned long long +osmo_gapk_bench_get_cycles(enum osmo_gapk_codec_type codec, int enc) +{ + struct osmo_gapk_bench_cycles *bench; + unsigned long long cycles = 0; + int i; + + /* Check if there are benchmark data */ + bench = osmo_gapk_bench_codec[codec]; + if (!bench) + return -EAGAIN; + + if (enc) { + for (i = 0; i < bench->enc_used; i++) + cycles += bench->enc[i]; + } else { + for (i = 0; i < bench->dec_used; i++) + cycles += bench->dec[i]; + } + + return cycles; +} + +unsigned int +osmo_gapk_bench_get_frames(enum osmo_gapk_codec_type codec, int enc) +{ + struct osmo_gapk_bench_cycles *bench; + + /* Check if there are benchmark data */ + bench = osmo_gapk_bench_codec[codec]; + if (!bench) + return -EAGAIN; + + return enc ? bench->enc_used : bench->dec_used; +} + void osmo_gapk_bench_free(void) { int i; @@ -313,32 +313,34 @@ check_options(struct gapk_state *gs) static void benchmark_dump(void) { - int i, j; + int i; for (i = 0; i < _CODEC_MAX; i++) { - struct osmo_gapk_bench_cycles *bc = osmo_gapk_bench_codec[i]; - unsigned long long total; + struct osmo_gapk_bench_cycles *bc; + unsigned long long cycles; + unsigned int frames; + + /* Check if there are benchmark data */ + bc = osmo_gapk_bench_codec[i]; + if (!bc) + continue; if (bc->enc_used) { - total = 0; - for (j = 0; j < bc->enc_used; j++) - total += bc->enc[j]; - - fprintf(stderr, - "Codec %u (ENC): %llu cycles for %u frames => " - "%llu cycles/frame\n", i, total, bc->enc_used, - total / bc->enc_used); + cycles = osmo_gapk_bench_get_cycles(i, 1); + frames = osmo_gapk_bench_get_frames(i, 1); + + fprintf(stderr, "Codec %u (ENC): %llu cycles for %u frames" + " => %llu cycles/frame\n", i, cycles, + frames, cycles / frames); } if (bc->dec_used) { - total = 0; - for (j = 0; j < bc->dec_used; j++) - total += bc->dec[j]; - - fprintf(stderr, - "Codec %u (DEC): %llu cycles for %u frames => " - "%llu cycles/frame\n", i, total, bc->dec_used, - total / bc->dec_used); + cycles = osmo_gapk_bench_get_cycles(i, 0); + frames = osmo_gapk_bench_get_frames(i, 0); + + fprintf(stderr, "Codec %u (DEC): %llu cycles for %u frames" + " => %llu cycles/frame\n", i, cycles, + frames, cycles / frames); } } } |