From d5b2d62b201aaf8f4698fdc0a9514bf50bb5d280 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Tue, 13 Sep 2011 15:06:21 -0700 Subject: [PATCH] Add build-system mechanisms for running benchmarks under 'perf'. --- Makefile.in | 6 ++++++ configure | 4 +++- mk/perf.mk | 1 + mk/platform.mk | 29 +++++++++++++++++++++++++++++ mk/tests.mk | 26 +++++++++++++++++++++++++- 5 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 mk/perf.mk diff --git a/Makefile.in b/Makefile.in index dbd98a31c00f..bdb55e1c574b 100644 --- a/Makefile.in +++ b/Makefile.in @@ -271,11 +271,17 @@ endif ifneq ($(strip $(findstring check,$(MAKECMDGOALS)) \ $(findstring test,$(MAKECMDGOALS)) \ + $(findstring perf,$(MAKECMDGOALS)) \ $(findstring tidy,$(MAKECMDGOALS))),) CFG_INFO := $(info cfg: including test rules) include $(CFG_SRC_DIR)/mk/tests.mk endif +ifneq ($(findstring perf,$(MAKECMDGOALS)),) + CFG_INFO := $(info cfg: including perf rules) + include $(CFG_SRC_DIR)/mk/perf.mk +endif + ifneq ($(findstring clean,$(MAKECMDGOALS)),) CFG_INFO := $(info cfg: including clean rules) include $(CFG_SRC_DIR)/mk/clean.mk diff --git a/configure b/configure index c1474edb0d7c..f6b6d8f5c4a3 100755 --- a/configure +++ b/configure @@ -183,7 +183,8 @@ for i in \ rustllvm \ dl stage0 stage1 stage2 stage3 \ stage0/lib stage1/lib stage2/lib stage3/lib \ - test/run-pass test/run-fail test/compile-fail test/bench test/pretty + test/run-pass test/run-fail test/compile-fail \ + test/bench test/perf test/pretty do make_dir $i done @@ -205,6 +206,7 @@ probe CFG_CLANG clang++ probe CFG_GCC gcc probe CFG_LLVM_CONFIG llvm-config probe CFG_VALGRIND valgrind +probe CFG_PERF perf probe CFG_MAKEINFO makeinfo probe CFG_TEXI2PDF texi2pdf probe CFG_TEX tex diff --git a/mk/perf.mk b/mk/perf.mk new file mode 100644 index 000000000000..9e7ffc6d665b --- /dev/null +++ b/mk/perf.mk @@ -0,0 +1 @@ +perf: check-stage2-perf diff --git a/mk/platform.mk b/mk/platform.mk index a647e9cb3c55..c7cd36331fb0 100644 --- a/mk/platform.mk +++ b/mk/platform.mk @@ -34,6 +34,35 @@ ifeq ($(CFG_OSTYPE), Linux) CFG_UNIXY := 1 CFG_LDENV := LD_LIBRARY_PATH CFG_DEF_SUFFIX := .linux.def + ifdef CFG_PERF + CFG_PERF_TOOL :=\ + $(CFG_PERF) \ + stat \ + -e cycles \ + -e instructions \ + -e cache-references \ + -e cache-misses \ + -e branches \ + -e branch-misses \ + -e bus-cycles \ + -e task-clock \ + -e page-faults \ + -e context-switches \ + -e cpu-migrations \ + -e kmem:mm_page_alloc \ + -e syscalls:sys_enter \ + -e sched:sched_switch \ + -e fs:do_sys_open \ + -i \ + -r 10 + else + ifdef CFG_VALGRIND + CFG_PERF_TOOL :=\ + $(CFG_VALGRIND) --tool=cachegrind --cache-sim=yes --branch-sim=yes + else + CFG_PERF_TOOL := /usr/bin/time --verbose + endif + endif endif ifeq ($(CFG_OSTYPE), Darwin) diff --git a/mk/tests.mk b/mk/tests.mk index c99a8cc61d29..6b28c16b2d13 100644 --- a/mk/tests.mk +++ b/mk/tests.mk @@ -15,10 +15,15 @@ CFAIL_RS := $(wildcard $(S)src/test/compile-fail/*.rs) BENCH_RS := $(wildcard $(S)src/test/bench/*.rs) PRETTY_RS := $(wildcard $(S)src/test/pretty/*.rs) +# perf tests are the same as bench tests only they run under +# a performance monitor. +PERF_RS := $(wildcard $(S)src/test/bench/*.rs) + RPASS_TESTS := $(RPASS_RC) $(RPASS_RS) RFAIL_TESTS := $(RFAIL_RC) $(RFAIL_RS) CFAIL_TESTS := $(CFAIL_RC) $(CFAIL_RS) BENCH_TESTS := $(BENCH_RS) +PERF_TESTS := $(PERF_RS) PRETTY_TESTS := $(PRETTY_RS) FT := run_pass_stage2 @@ -40,6 +45,11 @@ ifdef CFG_VALGRIND CTEST_RUNTOOL = --runtool "$(CFG_VALGRIND)" endif +# Arguments to the perf tests +ifdef CFG_PERF_TOOL + CTEST_PERF_RUNTOOL = --runtool "$(CFG_PERF_TOOL)" +endif + CTEST_TESTARGS := $(TESTARGS) ifdef VERBOSE @@ -150,7 +160,7 @@ test/rustctest.stage$(2).out.tmp: test/rustctest.stage$(2)$$(X) $$(Q)touch $$@ -# Rules for the cfail/rfail/rpass/bench test runner +# Rules for the cfail/rfail/rpass/bench/perf test runner check-stage$(2)-cfail: test/compile-fail.stage$(2).out \ @@ -160,6 +170,8 @@ check-stage$(2)-rpass: test/run-pass.stage$(2).out \ check-stage$(2)-bench: test/bench.stage$(2).out \ +check-stage$(2)-perf: test/perf.stage$(2).out \ + check-stage$(2)-pretty-rpass: test/pretty-rpass.stage$(2).out \ check-stage$(2)-pretty-rfail: test/pretty-rfail.stage$(2).out \ @@ -203,6 +215,12 @@ BENCH_ARGS$(2) := $$(CTEST_COMMON_ARGS$(2)) \ --mode run-pass \ $$(CTEST_RUNTOOL) \ +PERF_ARGS$(2) := $$(CTEST_COMMON_ARGS$(2)) \ + --src-base $(S)src/test/bench/ \ + --build-base test/perf/ \ + --mode run-pass \ + $$(CTEST_PERF_RUNTOOL) \ + PRETTY_RPASS_ARGS$(2) := $$(CTEST_COMMON_ARGS$(2)) \ --src-base $$(S)src/test/run-pass/ \ --build-base test/run-pass/ \ @@ -253,6 +271,12 @@ test/bench.stage$(2).out.tmp: test/compiletest.stage$(2)$$(X) \ $$(Q)$$(call CFG_RUN_CTEST,$(2),$$<) $$(BENCH_ARGS$(2)) $$(Q)touch $$@ +test/perf.stage$(2).out.tmp: test/compiletest.stage$(2)$$(X) \ + $$(BENCH_TESTS) + @$$(call E, perf: $$<) + $$(Q)$$(call CFG_RUN_CTEST,$(2),$$<) $$(PERF_ARGS$(2)) + $$(Q)touch $$@ + test/pretty-rpass.stage$(2).out.tmp: test/compiletest.stage$(2)$$(X) \ $$(RPASS_TESTS) @$$(call E, run: $$<)