]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
meson: bench - compile and run
authorTomas Krizek <tomas.krizek@nic.cz>
Thu, 14 Feb 2019 16:08:43 +0000 (17:08 +0100)
committerTomas Krizek <tomas.krizek@nic.cz>
Tue, 12 Mar 2019 09:43:30 +0000 (10:43 +0100)
bench/bench.mk [deleted file]
bench/bench_lru.c
bench/meson.build [new file with mode: 0644]
meson.build
meson_options.txt
scripts/bench.sh [new file with mode: 0755]

diff --git a/bench/bench.mk b/bench/bench.mk
deleted file mode 100644 (file)
index e010039..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-bench_BIN := \
-       bench_lru
-
-# Dependencies
-bench_DEPEND := $(libkres)
-bench_LIBS :=  $(libkres_TARGET) $(libkres_LIBS)
-
-# Make bench binaries
-define make_bench
-$(1)_CFLAGS := -fPIE
-$(1)_SOURCES := bench/$(1).c
-$(1)_LIBS := $(bench_LIBS)
-$(1)_DEPEND := $(bench_DEPEND)
-$(call make_bin,$(1),bench)
-endef
-
-$(foreach bench,$(bench_BIN),$(eval $(call make_bench,$(bench))))
-
-# Targets
-.PHONY: bench bench-clean
-bench-clean: $(foreach bench,$(bench_BIN),$(bench)-clean)
-bench: $(foreach bench,$(bench_BIN),bench/$(bench))
-       @echo "Test LRU with increasing overfill, misses should increase ~ linearly" >&2
-       $(preload_syms) ./bench/bench_lru 23 bench/bench_lru_set1.tsv - 65536 # fill ~ 1
-       $(preload_syms) ./bench/bench_lru 23 bench/bench_lru_set1.tsv - 32768 # fill ~ 2
-       $(preload_syms) ./bench/bench_lru 23 bench/bench_lru_set1.tsv - 16384 # fill ~ 4
-       $(preload_syms) ./bench/bench_lru 23 bench/bench_lru_set1.tsv - 8192  # fill ~ 8
-       $(preload_syms) ./bench/bench_lru 23 bench/bench_lru_set1.tsv - 4096  # fill ~ 16
index 63bbeebdbfa5568ebb836bc1a67c9672a45720b7..237be669387431a0c023a80f90fa58b1d96fb43a 100644 (file)
@@ -33,6 +33,10 @@ typedef kr_nsrep_lru_t lru_bench_t;
        } while (0)
 #define p_err(...) fprintf(stderr, __VA_ARGS__)
 
+#ifndef LRU_RTT_SIZE
+#define LRU_RTT_SIZE 65536 /**< NS RTT cache size */
+#endif
+
 static int die(const char *cause)
 {
        fprintf(stderr, "%s: %s\n", cause, strerror(errno));
diff --git a/bench/meson.build b/bench/meson.build
new file mode 100644 (file)
index 0000000..2d466ab
--- /dev/null
@@ -0,0 +1,23 @@
+# bench
+
+bench_lru_src = [
+  'bench_lru.c',
+]
+
+cc = meson.get_compiler('c')
+m_dep = cc.find_library('m', required : false)
+
+bench_lru = executable(
+  'bench_lru',
+  bench_lru_src,
+  dependencies: [
+    contrib_dep,
+    libkres_dep,
+    m_dep,
+  ],
+)
+
+run_target(
+  'bench',
+  command: '../scripts/bench.sh',
+)
index c5a4f2ed74ddac565f0e030c05312243cf514fd9..e715e419d42b3c8922d1dacf26e766c1dc72c446 100644 (file)
@@ -163,6 +163,9 @@ subdir('lib')
 subdir('client')
 subdir('daemon')
 subdir('modules')
+if get_option('bench').enabled()
+  subdir('bench')
+endif
 
 
 # Tests
index f92d4ea601b82184cdae79e479dd5f4b59b03f37..3476f3b8f57411eeb962b8b59c18e1c68a1475ca 100644 (file)
@@ -63,6 +63,13 @@ option(
 
 
 # Component options
+option(
+  'bench',
+  type: 'feature',
+  value: 'disabled',
+  description: 'build benchmarks'
+)
+
 option(
   'client',
   type: 'feature',
diff --git a/scripts/bench.sh b/scripts/bench.sh
new file mode 100755 (executable)
index 0000000..458907e
--- /dev/null
@@ -0,0 +1,11 @@
+#!/bin/bash
+set -o errexit -o nounset
+
+# Run benchmark
+cd "${MESON_SOURCE_ROOT}"
+
+echo "Test LRU with increasing overfill, misses should increase ~ linearly"
+
+for num in 65536 32768 16384 8192 4096; do
+    "${MESON_BUILD_ROOT}/${MESON_SUBDIR}/bench_lru" 23 "${MESON_SOURCE_ROOT}/${MESON_SUBDIR}/bench_lru_set1.tsv" - "${num}"
+done