[erlang-questions] DTrace + R14B04: an automated patch & compile script

Scott Lystig Fritchie <>
Sat Oct 22 19:53:06 CEST 2011


Hi, all.  I've created a fully-automated shell script that will automate
the patch (text and binary) required to convert an R14B04 source tarball
from the official OTP release into an Erlang runtime that has basic
DTrace support.

Your feedback is welcome, please let me know how this all works for you.
The script is available at:

    http://www.snookles.com/scott/publications/erlang-factory/DTRACE-PATCH-R14B04.current.sh

Follow the instructions in the comments at the top of the script.  If
you don't trust running arbitrary shell scripts that you download from
the Internet, you are indeed perfectly sane.  Below I've created an
abridged form of the script, something that's quicker & easier to read.
Of course, you shouldn't trust *that* either, but it should be easy to
verify that I'm not trying play a trick on you.  :-)

This script works on the following platforms:

    OS X / Snow Leopard
        My primary development platform

    Linux + SystemTap & DTrace emulation packages installed
        I know that this will compile cleanly, but actually *using* the
	SystemTap stuff for DTrace user-space probes is a huge PITA.
	So, I don't know yet if the user-space probes actually work.

    Solaris
        I know this works, though using certain GCC compilers can run
        into problems with the linker not understanding "-32" or "-64"
        flags.  This isn't my fault, sorry, the problem is there in the
        unpatched R14B04 source.  See below for more comments on this.

On my MacBook Pro, the total patch & build time is less than 15 minutes.

For "git" users, this patch script is based on the "dtrace-r14b04"
branch of git://github.com/slfritchie/otp.git.  There is also a
"dtrace-r15" branch which has the same code.  Both branches are based on
development that I first started (and am still working on) on the
"dtrace-experiement+michal2" branch.

-Scott

--- snip --- snip ---

#!/bin/sh

# Steps to use:
#
#  1. Assume that the otp_src_R14B04.tar.gz file is in the current working dir.
#  2. Assume that you want to build in the current working dir.
#  2b. Assume that "uudecode" is available on your platform.  If you're
#      using a Linux system, you may need to install a package like
#      "sharutils" (CentOS and perhaps Fedora).
#  3. Edit the CONFIGURE_OPTIONS variable below to suit yourself.  Its
#     current value is what I use to build on a OS X box.
#  4. Run "sh -x THIS-SCRIPT-FILE".  This script will be executing the
#     "make install" step, so you will need to do one of three things:
#        a. Run the script as the superuser so that "make install" will
#           have permission to create all necessary directories and files.
#        b. Create the top-level destination directory, the same dir that
#           you use for the CONFIGURE_OPTIONS "--prefix" directory.
#        c. Edit the bottom of this script to comment out (or delete) the
#           "make install" step.  Then perform the installation step
#           yourself.
#  5. Wait for the build to finish.
#  6. Run "/your/path/to/R14B04/bin/erl +A 5"
#  7. Run as root: "dtrace -q -s /your/path/to/R14B04/lib/erlang/lib/dtrace-0.8/examples/process-scheduling.d"
#  8. Type stuff in the Erlang shell.  Watch the process scheduling
#     events in the D script output.
#  9. Run as root: "dtrace -q -s /your/path/to/R14B04/lib/erlang/lib/dtrace-0.8/examples/efile_drv.d"
# 10. Type in the Erlang shell and then watch the D script output: cd("foo").
 
CONFIGURE_OPTIONS="--prefix=/usr/local/erlang/R14B04.via-patch.dtrace --enable-darwin-64bit --enable-dtrace"

set -x

rm -rf otp_src_R14B04
gunzip -c otp_src_R14B04.tar.gz | tar xf -
cd otp_src_R14B04

patch -p1 <<'EOFEOFEOFEOFEOFEOFEOFEOF'
[... lots of stuff deleted ...]
EOFEOFEOFEOFEOFEOFEOFEOF

mkdir -p lib/dtrace/ebin

uudecode -o ./erts/preloaded/ebin/prim_file.beam <<'ENDOFDAFILEENDOFDAFILE'
begin 664 -
[... lots of stuff deleted ...]
end
ENDOFDAFILEENDOFDAFILE

./otp_build autoconf
./configure $CONFIGURE_OPTIONS
make
make install

--- snip --- snip ---

There is a Solaris makefile compilation problem that my patch does
not address, and that's the linking of various shared libraries used
by various OTP libraries.  I don't know if I see these because of the
version of GCC that I'm using or if the error is fairly common:

   ld -64 -G -o ../priv/lib/i386-pc-solaris2.10/trace_ip_drv.so
../priv/obj/i386-pc-solaris2.10/trace_ip_drv.o -lc -lrt -ldl -lm
-lsocket -lnsl -ldtrace
   ld: unrecognized option '-64'
   ld: use the --help option for usage information
   make[6]: *** [../priv/lib/i386-pc-solaris2.10/trace_ip_drv.so] Error 1

My stupid workaround is to manually chdir to each source subdir
and run "ld" with the "-melf_x86_64" flag substituted for the bogus "-64"
flag.  Or I copy the .so files from previously-compiled set of objects.
Neither are particularly automated, sorry.



More information about the erlang-questions mailing list