#!/bin/bash # Script to format benchmarks results into a single xml file. # See https://wiki.jenkins-ci.org/display/JENKINS/PerfPublisher+Plugin # ----- # 2014/11/17 - Written by AB XMLFILE=$1 benchmarks=$2 COMPILER=$3 # choose gdate on OS X if command -v "gdate" >/dev/null; then DATE=gdate else DATE=date fi #=================# # Plateform infos # #=================# COMPILERVERSION=$($COMPILER --version 2>&1 | head -1) if command -v "lscpu" >/dev/null; then CPUFREQ=$(lscpu | grep "MHz" | rev | cut -f1 -d' ' | rev) else CPUFREQ=$((`sysctl -n hw.cpufrequency`/1000000)) fi ARCH=$(uname -m) OSNAME=$(uname -s) OSVERSION=$(uname -r) if hash lsb_release 2>/dev/null then DISTRIB=$(lsb_release -ds) else DISTRIB='Unknown distribution' fi #==========# # Prologue # #==========# if [[ -f $XMLFILE ]] then echo '----> WARNING: File '$XMLFILE' is not empty.' echo '----> Results will be added to its end.' fi #========# # Header # #========# echo '' >> $XMLFILE echo '' >> $XMLFILE #=======# # Start # #=======# echo '' >> $XMLFILE echo '' >> $XMLFILE echo '' >> $XMLFILE #============# # Benchmarks # #============# for benchmark in $benchmarks do if [[ ! -f $benchmark ]] then #File does not exist: compile it echo '[Compiling]' $benchmark COMPILESTART=$($DATE +%s%3N) COMPILELOG=$(make $benchmark 2>&1; echo 'Returned state: '$?) COMPILEEND=$($DATE +%s%3N) COMPILETIME=$(($COMPILEEND - $COMPILESTART)) COMPILECHECK=$(echo $COMPILELOG | grep -o '[^ ]*$') COMPILETIMERELEVANT='true' else #File does exist echo '[Already compiled]' $benchmark COMPILELOG='(Previously compiled)' COMPILETIME='0.0' COMPILECHECK='0' COMPILETIMERELEVANT='false' fi if [[ $COMPILECHECK -ne 0 ]] then #Compilation failure # EXECUTED='no' - keep it to yes so that Jenkins # uses it within its results EXECUTED='yes' PASSED='no' STATE='0' EXECUTIONLOG='(Not executed)' EXECUTIONTIME='0.0' PERFORMANCEFLOPS='0.0' COMPILETIMERELEVANT='false' EXECUTIONTIMERELEVANT='false' PERFORMANCEFLOPSRELEVANT='false' ERRORLOG='Does not compile.' echo '-> Does not compile.' else #Compilation success echo '[Executing]' $benchmark EXECUTED='yes' EXECUTIONLOG=$(./$benchmark 2>&1) if [[ ${EXECUTIONLOG} != "Time:"* ]] then #Execution failure PASSED='no' STATE='0' EXECUTIONTIME='0.0' PERFORMANCEFLOPS='0.0' EXECUTIONTIMERELEVANT='false' PERFORMANCEFLOPSRELEVANT='false' ERRORLOG='Unexpected output.' echo '-> Unexpected output.' else #Execution success PASSED='yes' STATE='100' EXECUTIONTIME=$(echo $EXECUTIONLOG | cut -d' ' -f2) PERFORMANCEFLOPS=$(echo $EXECUTIONLOG | cut -d' ' -f4) EXECUTIONTIMERELEVANT='true' if [[ ${PERFORMANCEFLOPS} != "Irrelevant" ]] then PERFORMANCEFLOPSRELEVANT='true' else PERFORMANCEFLOPSRELEVANT='false' PERFORMANCEFLOPS='0.0' fi ERRORLOG='' fi fi echo '' >> $XMLFILE echo 'BENCHMARK' >> $XMLFILE echo '' >> $XMLFILE echo '' >> $XMLFILE echo '' >> $XMLFILE echo '' >> $XMLFILE echo '' >> $XMLFILE echo '' >> $XMLFILE echo '' >> $XMLFILE echo '' >> $XMLFILE echo '' >> $XMLFILE echo '' >> $XMLFILE echo '' >> $XMLFILE echo '' >> $XMLFILE # Logs echo '' >> $XMLFILE echo '' >> $XMLFILE echo '' >> $XMLFILE echo '' >> $XMLFILE # Times echo '' >> $XMLFILE echo '' >> $XMLFILE echo '' >> $XMLFILE echo '' >> $XMLFILE echo '' >> $XMLFILE done #========# # Footer # #========# echo '' >> $XMLFILE #==========# # Epilogue # #==========# echo 'Results correctly exported to' $XMLFILE