From 8693ed7da803326faf147904a6c220b96cc8aacc Mon Sep 17 00:00:00 2001
From: Ralf Jung <post@ralfj.de>
Date: Thu, 21 Jun 2018 11:03:00 +0200
Subject: [PATCH] collect timing information using perf

---
 buildjob | 13 ++++++++-----
 perf     |  8 ++++++++
 2 files changed, 16 insertions(+), 5 deletions(-)
 create mode 100755 perf

diff --git a/buildjob b/buildjob
index 2ab2088..ad4036f 100755
--- a/buildjob
+++ b/buildjob
@@ -26,16 +26,16 @@ set -o pipefail
 . ci/prepare-opam.sh $OPAM_PINS # deliberately not quoted
 env | egrep '^(CI_BUILD_REF|CI_RUNNER)' > build-env.txt
 
-# maybe set some coq flags
 if [[ -n "$MANGLE_NAMES" ]]; then
     export COQEXTRAFLAGS="$COQEXTRAFLAGS -mangle-names mangled_"
 fi
+if [[ -n "$TIMING_PROJECT" ]]; then
+    export TIMECMD=ci/perf
+fi
 
 # Build
 echo_color "$BOLDGREEN" "[buildjob] Perfoming build"
-time make --output-sync --no-print-directory -k -j$CPU_CORES TIMED=y 2>&1 | tee build-log.txt
-echo_color "$BOLDGREEN" "[buildjob] Build time summary"
-cat build-log.txt | egrep "(real|user): [0-9]" | tee build-time.txt
+time make --output-sync --no-print-directory -k -j$CPU_CORES 2>&1
 
 # maybe check for axioms
 if [[ -z "$AXIOMS_IGNORE" ]]; then
@@ -53,6 +53,9 @@ if [[ -n "$TIMING_PROJECT" && -n "$TIMING_CONF" ]]; then
         echo_color "$BOLDRED" "[buildjob] TIMING_SECRET variable is missing"
         exit 1
     fi
+    # collect all information into one file
+    find -name "*.v.perf" -print0 | xargs -0 cat > build-times.txt
+    cat build-times.txt
     # Submit to webhook endpoint
     curl --fail -sS -X POST https://coq-speed.mpi-sws.org/webhook/build_times \
          --user "$TIMING_SECRET" \
@@ -61,7 +64,7 @@ if [[ -n "$TIMING_PROJECT" && -n "$TIMING_CONF" ]]; then
          -H "X-Branch: $CI_COMMIT_REF_NAME" \
          -H "X-Config: $TIMING_CONF" \
          -H "X-Date: $(git show $CI_COMMIT_SHA -s --pretty=%cI)" \
-         --data-binary @- < build-time.txt
+         --data-binary @- < build-times.txt
 fi
 
 # maybe create opam package
diff --git a/perf b/perf
new file mode 100755
index 0000000..6cd60e4
--- /dev/null
+++ b/perf
@@ -0,0 +1,8 @@
+#!/bin/bash
+set -e
+# Wrapper script to use perf as TIMECMD for the build.
+
+VFILE="${!#}"
+perf stat -o "$VFILE.perf.tmp" -x ';' -e instructions,cycles -- "$@"
+(echo "## $VFILE" && (cat "$VFILE.perf.tmp" | egrep -v '^(# .*)?$') && echo) > "$VFILE.perf"
+rm "$VFILE.perf.tmp"
-- 
GitLab