# helper methods to keep from cluttering up the Rakefile
KERNEL = "/usr/src/linux-2.6.25-gentoo-r6/vmlinux"
LIBC="/lib64/libc-2.8.so"
# patch the shared library linking flags
def patch_ldshared(target)
# TODO: rewrite using "patch"!
# as currently shipped, non-standard "CFLAGS" don't get propagated during
# shared library builds. There are two places we need to hack to get this
# to work: #{target}/lib/mkmf.rb and #{target}/Makefile.in
k1 = '$(LDSHARED) #{OUTFLAG}$@ $(OBJS)'
k2 = '$(LDSHARED) ${CFLAGS} #{OUTFLAG}$@ $(OBJS)'
cp "#{target}/lib/mkmf.rb", "."
sh "sed 's/#{k1}/#{k2}/' mkmf.rb > #{target}/lib/mkmf.rb"
print `diff mkmf.rb #{target}/lib/mkmf.rb`
k3 = 'LDSHARED = @LIBRUBY_LDSHARED@'
k4 = 'LDSHARED = @LIBRUBY_LDSHARED@ @CFLAGS@'
cp "#{target}/Makefile.in", "."
sh "sed 's/#{k3}/#{k4}/' Makefile.in > #{target}/Makefile.in"
print `diff Makefile.in #{target}/Makefile.in`
end
# check out and configure a Ruby source tree
def checkout(repos, target)
sh "svn co #{repos} #{target}"
patch_ldshared target
# set up for builds
cd "#{target}"
cflags = "-g3 -march=athlon64 -pipe -O3"
config_flags = "--enable-pthread --disable-shared --disable-install-doc --prefix=#{HERE}/#{target}.inst"
sh "export CFLAGS=\'#{cflags}\'; autoconf; ./configure #{config_flags}"
cd ".."
end
# build a C Ruby (MRI or KRI) and capture profiles of testing and benchmarks
def build_ruby(target)
mkdir_p "#{target}.inst"
cd target
sh "make 2>&1 | tee ../make.log"
#sh "make test 2>&1 | tee ../test.log"
sh "make install 2>&1 | tee ../#{target}_inst.log"
cd ".."
end
# Run benchmark suite
def run_benchmark_suite(target, path, executable, blacklist)
mkdir_p "#{target}_profiles"
cd "ruby-benchmark-suite"
here = Dir.getwd
Find.find(here) do |filename|
basename = File.basename(filename)
dirname = File.dirname(filename)
next if basename !~ /^bm_.+\.rb$/
next if blacklist.include? basename
puts "Benchmark #{basename}"
cd dirname
start_oprofile
sh "unset RUBYOPT; " +
"export JAVA_TOOL_OPTIONS='-agentpath:/usr/local/lib64/oprofile/libjvmti_oprofile.so'; " +
"export PATH=\"#{path}:$PATH\"; " +
"ulimit -s 32768; " +
"/usr/bin/time #{executable} #{filename} > /dev/null"
stop_oprofile "#{basename}_benchmark_suite"
cd here
sh "opreport -l session:#{basename}_benchmark_suite > ../#{target}_profiles/#{basename}_symbols.opreport"
end
cd ".."
end
def start_oprofile
sh "sudo opcontrol --reset"
sh "sudo opcontrol --start"
sh "sudo opcontrol --status"
end
def stop_oprofile(session)
sh "sudo opcontrol --shutdown"
sh "sudo rm -rf /var/lib/oprofile/samples/#{session}"
sh "sudo opcontrol --save #{session}"
sh "sudo opcontrol --status"
end
# factored pet store start task
def start_pet_store(target)
path = "#{Dir.getwd}/#{target}/bin"
ruby = "#{path}/ruby"
script = "script/server -e production"
cd "pet_store"
sh "unset RUBYOPT; export PATH=#{path}:$PATH; #{ruby} #{script}"
cd ".."
end