50f89d
objpfx = $(prefix)/$(ver)/usr/libexec/glibc-benchtests/
50f89d
50f89d
bench-math := acos acosh asin asinh atan atanh cos cosh exp exp2 ffs ffsll \
50f89d
	      log log2 modf pow rint sin sincos sinh sqrt tan tanh
50f89d
50f89d
bench-pthread := pthread_once
50f89d
50f89d
bench := $(bench-math) $(bench-pthread)
50f89d
50f89d
run-bench := $(prefix)/$(ver)/lib64/ld-linux-x86-64.so.2 --library-path $(prefix)/$(ver)/lib64 $${run}
50f89d
50f89d
# String function benchmarks.
50f89d
string-bench := bcopy bzero memccpy memchr memcmp memcpy memmem memmove \
50f89d
		mempcpy memset rawmemchr stpcpy stpncpy strcasecmp strcasestr \
50f89d
		strcat strchr strchrnul strcmp strcpy strcspn strlen \
50f89d
		strncasecmp strncat strncmp strncpy strnlen strpbrk strrchr \
50f89d
		strspn strstr strcpy_chk stpcpy_chk memrchr strsep strtok
50f89d
string-bench-all := $(string-bench)
50f89d
50f89d
stdlib-bench := strtod
50f89d
50f89d
benchset := $(string-bench-all) $(stdlib-bench)
50f89d
50f89d
bench-malloc := malloc-thread
50f89d
50f89d
binaries-bench := $(addprefix $(objpfx)bench-,$(bench))
50f89d
binaries-benchset := $(addprefix $(objpfx)bench-,$(benchset))
50f89d
binaries-bench-malloc := $(addprefix $(objpfx)bench-,$(bench-malloc))
50f89d
50f89d
DETAILED_OPT :=
50f89d
50f89d
ifdef DETAILED
50f89d
	DETAILED_OPT := -d
50f89d
endif
50f89d
50f89d
bench: bench-set bench-func bench-malloc
50f89d
50f89d
bench-set: $(binaries-benchset)
50f89d
	for run in $^; do \
50f89d
	  outfile=$(prefix)/$$(basename $${run}.$(ver).out); \
50f89d
	  echo "Running $${run}"; \
50f89d
	  $(run-bench) > $${outfile}.tmp; \
50f89d
	  mv $${outfile}{.tmp,}; \
50f89d
	done
50f89d
50f89d
bench-malloc: $(binaries-bench-malloc)
50f89d
	run=$(objpfx)bench-malloc-thread; \
50f89d
	outfile=$(prefix)/$$(basename $${run}.$(ver).out); \
50f89d
	for thr in 1 8 16 32; do \
50f89d
	  echo "Running $${run} $${thr}"; \
50f89d
	  $(run-bench) $${thr} > $${outfile}.tmp; \
50f89d
	  mv $${outfile}{.tmp,}; \
50f89d
	done
50f89d
50f89d
# Build and execute the benchmark functions.  This target generates JSON
50f89d
# formatted bench.out.  Each of the programs produce independent JSON output,
50f89d
# so one could even execute them individually and process it using any JSON
50f89d
# capable language or tool.
50f89d
bench-func: $(binaries-bench)
50f89d
	{ echo "{\"timing_type\": \"hp-timing\","; \
50f89d
	echo " \"functions\": {"; \
50f89d
	for run in $^; do \
50f89d
	  if ! [ "x$${run}" = "x$<" ]; then \
50f89d
	    echo ","; \
50f89d
	  fi; \
50f89d
	  echo "Running $${run}" >&2; \
50f89d
	  $(run-bench) $(DETAILED_OPT); \
50f89d
	done; \
50f89d
	echo; \
50f89d
	echo " }"; \
50f89d
	echo "}"; } > $(prefix)/bench.$(ver).out-tmp; \
50f89d
	if [ -f $(prefix)/bench.$(ver).out ]; then \
50f89d
	  mv -f $(prefix)/bench.$(ver).out{,.old}; \
50f89d
	fi; \
50f89d
	mv -f $(prefix)/bench.$(ver).out{-tmp,}
50f89d
#	scripts/validate_benchout.py bench.out \
50f89d
#		scripts/benchout.schema.json