aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2017-09-04 04:18:06 +0700
committerVadim Yanitskiy <axilirator@gmail.com>2017-09-04 04:37:21 +0700
commitf72d01558f16717d49380428310d1a269f8540c6 (patch)
treecac545ae172bf50eba2c9f136170cdda1d49e6b8
parentea53827e34b3d223c053289f7ef39f3105712a18 (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.
-rw-r--r--include/osmocom/gapk/benchmark.h5
-rw-r--r--src/benchmark.c36
-rw-r--r--src/main.c40
3 files changed, 62 insertions, 19 deletions
diff --git a/include/osmocom/gapk/benchmark.h b/include/osmocom/gapk/benchmark.h
index cce7076..f87899d 100644
--- a/include/osmocom/gapk/benchmark.h
+++ b/include/osmocom/gapk/benchmark.h
@@ -35,3 +35,8 @@ extern struct osmo_gapk_bench_cycles *osmo_gapk_bench_codec[_CODEC_MAX];
int osmo_gapk_bench_enable(enum osmo_gapk_codec_type codec);
void osmo_gapk_bench_free(void);
+
+unsigned long long
+osmo_gapk_bench_get_cycles(enum osmo_gapk_codec_type codec, int enc);
+unsigned int
+osmo_gapk_bench_get_frames(enum osmo_gapk_codec_type codec, int enc);
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;
diff --git a/src/main.c b/src/main.c
index 623926f..3596ec1 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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);
}
}
}