[test-suite] r209732 - Use perf tool for more accurate time measuring on Linux

Yi Kong Yi.Kong at arm.com
Wed May 28 06:01:23 PDT 2014


Author: kongyi
Date: Wed May 28 08:01:23 2014
New Revision: 209732

URL: http://llvm.org/viewvc/llvm-project?rev=209732&view=rev
Log:
Use perf tool for more accurate time measuring on Linux

A wrapper over Linux perf tool which mimics original timeit tool to provide
more accurate time measurements on Linux systems. It automatically falls back
to timeit if any dependency is not installed.

Added:
    test-suite/trunk/tools/timeit.sh
Modified:
    test-suite/trunk/tools/Makefile

Modified: test-suite/trunk/tools/Makefile
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/tools/Makefile?rev=209732&r1=209731&r2=209732&view=diff
==============================================================================
--- test-suite/trunk/tools/Makefile (original)
+++ test-suite/trunk/tools/Makefile Wed May 28 08:01:23 2014
@@ -8,8 +8,17 @@ ifndef USER_MODE_EMULATION
 all:: timeit-target
 endif
 
+ifeq ($(TARGET_OS),Linux)
+all:: ctimeit
+timeit: timeit.sh
+	cp -f $< $@
+	chmod u+x $@
+ctimeit: timeit.c
+	$(ORIGINAL_CC) $(CFLAGS) -O3 -o $@ $<
+else
 timeit: timeit.c
 	$(ORIGINAL_CC) $(CFLAGS) -O3 -o $@ $<
+endif
 
 timeit-target: timeit.c
 	$(LD_ENV_OVERRIDES) $(LCC) -o $@ $< $(LDFLAGS) $(CFLAGS) $(TARGET_FLAGS) -O3

Added: test-suite/trunk/tools/timeit.sh
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/tools/timeit.sh?rev=209732&view=auto
==============================================================================
--- test-suite/trunk/tools/timeit.sh (added)
+++ test-suite/trunk/tools/timeit.sh Wed May 28 08:01:23 2014
@@ -0,0 +1,38 @@
+#! /bin/bash
+# A wrapper over perf to provide similar functionality to timeit.c
+
+DEPENDS="perf schedtool"
+
+# Fallback to ctimeit if dependencies are not met
+for cmd in ${DEPENDS} ; do
+	if ! command -v ${cmd} &> /dev/null ; then
+		./ctimeit $@
+		exit $?
+	fi
+done
+
+REPORT=/dev/stderr
+INPUT=/dev/stdin
+OUTPUT=/dev/stdout
+
+while [[ $1 = -* ]]; do
+	if [ $1 = "--summary" ]; then
+		REPORT=$2
+	elif [ $1 = "--redirect-input" ]; then
+		INPUT=$2
+	elif [ $1 = "--redirect-output" ]; then
+		OUTPUT=$2
+	fi
+	shift 2
+done
+
+perf stat -o stats schedtool -a 0x1 -e $@ < $INPUT > $OUTPUT
+
+EXITCODE=$?
+
+echo exit $EXITCODE > $REPORT
+awk -F' ' '{if ($2 == "task-clock") print "user",$1/1000; else if($2 =="seconds") print "real",$1;}' stats >> $REPORT
+
+rm stats
+
+exit $EXITCODE





More information about the llvm-commits mailing list