From a754ce9eb6aeb6379e9d55064683d163eca6ff90 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Wed, 16 Sep 2009 01:46:04 +0000 Subject: [PATCH] Initial check in of code analysis tool --- contrib/codeanalysis/analyzedata.sh | 43 +++++++++++++++ contrib/codeanalysis/codeanalysis.sh | 81 ++++++++++++++++++++++++++++ contrib/codeanalysis/profile.chai | 15 ++++++ 3 files changed, 139 insertions(+) create mode 100755 contrib/codeanalysis/analyzedata.sh create mode 100755 contrib/codeanalysis/codeanalysis.sh create mode 100644 contrib/codeanalysis/profile.chai diff --git a/contrib/codeanalysis/analyzedata.sh b/contrib/codeanalysis/analyzedata.sh new file mode 100755 index 0000000..fc7203e --- /dev/null +++ b/contrib/codeanalysis/analyzedata.sh @@ -0,0 +1,43 @@ + +function analyze_data +{ + echo -n "$1," >> $2 + awk 'END {printf "%s,", $1}' r$1-codesize.out >> $2 + awk '{printf "%s,", $1}' r$1-numunittests.out >> $2 + awk 'END {printf "%s,", $1}' r$1-unittestsoutput.out >> $2 + + awk '{printf "%s,", $1}' r$1-debugbinarysize.out >> $2 + awk 'NR>1{exit} 1 {printf "%s,", $2}' r$1-debugbuildtime.out >> $2 + awk 'NR>1{exit} 1 {printf "%s,", $2}' r$1-debugprofiletime.out >> $2 + + awk '{printf "%s,", $1}' r$1-releasebinarysize.out >> $2 + awk 'NR>1{exit} 1 {printf "%s,", $2}' r$1-releasebuildtime.out >> $2 + awk 'NR>1{exit} 1 {printf "%s,", $2}' r$1-releasemodulesbuildtime.out >> $2 + awk 'NR>1{exit} 1 {printf "%s,", $2}' r$1-releaseprofiletime.out >> $2 + awk 'NR>1{exit} 1 {printf "%s,", $2}' r$1-releaseunittestruntime.out >> $2 + + if [ -x r$1-threadfreebinarysize.out ] + then + awk '{printf "%s,", $1}' r$1-threadfreebinarysize.out >> $2 + awk 'NR>1{exit} 1 {printf "%s,", $2}' r$1-threadfreeprofiletime.out >> $2 + + awk 'NR>1{exit} 1 {printf "%s,", $2}' r$1-1threadruntime.out >> $2 + awk 'NR>1{exit} 1 {printf "%s,", $2}' r$1-2threadruntime.out >> $2 + awk 'NR>1{exit} 1 {printf "%s,", $2}' r$1-4threadruntime.out >> $2 + awk 'NR>1{exit} 1 {printf "%s,", $2}' r$1-8threadruntime.out >> $2 + else + echo -n ",,,,,," >> $2 + fi + + awk -F "\n" 'NR>1{exit} 1 {printf "\"%s\"\n", $1}' r$1-revisionlog.out >> $2 +} + + +filename=output-$1-$2.csv + +echo "Revision, LOC, Num Unit Tests, Successful Unit Tests, Debug Binary Size, Debug Build Time, Debug Profile Time, Release Binary Size, Release Core Build Time, Release Modules Build Time, Release Profile Time, Release Unit Tests Time, Threadless Binary Size, Threadless Profile Time, 1 Thread Profile Time, 2 Threads Profile Time, 4 Threads Profile Time, 8 Threads Profile Time, Revision Log" > $filename + +for i in `seq $1 $2` +do + analyze_data $i $filename +done diff --git a/contrib/codeanalysis/codeanalysis.sh b/contrib/codeanalysis/codeanalysis.sh new file mode 100755 index 0000000..6a32210 --- /dev/null +++ b/contrib/codeanalysis/codeanalysis.sh @@ -0,0 +1,81 @@ + +function run_test +{ + echo "****Getting r$1 from SVN" + svn export --quiet -r$1 http://chaiscript.googlecode.com/svn/trunk chaiscript-r$1 + + pushd chaiscript-r$1 + + echo "****Getting svn revision log" + svn propget svn:log --revprop -r$1 http://chaiscript.googlecode.com/svn/trunk > ../r$1-revisionlog.out + + echo "****Editing CMakeLists.txt to allow for build type switching" + # Clean up CMakeLists.txt so that we can set the build type at configure time + sed -i -e "s/SET (CMAKE_BUILD_TYPE.*//" CMakeLists.txt + + echo "****Compiling Debug Build" + cmake -D CMAKE_BUILD_TYPE=Debug CMakeLists.txt + /usr/bin/time -p make chaiscript_eval 2> ../r$1-debugbuildtime.out + + echo "****Analyzing Debug Build" + /usr/bin/time -p ./chaiscript_eval ../profile.chai 2>../r$1-debugprofiletime.out + ls -s --block-size=1 ./chaiscript_eval > ../r$1-debugbinarysize.out + + make clean + + echo "****Compiling Release Build" + cmake -D CMAKE_BUILD_TYPE=Release CMakeLists.txt + /usr/bin/time -p make chaiscript_eval 2> ../r$1-releasebuildtime.out + + echo "****Analyzing Release Build" + /usr/bin/time -p ./chaiscript_eval ../profile.chai 2>../r$1-releaseprofiletime.out + ls -s --block-size=1 ./chaiscript_eval > ../r$1-releasebinarysize.out + + echo "****Analyzing Code Size" + find ./include -name "*.hpp" | xargs wc > ../r$1-codesize.out + + echo "****Building Remaining Modules" + /usr/bin/time -p make 2> ../r$1-releasemodulesbuildtime.out + + echo "****Running unit tests" + /usr/bin/time -p ./run_unit_tests.sh 2> ../r$1-releaseunittestruntime.out > ../r$1-unittestsoutput.out + + echo "****Counting number of unit tests" + find unittests/ -name "*.chai" | wc | awk '{print $1}' > ../r$1-numunittests.out + + + echo "****Running multithreaded tests" + if [ -e src/multithreaded.cpp ] + then + # Run multithreaded tests + echo "****Building multithreaded test" + pushd src + g++ multithreaded.cpp -lboost_thread-mt -ldl -omultithreaded -I../include -O3 + echo "****Testing 1 thread runtime" + /usr/bin/time -p ./multithreaded 1 2> ../../r$1-1threadruntime.out + echo "****Testing 2 thread runtime" + /usr/bin/time -p ./multithreaded 1 1 2> ../../r$1-2threadruntime.out + echo "****Testing 4 thread runtime" + /usr/bin/time -p ./multithreaded 1 1 1 1 2> ../../r$1-4threadruntime.out + echo "****Testing 8 thread runtime" + /usr/bin/time -p ./multithreaded 1 1 1 1 1 1 1 1 2> ../../r$1-8threadruntime.out + + + echo "****Compiling thread-free version" + g++ main.cpp -ldl -othreadfree -I../include -O3 -DCHAISCRIPT_NO_THREADS + echo "****Analyzing thread-free version" + /usr/bin/time -p ./threadfree ../../profile.chai 2>../../r$1-threadfreeprofiletime.out + ls -s --block-size=1 ./threadfree > ../../r$1-threadfreebinarysize.out + + popd + else + echo "Multithreaded test non-existent" + fi + + popd +} + +for i in `seq $1 $2` +do + run_test $i +done diff --git a/contrib/codeanalysis/profile.chai b/contrib/codeanalysis/profile.chai new file mode 100644 index 0000000..0821049 --- /dev/null +++ b/contrib/codeanalysis/profile.chai @@ -0,0 +1,15 @@ +var total = 0 + +for (var i = 0.0; i < 10000.0; i += 0.1) { + total += int(double(i) + int(10)); + if (i < 9000.0) + { + total += double(11); + if (i > double(4000.0)) + { + total += double(10); + } + } +} + +print(total)