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.
This commit is contained in:
Vadim Yanitskiy 2017-09-04 04:18:06 +07:00
parent 72218e7da0
commit cda8995ac8
3 changed files with 60 additions and 17 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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];
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, total, bc->enc_used,
total / bc->enc_used);
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];
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, total, bc->dec_used,
total / bc->dec_used);
fprintf(stderr, "Codec %u (DEC): %llu cycles for %u frames"
" => %llu cycles/frame\n", i, cycles,
frames, cycles / frames);
}
}
}