diff options
author | Vadim Yanitskiy <axilirator@gmail.com> | 2017-09-04 03:33:48 +0700 |
---|---|---|
committer | Vadim Yanitskiy <axilirator@gmail.com> | 2017-12-31 12:20:59 +0100 |
commit | 72218e7da04783222f04492d939268ac40585027 (patch) | |
tree | a215de5bb42f75c5b37a88fe1bc20c5b9acd3c30 /src | |
parent | c9a75e59c67d62bc9d64c8c110ef47feb60e7ebf (diff) |
benchmark: allocate memory dynamically
Having statically allocated memory for benchmark data of every
codec causes high memory usage, especially if actual benchmarking
is not required for a particular use case. Instead of that, let's
provide an optional opportunity to enable benchmarking for a
particular codec by calling the osmo_gapk_bench_enable(). The
required amount of memory would be allocated, and then can be
freed by calling the osmo_gapk_bench_free() or manually.
Diffstat (limited to 'src')
-rw-r--r-- | src/benchmark.c | 30 | ||||
-rw-r--r-- | src/main.c | 11 |
2 files changed, 39 insertions, 2 deletions
diff --git a/src/benchmark.c b/src/benchmark.c index 3dead5a..8896a3b 100644 --- a/src/benchmark.c +++ b/src/benchmark.c @@ -18,7 +18,35 @@ */ #include <stdio.h> +#include <errno.h> +#include <stdlib.h> #include <osmocom/gapk/benchmark.h> +#include <osmocom/gapk/codecs.h> -struct osmo_gapk_bench_cycles osmo_gapk_bench_codec[_CODEC_MAX]; +struct osmo_gapk_bench_cycles * + osmo_gapk_bench_codec[_CODEC_MAX] = { NULL }; + +int osmo_gapk_bench_enable(enum osmo_gapk_codec_type codec) +{ + struct osmo_gapk_bench_cycles *bench; + + /* Allocate zero-initialized memory */ + bench = (struct osmo_gapk_bench_cycles *) + calloc(1, sizeof(struct osmo_gapk_bench_cycles)); + if (!bench) + return -ENOMEM; + + /* Set up pointer */ + osmo_gapk_bench_codec[codec] = bench; + + return 0; +} + +void osmo_gapk_bench_free(void) +{ + int i; + + for (i = 0; i < _CODEC_MAX; i++) + free(osmo_gapk_bench_codec[i]); +} @@ -316,7 +316,7 @@ benchmark_dump(void) int i, j; for (i = 0; i < _CODEC_MAX; i++) { - struct osmo_gapk_bench_cycles *bc = &osmo_gapk_bench_codec[i]; + struct osmo_gapk_bench_cycles *bc = osmo_gapk_bench_codec[i]; unsigned long long total; if (bc->enc_used) { @@ -498,6 +498,9 @@ make_processing_chain(struct gapk_state *gs) /* Do decoding */ osmo_gapk_pq_queue_codec(gs->pq, codec_in, 0); + + /* Allocate memory for benchmarking */ + osmo_gapk_bench_enable(fmt_in->codec_type); } else if (fmt_in->type != fmt_out->type) { @@ -511,6 +514,9 @@ make_processing_chain(struct gapk_state *gs) /* Do encoding */ osmo_gapk_pq_queue_codec(gs->pq, codec_out, 1); + /* Allocate memory for benchmarking */ + osmo_gapk_bench_enable(fmt_out->codec_type); + /* Convert encoder output to output fmt */ if (fmt_out->type != codec_out->codec_enc_format_type) { @@ -649,6 +655,9 @@ error: osmo_gapk_pq_destroy(gs->pq); benchmark_dump(); + + /* Free memory taken by benchmark data */ + osmo_gapk_bench_free(); return rv; } |