aboutsummaryrefslogtreecommitdiffstats
path: root/lib/runtime_tools
diff options
context:
space:
mode:
Diffstat (limited to 'lib/runtime_tools')
-rw-r--r--lib/runtime_tools/c_src/Makefile.in83
-rw-r--r--lib/runtime_tools/c_src/dtrace_user.d33
-rw-r--r--lib/runtime_tools/c_src/dyntrace.c127
-rw-r--r--lib/runtime_tools/c_src/trace_ip_drv.c10
-rw-r--r--lib/runtime_tools/doc/src/Makefile22
-rw-r--r--lib/runtime_tools/doc/src/dyntrace.xml209
-rw-r--r--lib/runtime_tools/doc/src/notes.xml22
-rw-r--r--lib/runtime_tools/doc/src/ref_man.xml3
-rw-r--r--lib/runtime_tools/examples/dist.d62
-rw-r--r--lib/runtime_tools/examples/dist.systemtap76
-rw-r--r--lib/runtime_tools/examples/driver1.d114
-rw-r--r--lib/runtime_tools/examples/driver1.systemtap125
-rw-r--r--lib/runtime_tools/examples/efile_drv.d104
-rw-r--r--lib/runtime_tools/examples/efile_drv.systemtap112
-rw-r--r--lib/runtime_tools/examples/function-calls.d57
-rw-r--r--lib/runtime_tools/examples/function-calls.systemtap67
-rw-r--r--lib/runtime_tools/examples/garbage-collection.d39
-rw-r--r--lib/runtime_tools/examples/garbage-collection.systemtap49
-rw-r--r--lib/runtime_tools/examples/memory1.d41
-rw-r--r--lib/runtime_tools/examples/memory1.systemtap51
-rw-r--r--lib/runtime_tools/examples/messages.d94
-rw-r--r--lib/runtime_tools/examples/messages.systemtap87
-rw-r--r--lib/runtime_tools/examples/port1.d142
-rw-r--r--lib/runtime_tools/examples/port1.systemtap152
-rw-r--r--lib/runtime_tools/examples/process-scheduling.d35
-rw-r--r--lib/runtime_tools/examples/process-scheduling.systemtap45
-rw-r--r--lib/runtime_tools/examples/spawn-exit.d41
-rw-r--r--lib/runtime_tools/examples/spawn-exit.systemtap51
-rw-r--r--lib/runtime_tools/examples/user-probe-n.d44
-rw-r--r--lib/runtime_tools/examples/user-probe-n.systemtap53
-rw-r--r--lib/runtime_tools/examples/user-probe.d36
-rw-r--r--lib/runtime_tools/examples/user-probe.systemtap46
-rw-r--r--lib/runtime_tools/src/Makefile24
-rw-r--r--lib/runtime_tools/src/dyntrace.erl352
-rw-r--r--lib/runtime_tools/src/runtime_tools.app.src4
-rw-r--r--lib/runtime_tools/test/Makefile11
-rw-r--r--lib/runtime_tools/test/dyntrace_SUITE.erl224
-rw-r--r--lib/runtime_tools/test/inviso_SUITE.erl2
-rw-r--r--lib/runtime_tools/vsn.mk2
39 files changed, 2809 insertions, 42 deletions
diff --git a/lib/runtime_tools/c_src/Makefile.in b/lib/runtime_tools/c_src/Makefile.in
index 3d9a7ed69d..754e6ccd78 100644
--- a/lib/runtime_tools/c_src/Makefile.in
+++ b/lib/runtime_tools/c_src/Makefile.in
@@ -1,7 +1,7 @@
#
# %CopyrightBegin%
#
-# Copyright Ericsson AB 1999-2011. All Rights Reserved.
+# Copyright Ericsson AB 1999-2012. All Rights Reserved.
#
# The contents of this file are subject to the Erlang Public License,
# Version 1.1, (the "License"); you may not use this file except in
@@ -21,6 +21,11 @@ include $(ERL_TOP)/make/$(TARGET)/otp.mk
include $(ERL_TOP)/make/$(TARGET)/otp_ded.mk
# ----------------------------------------------------
+# Items from top-level configure
+# ----------------------------------------------------
+DTRACE_ENABLED=@DTRACE_ENABLED@
+DTRACE_ENABLED_2STEP=@DTRACE_ENABLED_2STEP@
+# ----------------------------------------------------
# Application version
# ----------------------------------------------------
include ../vsn.mk
@@ -38,6 +43,8 @@ SHELL = /bin/sh
LIBS = $(DED_LIBS)
LDFLAGS += $(DED_LDFLAGS)
+DTRACE_LIBNAME = dyntrace
+
SYSINCLUDE = $(DED_SYS_INCLUDE)
ifeq ($(findstring vxworks,$(TARGET)),vxworks)
SYSINCLUDE += -I$(ERL_TOP)/erts/etc/vxworks
@@ -45,15 +52,20 @@ endif
TRACE_DRV_INCLUDES = $(SYSINCLUDE)
-ALL_CFLAGS = $(CFLAGS) @DEFS@ $(TYPE_FLAGS) $(TRACE_DRV_INCLUDES)
-
+ALL_CFLAGS = $(CFLAGS) @DEFS@ $(TYPE_FLAGS) $(TRACE_DRV_INCLUDES) \
+ -I$(OBJDIR) -I$(ERL_TOP)/erts/emulator/$(TARGET)
ifeq ($(TYPE),debug)
TYPEMARKER = .debug
-TYPE_FLAGS = -g -DDEBUG @DEBUG_FLAGS@
+TYPE_FLAGS = $(subst -O3,,$(subst -O2,,$(CFLAGS))) -DDEBUG @DEBUG_FLAGS@
+else
+ifeq ($(TYPE),valgrind)
+TYPEMARKER = .valgrind
+TYPE_FLAGS = $(subst -O3,,$(subst -O2,,$(CFLAGS))) -DVALGRIND
else
TYPEMARKER =
-TYPE_FLAGS = -O2
+TYPE_FLAGS = $(CFLAGS)
+endif
endif
ROOTDIR = $(ERL_TOP)/lib
@@ -69,6 +81,16 @@ RELSYSDIR = $(RELEASE_PATH)/lib/runtime_tools-$(VSN)
# ----------------------------------------------------
# Misc Macros
# ----------------------------------------------------
+before_DTrace_OBJS = $(OBJDIR)/dyntrace$(TYPEMARKER).o
+## NIF_MAKEFILE = $(PRIVDIR)/Makefile
+
+# Higher-level makefiles says that we can only compile on UNIX flavors
+NIF_LIB = $(LIBDIR)/dyntrace$(TYPEMARKER).@DED_EXT@
+
+ifeq ($(HOST_OS),)
+HOST_OS := $(shell $(ERL_TOP)/erts/autoconf/config.guess)
+endif
+
TRACE_IP_DRV_OBJS = \
$(OBJDIR)/trace_ip_drv.o
@@ -91,7 +113,44 @@ endif
_create_dirs := $(shell mkdir -p $(OBJDIR) $(LIBDIR))
-debug opt: $(SOLIBS)
+debug opt valgrind: $(SOLIBS) $(OBJDIR) $(LIBDIR) $(NIF_LIB)
+
+ifdef DTRACE_ENABLED
+DTRACE_USER_HEADER=$(OBJDIR)/dtrace_user.h
+$(OBJDIR)/dtrace_user.h: ./dtrace_user.d
+ dtrace -h -C $(INCLUDES) \
+ -s ./dtrace_user.d \
+ -o ./dtrace_user.tmp
+ sed -e '/^#define[ ]*ERLANG_[A-Z0-9_]*(.*)/y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/' ./dtrace_user.tmp > $@
+ rm ./dtrace_user.tmp
+else
+DTRACE_USER_HEADER=
+endif
+
+DTRACE_OBJS =
+ifdef DTRACE_ENABLED_2STEP
+DTRACE_OBJS += $(OBJDIR)/dtrace_user.o
+$(OBJDIR)/dtrace_user.o: $(before_DTrace_OBJS) $(OBJDIR)/dtrace_user.h
+ dtrace -G -C \
+ -s ./dtrace_user.d \
+ -o $@ $(before_DTrace_OBJS)
+endif
+
+DYNTRACE_OBJS = $(before_DTrace_OBJS) $(DTRACE_OBJS)
+
+$(OBJDIR):
+ -@mkdir -p $(OBJDIR)
+
+$(LIBDIR):
+ -@mkdir -p $(LIBDIR)
+
+$(OBJDIR)/dyntrace$(TYPEMARKER).o: dyntrace.c $(DTRACE_USER_HEADER)
+ $(INSTALL_DIR) $(OBJDIR)
+ $(CC) -c -o $@ $(ALL_CFLAGS) $<
+
+$(NIF_LIB): $(DYNTRACE_OBJS)
+ $(INSTALL_DIR) $(LIBDIR)
+ $(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS)
$(OBJDIR)/%.o: %.c
$(CC) -c -o $@ $(ALL_CFLAGS) $<
@@ -118,6 +177,12 @@ $(LIBDIR)/trace_file_drv.eld: $(TRACE_FILE_DRV_OBJS)
clean:
rm -f $(SOLIBS) $(TRACE_IP_DRV_OBJS) $(TRACE_FILE_DRV_OBJS)
+ rm -f $(LIBDIR)/dyntrace.@DED_EXT@
+ rm -f $(LIBDIR)/dyntrace.debug.@DED_EXT@
+ rm -f $(LIBDIR)/dyntrace.valgrind.@DED_EXT@
+ rm -f $(OBJDIR)/dyntrace.o
+ rm -f $(OBJDIR)/dyntrace.debug.o
+ rm -f $(OBJDIR)/dyntrace.valgrind.o
rm -f core *~
docs:
@@ -128,8 +193,10 @@ docs:
include $(ERL_TOP)/make/otp_release_targets.mk
release_spec: opt
- $(INSTALL_DIR) $(RELSYSDIR)/priv/lib
- $(INSTALL_PROGRAM) $(SOLIBS) $(RELSYSDIR)/priv/lib
+ $(INSTALL_DIR) "$(RELSYSDIR)/priv/obj"
+ $(INSTALL_DIR) "$(RELSYSDIR)/priv/lib"
+ $(INSTALL_PROGRAM) $(DYNTRACE_OBJS) "$(RELSYSDIR)/priv/obj"
+ $(INSTALL_PROGRAM) $(NIF_LIB) $(SOLIBS) "$(RELSYSDIR)/priv/lib"
release_docs_spec:
diff --git a/lib/runtime_tools/c_src/dtrace_user.d b/lib/runtime_tools/c_src/dtrace_user.d
new file mode 100644
index 0000000000..9e180a3cb2
--- /dev/null
+++ b/lib/runtime_tools/c_src/dtrace_user.d
@@ -0,0 +1,33 @@
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Scott Lystig Fritchie 2011-2012.
+ * All Rights Reserved.
+ *
+ * The contents of this file are subject to the Erlang Public License,
+ * Version 1.1, (the "License"); you may not use this file except in
+ * compliance with the License. You should have received a copy of the
+ * Erlang Public License along with this software. If not, it can be
+ * retrieved online at http://www.erlang.org/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * %CopyrightEnd%
+ */
+
+provider erlang {
+ /*
+ * The set of probes for use by Erlang code ... moved from here to
+ * erts/emulator/beam/erlang_dtrace.d until a more portable solution is
+ * found; see erlang_dtrace.d for details.
+ */
+};
+
+#pragma D attributes Evolving/Evolving/Common provider erlang provider
+#pragma D attributes Private/Private/Common provider erlang module
+#pragma D attributes Private/Private/Common provider erlang function
+#pragma D attributes Evolving/Evolving/Common provider erlang name
+#pragma D attributes Evolving/Evolving/Common provider erlang args
diff --git a/lib/runtime_tools/c_src/dyntrace.c b/lib/runtime_tools/c_src/dyntrace.c
new file mode 100644
index 0000000000..eef03afd1c
--- /dev/null
+++ b/lib/runtime_tools/c_src/dyntrace.c
@@ -0,0 +1,127 @@
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Scott Lystig Fritchie 2011-2012. All Rights Reserved.
+ *
+ * The contents of this file are subject to the Erlang Public License,
+ * Version 1.1, (the "License"); you may not use this file except in
+ * compliance with the License. You should have received a copy of the
+ * Erlang Public License along with this software. If not, it can be
+ * retrieved online at http://www.erlang.org/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * %CopyrightEnd%
+ */
+
+/*
+ * Purpose: Dynamically loadable NIF library for DTrace
+ */
+
+
+
+#include "erl_nif.h"
+#include "config.h"
+#include "sys.h"
+#include "dtrace-wrapper.h"
+#if defined(USE_DYNAMIC_TRACE) && (defined(USE_DTRACE) || defined(USE_SYSTEMTAP))
+#define HAVE_USE_DTRACE 1
+#endif
+#ifdef HAVE_USE_DTRACE
+#include "dtrace_user.h"
+#endif
+
+void dtrace_nifenv_str(ErlNifEnv *env, char *process_buf);
+void get_string_maybe(ErlNifEnv *env, const ERL_NIF_TERM term, char **ptr, char *buf, int bufsiz);
+#ifdef HAVE_USE_DTRACE
+ERL_NIF_TERM erl_nif_user_trace_s1(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
+ERL_NIF_TERM erl_nif_user_trace_i4s4(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
+#endif
+
+#ifdef VALGRIND
+ # include <valgrind/memcheck.h>
+#endif
+
+#ifdef __GNUC__
+ # define INLINE __inline__
+#else
+ # define INLINE
+#endif
+
+#define MESSAGE_BUFSIZ 1024
+
+/* NIF interface declarations */
+static int load(ErlNifEnv* env, void** priv_data, ERL_NIF_TERM load_info);
+
+/* The NIFs: */
+static ERL_NIF_TERM available(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
+static ERL_NIF_TERM user_trace_s1(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
+static ERL_NIF_TERM user_trace_i4s4(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
+static ERL_NIF_TERM user_trace_n(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
+
+static ErlNifFunc nif_funcs[] = {
+ {"available", 0, available},
+ {"user_trace_s1", 1, user_trace_s1},
+ {"user_trace_i4s4", 9, user_trace_i4s4},
+ {"user_trace_n", 10, user_trace_n}
+};
+
+ERL_NIF_INIT(dyntrace, nif_funcs, load, NULL, NULL, NULL)
+
+static ERL_NIF_TERM atom_true;
+static ERL_NIF_TERM atom_false;
+static ERL_NIF_TERM atom_error;
+static ERL_NIF_TERM atom_not_available;
+static ERL_NIF_TERM atom_badarg;
+static ERL_NIF_TERM atom_ok;
+
+static int load(ErlNifEnv* env, void** priv_data, ERL_NIF_TERM load_info)
+{
+ atom_true = enif_make_atom(env,"true");
+ atom_false = enif_make_atom(env,"false");
+ atom_error = enif_make_atom(env,"error");
+ atom_not_available = enif_make_atom(env,"not_available");
+ atom_badarg = enif_make_atom(env,"badarg");
+ atom_ok = enif_make_atom(env,"ok");
+
+ return 0;
+}
+
+static ERL_NIF_TERM available(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
+{
+#ifdef HAVE_USE_DTRACE
+ return atom_true;
+#else
+ return atom_false;
+#endif
+}
+
+static ERL_NIF_TERM user_trace_s1(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
+{
+#ifdef HAVE_USE_DTRACE
+ return erl_nif_user_trace_s1(env, argc, argv);
+#else
+ return atom_error;
+#endif
+}
+
+static ERL_NIF_TERM user_trace_i4s4(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
+{
+#ifdef HAVE_USE_DTRACE
+ return erl_nif_user_trace_i4s4(env, argc, argv);
+#else
+ return atom_error;
+#endif
+}
+
+static ERL_NIF_TERM user_trace_n(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
+{
+#ifdef HAVE_USE_DTRACE
+ return erl_nif_user_trace_n(env, argc, argv);
+#else
+ return atom_error;
+#endif
+}
diff --git a/lib/runtime_tools/c_src/trace_ip_drv.c b/lib/runtime_tools/c_src/trace_ip_drv.c
index 7ae6c1b329..6b77128761 100644
--- a/lib/runtime_tools/c_src/trace_ip_drv.c
+++ b/lib/runtime_tools/c_src/trace_ip_drv.c
@@ -1,7 +1,7 @@
/*
* %CopyrightBegin%
*
- * Copyright Ericsson AB 1999-2011. All Rights Reserved.
+ * Copyright Ericsson AB 1999-2012. All Rights Reserved.
*
* The contents of this file are subject to the Erlang Public License,
* Version 1.1, (the "License"); you may not use this file except in
@@ -590,8 +590,8 @@ static void *my_alloc(size_t size)
void *ret;
if ((ret = driver_alloc(size)) == NULL) {
/* May or may not work... */
- fprintf(stderr, "Could not allocate %d bytes of memory in %s.",
- (int) size, __FILE__);
+ fprintf(stderr, "Could not allocate %lu bytes of memory in %s.",
+ (unsigned long) size, __FILE__);
exit(1);
}
return ret;
@@ -605,8 +605,8 @@ static ErlDrvBinary *my_alloc_binary(int size)
ErlDrvBinary *ret;
if ((ret = driver_alloc_binary(size)) == NULL) {
/* May or may not work... */
- fprintf(stderr, "Could not allocate a binary of %d bytes in %s.",
- (int) size, __FILE__);
+ fprintf(stderr, "Could not allocate a binary of %lu bytes in %s.",
+ (unsigned long) size, __FILE__);
exit(1);
}
return ret;
diff --git a/lib/runtime_tools/doc/src/Makefile b/lib/runtime_tools/doc/src/Makefile
index dbbae81cfe..d240b287c3 100644
--- a/lib/runtime_tools/doc/src/Makefile
+++ b/lib/runtime_tools/doc/src/Makefile
@@ -1,7 +1,7 @@
#
# %CopyrightBegin%
#
-# Copyright Ericsson AB 1999-2009. All Rights Reserved.
+# Copyright Ericsson AB 1999-2012. All Rights Reserved.
#
# The contents of this file are subject to the Erlang Public License,
# Version 1.1, (the "License"); you may not use this file except in
@@ -40,7 +40,7 @@ RELSYSDIR = $(RELEASE_PATH)/lib/$(APPLICATION)-$(VSN)
# Target Specs
# ----------------------------------------------------
XML_APPLICATION_FILES = ref_man.xml
-XML_REF3_FILES = dbg.xml erts_alloc_config.xml
+XML_REF3_FILES = dbg.xml dyntrace.xml erts_alloc_config.xml
XML_REF6_FILES = runtime_tools_app.xml
XML_PART_FILES = part_notes.xml part_notes_history.xml
@@ -108,16 +108,16 @@ clean clean_docs:
include $(ERL_TOP)/make/otp_release_targets.mk
release_docs_spec: docs
- $(INSTALL_DIR) $(RELSYSDIR)/doc/pdf
- $(INSTALL_DATA) $(TOP_PDF_FILE) $(RELSYSDIR)/doc/pdf
- $(INSTALL_DIR) $(RELSYSDIR)/doc/html
+ $(INSTALL_DIR) "$(RELSYSDIR)/doc/pdf"
+ $(INSTALL_DATA) $(TOP_PDF_FILE) "$(RELSYSDIR)/doc/pdf"
+ $(INSTALL_DIR) "$(RELSYSDIR)/doc/html"
$(INSTALL_DATA) $(HTMLDIR)/* \
- $(RELSYSDIR)/doc/html
- $(INSTALL_DATA) $(INFO_FILE) $(RELSYSDIR)
- $(INSTALL_DIR) $(RELEASE_PATH)/man/man3
- $(INSTALL_DATA) $(MAN3DIR)/* $(RELEASE_PATH)/man/man3
- $(INSTALL_DIR) $(RELEASE_PATH)/man/man6
- $(INSTALL_DATA) $(MAN6_FILES) $(RELEASE_PATH)/man/man6
+ "$(RELSYSDIR)/doc/html"
+ $(INSTALL_DATA) $(INFO_FILE) "$(RELSYSDIR)"
+ $(INSTALL_DIR) "$(RELEASE_PATH)/man/man3"
+ $(INSTALL_DATA) $(MAN3DIR)/* "$(RELEASE_PATH)/man/man3"
+ $(INSTALL_DIR) "$(RELEASE_PATH)/man/man6"
+ $(INSTALL_DATA) $(MAN6_FILES) "$(RELEASE_PATH)/man/man6"
release_spec:
diff --git a/lib/runtime_tools/doc/src/dyntrace.xml b/lib/runtime_tools/doc/src/dyntrace.xml
new file mode 100644
index 0000000000..5fc5530f25
--- /dev/null
+++ b/lib/runtime_tools/doc/src/dyntrace.xml
@@ -0,0 +1,209 @@
+<?xml version="1.0" encoding="latin1" ?>
+<!DOCTYPE erlref SYSTEM "erlref.dtd">
+
+<erlref>
+ <header>
+ <copyright>
+ <year>1996</year><year>2012</year>
+ <holder>Ericsson AB. All Rights Reserved.</holder>
+ </copyright>
+ <legalnotice>
+ The contents of this file are subject to the Erlang Public License,
+ Version 1.1, (the "License"); you may not use this file except in
+ compliance with the License. You should have received a copy of the
+ Erlang Public License along with this software. If not, it can be
+ retrieved online at http://www.erlang.org/.
+
+ Software distributed under the License is distributed on an "AS IS"
+ basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ the License for the specific language governing rights and limitations
+ under the License.
+
+ </legalnotice>
+
+ <title>dyntrace</title>
+ <prepared>Patrik Nyblom</prepared>
+ <responsible></responsible>
+ <docno>1</docno>
+ <approved>ETX/B/SFP (Kenneth Lundin)</approved>
+ <checked></checked>
+ <date>12-03-20</date>
+ <rev>A</rev>
+ <file>dyntrace.xml</file>
+ </header>
+ <module>dyntrace</module>
+ <modulesummary>Interface to dynamic tracing</modulesummary>
+ <description>
+ <p>This module implements interfaces to dynamic tracing, should such be compiled into the virtual machine. For a standard and/or commercial build, no dynamic tracing is available, in which case none of the functions in this module is usable or give any effect.</p>
+ <p>Should dynamic tracing be enabled in the current build, either by configuring with <c>./configure --with-dynamic-trace=dtrace</c> or with <c>./configure --with-dynamic-trace=systemtap</c>, the module can be used for two things:</p>
+ <list type="bulleted">
+ <item>Trigger the user-probe <c>user_trace_i4s4</c> in the NIF library <c>dyntrace.so</c> by calling <c>dyntrace:p/{1,2,3,4,5,6,7,8}</c>.</item>
+ <item>Set a user specified tag that will be present in the trace messages of both the <c>efile_drv</c> and the user-probe mentioned above.</item>
+ </list>
+ <p>Both building with dynamic trace probes and using them is experimental and unsupported by Erlang/OTP. It is included as an option for the developer to trace and debug performance issues in their systems.</p>
+ <p>The original implementation is mostly done by Scott Lystiger Fritchie as an Open Source Contribution and it should be viewed as such even though the source for dynamic tracing as well as this module is included in the main distribution. However, the ability to use dynamic tracing of the virtual machine is a very valuable contribution which OTP has every intention to maintain as a tool for the developer.</p>
+ <p>How to write <c>d</c> programs or <c>systemtap</c> scripts can be learned from books and from a lot of pages on the Internet. This manual page does not include any documentation about using the dynamic trace tools of respective platform. The <c>examples</c> directory of the <c>runtime_tools</c> application however contains comprehensive examples of both <c>d</c> and <c>systemtap</c> programs that will help you get started. Another source of information is the <c>README.dtrace(.md)</c> and <c>README.systemtap(.md)</c> files in the Erlang source top directory.</p>
+ </description>
+ <funcs>
+ <func>
+ <name>available() -> boolean()</name>
+ <fsummary>Check if dynamic tracing is available</fsummary>
+ <desc>
+ <p>This function uses the NIF library to determine if dynamic
+ tracing is available. Usually calling <seealso
+ marker="erts:erlang#system_info/1">erlang:system_info/1</seealso>
+ is a better indicator of the availability of dynamic
+ tracing.</p>
+ <p>The function will throw an exception if the <c>dyntrace</c> NIF library could not be loaded by the on_load function of this module.</p>
+ </desc>
+ </func>
+ <func>
+ <name>p() -> true | false | error | badarg</name>
+ <fsummary>Trigger the user trace probe.</fsummary>
+ <desc>
+ <p>Calling this function will trigger the "user" trace probe user_trace_i4s4 in the dyntrace NIF module, sending a trace message only containing the user tag and zeroes/empty strings in all other fields.</p>
+ </desc>
+ </func>
+ <func>
+ <name>p(integer() | string()) -> true | false | error | badarg</name>
+ <fsummary>Trigger the user trace probe.</fsummary>
+ <desc>
+ <p>Calling this function will trigger the "user" trace probe user_trace_i4s4 in the dyntrace NIF module, sending a trace message containing the user tag and the integer or string parameter in the first integer/string field.</p>
+ </desc>
+ </func>
+ <func>
+ <name>p(integer() | string(), integer() | string()) -> true | false | error | badarg</name>
+ <fsummary>Trigger the user trace probe.</fsummary>
+ <desc>
+ <p>Calling this function will trigger the "user" trace probe user_trace_i4s4 in the dyntrace NIF module, sending a trace message containing the user tag and the integer() or string() parameters as the first fields of respective type. integer() parameters should be put before any string() parameters. I.e. <c>p(1,"Hello")</c> is ok, as is <c>p(1,1)</c> and <c>p("Hello","Again")</c>, but not <c>p("Hello",1)</c>.</p>
+ </desc>
+ </func>
+ <func>
+ <name>p(integer() | string(), integer() | string(), integer() | string()) -> true | false | error | badarg</name>
+ <fsummary>Trigger the user trace probe.</fsummary>
+ <desc>
+ <p>Calling this function will trigger the "user" trace probe user_trace_i4s4 in the dyntrace NIF module, sending a trace message containing the user tag and the integer() or string() parameters as the first fields of respective type. integer() parameters should be put before any string() parameters, as in <seealso marker="#p/2">p/2</seealso>.</p>
+ </desc>
+ </func>
+ <func>
+ <name>p(integer() | string(), integer() | string(), integer() | string(), integer() | string()) -> true | false | error | badarg</name>
+ <fsummary>Trigger the user trace probe.</fsummary>
+ <desc>
+ <p>Calling this function will trigger the "user" trace probe user_trace_i4s4 in the dyntrace NIF module, sending a trace message containing the user tag and the integer() or string() parameters as the first fields of respective type. integer() parameters should be put before any string() parameters, as in <seealso marker="#p/2">p/2</seealso>.</p>
+ </desc>
+ </func>
+ <func>
+ <name>p(integer(), integer() | string(), integer() | string(), integer() | string(), string()) -> true | false | error | badarg</name>
+ <fsummary>Trigger the user trace probe.</fsummary>
+ <desc>
+ <p>Calling this function will trigger the "user" trace probe user_trace_i4s4 in the dyntrace NIF module, sending a trace message containing the user tag and the integer() or string() parameters as the first fields of respective type. integer() parameters should be put before any string() parameters, as in <seealso marker="#p/2">p/2</seealso>.</p>
+ <p>There can be no more than four parameters of any type (integer() or string()), so the first parameter has to be an integer() and the last a string().</p>
+ </desc>
+ </func>
+ <func>
+ <name>p(integer(), integer(), integer() | string(), integer() | string(), string(), string()) -> true | false | error | badarg</name>
+ <fsummary>Trigger the user trace probe.</fsummary>
+ <desc>
+ <p>Calling this function will trigger the "user" trace probe user_trace_i4s4 in the dyntrace NIF module, sending a trace message containing the user tag and the integer() or string() parameters as the first fields of respective type. integer() parameters should be put before any string() parameters, as in <seealso marker="#p/2">p/2</seealso>.</p>
+ <p>There can be no more than four parameters of any type (integer() or string()), so the first two parameters has to be integer()'s and the last two string()'s.</p>
+ </desc>
+ </func>
+ <func>
+ <name>p(integer(), integer(), integer(), integer() | string(), string(), string(), string()) -> true | false | error | badarg</name>
+ <fsummary>Trigger the user trace probe.</fsummary>
+ <desc>
+ <p>Calling this function will trigger the "user" trace probe user_trace_i4s4 in the dyntrace NIF module, sending a trace message containing the user tag and the integer() or string() parameters as the first fields of respective type. integer() parameters should be put before any string() parameters, as in <seealso marker="#p/2">p/2</seealso>.</p>
+ <p>There can be no more than four parameters of any type (integer() or string()), so the first three parameters has to be integer()'s and the last three string()'s.</p>
+ </desc>
+ </func>
+ <func>
+ <name>p(integer(), integer(), integer(), integer(), string(), string(), string(), string()) -> true | false | error | badarg</name>
+ <fsummary>Trigger the user trace probe.</fsummary>
+ <desc>
+ <p>Calling this function will trigger the "user" trace probe user_trace_i4s4 in the dyntrace NIF module, sending a trace message containing all the integer()'s and string()'s provided, as well as any user tag set in the current process.</p>
+ </desc>
+ </func>
+ <func>
+ <name>get_tag() -> binary() | undefined</name>
+ <fsummary>Get the user tag set in the process.</fsummary>
+ <desc>
+ <p>This function returns the user tag set in the current
+ process. If no tag is set or dynamic tracing is not available,
+ it returns <c>undefined</c></p>
+ </desc>
+ </func>
+ <func>
+ <name>get_tag() -> binary() | undefined</name>
+ <fsummary>Get the user tag set in the process or sent to the process.</fsummary>
+ <desc>
+ <p>This function returns the user tag set in the current
+ process or, if no user tag is present, the last user tag sent
+ to the process together with a message (in the same way as
+ <seealso marker="kernel:seq_trace">sequential trace
+ tokens</seealso> are spread to other processes together with
+ messages. For an explanation of how user tags can be spread
+ together with messages, see <seealso
+ marker="#spread_tag/1">spread_tag/1</seealso>. If no tag is
+ found or dynamic tracing is not available, it returns
+ <c>undefined</c></p>
+ </desc>
+ </func>
+
+ <func>
+ <name>put_tag(Item) -> binary() | undefined </name>
+ <fsummary>Set the user tag of the current process.</fsummary>
+ <type>
+ <v>Item = iodata()</v>
+ </type>
+ <desc>
+ <p>This function sets the user tag of the current process. The user tag is a binary(), but can be specified as any iodata(), which is automatically converted to a binary by this function.</p>
+ <p>The user tag is provided to the user probes triggered by calls top <c>dyntrace:p/{1,2,3,4,5,6,7,8}</c> as well as probes in the efile_driver. In the future, user tags might be added to more probes.</p>
+ <p>The old user tag (if any) is returned, or <c>undefined</c> if no user tag was present or dynamic tracing is not enabled.</p>
+ </desc>
+ </func>
+ <func>
+ <name>spread_tag(boolean()) -> TagData</name>
+ <fsummary>Start or stop spreading dynamic trace user tags with the next message.</fsummary>
+ <type>
+ <v>TagData = opaque data that can be used as parameter to <seealso marker="#restore_tag/1">restore_tag/1</seealso></v>
+ </type>
+ <desc>
+ <p>This function controls if user tags are to be spread to other processes with the next message. Spreading of user tags work like spreading of sequential trace tokens, so that a received user tag will be active in the process until the next message arrives (if that message does not also contain the user tag.</p>
+ <p>This functionality is used when a client process communicates with a file i/o-server to spread the user tag to the I/O-server and then down to the efile_drv driver. By using <c>spread_tag/1</c> and <c>restore_tag/1</c>, one can enable or disable spreading of user tags to other processes and then restore the previous state of the user tag. The TagData returned from this call contains all previous information so the state (including any previously spread user tags) will be completely restored by a later call to <c>restore_tag/1</c>.</p>
+ <p>The <seealso marker="kernel:file">file</seealso> module already spread's tags, so there is noo need to manually call these function to get user tags spread to the efile driver through that module.</p>
+ <p>The most use of this function would be if one for example uses the <seealso marker="stdlib:io">io</seealso> module to communicate with an I/O-server for a regular file, like in the following example:</p>
+<pre>
+f() ->
+ {ok, F} = file:open("test.tst",[write]),
+ Saved = dyntrace:spread_tag(true),
+ io:format(F,"Hello world!",[]),
+ dyntrace:restore_tag(Saved),
+ file:close(F).
+</pre>
+ <p>In this example, any user tag set in the calling process will be spread to the I/O-server when the io:format call is done.</p>
+ </desc>
+ </func>
+ <func>
+ <name>restore_tag(TagData) -> true</name>
+ <fsummary>Restore to a previous state of user tag spreading.</fsummary>
+ <type>
+ <v>TagData = opaque data returned by <seealso marker="#spread_tag/1">spread_tag/1</seealso></v>
+ </type>
+ <desc>
+ <p>Restores the previous state of user tags and their spreading as it was before a call to <seealso marker="#spread_tag/1">spread_tag/1</seealso>. Note that the restoring is not limited to the same process, one can utilize this to turn off spreding in one process and restore it in a newly created, the one that actually is going to send messages:</p>
+<pre>
+f() ->
+ TagData=dyntrace:spread_tag(false),
+ spawn(fun() ->
+ dyntrace:restore_tag(TagData),
+ do_something()
+ end),
+ do_something_else(),
+ dyntrace:restore_tag(TagData).
+</pre>
+ <p>Correctly handling user tags and their spreading might take some effort, as Erlang programs tend to send and receive messages so that sometimes the user tag gets lost due to various things, like double receives or communication with a port (ports do not handle user tags, in the same way as they do not handle regular sequential trace tokens).</p>
+ </desc>
+ </func>
+ </funcs>
+ </erlref>
+
diff --git a/lib/runtime_tools/doc/src/notes.xml b/lib/runtime_tools/doc/src/notes.xml
index ccf11bf0fe..2d4a206e1c 100644
--- a/lib/runtime_tools/doc/src/notes.xml
+++ b/lib/runtime_tools/doc/src/notes.xml
@@ -31,6 +31,28 @@
<p>This document describes the changes made to the Runtime_Tools
application.</p>
+<section><title>Runtime_Tools 1.8.8</title>
+
+ <section><title>Improvements and New Features</title>
+ <list>
+ <item>
+ <p>
+ The DTrace source patch from Scott Lystig Fritchie is
+ integrated in the source tree. Using an emulator with
+ dtrace probe is still not supported for production use,
+ but may be a valuable debugging tool. Configure with
+ --with-dynamic-trace=dtrace (or
+ --with-dynamic-trace=systemtap) to create a build with
+ dtrace probes enabled. See runtime_tools for
+ documentation and examples.</p>
+ <p>
+ Own Id: OTP-10017</p>
+ </item>
+ </list>
+ </section>
+
+</section>
+
<section><title>Runtime_Tools 1.8.7</title>
<section><title>Fixed Bugs and Malfunctions</title>
diff --git a/lib/runtime_tools/doc/src/ref_man.xml b/lib/runtime_tools/doc/src/ref_man.xml
index 579efcd969..df3446cd17 100644
--- a/lib/runtime_tools/doc/src/ref_man.xml
+++ b/lib/runtime_tools/doc/src/ref_man.xml
@@ -4,7 +4,7 @@
<application xmlns:xi="http://www.w3.org/2001/XInclude">
<header>
<copyright>
- <year>1999</year><year>2009</year>
+ <year>1999</year><year>2012</year>
<holder>Ericsson AB. All Rights Reserved.</holder>
</copyright>
<legalnotice>
@@ -33,6 +33,7 @@
</description>
<xi:include href="runtime_tools_app.xml"/>
<xi:include href="dbg.xml"/>
+ <xi:include href="dyntrace.xml"/>
<xi:include href="erts_alloc_config.xml"/>
</application>
diff --git a/lib/runtime_tools/examples/dist.d b/lib/runtime_tools/examples/dist.d
new file mode 100644
index 0000000000..7e2d7f0e35
--- /dev/null
+++ b/lib/runtime_tools/examples/dist.d
@@ -0,0 +1,62 @@
+/* example usage: dtrace -q -s /path/to/dist.d */
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Scott Lystig Fritchie 2011-2012. All Rights Reserved.
+ *
+ * The contents of this file are subject to the Erlang Public License,
+ * Version 1.1, (the "License"); you may not use this file except in
+ * compliance with the License. You should have received a copy of the
+ * Erlang Public License along with this software. If not, it can be
+ * retrieved online at http://www.erlang.org/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * %CopyrightEnd%
+ */
+
+erlang*:::dist-monitor
+{
+ printf("monitor: pid %d, who %s, what %s, node %s, type %s, reason %s\n",
+ pid,
+ copyinstr(arg0), copyinstr(arg1), copyinstr(arg2), copyinstr(arg3),
+ copyinstr(arg4));
+}
+
+erlang*:::dist-port_busy
+{
+ printf("dist port_busy: node %s, port %s, remote_node %s, blocked pid %s\n",
+ copyinstr(arg0), copyinstr(arg1), copyinstr(arg2), copyinstr(arg3));
+ /*
+ * For variable use advice, see:
+ * http://dtrace.org/blogs/brendan/2011/11/25/dtrace-variable-types/
+ *
+ * Howevever, it's quite possible for the blocked events to span
+ * threads, so we'll use globals.
+ */
+ blocked_procs[copyinstr(arg3)] = timestamp;
+}
+
+erlang*:::dist-output
+{
+ printf("dist output: node %s, port %s, remote_node %s bytes %d\n",
+ copyinstr(arg0), copyinstr(arg1), copyinstr(arg2), arg3);
+}
+
+erlang*:::dist-outputv
+{
+ printf("port outputv: node %s, port %s, remote_node %s bytes %d\n",
+ copyinstr(arg0), copyinstr(arg1), copyinstr(arg2), arg3);
+}
+
+erlang*:::process-scheduled
+/blocked_procs[copyinstr(arg0)]/
+{
+ pidstr = copyinstr(arg0);
+ printf("blocked pid %s scheduled now, waited %d microseconds\n",
+ pidstr, (timestamp - blocked_procs[pidstr]) / 1000);
+ blocked_procs[pidstr] = 0;
+}
diff --git a/lib/runtime_tools/examples/dist.systemtap b/lib/runtime_tools/examples/dist.systemtap
new file mode 100644
index 0000000000..8935e19e28
--- /dev/null
+++ b/lib/runtime_tools/examples/dist.systemtap
@@ -0,0 +1,76 @@
+/* example usage: stap /path/to/dist.systemtap -x <pid> */
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011-2012. All Rights Reserved.
+ *
+ * The contents of this file are subject to the Erlang Public License,
+ * Version 1.1, (the "License"); you may not use this file except in
+ * compliance with the License. You should have received a copy of the
+ * Erlang Public License along with this software. If not, it can be
+ * retrieved online at http://www.erlang.org/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * %CopyrightEnd%
+ */
+/*
+ * Note: This file assumes that you're using the non-SMP-enabled Erlang
+ * virtual machine, "beam". The SMP-enabled VM is called "beam.smp".
+ * Note that other variations of the virtual machine also have
+ * different names, e.g. the debug build of the SMP-enabled VM
+ * is "beam.debug.smp".
+ *
+ * To use a different virtual machine, replace each instance of
+ * "beam" with "beam.smp" or the VM name appropriate to your
+ * environment.
+ */
+
+probe process("beam").mark("dist-monitor")
+{
+ printf("monitor: pid %d, who %s, what %s, node %s, type %s, reason %s\n",
+ pid(),
+ user_string($arg1), user_string($arg2), user_string($arg3), user_string($arg4),
+ user_string($arg5));
+}
+
+probe process("beam").mark("dist-port_busy")
+{
+ printf("dist port_busy: node %s, port %s, remote_node %s, blocked pid %s\n",
+ user_string($arg1), user_string($arg2), user_string($arg3), user_string($arg4));
+ blocked_procs[user_string($arg4)] = timestamp;
+}
+
+probe process("beam").mark("dist-port_busy")
+{
+ printf("dist port_busy: node %s, port %s, remote_node %s, blocked pid %s\n",
+ user_string($arg1), user_string($arg2), user_string($arg3), user_string($arg4));
+ blocked_procs[user_string($arg4)] = timestamp;
+}
+
+probe process("beam").mark("dist-output")
+{
+ printf("dist output: node %s, port %s, remote_node %s bytes %d\n",
+ user_string($arg1), user_string($arg2), user_string($arg3), $arg4);
+}
+
+probe process("beam").mark("dist-outputv")
+{
+ printf("port outputv: node %s, port %s, remote_node %s bytes %d\n",
+ user_string($arg1), user_string($arg2), user_string($arg3), $arg4);
+}
+
+probe process("beam").mark("process-scheduled")
+{
+ pidstr = user_string($arg1);
+ if (pidstr in blocked_procs) {
+ printf("blocked pid %s scheduled now, waited %d microseconds\n",
+ pidstr, (timestamp - blocked_procs[pidstr]) / 1000);
+ delete blocked_procs[pidstr];
+ }
+}
+
+global blocked_procs;
diff --git a/lib/runtime_tools/examples/driver1.d b/lib/runtime_tools/examples/driver1.d
new file mode 100644
index 0000000000..4871a8ee69
--- /dev/null
+++ b/lib/runtime_tools/examples/driver1.d
@@ -0,0 +1,114 @@
+/* example usage: dtrace -q -s /path/to/driver1.d */
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Scott Lystig Fritchie 2011-2012. All Rights Reserved.
+ *
+ * The contents of this file are subject to the Erlang Public License,
+ * Version 1.1, (the "License"); you may not use this file except in
+ * compliance with the License. You should have received a copy of the
+ * Erlang Public License along with this software. If not, it can be
+ * retrieved online at http://www.erlang.org/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * %CopyrightEnd%
+ */
+
+erlang*:::driver-init
+{
+ printf("driver init name %s major %d minor %d flags %d\n",
+ copyinstr(arg0), arg1, arg2, arg3);
+}
+
+erlang*:::driver-start
+{
+ printf("driver start pid %s driver name %s port %s\n",
+ copyinstr(arg0), copyinstr(arg1), copyinstr(arg2));
+}
+
+erlang*:::driver-stop
+{
+ printf("driver stop pid %s driver name %s port %s\n",
+ copyinstr(arg0), copyinstr(arg1), copyinstr(arg2));
+}
+
+erlang*:::driver-finish
+{
+ printf("driver finish driver name %s port %s\n",
+ copyinstr(arg0), copyinstr(arg1));
+}
+
+erlang*:::driver-flush
+{
+ printf("driver flush pid %s port %s port name %s\n",
+ copyinstr(arg0), copyinstr(arg1), copyinstr(arg2));
+}
+
+erlang*:::driver-output
+{
+ printf("driver output pid %s port %s port name %s bytes %d\n",
+ copyinstr(arg0), copyinstr(arg1), copyinstr(arg2), arg3);
+}
+
+erlang*:::driver-outputv
+{
+ printf("driver outputv pid %s port %s port name %s bytes %d\n",
+ copyinstr(arg0), copyinstr(arg1), copyinstr(arg2), arg3);
+}
+
+erlang*:::driver-control
+{
+ printf("driver control pid %s port %s port name %s command %d bytes %d\n",
+ copyinstr(arg0), copyinstr(arg1), copyinstr(arg2), arg3, arg4);
+}
+
+erlang*:::driver-call
+{
+ printf("driver call pid %s port %s port name %s command %d bytes %d\n",
+ copyinstr(arg0), copyinstr(arg1), copyinstr(arg2), arg3, arg4);
+}
+
+erlang*:::driver-event
+{
+ printf("driver event pid %s port %s port name %s\n",
+ copyinstr(arg0), copyinstr(arg1), copyinstr(arg2));
+}
+
+erlang*:::driver-ready_input
+{
+ printf("driver ready_input pid %s port %s port name %s\n",
+ copyinstr(arg0), copyinstr(arg1), copyinstr(arg2));
+}
+
+erlang*:::driver-ready_output
+{
+ printf("driver ready_output pid %s port %s port name %s\n",
+ copyinstr(arg0), copyinstr(arg1), copyinstr(arg2));
+}
+
+erlang*:::driver-timeout
+{
+ printf("driver timeout pid %s port %s port name %s\n",
+ copyinstr(arg0), copyinstr(arg1), copyinstr(arg2));
+}
+
+erlang*:::driver-ready_async
+{
+ printf("driver ready_async pid %s port %s port name %s\n",
+ copyinstr(arg0), copyinstr(arg1), copyinstr(arg2));
+}
+
+erlang*:::driver-process_exit
+{
+ printf("driver process_exit pid %s port %s port name %s\n",
+ copyinstr(arg0), copyinstr(arg1), copyinstr(arg2));
+}
+
+erlang*:::driver-stop_select
+{
+ printf("driver stop_select driver name %s\n", copyinstr(arg0));
+}
diff --git a/lib/runtime_tools/examples/driver1.systemtap b/lib/runtime_tools/examples/driver1.systemtap
new file mode 100644
index 0000000000..deae82f8fb
--- /dev/null
+++ b/lib/runtime_tools/examples/driver1.systemtap
@@ -0,0 +1,125 @@
+/* example usage: stap /path/to/driver1.systemtap -x <pid> */
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011-2012. All Rights Reserved.
+ *
+ * The contents of this file are subject to the Erlang Public License,
+ * Version 1.1, (the "License"); you may not use this file except in
+ * compliance with the License. You should have received a copy of the
+ * Erlang Public License along with this software. If not, it can be
+ * retrieved online at http://www.erlang.org/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * %CopyrightEnd%
+ */
+/*
+ * Note: This file assumes that you're using the non-SMP-enabled Erlang
+ * virtual machine, "beam". The SMP-enabled VM is called "beam.smp".
+ * Note that other variations of the virtual machine also have
+ * different names, e.g. the debug build of the SMP-enabled VM
+ * is "beam.debug.smp".
+ *
+ * To use a different virtual machine, replace each instance of
+ * "beam" with "beam.smp" or the VM name appropriate to your
+ * environment.
+ */
+
+probe process("beam").mark("driver-init")
+{
+ printf("driver init name %s major %d minor %d flags %d\n",
+ user_string($arg1), $arg2, $arg3, $arg4);
+}
+
+probe process("beam").mark("driver-start")
+{
+ printf("driver start pid %s driver name %s port %s\n",
+ user_string($arg1), user_string($arg2), user_string($arg3));
+}
+
+probe process("beam").mark("driver-stop")
+{
+ printf("driver stop pid %s driver name %s port %s\n",
+ user_string($arg1), user_string($arg2), user_string($arg3));
+}
+
+probe process("beam").mark("driver-finish")
+{
+ printf("driver finish driver name %s\n",
+ user_string($arg1));
+}
+
+probe process("beam").mark("driver-flush")
+{
+ printf("driver flush pid %s port %s port name %s\n",
+ user_string($arg1), user_string($arg2), user_string($arg3));
+}
+
+probe process("beam").mark("driver-output")
+{
+ printf("driver output pid %s port %s port name %s bytes %d\n",
+ user_string($arg1), user_string($arg2), user_string($arg3), $arg4);
+}
+
+probe process("beam").mark("driver-outputv")
+{
+ printf("driver outputv pid %s port %s port name %s bytes %d\n",
+ user_string($arg1), user_string($arg2), user_string($arg3), $arg4);
+}
+
+probe process("beam").mark("driver-control")
+{
+ printf("driver control pid %s port %s port name %s command %d bytes %d\n",
+ user_string($arg1), user_string($arg2), user_string($arg3), $arg4, $arg5);
+}
+
+probe process("beam").mark("driver-call")
+{
+ printf("driver call pid %s port %s port name %s command %d bytes %d\n",
+ user_string($arg1), user_string($arg2), user_string($arg3), $arg4, $arg5);
+}
+
+probe process("beam").mark("driver-event")
+{
+ printf("driver event pid %s port %s port name %s\n",
+ user_string($arg1), user_string($arg2), user_string($arg3));
+}
+
+probe process("beam").mark("driver-ready_input")
+{
+ printf("driver ready_input pid %s port %s port name %s\n",
+ user_string($arg1), user_string($arg2), user_string($arg3));
+}
+
+probe process("beam").mark("driver-ready_output")
+{
+ printf("driver ready_output pid %s port %s port name %s\n",
+ user_string($arg1), user_string($arg2), user_string($arg3));
+}
+
+probe process("beam").mark("driver-timeout")
+{
+ printf("driver timeout pid %s port %s port name %s\n",
+ user_string($arg1), user_string($arg2), user_string($arg3));
+}
+
+probe process("beam").mark("driver-ready_async")
+{
+ printf("driver ready_async pid %s port %s port name %s\n",
+ user_string($arg1), user_string($arg2), user_string($arg3));
+}
+
+probe process("beam").mark("driver-process_exit")
+{
+ printf("driver process_exit pid %s port %s port name %s\n",
+ user_string($arg1), user_string($arg2), user_string($arg3));
+}
+
+probe process("beam").mark("driver-stop_select")
+{
+ printf("driver stop_select driver name %s\n", user_string($arg1));
+}
diff --git a/lib/runtime_tools/examples/efile_drv.d b/lib/runtime_tools/examples/efile_drv.d
new file mode 100644
index 0000000000..2442222552
--- /dev/null
+++ b/lib/runtime_tools/examples/efile_drv.d
@@ -0,0 +1,104 @@
+/* example usage: dtrace -q -s /path/to/efile_drv.d */
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Scott Lystig Fritchie 2011-2012. All Rights Reserved.
+ *
+ * The contents of this file are subject to the Erlang Public License,
+ * Version 1.1, (the "License"); you may not use this file except in
+ * compliance with the License. You should have received a copy of the
+ * Erlang Public License along with this software. If not, it can be
+ * retrieved online at http://www.erlang.org/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * %CopyrightEnd%
+ */
+
+BEGIN
+{
+ op_map[1] = "OPEN";
+ op_map[2] = "READ";
+ op_map[3] = "LSEEK";
+ op_map[4] = "WRITE";
+ op_map[5] = "FSTAT";
+ op_map[6] = "PWD";
+ op_map[7] = "READDIR";
+ op_map[8] = "CHDIR";
+ op_map[9] = "FSYNC";
+ op_map[10] = "MKDIR";
+ op_map[11] = "DELETE";
+ op_map[12] = "RENAME";
+ op_map[13] = "RMDIR";
+ op_map[14] = "TRUNCATE";
+ op_map[15] = "READ_FILE";
+ op_map[16] = "WRITE_INFO";
+ op_map[19] = "LSTAT";
+ op_map[20] = "READLINK";
+ op_map[21] = "LINK";
+ op_map[22] = "SYMLINK";
+ op_map[23] = "CLOSE";
+ op_map[24] = "PWRITEV";
+ op_map[25] = "PREADV";
+ op_map[26] = "SETOPT";
+ op_map[27] = "IPREAD";
+ op_map[28] = "ALTNAME";
+ op_map[29] = "READ_LINE";
+ op_map[30] = "FDATASYNC";
+ op_map[31] = "FADVISE";
+}
+
+erlang*:::aio_pool-add
+{
+ printf("async I/O pool port %s queue len %d\n", copyinstr(arg0), arg1);
+}
+
+erlang*:::aio_pool-get
+{
+ printf("async I/O pool port %s queue len %d\n", copyinstr(arg0), arg1);
+}
+
+erlang*:::efile_drv-entry
+{
+ printf("efile_drv enter tag={%d,%d} %s%s | %s (%d) | args: %s %s , %d %d (port %s)\n",
+ arg0, arg1,
+ arg2 == NULL ? "" : "user tag ",
+ arg2 == NULL ? "" : copyinstr(arg2),
+ op_map[arg3], arg3,
+ arg4 == NULL ? "" : copyinstr(arg4),
+ arg5 == NULL ? "" : copyinstr(arg5), arg6, arg7,
+ /* NOTE: port name in args[10] is experimental */
+ (args[10] == NULL) ?
+ "?" : copyinstr((user_addr_t) args[10]));
+}
+
+erlang*:::efile_drv-int*
+{
+ printf("async I/O worker tag={%d,%d} | %s (%d) | %s\n",
+ arg0, arg1, op_map[arg2], arg2, probename);
+}
+
+/* efile_drv-return error case */
+erlang*:::efile_drv-return
+/arg4 == 0/
+{
+ printf("efile_drv return tag={%d,%d} %s%s | %s (%d) | errno %d\n",
+ arg0, arg1,
+ arg2 == NULL ? "" : "user tag ",
+ arg2 == NULL ? "" : copyinstr(arg2),
+ op_map[arg3], arg3,
+ arg5);
+}
+
+/* efile_drv-return success case */
+erlang*:::efile_drv-return
+/arg4 != 0/
+{
+ printf("efile_drv return tag={%d,%d} %s | %s (%d) ok\n",
+ arg0, arg1,
+ arg2 == NULL ? "" : copyinstr(arg2),
+ op_map[arg3], arg3);
+}
diff --git a/lib/runtime_tools/examples/efile_drv.systemtap b/lib/runtime_tools/examples/efile_drv.systemtap
new file mode 100644
index 0000000000..4b92e67048
--- /dev/null
+++ b/lib/runtime_tools/examples/efile_drv.systemtap
@@ -0,0 +1,112 @@
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011-2012. All Rights Reserved.
+ *
+ * The contents of this file are subject to the Erlang Public License,
+ * Version 1.1, (the "License"); you may not use this file except in
+ * compliance with the License. You should have received a copy of the
+ * Erlang Public License along with this software. If not, it can be
+ * retrieved online at http://www.erlang.org/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * %CopyrightEnd%
+ */
+/*
+ * Note: This file assumes that you're using the non-SMP-enabled Erlang
+ * virtual machine, "beam". The SMP-enabled VM is called "beam.smp".
+ * Note that other variations of the virtual machine also have
+ * different names, e.g. the debug build of the SMP-enabled VM
+ * is "beam.debug.smp".
+ *
+ * To use a different virtual machine, replace each instance of
+ * "beam" with "beam.smp" or the VM name appropriate to your
+ * environment.
+ */
+
+probe begin
+{
+ op_map[1] = "OPEN";
+ op_map[2] = "READ";
+ op_map[3] = "LSEEK";
+ op_map[4] = "WRITE";
+ op_map[5] = "FSTAT";
+ op_map[6] = "PWD";
+ op_map[7] = "READDIR";
+ op_map[8] = "CHDIR";
+ op_map[9] = "FSYNC";
+ op_map[10] = "MKDIR";
+ op_map[11] = "DELETE";
+ op_map[12] = "RENAME";
+ op_map[13] = "RMDIR";
+ op_map[14] = "TRUNCATE";
+ op_map[15] = "READ_FILE";
+ op_map[16] = "WRITE_INFO";
+ op_map[19] = "LSTAT";
+ op_map[20] = "READLINK";
+ op_map[21] = "LINK";
+ op_map[22] = "SYMLINK";
+ op_map[23] = "CLOSE";
+ op_map[24] = "PWRITEV";
+ op_map[25] = "PREADV";
+ op_map[26] = "SETOPT";
+ op_map[27] = "IPREAD";
+ op_map[28] = "ALTNAME";
+ op_map[29] = "READ_LINE";
+ op_map[30] = "FDATASYNC";
+ op_map[31] = "FADVISE";
+}
+
+probe process("beam").mark("aio_pool-add")
+{
+ printf("async I/O pool port %s queue len %d\n", user_string($arg1), $arg2);
+}
+
+probe process("beam").mark("aio_pool-get")
+{
+ printf("async I/O pool port %s queue len %d\n", user_string($arg1), $arg2);
+}
+
+probe process("beam").mark("efile_drv-entry")
+{
+ printf("efile_drv enter tag={%d,%d} %s%s | %s (%d) | args: %s %s , %d %d (port %s)\n",
+ $arg1, $arg2,
+ $arg3 == NULL ? "" : "user tag ",
+ $arg3 == NULL ? "" : user_string($arg3),
+ op_map[$arg4], $arg4,
+ $arg5 == NULL ? "" : user_string($arg5),
+ $arg6 == NULL ? "" : user_string($arg6), $arg7, $arg8,
+ /* NOTE: port name in $arg[11] is experimental */
+ user_string($arg11))
+}
+
+probe process("beam").mark("efile_drv-int*")
+{
+ printf("async I/O worker tag={%d,%d} | %s (%d) | %s\n",
+ $arg1, $arg2, op_map[$arg3], $arg3, probefunc());
+}
+
+probe process("beam").mark("efile_drv-return")
+{
+ if ($arg5 == 0) {
+ /* efile_drv-return error case */
+ printf("efile_drv return tag={%d,%d} %s%s | %s (%d) | errno %d\n",
+ $arg1, $arg2,
+ $arg3 == NULL ? "" : "user tag ",
+ $arg3 == NULL ? "" : user_string($arg3),
+ op_map[$arg4], $arg4,
+ $arg6);
+ } else {
+ /* efile_drv-return success case */
+ printf("efile_drv return tag={%d,%d} %s | %s (%d) ok\n",
+ $arg1, $arg2,
+ $arg3 == NULL ? "" : user_string($arg3),
+ op_map[$arg4], $arg4);
+ }
+}
+
+global op_map;
diff --git a/lib/runtime_tools/examples/function-calls.d b/lib/runtime_tools/examples/function-calls.d
new file mode 100644
index 0000000000..ec6090553e
--- /dev/null
+++ b/lib/runtime_tools/examples/function-calls.d
@@ -0,0 +1,57 @@
+/* example usage: dtrace -q -s /path/to/function-calls.d */
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Scott Lystig Fritchie 2011-2012. All Rights Reserved.
+ *
+ * The contents of this file are subject to the Erlang Public License,
+ * Version 1.1, (the "License"); you may not use this file except in
+ * compliance with the License. You should have received a copy of the
+ * Erlang Public License along with this software. If not, it can be
+ * retrieved online at http://www.erlang.org/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * %CopyrightEnd%
+ */
+
+erlang*:::local-function-entry
+{
+ printf("pid %s enter (local) %s depth %d\n",
+ copyinstr(arg0), copyinstr(arg1), arg2);
+}
+
+erlang*:::global-function-entry
+{
+ printf("pid %s enter (global) %s depth %d\n",
+ copyinstr(arg0), copyinstr(arg1), arg2);
+}
+
+erlang*:::function-return
+{
+ printf("pid %s return %s depth %d\n",
+ copyinstr(arg0), copyinstr(arg1), arg2);
+}
+
+erlang*:::bif-entry
+{
+ printf("pid %s BIF entry mfa %s\n", copyinstr(arg0), copyinstr(arg1));
+}
+
+erlang*:::bif-return
+{
+ printf("pid %s BIF return mfa %s\n", copyinstr(arg0), copyinstr(arg1));
+}
+
+erlang*:::nif-entry
+{
+ printf("pid %s NIF entry mfa %s\n", copyinstr(arg0), copyinstr(arg1));
+}
+
+erlang*:::nif-return
+{
+ printf("pid %s NIF return mfa %s\n", copyinstr(arg0), copyinstr(arg1));
+}
diff --git a/lib/runtime_tools/examples/function-calls.systemtap b/lib/runtime_tools/examples/function-calls.systemtap
new file mode 100644
index 0000000000..4de54cfb5a
--- /dev/null
+++ b/lib/runtime_tools/examples/function-calls.systemtap
@@ -0,0 +1,67 @@
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011-2012. All Rights Reserved.
+ *
+ * The contents of this file are subject to the Erlang Public License,
+ * Version 1.1, (the "License"); you may not use this file except in
+ * compliance with the License. You should have received a copy of the
+ * Erlang Public License along with this software. If not, it can be
+ * retrieved online at http://www.erlang.org/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * %CopyrightEnd%
+ */
+/*
+ * Note: This file assumes that you're using the non-SMP-enabled Erlang
+ * virtual machine, "beam". The SMP-enabled VM is called "beam.smp".
+ * Note that other variations of the virtual machine also have
+ * different names, e.g. the debug build of the SMP-enabled VM
+ * is "beam.debug.smp".
+ *
+ * To use a different virtual machine, replace each instance of
+ * "beam" with "beam.smp" or the VM name appropriate to your
+ * environment.
+ */
+
+probe process("beam").mark("local-function-entry")
+{
+ printf("pid %s enter (local) %s depth %d\n",
+ user_string($arg1), user_string($arg2), $arg3);
+}
+
+probe process("beam").mark("global-function-entry")
+{
+ printf("pid %s enter (global) %s depth %d\n",
+ user_string($arg1), user_string($arg2), $arg3);
+}
+
+probe process("beam").mark("function-return")
+{
+ printf("pid %s return %s depth %d\n",
+ user_string($arg1), user_string($arg2), $arg3);
+}
+
+probe process("beam").mark("bif-entry")
+{
+ printf("pid %s BIF entry mfa %s\n", user_string($arg1), user_string($arg2));
+}
+
+probe process("beam").mark("bif-return")
+{
+ printf("pid %s BIF return mfa %s\n", user_string($arg1), user_string($arg2));
+}
+
+probe process("beam").mark("nif-entry")
+{
+ printf("pid %s NIF entry mfa %s\n", user_string($arg1), user_string($arg2));
+}
+
+probe process("beam").mark("nif-return")
+{
+ printf("pid %s NIF return mfa %s\n", user_string($arg1), user_string($arg2));
+}
diff --git a/lib/runtime_tools/examples/garbage-collection.d b/lib/runtime_tools/examples/garbage-collection.d
new file mode 100644
index 0000000000..ebc40a19ec
--- /dev/null
+++ b/lib/runtime_tools/examples/garbage-collection.d
@@ -0,0 +1,39 @@
+/* example usage: dtrace -q -s /path/to/garbage-collection.d */
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Scott Lystig Fritchie 2011-2012. All Rights Reserved.
+ *
+ * The contents of this file are subject to the Erlang Public License,
+ * Version 1.1, (the "License"); you may not use this file except in
+ * compliance with the License. You should have received a copy of the
+ * Erlang Public License along with this software. If not, it can be
+ * retrieved online at http://www.erlang.org/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * %CopyrightEnd%
+ */
+
+erlang*:::gc_major-start
+{
+ printf("GC major start pid %s need %d words\n", copyinstr(arg0), arg1);
+}
+
+erlang*:::gc_minor-start
+{
+ printf("GC minor start pid %s need %d words\n", copyinstr(arg0), arg1);
+}
+
+erlang*:::gc_major-end
+{
+ printf("GC major end pid %s reclaimed %d words\n", copyinstr(arg0), arg1);
+}
+
+erlang*:::gc_minor-start
+{
+ printf("GC minor end pid %s reclaimed %d words\n", copyinstr(arg0), arg1);
+}
diff --git a/lib/runtime_tools/examples/garbage-collection.systemtap b/lib/runtime_tools/examples/garbage-collection.systemtap
new file mode 100644
index 0000000000..81e9d38196
--- /dev/null
+++ b/lib/runtime_tools/examples/garbage-collection.systemtap
@@ -0,0 +1,49 @@
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011-2012. All Rights Reserved.
+ *
+ * The contents of this file are subject to the Erlang Public License,
+ * Version 1.1, (the "License"); you may not use this file except in
+ * compliance with the License. You should have received a copy of the
+ * Erlang Public License along with this software. If not, it can be
+ * retrieved online at http://www.erlang.org/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * %CopyrightEnd%
+ */
+/*
+ * Note: This file assumes that you're using the non-SMP-enabled Erlang
+ * virtual machine, "beam". The SMP-enabled VM is called "beam.smp".
+ * Note that other variations of the virtual machine also have
+ * different names, e.g. the debug build of the SMP-enabled VM
+ * is "beam.debug.smp".
+ *
+ * To use a different virtual machine, replace each instance of
+ * "beam" with "beam.smp" or the VM name appropriate to your
+ * environment.
+ */
+
+probe process("beam").mark("gc_major-start")
+{
+ printf("GC major start pid %s need %d words\n", user_string($arg1), $arg2);
+}
+
+probe process("beam").mark("gc_minor-start")
+{
+ printf("GC minor start pid %s need %d words\n", user_string($arg1), $arg2);
+}
+
+probe process("beam").mark("gc_major-end")
+{
+ printf("GC major end pid %s reclaimed %d words\n", user_string($arg1), $arg2);
+}
+
+probe process("beam").mark("gc_minor-start")
+{
+ printf("GC minor end pid %s reclaimed %d words\n", user_string($arg1), $arg2);
+}
diff --git a/lib/runtime_tools/examples/memory1.d b/lib/runtime_tools/examples/memory1.d
new file mode 100644
index 0000000000..b222aeae62
--- /dev/null
+++ b/lib/runtime_tools/examples/memory1.d
@@ -0,0 +1,41 @@
+/* example usage: dtrace -q -s /path/to/memory1.d */
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Scott Lystig Fritchie 2011-2012. All Rights Reserved.
+ *
+ * The contents of this file are subject to the Erlang Public License,
+ * Version 1.1, (the "License"); you may not use this file except in
+ * compliance with the License. You should have received a copy of the
+ * Erlang Public License along with this software. If not, it can be
+ * retrieved online at http://www.erlang.org/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * %CopyrightEnd%
+ */
+
+erlang*:::copy-struct
+{
+ printf("copy_struct %d bytes\n", arg0);
+}
+
+erlang*:::copy-object
+{
+ printf("copy_object pid %s %d bytes\n", copyinstr(arg0), arg1);
+}
+
+erlang*:::process-heap_grow
+{
+ printf("proc heap grow pid %s %d -> %d bytes\n", copyinstr(arg0),
+ arg1, arg2);
+}
+
+erlang*:::process-heap_shrink
+{
+ printf("proc heap shrink pid %s %d -> %d bytes\n", copyinstr(arg0),
+ arg1, arg2);
+}
diff --git a/lib/runtime_tools/examples/memory1.systemtap b/lib/runtime_tools/examples/memory1.systemtap
new file mode 100644
index 0000000000..9374b97d18
--- /dev/null
+++ b/lib/runtime_tools/examples/memory1.systemtap
@@ -0,0 +1,51 @@
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011-2012. All Rights Reserved.
+ *
+ * The contents of this file are subject to the Erlang Public License,
+ * Version 1.1, (the "License"); you may not use this file except in
+ * compliance with the License. You should have received a copy of the
+ * Erlang Public License along with this software. If not, it can be
+ * retrieved online at http://www.erlang.org/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * %CopyrightEnd%
+ */
+/*
+ * Note: This file assumes that you're using the non-SMP-enabled Erlang
+ * virtual machine, "beam". The SMP-enabled VM is called "beam.smp".
+ * Note that other variations of the virtual machine also have
+ * different names, e.g. the debug build of the SMP-enabled VM
+ * is "beam.debug.smp".
+ *
+ * To use a different virtual machine, replace each instance of
+ * "beam" with "beam.smp" or the VM name appropriate to your
+ * environment.
+ */
+
+probe process("beam").mark("copy-struct")
+{
+ printf("copy_struct %d bytes\n", $arg1);
+}
+
+probe process("beam").mark("copy-object")
+{
+ printf("copy_object pid %s %d bytes\n", user_string($arg1), $arg2);
+}
+
+probe process("beam").mark("process-heap_grow")
+{
+ printf("proc heap grow pid %s %d -> %d bytes\n", user_string($arg1),
+ $arg2, $arg3);
+}
+
+probe process("beam").mark("process-heap_shrink")
+{
+ printf("proc heap shrink pid %s %d -> %d bytes\n", user_string($arg1),
+ $arg2, $arg3);
+}
diff --git a/lib/runtime_tools/examples/messages.d b/lib/runtime_tools/examples/messages.d
new file mode 100644
index 0000000000..08cf52f3d2
--- /dev/null
+++ b/lib/runtime_tools/examples/messages.d
@@ -0,0 +1,94 @@
+/* example usage: dtrace -q -s /path/to/messages.d */
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Scott Lystig Fritchie 2011-2012. All Rights Reserved.
+ *
+ * The contents of this file are subject to the Erlang Public License,
+ * Version 1.1, (the "License"); you may not use this file except in
+ * compliance with the License. You should have received a copy of the
+ * Erlang Public License along with this software. If not, it can be
+ * retrieved online at http://www.erlang.org/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * %CopyrightEnd%
+ */
+
+BEGIN
+{
+ printf("\n");
+ printf("NOTE: message-queue message size 4294967295 means an external\n");
+ printf(" message that the code isn't smart enough to determine\n");
+ printf(" the actual size.\n");
+ printf("\n");
+}
+
+erlang*:::message-send
+/arg3 == 0 && arg4 == 0 && arg5 == 0/
+{
+ printf("send: %s -> %s: %d words\n",
+ copyinstr(arg0), copyinstr(arg1), arg2);
+}
+
+erlang*:::message-send
+/arg3 != 0 || arg4 != 0 || arg5 != 0/
+{
+ printf("send: %s label %d token {%d,%d} -> %s: %d words\n",
+ copyinstr(arg0),
+ arg3, arg4, arg5,
+ copyinstr(arg1), arg2);
+}
+
+/*
+ * TODO:
+ * Weird, on my OS X box, beam says arg6 = 0 but this script says 4294967296.
+ */
+
+erlang*:::message-send-remote
+/arg4 == 0 && arg5 == 0 && (arg6 == 0 || arg6 >= 4294967296)/
+{
+ printf("send : %s -> %s %s: %d words\n",
+ copyinstr(arg0), copyinstr(arg1), copyinstr(arg2), arg3);
+}
+
+erlang*:::message-send-remote
+/arg4 != 0 || arg5 != 0 || arg6 < 4294967296/
+{
+ printf("send : %s label %d token {%d,%d} -> %s %s: %d words\n",
+ copyinstr(arg0),
+ arg4, arg5, arg6,
+ copyinstr(arg1), copyinstr(arg2), arg3);
+}
+
+erlang*:::message-queued
+/arg3 == 0 && arg4 == 0 && arg5 == 0/
+{
+ printf("queued: %s: %d words, queue len %d\n", copyinstr(arg0), arg1, arg2);
+}
+
+erlang*:::message-queued
+/arg3 != 0 || arg4 != 0 || arg5 != 0/
+{
+ printf("queued: %s label %d token {%d,%d}: %d words, queue len %d\n",
+ copyinstr(arg0), arg3, arg4, arg5,
+ arg1, arg2);
+}
+
+erlang*:::message-receive
+/arg3 == 0 && arg4 == 0 && arg5 == 0/
+{
+ printf("receive: %s: %d words, queue len %d\n",
+ copyinstr(arg0), arg1, arg2);
+}
+
+erlang*:::message-receive
+/arg3 != 0 || arg4 != 0 || arg5 != 0/
+{
+ printf("receive: %s label %d token {%d,%d}: %d words, queue len %d\n",
+ copyinstr(arg0), arg3, arg4, arg5,
+ arg1, arg2);
+}
diff --git a/lib/runtime_tools/examples/messages.systemtap b/lib/runtime_tools/examples/messages.systemtap
new file mode 100644
index 0000000000..c58e1168f9
--- /dev/null
+++ b/lib/runtime_tools/examples/messages.systemtap
@@ -0,0 +1,87 @@
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011-2012. All Rights Reserved.
+ *
+ * The contents of this file are subject to the Erlang Public License,
+ * Version 1.1, (the "License"); you may not use this file except in
+ * compliance with the License. You should have received a copy of the
+ * Erlang Public License along with this software. If not, it can be
+ * retrieved online at http://www.erlang.org/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * %CopyrightEnd%
+ */
+/*
+ * Note: This file assumes that you're using the non-SMP-enabled Erlang
+ * virtual machine, "beam". The SMP-enabled VM is called "beam.smp".
+ * Note that other variations of the virtual machine also have
+ * different names, e.g. the debug build of the SMP-enabled VM
+ * is "beam.debug.smp".
+ *
+ * To use a different virtual machine, replace each instance of
+ * "beam" with "beam.smp" or the VM name appropriate to your
+ * environment.
+ */
+
+probe begin
+{
+ printf("\n");
+ printf("NOTE: message-queue message size 4294967295 means an external\n");
+ printf(" message that the code isn't smart enough to determine\n");
+ printf(" the actual size.\n");
+ printf("\n");
+}
+
+probe process("beam").mark("message-send")
+{
+ if ($arg4 == 0 && $arg5 == 0 && $arg6 == 0) {
+ printf("send: %s -> %s: %d words\n",
+ user_string($arg1), user_string($arg2), $arg3);
+ } else {
+ printf("send: %s label %d token {%d,%d} -> %s: %d words\n",
+ user_string($arg1),
+ $arg4, $arg5, $arg6,
+ user_string($arg2), $arg3);
+ }
+}
+
+probe process("beam").mark("message-send-remote")
+{
+ if ($arg5 == 0 && $arg6 == 0 && $arg7 == 0) {
+ printf("send : %s -> %s %s: %d words\n",
+ user_string($arg1), user_string($arg2), user_string($arg3), $arg4);
+ } else {
+ printf("send : %s label %d token {%d,%d} -> %s %s: %d words\n",
+ user_string($arg1),
+ $arg5, $arg6, $arg7,
+ user_string($arg2), user_string($arg3), $arg4);
+ }
+}
+
+probe process("beam").mark("message-queued")
+{
+ if ($arg4 == 0 && $arg5 == 0 && $arg6 == 0) {
+ printf("queued: %s: %d words, queue len %d\n", user_string($arg1), $arg2, $arg3);
+ } else {
+ printf("queued: %s label %d token {%d,%d}: %d words, queue len %d\n",
+ user_string($arg1), $arg4, $arg5, $arg6,
+ $arg2, $arg3);
+ }
+}
+
+probe process("beam").mark("message-receive")
+{
+ if ($arg4 == 0 && $arg5 == 0 && $arg6 == 0) {
+ printf("receive: %s: %d words, queue len %d\n",
+ user_string($arg1), $arg2, $arg3);
+ } else {
+ printf("receive: %s label %d token {%d,%d}: %d words, queue len %d\n",
+ user_string($arg1), $arg4, $arg5, $arg6,
+ $arg2, $arg3);
+ }
+}
diff --git a/lib/runtime_tools/examples/port1.d b/lib/runtime_tools/examples/port1.d
new file mode 100644
index 0000000000..1e3bd3d8a9
--- /dev/null
+++ b/lib/runtime_tools/examples/port1.d
@@ -0,0 +1,142 @@
+/* example usage: dtrace -q -s /path/to/port1.d */
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Scott Lystig Fritchie 2011-2012. All Rights Reserved.
+ *
+ * The contents of this file are subject to the Erlang Public License,
+ * Version 1.1, (the "License"); you may not use this file except in
+ * compliance with the License. You should have received a copy of the
+ * Erlang Public License along with this software. If not, it can be
+ * retrieved online at http://www.erlang.org/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * %CopyrightEnd%
+ */
+
+BEGIN
+{
+ driver_map["tcp_inet", 1] = "OPEN";
+ driver_map["tcp_inet", 2] = "CLOSE";
+ driver_map["tcp_inet", 3] = "CONNECT";
+ driver_map["tcp_inet", 4] = "PEER";
+ driver_map["tcp_inet", 5] = "NAME";
+ driver_map["tcp_inet", 6] = "BIND";
+ driver_map["tcp_inet", 7] = "SETOPTS";
+ driver_map["tcp_inet", 8] = "GETOPTS";
+ driver_map["tcp_inet", 11] = "GETSTAT";
+ driver_map["tcp_inet", 12] = "GETHOSTNAME";
+ driver_map["tcp_inet", 13] = "FDOPEN";
+ driver_map["tcp_inet", 14] = "GETFD";
+ driver_map["tcp_inet", 15] = "GETTYPE";
+ driver_map["tcp_inet", 16] = "GETSTATUS";
+ driver_map["tcp_inet", 17] = "GETSERVBYNAME";
+ driver_map["tcp_inet", 18] = "GETSERVBYPORT";
+ driver_map["tcp_inet", 19] = "SETNAME";
+ driver_map["tcp_inet", 20] = "SETPEER";
+ driver_map["tcp_inet", 21] = "GETIFLIST";
+ driver_map["tcp_inet", 22] = "IFGET";
+ driver_map["tcp_inet", 23] = "IFSET";
+ driver_map["tcp_inet", 24] = "SUBSCRIBE";
+ driver_map["tcp_inet", 25] = "GETIFADDRS";
+ driver_map["tcp_inet", 40] = "ACCEPT";
+ driver_map["tcp_inet", 41] = "LISTEN";
+ driver_map["tcp_inet", 42] = "RECV";
+ driver_map["tcp_inet", 43] = "UNRECV";
+ driver_map["tcp_inet", 44] = "SHUTDOWN";
+ driver_map["tcp_inet", 60] = "RECV";
+ driver_map["tcp_inet", 61] = "LISTEN";
+ driver_map["tcp_inet", 62] = "BINDX";
+ /* No looping constructs, so repeat for udp_inet */
+ driver_map["udp_inet", 1] = "OPEN";
+ driver_map["udp_inet", 2] = "CLOSE";
+ driver_map["udp_inet", 3] = "CONNECT";
+ driver_map["udp_inet", 4] = "PEER";
+ driver_map["udp_inet", 5] = "NAME";
+ driver_map["udp_inet", 6] = "BIND";
+ driver_map["udp_inet", 7] = "SETOPTS";
+ driver_map["udp_inet", 8] = "GETOPTS";
+ driver_map["udp_inet", 11] = "GETSTAT";
+ driver_map["udp_inet", 12] = "GETHOSTNAME";
+ driver_map["udp_inet", 13] = "FDOPEN";
+ driver_map["udp_inet", 14] = "GETFD";
+ driver_map["udp_inet", 15] = "GETTYPE";
+ driver_map["udp_inet", 16] = "GETSTATUS";
+ driver_map["udp_inet", 17] = "GETSERVBYNAME";
+ driver_map["udp_inet", 18] = "GETSERVBYPORT";
+ driver_map["udp_inet", 19] = "SETNAME";
+ driver_map["udp_inet", 20] = "SETPEER";
+ driver_map["udp_inet", 21] = "GETIFLIST";
+ driver_map["udp_inet", 22] = "IFGET";
+ driver_map["udp_inet", 23] = "IFSET";
+ driver_map["udp_inet", 24] = "SUBSCRIBE";
+ driver_map["udp_inet", 25] = "GETIFADDRS";
+ driver_map["udp_inet", 40] = "ACCEPT";
+ driver_map["udp_inet", 41] = "LISTEN";
+ driver_map["udp_inet", 42] = "RECV";
+ driver_map["udp_inet", 43] = "UNRECV";
+ driver_map["udp_inet", 44] = "SHUTDOWN";
+ driver_map["udp_inet", 60] = "RECV";
+ driver_map["udp_inet", 61] = "LISTEN";
+ driver_map["udp_inet", 62] = "BINDX";
+}
+
+erlang*:::port-open
+{
+ printf("port open pid %s port name %s port %s\n",
+ copyinstr(arg0), copyinstr(arg1), copyinstr(arg2));
+}
+
+erlang*:::port-command
+{
+ printf("port command pid %s port %s port name %s command type %s\n",
+ copyinstr(arg0), copyinstr(arg1), copyinstr(arg2), copyinstr(arg3));
+}
+
+erlang*:::port-control
+{
+ /* http://dtrace.org/blogs/brendan/2011/11/25/dtrace-variable-types/ */
+ this->cmd = driver_map[copyinstr(arg2), arg3];
+ this->cmd_str = (this->cmd == 0) ? "unknown" : this->cmd;
+ printf("port control pid %s port %s port name %s command %d %s\n",
+ copyinstr(arg0), copyinstr(arg1), copyinstr(arg2), arg3,
+ this->cmd_str);
+}
+
+/* port-exit is fired as a result of port_close() or exit signal */
+
+erlang*:::port-exit
+{
+ printf("port exit pid %s port %s port name %s reason %s\n",
+ copyinstr(arg0), copyinstr(arg1), copyinstr(arg2), copyinstr(arg3));
+}
+
+erlang*:::port-connect
+{
+ printf("port connect pid %s port %s port name %s new pid %s\n",
+ copyinstr(arg0), copyinstr(arg1), copyinstr(arg2), copyinstr(arg3));
+}
+
+erlang*:::port-busy
+{
+ printf("port busy %s\n", copyinstr(arg0));
+}
+
+erlang*:::port-not_busy
+{
+ printf("port not busy %s\n", copyinstr(arg0));
+}
+
+erlang*:::aio_pool-add
+{
+ printf("async I/O pool add thread %d queue len %d\n", arg0, arg1);
+}
+
+erlang*:::aio_pool-get
+{
+ printf("async I/O pool get thread %d queue len %d\n", arg0, arg1);
+}
diff --git a/lib/runtime_tools/examples/port1.systemtap b/lib/runtime_tools/examples/port1.systemtap
new file mode 100644
index 0000000000..c8af240d85
--- /dev/null
+++ b/lib/runtime_tools/examples/port1.systemtap
@@ -0,0 +1,152 @@
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011-2012. All Rights Reserved.
+ *
+ * The contents of this file are subject to the Erlang Public License,
+ * Version 1.1, (the "License"); you may not use this file except in
+ * compliance with the License. You should have received a copy of the
+ * Erlang Public License along with this software. If not, it can be
+ * retrieved online at http://www.erlang.org/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * %CopyrightEnd%
+ */
+/*
+ * Note: This file assumes that you're using the non-SMP-enabled Erlang
+ * virtual machine, "beam". The SMP-enabled VM is called "beam.smp".
+ * Note that other variations of the virtual machine also have
+ * different names, e.g. the debug build of the SMP-enabled VM
+ * is "beam.debug.smp".
+ *
+ * To use a different virtual machine, replace each instance of
+ * "beam" with "beam.smp" or the VM name appropriate to your
+ * environment.
+ */
+
+probe begin
+{
+ driver_map["tcp_inet", 1] = "OPEN";
+ driver_map["tcp_inet", 2] = "CLOSE";
+ driver_map["tcp_inet", 3] = "CONNECT";
+ driver_map["tcp_inet", 4] = "PEER";
+ driver_map["tcp_inet", 5] = "NAME";
+ driver_map["tcp_inet", 6] = "BIND";
+ driver_map["tcp_inet", 7] = "SETOPTS";
+ driver_map["tcp_inet", 8] = "GETOPTS";
+ driver_map["tcp_inet", 11] = "GETSTAT";
+ driver_map["tcp_inet", 12] = "GETHOSTNAME";
+ driver_map["tcp_inet", 13] = "FDOPEN";
+ driver_map["tcp_inet", 14] = "GETFD";
+ driver_map["tcp_inet", 15] = "GETTYPE";
+ driver_map["tcp_inet", 16] = "GETSTATUS";
+ driver_map["tcp_inet", 17] = "GETSERVBYNAME";
+ driver_map["tcp_inet", 18] = "GETSERVBYPORT";
+ driver_map["tcp_inet", 19] = "SETNAME";
+ driver_map["tcp_inet", 20] = "SETPEER";
+ driver_map["tcp_inet", 21] = "GETIFLIST";
+ driver_map["tcp_inet", 22] = "IFGET";
+ driver_map["tcp_inet", 23] = "IFSET";
+ driver_map["tcp_inet", 24] = "SUBSCRIBE";
+ driver_map["tcp_inet", 25] = "GETIFADDRS";
+ driver_map["tcp_inet", 40] = "ACCEPT";
+ driver_map["tcp_inet", 41] = "LISTEN";
+ driver_map["tcp_inet", 42] = "RECV";
+ driver_map["tcp_inet", 43] = "UNRECV";
+ driver_map["tcp_inet", 44] = "SHUTDOWN";
+ driver_map["tcp_inet", 60] = "RECV";
+ driver_map["tcp_inet", 61] = "LISTEN";
+ driver_map["tcp_inet", 62] = "BINDX";
+ /* No looping constructs, so repeat for udp_inet */
+ driver_map["udp_inet", 1] = "OPEN";
+ driver_map["udp_inet", 2] = "CLOSE";
+ driver_map["udp_inet", 3] = "CONNECT";
+ driver_map["udp_inet", 4] = "PEER";
+ driver_map["udp_inet", 5] = "NAME";
+ driver_map["udp_inet", 6] = "BIND";
+ driver_map["udp_inet", 7] = "SETOPTS";
+ driver_map["udp_inet", 8] = "GETOPTS";
+ driver_map["udp_inet", 11] = "GETSTAT";
+ driver_map["udp_inet", 12] = "GETHOSTNAME";
+ driver_map["udp_inet", 13] = "FDOPEN";
+ driver_map["udp_inet", 14] = "GETFD";
+ driver_map["udp_inet", 15] = "GETTYPE";
+ driver_map["udp_inet", 16] = "GETSTATUS";
+ driver_map["udp_inet", 17] = "GETSERVBYNAME";
+ driver_map["udp_inet", 18] = "GETSERVBYPORT";
+ driver_map["udp_inet", 19] = "SETNAME";
+ driver_map["udp_inet", 20] = "SETPEER";
+ driver_map["udp_inet", 21] = "GETIFLIST";
+ driver_map["udp_inet", 22] = "IFGET";
+ driver_map["udp_inet", 23] = "IFSET";
+ driver_map["udp_inet", 24] = "SUBSCRIBE";
+ driver_map["udp_inet", 25] = "GETIFADDRS";
+ driver_map["udp_inet", 40] = "ACCEPT";
+ driver_map["udp_inet", 41] = "LISTEN";
+ driver_map["udp_inet", 42] = "RECV";
+ driver_map["udp_inet", 43] = "UNRECV";
+ driver_map["udp_inet", 44] = "SHUTDOWN";
+ driver_map["udp_inet", 60] = "RECV";
+ driver_map["udp_inet", 61] = "LISTEN";
+ driver_map["udp_inet", 62] = "BINDX";
+}
+
+probe process("beam").mark("port-open")
+{
+ printf("port open pid %s port name %s port %s\n",
+ user_string($arg1), user_string($arg2), user_string($arg3));
+}
+
+probe process("beam").mark("port-command")
+{
+ printf("port command pid %s port %s port name %s command type %s\n",
+ user_string($arg1), user_string($arg2), user_string($arg3), user_string($arg4));
+}
+
+probe process("beam").mark("port-control")
+{
+ cmd = driver_map[user_string($arg3), $arg4];
+ cmd_str = (cmd == "") ? "unknown" : cmd;
+ printf("port control pid %s port %s port name %s command %d %s\n",
+ user_string($arg1), user_string($arg2), user_string($arg3), $arg4, cmd_str);
+}
+
+/* port-exit is fired as a result of port_close() or exit signal */
+
+probe process("beam").mark("port-exit")
+{
+ printf("port exit pid %s port %s port name %s reason %s\n",
+ user_string($arg1), user_string($arg2), user_string($arg3), user_string($arg4));
+}
+
+probe process("beam").mark("port-connect")
+{
+ printf("port connect pid %s port %s port name %s new pid %s\n",
+ user_string($arg1), user_string($arg2), user_string($arg3), user_string($arg4));
+}
+
+probe process("beam").mark("port-busy")
+{
+ printf("port busy %s\n", user_string($arg1));
+}
+
+probe process("beam").mark("port-not_busy")
+{
+ printf("port not busy %s\n", user_string($arg1));
+}
+
+probe process("beam").mark("aio_pool-add")
+{
+ printf("async I/O pool add thread %d queue len %d\n", $arg1, $arg2);
+}
+
+probe process("beam").mark("aio_pool-get")
+{
+ printf("async I/O pool get thread %d queue len %d\n", $arg1, $arg2);
+}
+
+global driver_map; \ No newline at end of file
diff --git a/lib/runtime_tools/examples/process-scheduling.d b/lib/runtime_tools/examples/process-scheduling.d
new file mode 100644
index 0000000000..6408d7d5f2
--- /dev/null
+++ b/lib/runtime_tools/examples/process-scheduling.d
@@ -0,0 +1,35 @@
+/* example usage: dtrace -q -s /path/to/process-scheduling.d */
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Scott Lystig Fritchie 2011-2012. All Rights Reserved.
+ *
+ * The contents of this file are subject to the Erlang Public License,
+ * Version 1.1, (the "License"); you may not use this file except in
+ * compliance with the License. You should have received a copy of the
+ * Erlang Public License along with this software. If not, it can be
+ * retrieved online at http://www.erlang.org/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * %CopyrightEnd%
+ */
+
+erlang*:::process-scheduled
+{
+ printf(" Schedule pid %s mfa %s\n", copyinstr(arg0), copyinstr(arg1));
+}
+
+erlang*:::process-unscheduled
+{
+ printf("Unschedule pid %s\n", copyinstr(arg0));
+}
+
+erlang*:::process-hibernate
+{
+ printf(" Hibernate pid %s resume mfa %s\n",
+ copyinstr(arg0), copyinstr(arg1));
+}
diff --git a/lib/runtime_tools/examples/process-scheduling.systemtap b/lib/runtime_tools/examples/process-scheduling.systemtap
new file mode 100644
index 0000000000..4cc3ef555c
--- /dev/null
+++ b/lib/runtime_tools/examples/process-scheduling.systemtap
@@ -0,0 +1,45 @@
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011-2012. All Rights Reserved.
+ *
+ * The contents of this file are subject to the Erlang Public License,
+ * Version 1.1, (the "License"); you may not use this file except in
+ * compliance with the License. You should have received a copy of the
+ * Erlang Public License along with this software. If not, it can be
+ * retrieved online at http://www.erlang.org/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * %CopyrightEnd%
+ */
+/*
+ * Note: This file assumes that you're using the non-SMP-enabled Erlang
+ * virtual machine, "beam". The SMP-enabled VM is called "beam.smp".
+ * Note that other variations of the virtual machine also have
+ * different names, e.g. the debug build of the SMP-enabled VM
+ * is "beam.debug.smp".
+ *
+ * To use a different virtual machine, replace each instance of
+ * "beam" with "beam.smp" or the VM name appropriate to your
+ * environment.
+ */
+
+probe process("beam").mark("process-scheduled")
+{
+ printf(" Schedule pid %s mfa %s\n", user_string($arg1), user_string($arg2));
+}
+
+probe process("beam").mark("process-unscheduled")
+{
+ printf("Unschedule pid %s\n", user_string($arg1));
+}
+
+probe process("beam").mark("process-hibernate")
+{
+ printf(" Hibernate pid %s resume mfa %s\n",
+ user_string($arg1), user_string($arg2));
+}
diff --git a/lib/runtime_tools/examples/spawn-exit.d b/lib/runtime_tools/examples/spawn-exit.d
new file mode 100644
index 0000000000..ae690b819a
--- /dev/null
+++ b/lib/runtime_tools/examples/spawn-exit.d
@@ -0,0 +1,41 @@
+/* example usage: dtrace -q -s /path/to/spawn-exit.d */
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Scott Lystig Fritchie 2011-2012. All Rights Reserved.
+ *
+ * The contents of this file are subject to the Erlang Public License,
+ * Version 1.1, (the "License"); you may not use this file except in
+ * compliance with the License. You should have received a copy of the
+ * Erlang Public License along with this software. If not, it can be
+ * retrieved online at http://www.erlang.org/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * %CopyrightEnd%
+ */
+
+erlang*:::process-spawn
+{
+ printf("pid %s mfa %s\n", copyinstr(arg0), copyinstr(arg1));
+}
+
+erlang*:::process-exit
+{
+ printf("pid %s reason %s\n", copyinstr(arg0), copyinstr(arg1));
+}
+
+erlang*:::process-exit_signal
+{
+ printf("sender %s -> pid %s reason %s\n",
+ copyinstr(arg0), copyinstr(arg1), copyinstr(arg2));
+}
+
+erlang*:::process-exit_signal-remote
+{
+ printf("sender %s -> node %s pid %s reason %s\n",
+ copyinstr(arg0), copyinstr(arg1), copyinstr(arg2), copyinstr(arg3));
+}
diff --git a/lib/runtime_tools/examples/spawn-exit.systemtap b/lib/runtime_tools/examples/spawn-exit.systemtap
new file mode 100644
index 0000000000..4b69e4aea6
--- /dev/null
+++ b/lib/runtime_tools/examples/spawn-exit.systemtap
@@ -0,0 +1,51 @@
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011-2012. All Rights Reserved.
+ *
+ * The contents of this file are subject to the Erlang Public License,
+ * Version 1.1, (the "License"); you may not use this file except in
+ * compliance with the License. You should have received a copy of the
+ * Erlang Public License along with this software. If not, it can be
+ * retrieved online at http://www.erlang.org/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * %CopyrightEnd%
+ */
+/*
+ * Note: This file assumes that you're using the non-SMP-enabled Erlang
+ * virtual machine, "beam". The SMP-enabled VM is called "beam.smp".
+ * Note that other variations of the virtual machine also have
+ * different names, e.g. the debug build of the SMP-enabled VM
+ * is "beam.debug.smp".
+ *
+ * To use a different virtual machine, replace each instance of
+ * "beam" with "beam.smp" or the VM name appropriate to your
+ * environment.
+ */
+
+probe process("beam").mark("process-spawn")
+{
+ printf("pid %s mfa %s\n", user_string($arg1), user_string($arg2));
+}
+
+probe process("beam").mark("process-exit")
+{
+ printf("pid %s reason %s\n", user_string($arg1), user_string($arg2));
+}
+
+probe process("beam").mark("process-exit_signal")
+{
+ printf("sender %s -> pid %s reason %s\n",
+ user_string($arg1), user_string($arg2), user_string($arg3));
+}
+
+probe process("beam").mark("process-exit_signal-remote")
+{
+ printf("sender %s -> node %s pid %s reason %s\n",
+ user_string($arg1), user_string($arg2), user_string($arg3), user_string($arg4));
+}
diff --git a/lib/runtime_tools/examples/user-probe-n.d b/lib/runtime_tools/examples/user-probe-n.d
new file mode 100644
index 0000000000..06a3e5c9b9
--- /dev/null
+++ b/lib/runtime_tools/examples/user-probe-n.d
@@ -0,0 +1,44 @@
+/* example usage: dtrace -q -s /path/to/user-probe.d */
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Scott Lystig Fritchie 2011-2012. All Rights Reserved.
+ *
+ * The contents of this file are subject to the Erlang Public License,
+ * Version 1.1, (the "License"); you may not use this file except in
+ * compliance with the License. You should have received a copy of the
+ * Erlang Public License along with this software. If not, it can be
+ * retrieved online at http://www.erlang.org/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * %CopyrightEnd%
+ */
+
+erlang*:::user_trace-n0
+{
+ printf("probe n0: %s %s %d %d %d %d '%s' '%s' '%s' '%s'\n",
+ copyinstr(arg0),
+ arg1 == NULL ? "" : copyinstr(arg1),
+ arg2, arg3, arg4, arg5,
+ arg6 == NULL ? "" : copyinstr(arg6),
+ arg7 == NULL ? "" : copyinstr(arg7),
+ arg8 == NULL ? "" : copyinstr(arg8),
+ arg9 == NULL ? "" : copyinstr(arg9));
+}
+
+erlang*:::user_trace-n1
+{
+ printf("probe n1: %s %s %d %d %d %d '%s' '%s' '%s' '%s'\n",
+ copyinstr(arg0),
+ arg1 == NULL ? "" : copyinstr(arg1),
+ arg2, arg3, arg4, arg5,
+ arg6 == NULL ? "" : copyinstr(arg6),
+ arg7 == NULL ? "" : copyinstr(arg7),
+ arg8 == NULL ? "" : copyinstr(arg8),
+ arg9 == NULL ? "" : copyinstr(arg9));
+}
+
diff --git a/lib/runtime_tools/examples/user-probe-n.systemtap b/lib/runtime_tools/examples/user-probe-n.systemtap
new file mode 100644
index 0000000000..6aa415bb67
--- /dev/null
+++ b/lib/runtime_tools/examples/user-probe-n.systemtap
@@ -0,0 +1,53 @@
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011-2012. All Rights Reserved.
+ *
+ * The contents of this file are subject to the Erlang Public License,
+ * Version 1.1, (the "License"); you may not use this file except in
+ * compliance with the License. You should have received a copy of the
+ * Erlang Public License along with this software. If not, it can be
+ * retrieved online at http://www.erlang.org/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * %CopyrightEnd%
+ */
+/*
+ * Note: This file assumes that you're using the non-SMP-enabled Erlang
+ * virtual machine, "beam". The SMP-enabled VM is called "beam.smp".
+ * Note that other variations of the virtual machine also have
+ * different names, e.g. the debug build of the SMP-enabled VM
+ * is "beam.debug.smp".
+ *
+ * To use a different virtual machine, replace each instance of
+ * "beam" with "beam.smp" or the VM name appropriate to your
+ * environment.
+ */
+
+probe process("beam").mark("user_trace-n0")
+{
+ printf("probe n0: %s %s %d %d %d %d '%s' '%s' '%s' '%s'\n",
+ user_string($arg1),
+ $arg2 == NULL ? "" : user_string($arg2),
+ $arg3, $arg4, $arg5, $arg6,
+ $arg7 == NULL ? "" : user_string($arg7),
+ $arg8 == NULL ? "" : user_string($arg8),
+ $arg9 == NULL ? "" : user_string($arg9),
+ $arg9 == NULL ? "" : user_string($arg9));
+}
+
+probe process("beam").mark("user_trace-n1")
+{
+ printf("probe n1: %s %s %d %d %d %d '%s' '%s' '%s' '%s'\n",
+ user_string($arg1),
+ $arg2 == NULL ? "" : user_string($arg2),
+ $arg3, $arg4, $arg5, $arg6,
+ $arg7 == NULL ? "" : user_string($arg7),
+ $arg8 == NULL ? "" : user_string($arg8),
+ $arg9 == NULL ? "" : user_string($arg9),
+ $arg9 == NULL ? "" : user_string($arg9));
+}
diff --git a/lib/runtime_tools/examples/user-probe.d b/lib/runtime_tools/examples/user-probe.d
new file mode 100644
index 0000000000..5cb5d61a76
--- /dev/null
+++ b/lib/runtime_tools/examples/user-probe.d
@@ -0,0 +1,36 @@
+/* example usage: dtrace -q -s /path/to/user-probe.d */
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Scott Lystig Fritchie 2011-2012. All Rights Reserved.
+ *
+ * The contents of this file are subject to the Erlang Public License,
+ * Version 1.1, (the "License"); you may not use this file except in
+ * compliance with the License. You should have received a copy of the
+ * Erlang Public License along with this software. If not, it can be
+ * retrieved online at http://www.erlang.org/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * %CopyrightEnd%
+ */
+
+erlang*:::user_trace-s1
+{
+ printf("%s\n", copyinstr(arg0));
+}
+
+erlang*:::user_trace-i4s4
+{
+ printf("%s %s %d %d %d %d '%s' '%s' '%s' '%s'\n",
+ copyinstr(arg0),
+ arg1 == NULL ? "" : copyinstr(arg1),
+ arg2, arg3, arg4, arg5,
+ arg6 == NULL ? "" : copyinstr(arg6),
+ arg7 == NULL ? "" : copyinstr(arg7),
+ arg8 == NULL ? "" : copyinstr(arg8),
+ arg9 == NULL ? "" : copyinstr(arg9));
+}
diff --git a/lib/runtime_tools/examples/user-probe.systemtap b/lib/runtime_tools/examples/user-probe.systemtap
new file mode 100644
index 0000000000..0482235324
--- /dev/null
+++ b/lib/runtime_tools/examples/user-probe.systemtap
@@ -0,0 +1,46 @@
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011-2012. All Rights Reserved.
+ *
+ * The contents of this file are subject to the Erlang Public License,
+ * Version 1.1, (the "License"); you may not use this file except in
+ * compliance with the License. You should have received a copy of the
+ * Erlang Public License along with this software. If not, it can be
+ * retrieved online at http://www.erlang.org/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * %CopyrightEnd%
+ */
+/*
+ * Note: This file assumes that you're using the non-SMP-enabled Erlang
+ * virtual machine, "beam". The SMP-enabled VM is called "beam.smp".
+ * Note that other variations of the virtual machine also have
+ * different names, e.g. the debug build of the SMP-enabled VM
+ * is "beam.debug.smp".
+ *
+ * To use a different virtual machine, replace each instance of
+ * "beam" with "beam.smp" or the VM name appropriate to your
+ * environment.
+ */
+
+probe process("beam").mark("user_trace-s1")
+{
+ printf("%s\n", user_string($arg1));
+}
+
+probe process("beam").mark("user_trace-i4s4")
+{
+ printf("%s %s %d %d %d %d '%s' '%s' '%s' '%s'\n",
+ user_string($arg1),
+ $arg2 == NULL ? "" : user_string($arg2),
+ $arg3, $arg4, $arg5, $arg6,
+ $arg7 == NULL ? "" : user_string($arg7),
+ $arg8 == NULL ? "" : user_string($arg8),
+ $arg9 == NULL ? "" : user_string($arg9),
+ $arg9 == NULL ? "" : user_string($arg9));
+}
diff --git a/lib/runtime_tools/src/Makefile b/lib/runtime_tools/src/Makefile
index 946409b262..810e3e8741 100644
--- a/lib/runtime_tools/src/Makefile
+++ b/lib/runtime_tools/src/Makefile
@@ -1,7 +1,7 @@
#
# %CopyrightBegin%
#
-# Copyright Ericsson AB 1999-2011. All Rights Reserved.
+# Copyright Ericsson AB 1999-2012. All Rights Reserved.
#
# The contents of this file are subject to the Erlang Public License,
# Version 1.1, (the "License"); you may not use this file except in
@@ -45,6 +45,7 @@ MODULES= \
runtime_tools \
runtime_tools_sup \
dbg \
+ dyntrace \
percept_profile \
observer_backend \
ttb_autostart
@@ -64,10 +65,15 @@ APPUP_FILE= runtime_tools.appup
APPUP_SRC= $(APPUP_FILE).src
APPUP_TARGET= $(EBIN)/$(APPUP_FILE)
+EXAMPLE_FILES= \
+ ../examples/*
# ----------------------------------------------------
# FLAGS
# ----------------------------------------------------
-ERL_COMPILE_FLAGS += -I../include
+ERL_COMPILE_FLAGS += \
+ -I../include \
+ -I ../../et/include \
+ -I ../../../libraries/et/include
# ----------------------------------------------------
# Targets
@@ -93,12 +99,14 @@ docs:
include $(ERL_TOP)/make/otp_release_targets.mk
release_spec: opt
- $(INSTALL_DIR) $(RELSYSDIR)/src
- $(INSTALL_DATA) $(ERL_FILES) $(RELSYSDIR)/src
- $(INSTALL_DIR) $(RELSYSDIR)/include
- $(INSTALL_DATA) $(HRL_FILES) $(RELSYSDIR)/include
- $(INSTALL_DIR) $(RELSYSDIR)/ebin
- $(INSTALL_DATA) $(TARGET_FILES) $(RELSYSDIR)/ebin
+ $(INSTALL_DIR) "$(RELSYSDIR)/src"
+ $(INSTALL_DATA) $(ERL_FILES) "$(RELSYSDIR)/src"
+ $(INSTALL_DIR) "$(RELSYSDIR)/include"
+ $(INSTALL_DATA) $(HRL_FILES) "$(RELSYSDIR)/include"
+ $(INSTALL_DIR) "$(RELSYSDIR)/examples"
+ $(INSTALL_DATA) $(EXAMPLE_FILES) "$(RELSYSDIR)/examples"
+ $(INSTALL_DIR) "$(RELSYSDIR)/ebin"
+ $(INSTALL_DATA) $(TARGET_FILES) "$(RELSYSDIR)/ebin"
release_docs_spec:
diff --git a/lib/runtime_tools/src/dyntrace.erl b/lib/runtime_tools/src/dyntrace.erl
new file mode 100644
index 0000000000..b4579fd5ce
--- /dev/null
+++ b/lib/runtime_tools/src/dyntrace.erl
@@ -0,0 +1,352 @@
+-module(dyntrace).
+
+%%% @doc The Dynamic tracing interface module
+%%%
+%%% This Dynamic tracing interface module, with the corresponding NIFs, should
+%%% work on any operating system platform where user-space DTrace/Systemtap
+%%% (and in the future LttNG UST) probes are supported.
+%%%
+%%% It is recommended that you use the `dyntrace:p()' function to add
+%%% Dynamic trace probes to your Erlang code. This function can accept up to
+%%% four integer arguments and four string arguments; the integer
+%%% argument(s) must come before any string argument.
+%%%
+%%% If using DTrace, enable the dynamic trace probe using the 'dtrace'
+%%% command, for example:
+%%%
+%%% dtrace -s /your/path/to/lib/runtime_tools-1.8.7/examples/user-probe.d
+%%%
+%%% Then, back at the Erlang shell, try this example:
+%%% ```
+%%% 1> dyntrace:put_tag("GGOOOAAALL!!!!!").
+%%% true
+%%%
+%%% 2> dyntrace:p(7, 8, 9, "one", "four").
+%%% true
+%%% '''
+%%%
+%%% Output from the example D script `user-probe.d' looks like:
+%%% ```
+%%% <0.34.0> GGOOOAAALL!!!!! 7 8 9 0 'one' 'four' '' ''
+%%% '''
+%%%
+%%% If the expected type of variable is not present, e.g. integer when
+%%% integer() is expected, or an I/O list when iolist() is expected,
+%%% then the driver will ignore the user's input and use a default
+%%% value of 0 or NULL, respectively.
+
+-export([available/0,
+ user_trace_s1/1, % TODO: unify with pid & tag args like user_trace_i4s4
+ p/0, p/1, p/2, p/3, p/4, p/5, p/6, p/7, p/8,
+ pn/1, pn/2, pn/3, pn/4, pn/5, pn/6, pn/7, pn/8, pn/9]).
+-export([put_tag/1, get_tag/0, get_tag_data/0, spread_tag/1, restore_tag/1]).
+
+-export([user_trace_i4s4/9]). % Know what you're doing!
+-on_load(on_load/0).
+
+-type probe_arg() :: integer() | iolist().
+-type int_p_arg() :: integer() | iolist() | undef.
+-type n_probe_label() :: 0..1023.
+
+%% The *_maybe() types use atom() instead of a stricter 'undef'
+%% because user_trace_i4s4/9 is exposed to the outside world, and
+%% because the driver will allow any atom to be used as a "not
+%% present" indication, we'll allow any atom in the types.
+
+-type integer_maybe() :: integer() | atom().
+-type iolist_maybe() :: iolist() | atom().
+
+on_load() ->
+ PrivDir = code:priv_dir(runtime_tools),
+ LibName = "dyntrace",
+ Lib = filename:join([PrivDir, "lib", LibName]),
+ Status = case erlang:load_nif(Lib, 0) of
+ ok -> ok;
+ {error, {load_failed, _}}=Error1 ->
+ ArchLibDir =
+ filename:join([PrivDir, "lib",
+ erlang:system_info(system_architecture)]),
+ Candidate =
+ filelib:wildcard(filename:join([ArchLibDir,LibName ++ "*" ])),
+ case Candidate of
+ [] -> Error1;
+ _ ->
+ ArchLib = filename:join([ArchLibDir, LibName]),
+ erlang:load_nif(ArchLib, 0)
+ end;
+ Error1 -> Error1
+ end,
+ case Status of
+ ok -> ok;
+ {error, {E, Str}} ->
+ case erlang:system_info(dynamic_trace) of
+ none ->
+ ok;
+ _ ->
+ error_logger:error_msg("Unable to load dyntrace library. Failed with error:~n
+\"~p, ~s\"~n"
+ "Dynamic tracing is enabled but the driver is not built correctly~n",[
+ E,Str]),
+ Status
+ end
+ end.
+
+%%%
+%%% NIF placeholders
+%%%
+
+-spec available() -> true | false.
+
+available() ->
+ erlang:nif_error(nif_not_loaded).
+
+-spec user_trace_s1(iolist()) -> true | false | error | badarg.
+
+user_trace_s1(_Message) ->
+ erlang:nif_error(nif_not_loaded).
+
+-spec user_trace_i4s4(iolist(),
+ integer_maybe(), integer_maybe(),
+ integer_maybe(), integer_maybe(),
+ iolist_maybe(), iolist_maybe(),
+ iolist_maybe(), iolist_maybe()) ->
+ true | false | error | badarg.
+
+user_trace_i4s4(_, _, _, _, _, _, _, _, _) ->
+ erlang:nif_error(nif_not_loaded).
+
+-spec user_trace_n(n_probe_label(), iolist(),
+ integer_maybe(), integer_maybe(),
+ integer_maybe(), integer_maybe(),
+ iolist_maybe(), iolist_maybe(),
+ iolist_maybe(), iolist_maybe()) ->
+ true | false | error | badarg.
+
+user_trace_n(_, _, _, _, _, _, _, _, _, _) ->
+ erlang:nif_error(nif_not_loaded).
+
+%%%
+%%% Erlang support functions
+%%%
+
+-spec p() -> true | false | error | badarg.
+
+p() ->
+ user_trace_int(undef, undef, undef, undef, undef, undef, undef, undef).
+
+-spec p(probe_arg()) -> true | false | error | badarg.
+
+p(I1) when is_integer(I1) ->
+ user_trace_int(I1, undef, undef, undef, undef, undef, undef, undef);
+p(S1) ->
+ user_trace_int(undef, undef, undef, undef, S1, undef, undef, undef).
+
+-spec p(probe_arg(), probe_arg()) -> true | false | error | badarg.
+
+p(I1, I2) when is_integer(I1), is_integer(I2) ->
+ user_trace_int(I1, I2, undef, undef, undef, undef, undef, undef);
+p(I1, S1) when is_integer(I1) ->
+ user_trace_int(I1, undef, undef, undef, S1, undef, undef, undef);
+p(S1, S2) ->
+ user_trace_int(undef, undef, undef, undef, S1, S2, undef, undef).
+
+-spec p(probe_arg(), probe_arg(), probe_arg()) -> true | false | error | badarg.
+
+p(I1, I2, I3) when is_integer(I1), is_integer(I2), is_integer(I3) ->
+ user_trace_int(I1, I2, I3, undef, undef, undef, undef, undef);
+p(I1, I2, S1) when is_integer(I1), is_integer(I2) ->
+ user_trace_int(I1, I2, undef, undef, S1, undef, undef, undef);
+p(I1, S1, S2) when is_integer(I1) ->
+ user_trace_int(I1, undef, undef, undef, S1, S2, undef, undef);
+p(S1, S2, S3) ->
+ user_trace_int(undef, undef, undef, undef, S1, S2, S3, undef).
+
+-spec p(probe_arg(), probe_arg(), probe_arg(), probe_arg()) ->
+ true | false | error | badarg.
+
+p(I1, I2, I3, I4) when is_integer(I1), is_integer(I2), is_integer(I3), is_integer(I4) ->
+ user_trace_int(I1, I2, I3, I4, undef, undef, undef, undef);
+p(I1, I2, I3, S1) when is_integer(I1), is_integer(I2), is_integer(I3) ->
+ user_trace_int(I1, I2, I3, undef, S1, undef, undef, undef);
+p(I1, I2, S1, S2) when is_integer(I1), is_integer(I2) ->
+ user_trace_int(I1, I2, undef, undef, S1, S2, undef, undef);
+p(I1, S1, S2, S3) when is_integer(I1) ->
+ user_trace_int(I1, undef, undef, undef, S1, S2, S3, undef);
+p(S1, S2, S3, S4) ->
+ user_trace_int(undef, undef, undef, undef, S1, S2, S3, S4).
+
+-spec p(probe_arg(), probe_arg(), probe_arg(), probe_arg(),
+ probe_arg()) ->
+ true | false | error | badarg.
+
+p(I1, I2, I3, I4, S1) when is_integer(I1), is_integer(I2), is_integer(I3), is_integer(I4) ->
+ user_trace_int(I1, I2, I3, I4, S1, undef, undef, undef);
+p(I1, I2, I3, S1, S2) when is_integer(I1), is_integer(I2), is_integer(I3) ->
+ user_trace_int(I1, I2, I3, undef, S1, S2, undef, undef);
+p(I1, I2, S1, S2, S3) when is_integer(I1), is_integer(I2) ->
+ user_trace_int(I1, I2, undef, undef, S1, S2, S3, undef);
+p(I1, S1, S2, S3, S4) when is_integer(I1) ->
+ user_trace_int(I1, undef, undef, undef, S1, S2, S3, S4).
+
+-spec p(probe_arg(), probe_arg(), probe_arg(), probe_arg(),
+ probe_arg(), probe_arg()) ->
+ true | false | error | badarg.
+
+p(I1, I2, I3, I4, S1, S2) when is_integer(I1), is_integer(I2), is_integer(I3), is_integer(I4) ->
+ user_trace_int(I1, I2, I3, I4, S1, S2, undef, undef);
+p(I1, I2, I3, S1, S2, S3) when is_integer(I1), is_integer(I2), is_integer(I3) ->
+ user_trace_int(I1, I2, I3, undef, S1, S2, S3, undef);
+p(I1, I2, S1, S2, S3, S4) when is_integer(I1), is_integer(I2) ->
+ user_trace_int(I1, I2, undef, undef, S1, S2, S3, S4).
+
+-spec p(probe_arg(), probe_arg(), probe_arg(), probe_arg(),
+ probe_arg(), probe_arg(), probe_arg()) ->
+ true | false | error | badarg.
+
+p(I1, I2, I3, I4, S1, S2, S3) when is_integer(I1), is_integer(I2), is_integer(I3), is_integer(I4) ->
+ user_trace_int(I1, I2, I3, I4, S1, S2, S3, undef);
+p(I1, I2, I3, S1, S2, S3, S4) when is_integer(I1), is_integer(I2), is_integer(I3) ->
+ user_trace_int(I1, I2, I3, undef, S1, S2, S3, S4).
+
+-spec p(probe_arg(), probe_arg(), probe_arg(), probe_arg(),
+ probe_arg(), probe_arg(), probe_arg(), probe_arg()) ->
+ true | false | error | badarg.
+
+p(I1, I2, I3, I4, S1, S2, S3, S4) when is_integer(I1), is_integer(I2), is_integer(I3), is_integer(I4) ->
+ user_trace_int(I1, I2, I3, I4, S1, S2, S3, S4).
+
+-spec user_trace_int(int_p_arg(), int_p_arg(), int_p_arg(), int_p_arg(),
+ int_p_arg(), int_p_arg(), int_p_arg(), int_p_arg()) ->
+ true | false | error | badarg.
+
+user_trace_int(I1, I2, I3, I4, S1, S2, S3, S4) ->
+ UTag = get_tag(),
+ try
+ user_trace_i4s4(UTag, I1, I2, I3, I4, S1, S2, S3, S4)
+ catch
+ error:nif_not_loaded ->
+ false
+ end.
+
+-spec pn(n_probe_label()) -> true | false | error | badarg.
+
+pn(ProbeLabel) ->
+ user_trace_n_int(ProbeLabel, undef, undef, undef, undef, undef, undef, undef, undef).
+
+-spec pn(n_probe_label(), probe_arg()) -> true | false | error | badarg.
+
+pn(ProbeLabel, I1) when is_integer(I1) ->
+ user_trace_n_int(ProbeLabel, I1, undef, undef, undef, undef, undef, undef, undef);
+pn(ProbeLabel, S1) ->
+ user_trace_n_int(ProbeLabel, undef, undef, undef, undef, S1, undef, undef, undef).
+
+-spec pn(n_probe_label(), probe_arg(), probe_arg()) -> true | false | error | badarg.
+
+pn(ProbeLabel, I1, I2) when is_integer(I1), is_integer(I2) ->
+ user_trace_n_int(ProbeLabel, I1, I2, undef, undef, undef, undef, undef, undef);
+pn(ProbeLabel, I1, S1) when is_integer(I1) ->
+ user_trace_n_int(ProbeLabel, I1, undef, undef, undef, S1, undef, undef, undef);
+pn(ProbeLabel, S1, S2) ->
+ user_trace_n_int(ProbeLabel, undef, undef, undef, undef, S1, S2, undef, undef).
+
+-spec pn(n_probe_label(), probe_arg(), probe_arg(), probe_arg()) -> true | false | error | badarg.
+
+pn(ProbeLabel, I1, I2, I3) when is_integer(I1), is_integer(I2), is_integer(I3) ->
+ user_trace_n_int(ProbeLabel, I1, I2, I3, undef, undef, undef, undef, undef);
+pn(ProbeLabel, I1, I2, S1) when is_integer(I1), is_integer(I2) ->
+ user_trace_n_int(ProbeLabel, I1, I2, undef, undef, S1, undef, undef, undef);
+pn(ProbeLabel, I1, S1, S2) when is_integer(I1) ->
+ user_trace_n_int(ProbeLabel, I1, undef, undef, undef, S1, S2, undef, undef);
+pn(ProbeLabel, S1, S2, S3) ->
+ user_trace_n_int(ProbeLabel, undef, undef, undef, undef, S1, S2, S3, undef).
+
+-spec pn(n_probe_label(), probe_arg(), probe_arg(), probe_arg(), probe_arg()) ->
+ true | false | error | badarg.
+
+pn(ProbeLabel, I1, I2, I3, I4) when is_integer(I1), is_integer(I2), is_integer(I3), is_integer(I4) ->
+ user_trace_n_int(ProbeLabel, I1, I2, I3, I4, undef, undef, undef, undef);
+pn(ProbeLabel, I1, I2, I3, S1) when is_integer(I1), is_integer(I2), is_integer(I3) ->
+ user_trace_n_int(ProbeLabel, I1, I2, I3, undef, S1, undef, undef, undef);
+pn(ProbeLabel, I1, I2, S1, S2) when is_integer(I1), is_integer(I2) ->
+ user_trace_n_int(ProbeLabel, I1, I2, undef, undef, S1, S2, undef, undef);
+pn(ProbeLabel, I1, S1, S2, S3) when is_integer(I1) ->
+ user_trace_n_int(ProbeLabel, I1, undef, undef, undef, S1, S2, S3, undef);
+pn(ProbeLabel, S1, S2, S3, S4) ->
+ user_trace_n_int(ProbeLabel, undef, undef, undef, undef, S1, S2, S3, S4).
+
+-spec pn(n_probe_label(), probe_arg(), probe_arg(), probe_arg(), probe_arg(),
+ probe_arg()) ->
+ true | false | error | badarg.
+
+pn(ProbeLabel, I1, I2, I3, I4, S1) when is_integer(I1), is_integer(I2), is_integer(I3), is_integer(I4) ->
+ user_trace_n_int(ProbeLabel, I1, I2, I3, I4, S1, undef, undef, undef);
+pn(ProbeLabel, I1, I2, I3, S1, S2) when is_integer(I1), is_integer(I2), is_integer(I3) ->
+ user_trace_n_int(ProbeLabel, I1, I2, I3, undef, S1, S2, undef, undef);
+pn(ProbeLabel, I1, I2, S1, S2, S3) when is_integer(I1), is_integer(I2) ->
+ user_trace_n_int(ProbeLabel, I1, I2, undef, undef, S1, S2, S3, undef);
+pn(ProbeLabel, I1, S1, S2, S3, S4) when is_integer(I1) ->
+ user_trace_n_int(ProbeLabel, I1, undef, undef, undef, S1, S2, S3, S4).
+
+-spec pn(n_probe_label(), probe_arg(), probe_arg(), probe_arg(), probe_arg(),
+ probe_arg(), probe_arg()) ->
+ true | false | error | badarg.
+
+pn(ProbeLabel, I1, I2, I3, I4, S1, S2) when is_integer(I1), is_integer(I2), is_integer(I3), is_integer(I4) ->
+ user_trace_n_int(ProbeLabel, I1, I2, I3, I4, S1, S2, undef, undef);
+pn(ProbeLabel, I1, I2, I3, S1, S2, S3) when is_integer(I1), is_integer(I2), is_integer(I3) ->
+ user_trace_n_int(ProbeLabel, I1, I2, I3, undef, S1, S2, S3, undef);
+pn(ProbeLabel, I1, I2, S1, S2, S3, S4) when is_integer(I1), is_integer(I2) ->
+ user_trace_n_int(ProbeLabel, I1, I2, undef, undef, S1, S2, S3, S4).
+
+-spec pn(n_probe_label(), probe_arg(), probe_arg(), probe_arg(), probe_arg(),
+ probe_arg(), probe_arg(), probe_arg()) ->
+ true | false | error | badarg.
+
+pn(ProbeLabel, I1, I2, I3, I4, S1, S2, S3) when is_integer(I1), is_integer(I2), is_integer(I3), is_integer(I4) ->
+ user_trace_n_int(ProbeLabel, I1, I2, I3, I4, S1, S2, S3, undef);
+pn(ProbeLabel, I1, I2, I3, S1, S2, S3, S4) when is_integer(I1), is_integer(I2), is_integer(I3) ->
+ user_trace_n_int(ProbeLabel, I1, I2, I3, undef, S1, S2, S3, S4).
+
+-spec pn(n_probe_label(), probe_arg(), probe_arg(), probe_arg(), probe_arg(),
+ probe_arg(), probe_arg(), probe_arg(), probe_arg()) ->
+ true | false | error | badarg.
+
+pn(ProbeLabel, I1, I2, I3, I4, S1, S2, S3, S4) when is_integer(I1), is_integer(I2), is_integer(I3), is_integer(I4) ->
+ user_trace_n_int(ProbeLabel, I1, I2, I3, I4, S1, S2, S3, S4).
+
+-spec user_trace_n_int(n_probe_label(),
+ int_p_arg(), int_p_arg(), int_p_arg(), int_p_arg(),
+ int_p_arg(), int_p_arg(), int_p_arg(), int_p_arg()) ->
+ true | false | error | badarg.
+
+user_trace_n_int(ProbeLabel, I1, I2, I3, I4, S1, S2, S3, S4) ->
+ UTag = get_tag(),
+ try
+ user_trace_n(ProbeLabel, UTag, I1, I2, I3, I4, S1, S2, S3, S4)
+ catch
+ error:nif_not_loaded ->
+ false
+ end.
+
+-spec put_tag(undefined | iodata()) -> binary() | undefined.
+put_tag(Data) ->
+ erlang:dt_put_tag(unicode:characters_to_binary(Data)).
+
+-spec get_tag() -> binary() | undefined.
+get_tag() ->
+ erlang:dt_get_tag().
+
+-spec get_tag_data() -> binary() | undefined.
+%% Gets tag if set, otherwise the spread tag data from last incoming message
+get_tag_data() ->
+ erlang:dt_get_tag_data().
+
+-spec spread_tag(boolean()) -> true | {non_neg_integer(), binary() | []}.
+%% Makes the tag behave as a sequential trace token, will spread with
+%% messages to be picked up by someone using get_tag_data
+spread_tag(B) ->
+ erlang:dt_spread_tag(B).
+
+-spec restore_tag(true | {non_neg_integer(), binary() | []}) -> true.
+restore_tag(T) ->
+ erlang:dt_restore_tag(T).
diff --git a/lib/runtime_tools/src/runtime_tools.app.src b/lib/runtime_tools/src/runtime_tools.app.src
index 76fd998530..1152f7259d 100644
--- a/lib/runtime_tools/src/runtime_tools.app.src
+++ b/lib/runtime_tools/src/runtime_tools.app.src
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 1999-2011. All Rights Reserved.
+%% Copyright Ericsson AB 1999-2012. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
@@ -23,7 +23,7 @@
inviso_rt,inviso_rt_lib,inviso_rt_meta,
inviso_as_lib,inviso_autostart,inviso_autostart_server,
runtime_tools,runtime_tools_sup,erts_alloc_config,
- ttb_autostart]},
+ ttb_autostart,dyntrace]},
{registered, [runtime_tools_sup,inviso_rt,inviso_rt_meta]},
{applications, [kernel, stdlib]},
% {env, [{inviso_autostart_mod,your_own_autostart_module}]},
diff --git a/lib/runtime_tools/test/Makefile b/lib/runtime_tools/test/Makefile
index cfaf420d65..4979b9c7b1 100644
--- a/lib/runtime_tools/test/Makefile
+++ b/lib/runtime_tools/test/Makefile
@@ -3,6 +3,7 @@ include $(ERL_TOP)/make/target.mk
include $(ERL_TOP)/make/$(TARGET)/otp.mk
MODULES = \
+ dyntrace_SUITE \
runtime_tools_SUITE \
inviso_testmodule1_foo \
inviso_SUITE \
@@ -56,10 +57,10 @@ include $(ERL_TOP)/make/otp_release_targets.mk
release_spec: opt
release_tests_spec: make_emakefile
- $(INSTALL_DIR) $(RELSYSDIR)
- $(INSTALL_DATA) runtime_tools.spec runtime_tools.cover $(ERL_FILES) $(RELSYSDIR)
- $(INSTALL_DATA) $(EMAKEFILE) runtime_tools.cover $(RELSYSDIR)
- chmod -R u+w $(RELSYSDIR)
- @tar cf - *_SUITE_data | (cd $(RELSYSDIR); tar xf -)
+ $(INSTALL_DIR) "$(RELSYSDIR)"
+ $(INSTALL_DATA) runtime_tools.spec runtime_tools.cover $(ERL_FILES) "$(RELSYSDIR)"
+ $(INSTALL_DATA) $(EMAKEFILE) runtime_tools.cover "$(RELSYSDIR)"
+ chmod -R u+w "$(RELSYSDIR)"
+ @tar cf - *_SUITE_data | (cd "$(RELSYSDIR)"; tar xf -)
release_docs_spec:
diff --git a/lib/runtime_tools/test/dyntrace_SUITE.erl b/lib/runtime_tools/test/dyntrace_SUITE.erl
new file mode 100644
index 0000000000..0e4f369ed0
--- /dev/null
+++ b/lib/runtime_tools/test/dyntrace_SUITE.erl
@@ -0,0 +1,224 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 2012. All Rights Reserved.
+%%
+%% The contents of this file are subject to the Erlang Public License,
+%% Version 1.1, (the "License"); you may not use this file except in
+%% compliance with the License. You should have received a copy of the
+%% Erlang Public License along with this software. If not, it can be
+%% retrieved online at http://www.erlang.org/.
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+%% the License for the specific language governing rights and limitations
+%% under the License.
+%%
+%% %CopyrightEnd%
+%%
+-module(dyntrace_SUITE).
+-include_lib("test_server/include/test_server.hrl").
+
+-export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1,
+ init_per_group/2,end_per_group/2]).
+-export([init_per_testcase/2, end_per_testcase/2]).
+
+%% Test cases
+-export([smoke/1,process/1]).
+
+%% Default timetrap timeout (set in init_per_testcase)
+-define(default_timeout, ?t:minutes(1)).
+
+init_per_testcase(_Case, Config) ->
+ Dog = test_server:timetrap(?default_timeout),
+ [{watchdog,Dog}|Config].
+
+end_per_testcase(_Case, Config) ->
+ Dog = ?config(watchdog, Config),
+ ?t:timetrap_cancel(Dog),
+ ok.
+
+suite() -> [{ct_hooks,[ts_install_cth]}].
+
+all() ->
+ case erlang:system_info(dynamic_trace) of
+ none ->
+ {skip,"No dynamic trace in this run-time system"};
+ dtrace ->
+ [{group,smoke}];
+ systemtap ->
+ {skip,"SystemTap tests currently not supported"}
+ end.
+
+groups() ->
+ [{smoke,[sequence],[smoke,{group,rest}]},
+ {rest,[],
+ [process]}].
+
+init_per_suite(Config) ->
+ N = "beam" ++
+ case erlang:system_info(debug_compiled) of
+ false -> "";
+ true -> ".debug"
+ end ++
+ case erlang:system_info(smp_support) of
+ false -> "";
+ true -> ".smp"
+ end,
+ [{emu_name,N}|Config].
+
+end_per_suite(_Config) ->
+ ok.
+
+init_per_group(_GroupName, Config) ->
+ Config.
+
+end_per_group(_GroupName, Config) ->
+ Config.
+
+smoke(Config) ->
+ Emu = ?t:lookup_config(emu_name, Config),
+ BinEmu = list_to_binary(Emu),
+ case erlang:system_info(dynamic_trace) of
+ dtrace ->
+ Probes = os:cmd("sudo /usr/sbin/dtrace -l -m" ++ Emu),
+ io:put_chars(Probes),
+ [_|Lines] = re:split(Probes, "\n", [trim]),
+ [{_,_} = binary:match(L, BinEmu) || L <- Lines],
+ ok
+ end,
+
+ %% Test that the framework for running dtrace/systemtap works
+ %% by executing an empty script.
+ {ok,[]} = dyntrace("", fun() -> ok end),
+ ok.
+
+
+process(_Config) ->
+ Script = [{probe,"process-spawn"},
+ {action,[{printf,["spawn %s %s\n",{arg,0},{arg,1}]}]},
+ {probe,"process-scheduled"},
+ {action,[{printf,["in %s\n",{arg,0}]}]},
+ {probe,"process-unscheduled"},
+ {action,[{printf,["out %s\n",{arg,0}]}]},
+ {probe,"process-hibernate"},
+ {action,[{printf,["hibernate %s %s\n",{arg,0},{arg,1}]}]},
+ {probe,"process-exit"},
+ {action,[{printf,["exit %s %s\n",{arg,0},{arg,1}]}]}
+ ],
+ F = fun() ->
+ {Pid,Ref} = spawn_monitor(fun my_process/0),
+ Pid ! hibernate,
+ Pid ! quit,
+ receive
+ {'DOWN',Ref,process,Pid,{terminated,Pid}} ->
+ ok
+ end,
+ Pid
+ end,
+ {Pid,Output0} = dyntrace(Script, F),
+ Output1 = [termify_line(L) || L <- Output0],
+ PidStr = pid_to_list(Pid),
+ Output = [L || L <- Output1, element(2, L) =:= PidStr],
+ Reason = "{terminated,"++PidStr++"}",
+ io:format("~p\n", [Output]),
+ [{spawn,PidStr,"erlang:apply/2"},
+ {in,PidStr},
+ {hibernate,PidStr,"erlang:apply/2"},
+ {out,PidStr},
+ {in,PidStr},
+ {exit,PidStr,Reason},
+ {out,PidStr}] = Output,
+ ok.
+
+termify_line(L) ->
+ [H|T] = re:split(L, " ", [{return,list}]),
+ list_to_tuple([list_to_atom(H)|T]).
+
+my_process() ->
+ receive
+ hibernate ->
+ erlang:hibernate(erlang, apply, [fun my_process/0,[]]);
+ quit ->
+ exit({terminated,self()})
+ end.
+
+%%%
+%%% Utility functions.
+%%%
+
+dyntrace(Script0, Action) ->
+ Sudo = os:find_executable(sudo),
+ {Termination,Pid} = termination_probe(),
+ Script1 = Script0++Termination,
+ Script = translate_script(Script1),
+ io:format("~s\n", [Script]),
+ SrcFile = "test-dyntrace.d",
+ ok = file:write_file(SrcFile, Script),
+ Args = ["/usr/sbin/dtrace", "-q","-s",SrcFile],
+ Port = open_port({spawn_executable,Sudo},
+ [{args,Args},stream,in,stderr_to_stdout,eof]),
+ receive
+ {Port,{data,Sofar}} ->
+ Res = Action(),
+ Pid ! quit,
+ {Res,get_data(Port, Sofar)}
+ end.
+
+get_data(Port, Sofar) ->
+ receive
+ {Port,{data,Bytes}} ->
+ get_data(Port, [Sofar|Bytes]);
+ {Port,eof} ->
+ port_close(Port),
+ [$\n|T] = lists:flatten(Sofar),
+ re:split(T, "\n", [{return,list},trim])
+ end.
+
+termination_probe() ->
+ Pid = spawn(fun() ->
+ receive
+ _ ->
+ exit(done)
+ end
+ end),
+ S = [{'BEGIN',[{printf,["\n"]}]},
+ {probe,"process-exit"},
+ {pred,{'==',{arg,0},Pid}},
+ {action,[{exit,[0]}]}],
+ {S,Pid}.
+
+translate_script(Script) ->
+ [dtrace_op(Op) || Op <- Script].
+
+dtrace_op({probe,Function}) ->
+ OsPid = os:getpid(),
+ ["erlang",OsPid,":::",Function,$\n];
+dtrace_op({pred,Pred}) ->
+ ["/",dtrace_op(Pred),"/\n"];
+dtrace_op({action,List}) ->
+ ["{ ",action_list(List)," }\n\n"];
+dtrace_op({'BEGIN',List}) ->
+ ["BEGIN { ",action_list(List)," }\n\n"];
+dtrace_op({'==',Op1,Op2}) ->
+ [dtrace_op(Op1)," == ",dtrace_op(Op2)];
+dtrace_op({arg,N}) ->
+ ["copyinstr(arg",integer_to_list(N),")"];
+dtrace_op({Func,List}) when is_atom(Func), is_list(List) ->
+ [atom_to_list(Func),"(",comma_sep_ops(List),")"];
+dtrace_op(Pid) when is_pid(Pid) ->
+ ["\"",pid_to_list(Pid),"\""];
+dtrace_op(Str) when is_integer(hd(Str)) ->
+ io_lib:format("~p", [Str]);
+dtrace_op(Int) when is_integer(Int) ->
+ integer_to_list(Int).
+
+comma_sep_ops([A,B|T]) ->
+ [dtrace_op(A),","|comma_sep_ops([B|T])];
+comma_sep_ops([H]) ->
+ dtrace_op(H);
+comma_sep_ops([]) -> [].
+
+action_list([H|T]) ->
+ [dtrace_op(H),";"|action_list(T)];
+action_list([]) -> [].
diff --git a/lib/runtime_tools/test/inviso_SUITE.erl b/lib/runtime_tools/test/inviso_SUITE.erl
index 33626ffd9e..c64c40b945 100644
--- a/lib/runtime_tools/test/inviso_SUITE.erl
+++ b/lib/runtime_tools/test/inviso_SUITE.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2010-2011. All Rights Reserved.
+%% Copyright Ericsson AB 2010-2012. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
diff --git a/lib/runtime_tools/vsn.mk b/lib/runtime_tools/vsn.mk
index 3fbc1b3379..c9b5cc1a41 100644
--- a/lib/runtime_tools/vsn.mk
+++ b/lib/runtime_tools/vsn.mk
@@ -1 +1 @@
-RUNTIME_TOOLS_VSN = 1.8.7
+RUNTIME_TOOLS_VSN = 1.8.8