Success! (My very first probe...)

4 views
Skip to first unread message

Tim

unread,
Dec 22, 2007, 1:19:16 PM12/22/07
to Erlang DTrace
Need to pat myself on the back a little:

Macintosh-3:~ root# dtrace -P erlang*
dtrace: description 'erlang*' matched 2 probes
CPU ID FUNCTION:NAME
0 18659 erts_garbage_collect:gc-begin
0 18660 erts_garbage_collect:gc-end
0 18659 erts_garbage_collect:gc-begin
0 18660 erts_garbage_collect:gc-end
1 18659 erts_garbage_collect:gc-begin
1 18660 erts_garbage_collect:gc-end
1 18659 erts_garbage_collect:gc-begin
1 18660 erts_garbage_collect:gc-end


I'll describe what to do below in case you'd like to follow along.
First some caveats:

* this is a really quick and dirty example that is just about as
primitive as it gets.
* I've only tried it on Leopard
* I haven't added any sort of auxilliary information to the probe (no
erl PID, no 'amount of space reclaimed', etc.)
* this is for R12 unpatched (I couldn't get the patched version to run
properly.)
* this is in no way integrated in the build system.

Anyway getting this far was ridiculously easy which makes me quite
optimistic about going on. In case you'd like your very own `gc-begin`
and `gc-end` probes:

1.) cd to `otp_src_R12B-0/erts/emulator/beam`
2.) create this file (erl_dtrace.d)

provider erlang {
probe gc__begin();
probe gc__end();
};

3.) run `dtrace -h -s erl_dtrace.d` this creates the header
`erl_dtrace.h` which contains all the necessary macros to trigger the
probes.

4.) patch `erl_gc.c` as follows:

38,40d37
< /* have fancy ifdef DTRACE_ENABLE here once we figure out
autoconf :) */
< #include "erl_dtrace.h"
<
339,342d335
< if (ERLANG_GC_BEGIN_ENABLED()) {
< ERLANG_GC_BEGIN();
< }
<
378,380d370
< if (ERLANG_GC_END_ENABLED()) {
< ERLANG_GC_END();
< }

5.) the usual `configure; make` and you're set to go.
5b.) Apparently the folks at Apple added some magic to dtrace and cc,
from my understanding, on Solaris you'll need to run `dtrace -G ...`
at some point in order to patch the object files.

-tim

G Bulmer

unread,
Dec 22, 2007, 3:30:32 PM12/22/07
to erlang...@googlegroups.com
Tim

Whoo!
Let me just check my understanding:
Your Erlang VM now generates these DTrace events at each garbage
collection event, from every Erlang VM runing when you run dtrace?
Very Cool.

It looks like you have done what I was only *thinking* about, i.e.
put ordinary DTrace probes into the right place in the C source code,
and skip using trace/3 for now.

Nice work. I am impressed. Have a double pat on the back, with tonic
and a slice of lemon!
Garry

Tim

unread,
Dec 22, 2007, 6:20:18 PM12/22/07
to Erlang DTrace

> Your Erlang VM now generates these DTrace events at each garbage
> collection event, from every Erlang VM runing when you run dtrace?
> Very Cool.

Precisely. And the nice part is that once you know where to put stuff
in the Erlang code, implementing the probes is more or less trivial.

> Nice work. I am impressed. Have a double pat on the back, with tonic
> and a slice of lemon!
What!? No gin?

Till soon,
-tim
Reply all
Reply to author
Forward
0 new messages