aboutsummaryrefslogtreecommitdiffstats
path: root/src/benchmark.c
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2017-09-04 03:33:48 +0700
committerVadim Yanitskiy <axilirator@gmail.com>2017-09-04 04:37:21 +0700
commitea53827e34b3d223c053289f7ef39f3105712a18 (patch)
tree371262962cd6c897b9b8e4d322c0eed32edf9319 /src/benchmark.c
parent36e92c49c510711bd7e88beb2935a2a298def9fe (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/benchmark.c')
-rw-r--r--src/benchmark.c30
1 files changed, 29 insertions, 1 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]);
+}