From 0721ac40f91295bb3995f86966e5dd031028ca85 Mon Sep 17 00:00:00 2001 From: Scott Lystig Fritchie Date: Thu, 17 Nov 2011 00:42:55 -0600 Subject: Add DTrace support for OS X, Solaris, and Linux (via SystemTap), 1/4 Since it's been quite a while since I've written C code, *and* I haven't done any significant hacking on the VM itself in years, it's quite likely that I haven't done things in 100% proper style. Or my co-collaborators Dustin Sallings (CouchBase) or Michal Ptaszek (Erlang Solutions). My intent for this patch is to start discussion and review of DTrace support for consideration for the R15 release. For additional background on the motivation for this work, please see the slides for the presentation at the Erlang User Conference 2011 in Stockholm: https://www.erlang-factory.com/upload/presentations/462/euc2011-draft2.pdf Changes relative to dtrace-review2 branch: * Fix errors in OTP test suite 'kernel' file_SUITE * Fix errors in OTP test suite 'kernel' prim_file_SUITE * Fix bad pointer bug in efile_drv.c flush_write() * Move the DTrace material from the top of `README.md` into a new file, `README.dtrace.md` Changes since last push to GitHub (relative to commit 5828a4fb28, which was the former `dtrace-review1` branch): * Rebased onto 14 Nov 2011's "master" branch * Recent changes to the async task queuing mechanism means that the async worker queue length is not available. A bogus value of -1 is hard-coded until there's a good way to peek into the new queue structure and find the queue length. * Small fixes based on review comments by Mikael Pettersson, Andrew Thompson, and Andreas Schultz. Add autoconf support: use "./configure --enable-dtrace" on all supported platforms: * OS X Snow Leopard or later * Solaris 10 or OpenSolaris * Linux, via SystemTap's DTrace compatibility packages * FreeBSD 9.0RC1. FreeBSD 8 and earlier do not have support for USDT, DTrace's User-land Statically Defined Tracing. See the file `erts/emulator/beam/erlang_dtrace.d` for the definition of all DTrace probes in the virtual machine so far. Example D scripts can be found in `lib/dtrace/examples`. Note that if you see the error message `{name of probe} does not match any probes`, then there is no Erlang VM process + DTrace probes running. To fix, start a DTrace-enabled VM or remove `-q` from the `dtrace` command line. The `lib/dtrace` directory contains a small code-only OTP application that contains code that allows Erlang code to trigger a DTrace probe. Dynamic creation & deletion of DTrace probes is not currently supported, so the `dtrace:p()` function is hacked to allow a variable number of arguments (up to four integers and up to four strings) to be used. See the comments at the top of `lib/dtrace/src/dtrace.c` for more detail. One feature that may be controversial is the notion I've introduced of a special process dictionary key that can be used by Erlang code to tag I/O operations for an application-specific purpose. Right now, that tag's name is `dtrace_utag`. The dictionary keys used by `sys` and other modules start with a dollar sign. Perhaps there is some convention (but not a dollar sign?) that this tag should use? The purpose of the process dictionary key is to allow the tag to be included in trace messages, e.g. for file I/O, without changing the API of the `file.erl` module's functions. For example, here's a use of the tag when calling the `file:rename/2` function: (bar@sbb2)1> put(dtrace_utag, "GGOOOAAALL!!!!!"). undefined (bar@sbb2)2> dtrace:init(). ok %% Now start both the `user-probe.d` and `efile_drv.d` D scripts %% found in the `lib/dtrace/examples` directory. (bar@sbb2)3> dtrace:p(7, 8, 9, "one", "four"). true %% The output from the `user-probe.d` script: <0.40.0> GGOOOAAALL!!!!! 7 8 9 0 'one' 'four' '' '' (bar@sbb2)4> file:rename("old-name", "new-name"). {error,enoent} %% The output from the `efile_drv.d` script: async I/O pool port #Port<0.59> queue len 1 async I/O pool port #Port<0.59> queue len 0 efile_drv enter tag={1,110} user tag GGOOOAAALL!!!!! | RENAME (12) | args: old-name new-name , 0 0 (port #Port<0.59>) async I/O worker tag={1,110} | RENAME (12) | efile_drv-int_entry async I/O worker tag={1,110} | RENAME (12) | efile_drv-int_return efile_drv return tag={1,110} user tag GGOOOAAALL!!!!! | RENAME (12) | errno 2 I'm not exactly happy with this choice of tagging, namely using `put(dtrace_utag, Tag::list())`. But this is an experiment, so we'll see how it goes. I can't imagine changing the API for all file.erl functions in order pass the tag explicitly. Some modules have some extensive (ab)use of the C preprocessor to reduce the amount of #ifdefs that clutter the code. In several places, I have not #ifdef'ed automatic variables because of clutter. For the same reason, there are a handful of cases where I added DTrace-related members to a struct definition without an #ifdef. I feel that the result is easier to read than earlier drafts where I did use many more `https://github.com/slfritchie/otp/tree/dtrace-experiment+michal2` if you're curious.) I expect there may be some debate about whether the bloat of the affected structs is worthwhile. I erred on adding stuff to structs, especially in the efile_drv.c driver, not having a full grasp on what was thread-safe and what was not ... so I erred on the side of caution. The efile_drv.c has a work-around for a crazy GCC optimization bug. Thank goodness for Google, I dunno how I would've found a work-around for this silly thing. Many thanks to Trond Norbye for writing clearly about the problem in a membase Git repo commit message. /* * A note on probe naming: if "__" appears in a provider probe * definition, then two things happen during compilation: * * 1. The "__" will turn into a hypen, "-", for the probe name. * 2. The "__" will turn into a single underscore, "_", for the * macro names and function definitions that the compiler and * C developers will see. * * We'll try to use the following naming convention. We're a bit * limited because, as a USDT probe, we can only specify the 4th part * of the probe name, e.g. erlang*:::mumble. The 2nd part of the * probe name is always going to be "beam" or "beam.smp", and the 3rd * part of the probe name will always be the name of the function * that's calling the probe. * * So, all probes will be have names defined in this file using the * convention category__name or category__sub_category__name. This * will translate to probe names of category-name or * category-sub_category-name. * * Each of "category", "sub_category", and "name" may have underscores * but may not have hyphens. */ Add tentative support for sequential tracing sending, queueing, and receiving a message. I don't believe I've fully covered all the major places where it would be useful to have the sequential trace token info in a probe -- guidance from the OTP team would be helpful, if there's time to do that kind of review. Add global variable `erts_this_node_sysname`. --- lib/Makefile | 2 +- lib/dtrace/Makefile | 36 +++++++ lib/dtrace/c_src/Makefile | 4 + lib/dtrace/c_src/Makefile.in | 152 ++++++++++++++++++++++++++++ lib/dtrace/c_src/dtrace.c | 174 ++++++++++++++++++++++++++++++++ lib/dtrace/c_src/dtrace_user.d | 53 ++++++++++ lib/dtrace/ebin/.placeholder | 0 lib/dtrace/src/Makefile | 102 +++++++++++++++++++ lib/dtrace/src/dtrace.app.src | 27 +++++ lib/dtrace/src/dtrace.appup.src | 19 ++++ lib/dtrace/src/dtrace.erl | 216 ++++++++++++++++++++++++++++++++++++++++ lib/dtrace/vsn.mk | 1 + 12 files changed, 785 insertions(+), 1 deletion(-) create mode 100644 lib/dtrace/Makefile create mode 100644 lib/dtrace/c_src/Makefile create mode 100644 lib/dtrace/c_src/Makefile.in create mode 100644 lib/dtrace/c_src/dtrace.c create mode 100644 lib/dtrace/c_src/dtrace_user.d create mode 100644 lib/dtrace/ebin/.placeholder create mode 100644 lib/dtrace/src/Makefile create mode 100644 lib/dtrace/src/dtrace.app.src create mode 100644 lib/dtrace/src/dtrace.appup.src create mode 100644 lib/dtrace/src/dtrace.erl create mode 100644 lib/dtrace/vsn.mk (limited to 'lib') diff --git a/lib/Makefile b/lib/Makefile index aa4e074830..96ce2d1315 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -31,7 +31,7 @@ ifdef BUILD_ALL cosTransactions cosEvent cosTime cosNotification \ cosProperty cosFileTransfer cosEventDomain et megaco webtool \ xmerl edoc eunit ssh inviso typer erl_docgen \ - percept dialyzer hipe + percept dialyzer dtrace hipe EXTRA_FILE := $(wildcard EXTRA-APPLICATIONS) EXTRA_APPLICATIONS := $(if $(EXTRA_FILE),$(shell cat $(EXTRA_FILE))) endif diff --git a/lib/dtrace/Makefile b/lib/dtrace/Makefile new file mode 100644 index 0000000000..29d463aab1 --- /dev/null +++ b/lib/dtrace/Makefile @@ -0,0 +1,36 @@ +# +# %CopyrightBegin% +# +# Copyright Ericsson AB 2002-2009. 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% +# +include $(ERL_TOP)/make/target.mk +include $(ERL_TOP)/make/$(TARGET)/otp.mk + +# +# Macros +# + +SUB_DIRECTORIES = src c_src + +include vsn.mk +VSN = $(DTRACE_VSN) + +SPECIAL_TARGETS = + +# +# Default Subdir Targets +# +include $(ERL_TOP)/make/otp_subdir.mk diff --git a/lib/dtrace/c_src/Makefile b/lib/dtrace/c_src/Makefile new file mode 100644 index 0000000000..f3320bb766 --- /dev/null +++ b/lib/dtrace/c_src/Makefile @@ -0,0 +1,4 @@ +# +# Invoke with GNU make or clearmake -C gnu. +# +include $(ERL_TOP)/make/run_make.mk diff --git a/lib/dtrace/c_src/Makefile.in b/lib/dtrace/c_src/Makefile.in new file mode 100644 index 0000000000..ed13684a95 --- /dev/null +++ b/lib/dtrace/c_src/Makefile.in @@ -0,0 +1,152 @@ +# +# %CopyrightBegin% +# +# Copyright Scott Lystig Fritchie 2011. 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% +# +include $(ERL_TOP)/make/target.mk +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 +VSN=$(DTRACE_VSN) + +# ---------------------------------------------------- +# The following variables differ between systems. +# Set by configure. +# ---------------------------------------------------- +CC = $(DED_CC) +LD = $(DED_LD) +SHELL = /bin/sh +LIBS = $(DED_LIBS) +LDFLAGS += $(DED_LDFLAGS) +CFLAGS = $(DED_CFLAGS) + +DTRACE_LIBNAME = dtrace + + +INCLUDES = $(DED_INCLUDES) + +ifeq ($(TYPE),debug) +TYPEMARKER = .debug +TYPE_FLAGS = $(subst -O3,,$(subst -O2,,$(CFLAGS))) -DDEBUG +else +ifeq ($(TYPE),valgrind) +TYPEMARKER = .valgrind +TYPE_FLAGS = $(subst -O3,,$(subst -O2,,$(CFLAGS))) -DVALGRIND +else +TYPEMARKER = +TYPE_FLAGS = $(CFLAGS) +endif +endif + +ALL_CFLAGS = $(TYPE_FLAGS) $(INCLUDES) -I$(OBJDIR) \ + -I$(ERL_TOP)/erts/emulator/$(TARGET) + +# ---------------------------------------------------- +# Release directory specification +# ---------------------------------------------------- +RELSYSDIR = $(RELEASE_PATH)/lib/dtrace-$(VSN) + +# ---------------------------------------------------- +# Misc Macros +# ---------------------------------------------------- +OBJS = $(OBJDIR)/dtrace$(TYPEMARKER).o +## NIF_MAKEFILE = $(PRIVDIR)/Makefile + +# Higher-level makefiles says that we can only compile on UNIX flavors +NIF_LIB = $(LIBDIR)/dtrace$(TYPEMARKER).so + +ifeq ($(HOST_OS),) +HOST_OS := $(shell $(ERL_TOP)/erts/autoconf/config.guess) +endif + +# ---------------------------------------------------- +# Targets +# ---------------------------------------------------- + +debug opt valgrind: $(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 + +ifdef DTRACE_ENABLED_2STEP +OBJS += $(OBJDIR)/dtrace_user.o +$(OBJDIR)/dtrace_user.o: $(OBJS) $(OBJDIR)/dtrace_user.h + touch $(OBJDIR)/erlang_dtrace.c + $(CC) $(CFLAGS) -c -o $@ $(OBJDIR)/erlang_dtrace.c + # The object file created above is immediately clobbered below. + # But creating it above avoids chicken-and-egg problem with OBJS + dtrace -G -C \ + -s ./dtrace_user.d \ + -o $@ $(OBJS) +endif + +$(OBJDIR): + -@mkdir -p $(OBJDIR) + +$(LIBDIR): + -@mkdir -p $(LIBDIR) + +$(OBJDIR)/%$(TYPEMARKER).o: %.c $(DTRACE_USER_HEADER) + $(INSTALL_DIR) $(OBJDIR) + $(CC) -c -o $@ $(ALL_CFLAGS) $< + +$(LIBDIR)/dtrace$(TYPEMARKER).so: $(OBJS) + $(INSTALL_DIR) $(LIBDIR) + $(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS) + +clean: + rm -f $(LIBDIR)/dtrace.so + rm -f $(LIBDIR)/dtrace.debug.so + rm -f $(LIBDIR)/dtrace.valgrind.so + rm -f $(OBJDIR)/dtrace.o + rm -f $(OBJDIR)/dtrace.debug.o + rm -f $(OBJDIR)/dtrace.valgrind.o + rm -f core *~ + +docs: + +# ---------------------------------------------------- +# Release Target +# ---------------------------------------------------- +include $(ERL_TOP)/make/otp_release_targets.mk + +release_spec: opt + $(INSTALL_DIR) $(RELSYSDIR)/priv/obj + $(INSTALL_DIR) $(RELSYSDIR)/priv/lib + # $(INSTALL_DATA) $(NIF_MAKEFILE) $(RELSYSDIR)/priv/obj + $(INSTALL_PROGRAM) $(OBJS) $(RELSYSDIR)/priv/obj + $(INSTALL_PROGRAM) $(NIF_LIB) $(RELSYSDIR)/priv/lib + +release_docs_spec: diff --git a/lib/dtrace/c_src/dtrace.c b/lib/dtrace/c_src/dtrace.c new file mode 100644 index 0000000000..c9d25ece9c --- /dev/null +++ b/lib/dtrace/c_src/dtrace.c @@ -0,0 +1,174 @@ +/* + * %CopyrightBegin% + * + * Copyright Scott Lystig Fritchie 2011. 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" +#define DTRACE_DRIVER_SKIP_FUNC_DECLARATIONS +#include "dtrace-wrapper.h" +#ifdef HAVE_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 VALGRIND + # include +#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 ErlNifFunc nif_funcs[] = { + {"available", 0, available}, + {"user_trace_s1", 1, user_trace_s1}, + {"user_trace_i4s4", 9, user_trace_i4s4} +}; + +ERL_NIF_INIT(dtrace, 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_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_DTRACE + ErlNifBinary message_bin; + DTRACE_CHARBUF(messagebuf, MESSAGE_BUFSIZ + 1); + + if (DTRACE_ENABLED(user_trace_s1)) { + if (!enif_inspect_iolist_as_binary(env, argv[0], &message_bin) || + message_bin.size > MESSAGE_BUFSIZ) { + return atom_badarg; + } + memcpy(messagebuf, (char *) message_bin.data, message_bin.size); + messagebuf[message_bin.size] = '\0'; + DTRACE1(user_trace_s1, messagebuf); + return atom_true; + } else { + return atom_false; + } +#else + return atom_error; +#endif +} + +void +get_string_maybe(ErlNifEnv *env, + const ERL_NIF_TERM term, char **ptr, char *buf, int bufsiz) +{ + ErlNifBinary str_bin; + + if (!enif_inspect_iolist_as_binary(env, term, &str_bin) || + str_bin.size > bufsiz) { + *ptr = NULL; + } else { + memcpy(buf, (char *) str_bin.data, str_bin.size); + buf[str_bin.size] = '\0'; + *ptr = buf; + } +} + +static ERL_NIF_TERM user_trace_i4s4(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) +{ +#ifdef HAVE_DTRACE + DTRACE_CHARBUF(procbuf, 32 + 1); + DTRACE_CHARBUF(user_tagbuf, MESSAGE_BUFSIZ + 1); + char *utbuf = NULL; + ErlNifSInt64 i1, i2, i3, i4; + DTRACE_CHARBUF(messagebuf1, MESSAGE_BUFSIZ + 1); + DTRACE_CHARBUF(messagebuf2, MESSAGE_BUFSIZ + 1); + DTRACE_CHARBUF(messagebuf3, MESSAGE_BUFSIZ + 1); + DTRACE_CHARBUF(messagebuf4, MESSAGE_BUFSIZ + 1); + char *mbuf1 = NULL, *mbuf2 = NULL, *mbuf3 = NULL, *mbuf4 = NULL; + + if (DTRACE_ENABLED(user_trace_i4s4)) { + dtrace_nifenv_str(env, procbuf); + get_string_maybe(env, argv[0], &utbuf, + user_tagbuf, sizeof(user_tagbuf)-1); + if (! enif_get_int64(env, argv[1], &i1)) + i1 = 0; + if (! enif_get_int64(env, argv[2], &i2)) + i2 = 0; + if (! enif_get_int64(env, argv[3], &i3)) + i3 = 0; + if (! enif_get_int64(env, argv[4], &i4)) + i4 = 0; + get_string_maybe(env, argv[5], &mbuf1, + messagebuf1, sizeof(messagebuf1)-1); + get_string_maybe(env, argv[6], &mbuf2, + messagebuf2, sizeof(messagebuf2)-1); + get_string_maybe(env, argv[7], &mbuf3, + messagebuf3, sizeof(messagebuf3)-1); + get_string_maybe(env, argv[8], &mbuf4, + messagebuf4, sizeof(messagebuf4)-1); + DTRACE10(user_trace_i4s4, procbuf, utbuf, + i1, i2, i3, i4, mbuf1, mbuf2, mbuf3, mbuf4); + return atom_true; + } else { + return atom_false; + } +#else + return atom_error; +#endif +} diff --git a/lib/dtrace/c_src/dtrace_user.d b/lib/dtrace/c_src/dtrace_user.d new file mode 100644 index 0000000000..45d3ef3b66 --- /dev/null +++ b/lib/dtrace/c_src/dtrace_user.d @@ -0,0 +1,53 @@ +/* + * %CopyrightBegin% + * + * Copyright Scott Lystig Fritchie 2011. + * 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 { + /** + * Send a single string to a probe. + * + * @param NUL-terminated string + */ + probe user_trace__s1(char* message); + + /** + * Multi-purpose probe: up to 4 NUL-terminated strings and 4 + * 64-bit integer arguments. + * + * @param proc, the PID (string form) of the sending process + * @param user_tag, the user tag of the sender + * @param i1, integer + * @param i2, integer + * @param i3, integer + * @param i4, integer + * @param s1, string/iolist. D's arg6 is NULL if not given by Erlang + * @param s2, string/iolist. D's arg7 is NULL if not given by Erlang + * @param s3, string/iolist. D's arg8 is NULL if not given by Erlang + * @param s4, string/iolist. D's arg9 is NULL if not given by Erlang + */ + probe user_trace__i4s4(char *proc, char *user_tag, + int i1, int i2, int i3, int i4, + char *s1, char *s2, char *s3, char *s4); +}; + +#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/dtrace/ebin/.placeholder b/lib/dtrace/ebin/.placeholder new file mode 100644 index 0000000000..e69de29bb2 diff --git a/lib/dtrace/src/Makefile b/lib/dtrace/src/Makefile new file mode 100644 index 0000000000..d613402a63 --- /dev/null +++ b/lib/dtrace/src/Makefile @@ -0,0 +1,102 @@ +# +# %CopyrightBegin% +# +# Copyright Ericsson AB 2002-2011. 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% +# +include $(ERL_TOP)/make/target.mk +include $(ERL_TOP)/make/$(TARGET)/otp.mk + +# ---------------------------------------------------- +# Application version +# ---------------------------------------------------- +include ../vsn.mk +VSN=$(DTRACE_VSN) + +# ---------------------------------------------------- +# Release directory specification +# ---------------------------------------------------- +RELSYSDIR = $(RELEASE_PATH)/lib/dtrace-$(VSN) + +# ---------------------------------------------------- +# Common Macros +# ---------------------------------------------------- + +MODULES= \ + dtrace + +HRL_FILES= \ + +INTERNAL_HRL_FILES= \ + +ERL_FILES= $(MODULES:%=%.erl) +EXAMPLE_FILES= \ + ../examples/* + +TARGET_FILES= $(MODULES:%=$(EBIN)/%.$(EMULATOR)) $(APP_TARGET) $(APPUP_TARGET) + +EXECUTABLES= \ + +APP_FILE= dtrace.app + +APP_SRC= $(APP_FILE).src +APP_TARGET= $(EBIN)/$(APP_FILE) + +APPUP_FILE= dtrace.appup + +APPUP_SRC= $(APPUP_FILE).src +APPUP_TARGET= $(EBIN)/$(APPUP_FILE) + +# ---------------------------------------------------- +# FLAGS +# ---------------------------------------------------- +ERL_COMPILE_FLAGS += \ + -I../include \ + -I ../../et/include \ + -I ../../../libraries/et/include + +# ---------------------------------------------------- +# Targets +# ---------------------------------------------------- + +debug opt: $(TARGET_FILES) + +clean: + rm -f $(TARGET_FILES) + rm -f errs core *~ + +$(APP_TARGET): $(APP_SRC) ../vsn.mk + sed -e 's;%VSN%;$(VSN);' $< > $@ + +$(APPUP_TARGET): $(APPUP_SRC) ../vsn.mk + sed -e 's;%VSN%;$(VSN);' $< > $@ + +docs: + +# ---------------------------------------------------- +# Release Target +# ---------------------------------------------------- +include $(ERL_TOP)/make/otp_release_targets.mk + +release_spec: opt + $(INSTALL_DIR) $(RELSYSDIR)/src + $(INSTALL_DATA) $(ERL_FILES) $(RELSYSDIR)/src + # $(INSTALL_DATA) $(INTERNAL_HRL_FILES) $(RELSYSDIR)/src + $(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/dtrace/src/dtrace.app.src b/lib/dtrace/src/dtrace.app.src new file mode 100644 index 0000000000..764e863559 --- /dev/null +++ b/lib/dtrace/src/dtrace.app.src @@ -0,0 +1,27 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2002-2009. 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% +%% +{application, dtrace, + [{description, "DTRACE version 1"}, + {vsn, "%VSN%"}, + {modules, [ + dtrace + ]}, + {registered, []}, + {applications, [kernel, stdlib]}, + {env, []}]}. diff --git a/lib/dtrace/src/dtrace.appup.src b/lib/dtrace/src/dtrace.appup.src new file mode 100644 index 0000000000..f730a2f8df --- /dev/null +++ b/lib/dtrace/src/dtrace.appup.src @@ -0,0 +1,19 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2002-2009. 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% +%% +{"%VSN%",[],[]}. diff --git a/lib/dtrace/src/dtrace.erl b/lib/dtrace/src/dtrace.erl new file mode 100644 index 0000000000..45addafc53 --- /dev/null +++ b/lib/dtrace/src/dtrace.erl @@ -0,0 +1,216 @@ +-module(dtrace). + +%%% @doc The DTrace interface module +%%% +%%% This DTrace interface module, with the corresponding NIFs, should +%%% work on any operating system platform where user-space DTrace +%%% probes are supported. +%%% +%%% Use the `dtrace:init()' function to load the NIF shared library and +%%% to initialize library's private state. +%%% +%%% It is recommended that you use the `dtrace:p()' function to add +%%% DTrace 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. For example: +%%% ``` +%%% 1> put(dtrace_utag, "GGOOOAAALL!!!!!"). +%%% undefined +%%% 2> dtrace:init(). +%%% ok +%%% +%%% % % % Enable the DTrace probe using the 'dtrace' command. +%%% +%%% 3> dtrace: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([init/0, 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]). +-export([scaff/0]). % Development only +-export([user_trace_i4s4/9]). % Know what you're doing! + +-type probe_arg() :: integer() | iolist(). +-type int_p_arg() :: integer() | iolist() | undef. +%% 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(). + +-spec init() -> ok | {error, {term(), term()}}. + +init() -> + PrivDir = code:priv_dir(dtrace), + Lib = filename:join([PrivDir, "lib", "dtrace"]), + erlang:load_nif(Lib, 0). + +%%% +%%% 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). + +%%% +%%% 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 = prim_file:get_dtrace_utag(), + user_trace_i4s4(UTag, I1, I2, I3, I4, S1, S2, S3, S4). + +%% Scaffolding to write tedious code: quick brute force and not 100% correct. + +scaff_int_args(N) -> + L = lists:sublist(["I1", "I2", "I3", "I4"], N), + [string:join(L, ", ")]. + +scaff_int_guards(N) -> + L = lists:sublist(["is_integer(I1)", "is_integer(I2)", "is_integer(I3)", + "is_integer(I4)"], N), + lists:flatten(string:join(L, ", ")). + +scaff_char_args(N) -> + L = lists:sublist(["S1", "S2", "S3", "S4"], N), + [string:join(L, ", ")]. + +scaff_fill(N) -> + [string:join(lists:duplicate(N, "undef"), ", ")]. + +scaff() -> + L = [begin + IntArgs = scaff_int_args(N_int), + IntGuards = scaff_int_guards(N_int), + IntFill = scaff_fill(4 - N_int), + CharArgs = scaff_char_args(N_char), + CharFill = scaff_fill(4 - N_char), + InArgs = string:join(IntArgs ++ CharArgs, ", "), + OutArgs = string:join(IntArgs ++ IntFill ++ CharArgs ++ CharFill, + ", "), + {N_int + N_char, + lists:flatten([io_lib:format("p(~s) when ~s ->\n", + [InArgs, IntGuards]), + io_lib:format(" user_trace_int(~s);\n", [OutArgs]) + ])} + end || N_int <- [0,1,2,3,4], N_char <- [0,1,2,3,4]], + [io:format("%%~p\n~s", [N, Str]) || {N, Str} <- lists:sort(L)]. diff --git a/lib/dtrace/vsn.mk b/lib/dtrace/vsn.mk new file mode 100644 index 0000000000..73bf983c00 --- /dev/null +++ b/lib/dtrace/vsn.mk @@ -0,0 +1 @@ +DTRACE_VSN = 0.8 -- cgit v1.2.3 From 0331c29e0e494d4c1e4fdd05e48a3f88a8caea0b Mon Sep 17 00:00:00 2001 From: Scott Lystig Fritchie Date: Thu, 17 Nov 2011 00:44:30 -0600 Subject: Add DTrace support for OS X, Solaris, and Linux (via SystemTap), 2/4 Add D scripts in the `lib/dtrace/examples` directory. Add SystemTap README and sample scripts, contributed by Andreas Schultz . --- lib/dtrace/examples/dist.d | 62 +++++++++ lib/dtrace/examples/dist.systemtap | 76 ++++++++++++ lib/dtrace/examples/driver1.d | 114 +++++++++++++++++ lib/dtrace/examples/driver1.systemtap | 125 +++++++++++++++++++ lib/dtrace/examples/efile_drv.d | 103 +++++++++++++++ lib/dtrace/examples/efile_drv.systemtap | 112 +++++++++++++++++ lib/dtrace/examples/function-calls.d | 51 ++++++++ lib/dtrace/examples/function-calls.systemtap | 61 +++++++++ lib/dtrace/examples/garbage-collection.d | 39 ++++++ lib/dtrace/examples/garbage-collection.systemtap | 49 ++++++++ lib/dtrace/examples/memory1.d | 41 ++++++ lib/dtrace/examples/memory1.systemtap | 51 ++++++++ lib/dtrace/examples/messages.d | 94 ++++++++++++++ lib/dtrace/examples/messages.systemtap | 87 +++++++++++++ lib/dtrace/examples/port1.d | 140 +++++++++++++++++++++ lib/dtrace/examples/port1.systemtap | 152 +++++++++++++++++++++++ lib/dtrace/examples/process-scheduling.d | 35 ++++++ lib/dtrace/examples/process-scheduling.systemtap | 45 +++++++ lib/dtrace/examples/spawn-exit.d | 41 ++++++ lib/dtrace/examples/spawn-exit.systemtap | 51 ++++++++ lib/dtrace/examples/user-probe.d | 36 ++++++ lib/dtrace/examples/user-probe.systemtap | 46 +++++++ 22 files changed, 1611 insertions(+) create mode 100644 lib/dtrace/examples/dist.d create mode 100644 lib/dtrace/examples/dist.systemtap create mode 100644 lib/dtrace/examples/driver1.d create mode 100644 lib/dtrace/examples/driver1.systemtap create mode 100644 lib/dtrace/examples/efile_drv.d create mode 100644 lib/dtrace/examples/efile_drv.systemtap create mode 100644 lib/dtrace/examples/function-calls.d create mode 100644 lib/dtrace/examples/function-calls.systemtap create mode 100644 lib/dtrace/examples/garbage-collection.d create mode 100644 lib/dtrace/examples/garbage-collection.systemtap create mode 100644 lib/dtrace/examples/memory1.d create mode 100644 lib/dtrace/examples/memory1.systemtap create mode 100644 lib/dtrace/examples/messages.d create mode 100644 lib/dtrace/examples/messages.systemtap create mode 100644 lib/dtrace/examples/port1.d create mode 100644 lib/dtrace/examples/port1.systemtap create mode 100644 lib/dtrace/examples/process-scheduling.d create mode 100644 lib/dtrace/examples/process-scheduling.systemtap create mode 100644 lib/dtrace/examples/spawn-exit.d create mode 100644 lib/dtrace/examples/spawn-exit.systemtap create mode 100644 lib/dtrace/examples/user-probe.d create mode 100644 lib/dtrace/examples/user-probe.systemtap (limited to 'lib') diff --git a/lib/dtrace/examples/dist.d b/lib/dtrace/examples/dist.d new file mode 100644 index 0000000000..f37c827f14 --- /dev/null +++ b/lib/dtrace/examples/dist.d @@ -0,0 +1,62 @@ +/* example usage: dtrace -q -s /path/to/dist.d */ +/* + * %CopyrightBegin% + * + * Copyright Scott Lystig Fritchie 2011. 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)); + blocked_procs[copyinstr(arg3)] = timestamp; +} + +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)); + 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/dtrace/examples/dist.systemtap b/lib/dtrace/examples/dist.systemtap new file mode 100644 index 0000000000..af27b2cab6 --- /dev/null +++ b/lib/dtrace/examples/dist.systemtap @@ -0,0 +1,76 @@ +/* example usage: stap /path/to/dist.systemtap -x */ +/* + * %CopyrightBegin% + * + * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011. 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/dtrace/examples/driver1.d b/lib/dtrace/examples/driver1.d new file mode 100644 index 0000000000..9f53ffeb2a --- /dev/null +++ b/lib/dtrace/examples/driver1.d @@ -0,0 +1,114 @@ +/* example usage: dtrace -q -s /path/to/driver1.d */ +/* + * %CopyrightBegin% + * + * Copyright Scott Lystig Fritchie 2011. 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/dtrace/examples/driver1.systemtap b/lib/dtrace/examples/driver1.systemtap new file mode 100644 index 0000000000..8b99e465b7 --- /dev/null +++ b/lib/dtrace/examples/driver1.systemtap @@ -0,0 +1,125 @@ +/* example usage: stap /path/to/driver1.systemtap -x */ +/* + * %CopyrightBegin% + * + * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011. 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/dtrace/examples/efile_drv.d b/lib/dtrace/examples/efile_drv.d new file mode 100644 index 0000000000..c9c8080dba --- /dev/null +++ b/lib/dtrace/examples/efile_drv.d @@ -0,0 +1,103 @@ +/* example usage: dtrace -q -s /path/to/efile_drv.d */ +/* + * %CopyrightBegin% + * + * Copyright Scott Lystig Fritchie 2011. 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 */ + 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/dtrace/examples/efile_drv.systemtap b/lib/dtrace/examples/efile_drv.systemtap new file mode 100644 index 0000000000..5a47b3e22b --- /dev/null +++ b/lib/dtrace/examples/efile_drv.systemtap @@ -0,0 +1,112 @@ +/* + * %CopyrightBegin% + * + * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011. 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/dtrace/examples/function-calls.d b/lib/dtrace/examples/function-calls.d new file mode 100644 index 0000000000..238c5211ac --- /dev/null +++ b/lib/dtrace/examples/function-calls.d @@ -0,0 +1,51 @@ +/* example usage: dtrace -q -s /path/to/function-calls.d */ +/* + * %CopyrightBegin% + * + * Copyright Scott Lystig Fritchie 2011. 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*:::function-entry +{ + printf("pid %s enter %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/dtrace/examples/function-calls.systemtap b/lib/dtrace/examples/function-calls.systemtap new file mode 100644 index 0000000000..8fc4375135 --- /dev/null +++ b/lib/dtrace/examples/function-calls.systemtap @@ -0,0 +1,61 @@ +/* + * %CopyrightBegin% + * + * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011. 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("function-entry") +{ + printf("pid %s enter %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/dtrace/examples/garbage-collection.d b/lib/dtrace/examples/garbage-collection.d new file mode 100644 index 0000000000..f234e7d4db --- /dev/null +++ b/lib/dtrace/examples/garbage-collection.d @@ -0,0 +1,39 @@ +/* example usage: dtrace -q -s /path/to/garbage-collection.d */ +/* + * %CopyrightBegin% + * + * Copyright Scott Lystig Fritchie 2011. 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/dtrace/examples/garbage-collection.systemtap b/lib/dtrace/examples/garbage-collection.systemtap new file mode 100644 index 0000000000..64d69c6fbd --- /dev/null +++ b/lib/dtrace/examples/garbage-collection.systemtap @@ -0,0 +1,49 @@ +/* + * %CopyrightBegin% + * + * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011. 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/dtrace/examples/memory1.d b/lib/dtrace/examples/memory1.d new file mode 100644 index 0000000000..c2e16e0779 --- /dev/null +++ b/lib/dtrace/examples/memory1.d @@ -0,0 +1,41 @@ +/* example usage: dtrace -q -s /path/to/memory1.d */ +/* + * %CopyrightBegin% + * + * Copyright Scott Lystig Fritchie 2011. 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/dtrace/examples/memory1.systemtap b/lib/dtrace/examples/memory1.systemtap new file mode 100644 index 0000000000..9723f2d02d --- /dev/null +++ b/lib/dtrace/examples/memory1.systemtap @@ -0,0 +1,51 @@ +/* + * %CopyrightBegin% + * + * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011. 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/dtrace/examples/messages.d b/lib/dtrace/examples/messages.d new file mode 100644 index 0000000000..6361f3a220 --- /dev/null +++ b/lib/dtrace/examples/messages.d @@ -0,0 +1,94 @@ +/* example usage: dtrace -q -s /path/to/messages.d */ +/* + * %CopyrightBegin% + * + * Copyright Scott Lystig Fritchie 2011. 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/dtrace/examples/messages.systemtap b/lib/dtrace/examples/messages.systemtap new file mode 100644 index 0000000000..ff8f4076b1 --- /dev/null +++ b/lib/dtrace/examples/messages.systemtap @@ -0,0 +1,87 @@ +/* + * %CopyrightBegin% + * + * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011. 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/dtrace/examples/port1.d b/lib/dtrace/examples/port1.d new file mode 100644 index 0000000000..b82e783a14 --- /dev/null +++ b/lib/dtrace/examples/port1.d @@ -0,0 +1,140 @@ +/* example usage: dtrace -q -s /path/to/port1.d */ +/* + * %CopyrightBegin% + * + * Copyright Scott Lystig Fritchie 2011. 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 +{ + cmd = driver_map[copyinstr(arg2), arg3]; + cmd_str = (cmd == 0) ? "unknown" : cmd; + printf("port control pid %s port %s port name %s command %d %s\n", + copyinstr(arg0), copyinstr(arg1), copyinstr(arg2), arg3, 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/dtrace/examples/port1.systemtap b/lib/dtrace/examples/port1.systemtap new file mode 100644 index 0000000000..a63d9b670c --- /dev/null +++ b/lib/dtrace/examples/port1.systemtap @@ -0,0 +1,152 @@ +/* + * %CopyrightBegin% + * + * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011. 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/dtrace/examples/process-scheduling.d b/lib/dtrace/examples/process-scheduling.d new file mode 100644 index 0000000000..9e31da2774 --- /dev/null +++ b/lib/dtrace/examples/process-scheduling.d @@ -0,0 +1,35 @@ +/* example usage: dtrace -q -s /path/to/process-scheduling.d */ +/* + * %CopyrightBegin% + * + * Copyright Scott Lystig Fritchie 2011. 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/dtrace/examples/process-scheduling.systemtap b/lib/dtrace/examples/process-scheduling.systemtap new file mode 100644 index 0000000000..c8cee60a07 --- /dev/null +++ b/lib/dtrace/examples/process-scheduling.systemtap @@ -0,0 +1,45 @@ +/* + * %CopyrightBegin% + * + * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011. 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/dtrace/examples/spawn-exit.d b/lib/dtrace/examples/spawn-exit.d new file mode 100644 index 0000000000..7310f3343d --- /dev/null +++ b/lib/dtrace/examples/spawn-exit.d @@ -0,0 +1,41 @@ +/* example usage: dtrace -q -s /path/to/spawn-exit.d */ +/* + * %CopyrightBegin% + * + * Copyright Scott Lystig Fritchie 2011. 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/dtrace/examples/spawn-exit.systemtap b/lib/dtrace/examples/spawn-exit.systemtap new file mode 100644 index 0000000000..5e3be9fc1b --- /dev/null +++ b/lib/dtrace/examples/spawn-exit.systemtap @@ -0,0 +1,51 @@ +/* + * %CopyrightBegin% + * + * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011. 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/dtrace/examples/user-probe.d b/lib/dtrace/examples/user-probe.d new file mode 100644 index 0000000000..13baff6a32 --- /dev/null +++ b/lib/dtrace/examples/user-probe.d @@ -0,0 +1,36 @@ +/* example usage: dtrace -q -s /path/to/user-probe.d */ +/* + * %CopyrightBegin% + * + * Copyright Scott Lystig Fritchie 2011. 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/dtrace/examples/user-probe.systemtap b/lib/dtrace/examples/user-probe.systemtap new file mode 100644 index 0000000000..c80bf94697 --- /dev/null +++ b/lib/dtrace/examples/user-probe.systemtap @@ -0,0 +1,46 @@ +/* + * %CopyrightBegin% + * + * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011. 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("dtrace.so").mark("user_trace-s1") +{ + printf("%s\n", user_string($arg1)); +} + +probe process("dtrace.so").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)); +} -- cgit v1.2.3 From ad6387b0242caa2b3c64d62a133752e10546211b Mon Sep 17 00:00:00 2001 From: Scott Lystig Fritchie Date: Thu, 17 Nov 2011 00:47:23 -0600 Subject: Add DTrace support for OS X, Solaris, and Linux (via SystemTap), 4/4 Add probes to (mostly) the efile_drv.c driver and other file I/O-related source files. --- lib/kernel/src/file.erl | 149 ++++++++++++++++++++++++------------ lib/kernel/src/file_io_server.erl | 15 ++-- lib/kernel/src/file_server.erl | 106 ++++++++++++------------- lib/kernel/test/prim_file_SUITE.erl | 108 +++++++++++++------------- 4 files changed, 214 insertions(+), 164 deletions(-) (limited to 'lib') diff --git a/lib/kernel/src/file.erl b/lib/kernel/src/file.erl index 4028dd4f0b..a2e0d261ee 100644 --- a/lib/kernel/src/file.erl +++ b/lib/kernel/src/file.erl @@ -39,7 +39,7 @@ -export([ipread_s32bu_p32bu/3]). %% Generic file contents. -export([open/2, close/1, advise/4, - read/2, write/2, + read/2, write/2, pread/2, pread/3, pwrite/2, pwrite/3, read_line/1, position/2, truncate/1, datasync/1, sync/1, @@ -62,7 +62,7 @@ %% Internal export to prim_file and ram_file until they implement %% an efficient copy themselves. --export([copy_opened/3]). +-export([copy_opened/4]). -export([ipread_s32bu_p32bu_int/3]). @@ -166,7 +166,7 @@ pid2name(Pid) when is_pid(Pid) -> Reason :: posix(). get_cwd() -> - call(get_cwd, []). + call(get_cwd, [no_drive, get_dtrace_utag()]). -spec get_cwd(Drive) -> {ok, Dir} | {error, Reason} when Drive :: string(), @@ -174,21 +174,21 @@ get_cwd() -> Reason :: posix() | badarg. get_cwd(Drive) -> - check_and_call(get_cwd, [file_name(Drive)]). + check_and_call(get_cwd, [file_name(Drive), get_dtrace_utag()]). -spec set_cwd(Dir) -> ok | {error, Reason} when Dir :: name(), Reason :: posix() | badarg. set_cwd(Dirname) -> - check_and_call(set_cwd, [file_name(Dirname)]). + check_and_call(set_cwd, [file_name(Dirname), get_dtrace_utag()]). -spec delete(Filename) -> ok | {error, Reason} when Filename :: name(), Reason :: posix() | badarg. delete(Name) -> - check_and_call(delete, [file_name(Name)]). + check_and_call(delete, [file_name(Name), get_dtrace_utag()]). -spec rename(Source, Destination) -> ok | {error, Reason} when Source :: name(), @@ -196,21 +196,21 @@ delete(Name) -> Reason :: posix() | badarg. rename(From, To) -> - check_and_call(rename, [file_name(From), file_name(To)]). + check_and_call(rename, [file_name(From), file_name(To), get_dtrace_utag()]). -spec make_dir(Dir) -> ok | {error, Reason} when Dir :: name(), Reason :: posix() | badarg. make_dir(Name) -> - check_and_call(make_dir, [file_name(Name)]). + check_and_call(make_dir, [file_name(Name), get_dtrace_utag()]). -spec del_dir(Dir) -> ok | {error, Reason} when Dir :: name(), Reason :: posix() | badarg. del_dir(Name) -> - check_and_call(del_dir, [file_name(Name)]). + check_and_call(del_dir, [file_name(Name), get_dtrace_utag()]). -spec read_file_info(Filename) -> {ok, FileInfo} | {error, Reason} when Filename :: name(), @@ -218,7 +218,7 @@ del_dir(Name) -> Reason :: posix() | badarg. read_file_info(Name) -> - check_and_call(read_file_info, [file_name(Name)]). + check_and_call(read_file_info, [file_name(Name), get_dtrace_utag()]). -spec read_file_info(Filename, Opts) -> {ok, FileInfo} | {error, Reason} when Filename :: name(), @@ -232,7 +232,7 @@ read_file_info(Name, Opts) when is_list(Opts) -> -spec altname(Name :: name()) -> any(). altname(Name) -> - check_and_call(altname, [file_name(Name)]). + check_and_call(altname, [file_name(Name), get_dtrace_utag()]). -spec read_link_info(Name) -> {ok, FileInfo} | {error, Reason} when Name :: name(), @@ -240,7 +240,7 @@ altname(Name) -> Reason :: posix() | badarg. read_link_info(Name) -> - check_and_call(read_link_info, [file_name(Name)]). + check_and_call(read_link_info, [file_name(Name), get_dtrace_utag()]). -spec read_link_info(Name, Opts) -> {ok, FileInfo} | {error, Reason} when Name :: name(), @@ -258,7 +258,7 @@ read_link_info(Name, Opts) when is_list(Opts) -> Reason :: posix() | badarg. read_link(Name) -> - check_and_call(read_link, [file_name(Name)]). + check_and_call(read_link, [file_name(Name), get_dtrace_utag()]). -spec write_file_info(Filename, FileInfo) -> ok | {error, Reason} when Filename :: name(), @@ -266,7 +266,7 @@ read_link(Name) -> Reason :: posix() | badarg. write_file_info(Name, Info = #file_info{}) -> - check_and_call(write_file_info, [file_name(Name), Info]). + check_and_call(write_file_info, [file_name(Name), Info, get_dtrace_utag()]). -spec write_file_info(Filename, FileInfo, Opts) -> ok | {error, Reason} when Filename :: name(), @@ -283,7 +283,7 @@ write_file_info(Name, Info = #file_info{}, Opts) when is_list(Opts) -> Reason :: posix() | badarg. list_dir(Name) -> - check_and_call(list_dir, [file_name(Name)]). + check_and_call(list_dir, [file_name(Name), get_dtrace_utag()]). -spec read_file(Filename) -> {ok, Binary} | {error, Reason} when Filename :: name(), @@ -291,7 +291,7 @@ list_dir(Name) -> Reason :: posix() | badarg | terminated | system_limit. read_file(Name) -> - check_and_call(read_file, [file_name(Name)]). + check_and_call(read_file, [file_name(Name), get_dtrace_utag()]). -spec make_link(Existing, New) -> ok | {error, Reason} when Existing :: name(), @@ -299,7 +299,7 @@ read_file(Name) -> Reason :: posix() | badarg. make_link(Old, New) -> - check_and_call(make_link, [file_name(Old), file_name(New)]). + check_and_call(make_link, [file_name(Old), file_name(New), get_dtrace_utag()]). -spec make_symlink(Existing, New) -> ok | {error, Reason} when Existing :: name(), @@ -307,7 +307,7 @@ make_link(Old, New) -> Reason :: posix() | badarg. make_symlink(Old, New) -> - check_and_call(make_symlink, [file_name(Old), file_name(New)]). + check_and_call(make_symlink, [file_name(Old), file_name(New), get_dtrace_utag()]). -spec write_file(Filename, Bytes) -> ok | {error, Reason} when Filename :: name(), @@ -315,7 +315,7 @@ make_symlink(Old, New) -> Reason :: posix() | badarg | terminated | system_limit. write_file(Name, Bin) -> - check_and_call(write_file, [file_name(Name), make_binary(Bin)]). + check_and_call(write_file, [file_name(Name), make_binary(Bin), get_dtrace_utag()]). %% This whole operation should be moved to the file_server and prim_file %% when it is time to change file server protocol again. @@ -367,7 +367,7 @@ raw_write_file_info(Name, #file_info{} = Info) -> case check_args(Args) of ok -> [FileName] = Args, - ?PRIM_FILE:write_file_info(FileName, Info); + ?PRIM_FILE:write_file_info(FileName, Info, get_dtrace_utag()); Error -> Error end. @@ -400,7 +400,7 @@ open(Item, ModeList) when is_list(ModeList) -> [FileName | _] = Args, %% We rely on the returned Handle (in {ok, Handle}) %% being a pid() or a #file_descriptor{} - ?PRIM_FILE:open(FileName, ModeList); + ?PRIM_FILE:open(FileName, ModeList, get_dtrace_utag()); Error -> Error end @@ -421,7 +421,7 @@ open(Item, ModeList) when is_list(ModeList) -> case check_args(Args) of ok -> [FileName | _] = Args, - call(open, [FileName, ModeList]); + call(open, [FileName, ModeList, get_dtrace_utag()]); Error -> Error end @@ -466,7 +466,10 @@ close(_) -> advise(File, Offset, Length, Advise) when is_pid(File) -> R = file_request(File, {advise, Offset, Length, Advise}), wait_file_reply(File, R); +advise(#file_descriptor{module = prim_file = Module} = Handle, Offset, Length, Advise) -> + Module:advise(Handle, Offset, Length, Advise, get_dtrace_utag()); advise(#file_descriptor{module = Module} = Handle, Offset, Length, Advise) -> + %% DTrace TODO: ram_file and other file drivers not yet DTrace'ified. Module:advise(Handle, Offset, Length, Advise); advise(_, _, _, _) -> {error, badarg}. @@ -477,17 +480,25 @@ advise(_, _, _, _) -> Data :: string() | binary(), Reason :: posix() | badarg | terminated. -read(File, Sz) when (is_pid(File) orelse is_atom(File)), is_integer(Sz), Sz >= 0 -> +read(File, Sz) -> + read(File, Sz, get_dtrace_utag()). + +read(File, Sz, _DTraceUtag) + when (is_pid(File) orelse is_atom(File)), is_integer(Sz), Sz >= 0 -> case io:request(File, {get_chars, '', Sz}) of Data when is_list(Data); is_binary(Data) -> {ok, Data}; Other -> Other end; -read(#file_descriptor{module = Module} = Handle, Sz) +read(#file_descriptor{module = prim_file = Module} = Handle, Sz, DTraceUtag) + when is_integer(Sz), Sz >= 0 -> + Module:read(Handle, Sz, DTraceUtag); +read(#file_descriptor{module = Module} = Handle, Sz, _DTraceUtag) when is_integer(Sz), Sz >= 0 -> + %% DTrace TODO: ram_file and other file drivers not yet DTrace'ified. Module:read(Handle, Sz); -read(_, _) -> +read(_, _, _) -> {error, badarg}. -spec read_line(IoDevice) -> {ok, Data} | eof | {error, Reason} when @@ -502,7 +513,10 @@ read_line(File) when (is_pid(File) orelse is_atom(File)) -> Other -> Other end; +read_line(#file_descriptor{module = prim_file = Module} = Handle) -> + Module:read_line(Handle, get_dtrace_utag()); read_line(#file_descriptor{module = Module} = Handle) -> + %% DTrace TODO: ram_file and other file drivers not yet DTrace'ified. Module:read_line(Handle); read_line(_) -> {error, badarg}. @@ -516,7 +530,10 @@ read_line(_) -> pread(File, L) when is_pid(File), is_list(L) -> pread_int(File, L, []); +pread(#file_descriptor{module = prim_file = Module} = Handle, L) when is_list(L) -> + Module:pread(Handle, L, get_dtrace_utag()); pread(#file_descriptor{module = Module} = Handle, L) when is_list(L) -> + %% DTrace TODO: ram_file and other file drivers not yet DTrace'ified. Module:pread(Handle, L); pread(_, _) -> {error, badarg}. @@ -548,6 +565,7 @@ pread(File, At, Sz) when is_pid(File), is_integer(Sz), Sz >= 0 -> wait_file_reply(File, R); pread(#file_descriptor{module = Module} = Handle, Offs, Sz) when is_integer(Sz), Sz >= 0 -> + %% DTrace TODO: ram_file and other file drivers not yet DTrace'ified. Module:pread(Handle, Offs, Sz); pread(_, _, _) -> {error, badarg}. @@ -557,16 +575,22 @@ pread(_, _, _) -> Bytes :: iodata(), Reason :: posix() | badarg | terminated. -write(File, Bytes) when (is_pid(File) orelse is_atom(File)) -> +write(File, Bytes) -> + write(File, Bytes, get_dtrace_utag()). + +write(File, Bytes, _DTraceUtag) when (is_pid(File) orelse is_atom(File)) -> case make_binary(Bytes) of Bin when is_binary(Bin) -> io:request(File, {put_chars,Bin}); Error -> Error end; -write(#file_descriptor{module = Module} = Handle, Bytes) -> +write(#file_descriptor{module = prim_file = Module} = Handle, Bytes, DTraceUtag) -> + Module:write(Handle, Bytes, DTraceUtag); +write(#file_descriptor{module = Module} = Handle, Bytes, _DTraceUtag) -> + %% DTrace TODO: ram_file and other file drivers not yet DTrace'ified. Module:write(Handle, Bytes); -write(_, _) -> +write(_, _, _) -> {error, badarg}. -spec pwrite(IoDevice, LocBytes) -> ok | {error, {N, Reason}} when @@ -577,7 +601,10 @@ write(_, _) -> pwrite(File, L) when is_pid(File), is_list(L) -> pwrite_int(File, L, 0); +pwrite(#file_descriptor{module = prim_file = Module} = Handle, L) when is_list(L) -> + Module:pwrite(Handle, L, get_dtrace_utag()); pwrite(#file_descriptor{module = Module} = Handle, L) when is_list(L) -> + %% DTrace TODO: ram_file and other file drivers not yet DTrace'ified. Module:pwrite(Handle, L); pwrite(_, _) -> {error, badarg}. @@ -604,6 +631,7 @@ pwrite(File, At, Bytes) when is_pid(File) -> R = file_request(File, {pwrite, At, Bytes}), wait_file_reply(File, R); pwrite(#file_descriptor{module = Module} = Handle, Offs, Bytes) -> + %% DTrace TODO: ram_file and other file drivers not yet DTrace'ified. Module:pwrite(Handle, Offs, Bytes); pwrite(_, _, _) -> {error, badarg}. @@ -615,7 +643,10 @@ pwrite(_, _, _) -> datasync(File) when is_pid(File) -> R = file_request(File, datasync), wait_file_reply(File, R); +datasync(#file_descriptor{module = prim_file = Module} = Handle) -> + Module:datasync(Handle, get_dtrace_utag()); datasync(#file_descriptor{module = Module} = Handle) -> + %% DTrace TODO: ram_file and other file drivers not yet DTrace'ified. Module:datasync(Handle); datasync(_) -> {error, badarg}. @@ -627,7 +658,10 @@ datasync(_) -> sync(File) when is_pid(File) -> R = file_request(File, sync), wait_file_reply(File, R); +sync(#file_descriptor{module = prim_file = Module} = Handle) -> + Module:sync(Handle, get_dtrace_utag()); sync(#file_descriptor{module = Module} = Handle) -> + %% DTrace TODO: ram_file and other file drivers not yet DTrace'ified. Module:sync(Handle); sync(_) -> {error, badarg}. @@ -641,7 +675,10 @@ sync(_) -> position(File, At) when is_pid(File) -> R = file_request(File, {position,At}), wait_file_reply(File, R); +position(#file_descriptor{module = prim_file = Module} = Handle, At) -> + Module:position(Handle, At, get_dtrace_utag()); position(#file_descriptor{module = Module} = Handle, At) -> + %% DTrace TODO: ram_file and other file drivers not yet DTrace'ified. Module:position(Handle, At); position(_, _) -> {error, badarg}. @@ -653,7 +690,10 @@ position(_, _) -> truncate(File) when is_pid(File) -> R = file_request(File, truncate), wait_file_reply(File, R); +truncate(#file_descriptor{module = prim_file = Module} = Handle) -> + Module:truncate(Handle, get_dtrace_utag()); truncate(#file_descriptor{module = Module} = Handle) -> + %% DTrace TODO: ram_file and other file drivers not yet DTrace'ified. Module:truncate(Handle); truncate(_) -> {error, badarg}. @@ -694,7 +734,7 @@ copy_int(Source, Dest, Length) when is_pid(Source), is_pid(Dest); is_pid(Source), is_record(Dest, file_descriptor); is_record(Source, file_descriptor), is_pid(Dest) -> - copy_opened_int(Source, Dest, Length, 0); + copy_opened_int(Source, Dest, Length, get_dtrace_utag()); %% Copy between open raw files, both handled by the same module copy_int(#file_descriptor{module = Module} = Source, #file_descriptor{module = Module} = Dest, @@ -703,14 +743,14 @@ copy_int(#file_descriptor{module = Module} = Source, %% Copy between open raw files of different modules copy_int(#file_descriptor{} = Source, #file_descriptor{} = Dest, Length) -> - copy_opened_int(Source, Dest, Length, 0); + copy_opened_int(Source, Dest, Length, get_dtrace_utag()); %% Copy between filenames, let the server do the copy copy_int({SourceName, SourceOpts}, {DestName, DestOpts}, Length) when is_list(SourceOpts), is_list(DestOpts) -> check_and_call(copy, [file_name(SourceName), SourceOpts, file_name(DestName), DestOpts, - Length]); + Length, get_dtrace_utag()]); %% Filename -> open file; must open Source and do client copy copy_int({SourceName, SourceOpts}, Dest, Length) when is_list(SourceOpts), is_pid(Dest); @@ -721,7 +761,8 @@ copy_int({SourceName, SourceOpts}, Dest, Length) Source -> case open(Source, [read | SourceOpts]) of {ok, Handle} -> - Result = copy_opened_int(Handle, Dest, Length, 0), + Result = copy_opened_int(Handle, Dest, Length, + get_dtrace_utag()), close(Handle), Result; {error, _} = Error -> @@ -738,7 +779,8 @@ copy_int(Source, {DestName, DestOpts}, Length) Dest -> case open(Dest, [write | DestOpts]) of {ok, Handle} -> - Result = copy_opened_int(Source, Handle, Length, 0), + Result = copy_opened_int(Source, Handle, Length, + get_dtrace_utag()), close(Handle), Result; {error, _} = Error -> @@ -773,45 +815,46 @@ copy_int(Source, Dest, Length) -> -copy_opened(Source, Dest, Length) +copy_opened(Source, Dest, Length, DTraceUtag) when is_integer(Length), Length >= 0; is_atom(Length) -> - copy_opened_int(Source, Dest, Length); -copy_opened(_, _, _) -> + copy_opened_int(Source, Dest, Length, DTraceUtag); +copy_opened(_, _, _, _) -> {error, badarg}. %% Here we know that Length is either an atom or an integer >= 0 %% (by the way, atoms > integers) -copy_opened_int(Source, Dest, Length) +copy_opened_int(Source, Dest, Length, DTraceUtag) when is_pid(Source), is_pid(Dest) -> - copy_opened_int(Source, Dest, Length, 0); -copy_opened_int(Source, Dest, Length) + copy_opened_int(Source, Dest, Length, 0, DTraceUtag); +copy_opened_int(Source, Dest, Length, DTraceUtag) when is_pid(Source), is_record(Dest, file_descriptor) -> - copy_opened_int(Source, Dest, Length, 0); -copy_opened_int(Source, Dest, Length) + copy_opened_int(Source, Dest, Length, 0, DTraceUtag); +copy_opened_int(Source, Dest, Length, DTraceUtag) when is_record(Source, file_descriptor), is_pid(Dest) -> - copy_opened_int(Source, Dest, Length, 0); -copy_opened_int(Source, Dest, Length) + copy_opened_int(Source, Dest, Length, 0, DTraceUtag); +copy_opened_int(Source, Dest, Length, DTraceUtag) when is_record(Source, file_descriptor), is_record(Dest, file_descriptor) -> - copy_opened_int(Source, Dest, Length, 0); -copy_opened_int(_, _, _) -> + copy_opened_int(Source, Dest, Length, 0, DTraceUtag); +copy_opened_int(_, _, _, _) -> {error, badarg}. %% Here we know that Source and Dest are handles to open files, Length is %% as above, and Copied is an integer >= 0 %% Copy loop in client process -copy_opened_int(_, _, Length, Copied) when Length =< 0 -> % atom() > integer() +copy_opened_int(_, _, Length, Copied, _DTraceUtag) + when Length =< 0 -> % atom() > integer() {ok, Copied}; -copy_opened_int(Source, Dest, Length, Copied) -> +copy_opened_int(Source, Dest, Length, Copied, DTraceUtag) -> N = if Length > 65536 -> 65536; true -> Length end, % atom() > integer() ! - case read(Source, N) of + case read(Source, N, DTraceUtag) of {ok, Data} -> M = if is_binary(Data) -> byte_size(Data); is_list(Data) -> length(Data) end, - case write(Dest, Data) of + case write(Dest, Data, DTraceUtag) of ok -> if M < N -> %% Got less than asked for - must be end of file @@ -821,7 +864,8 @@ copy_opened_int(Source, Dest, Length, Copied) -> NewLength = if is_atom(Length) -> Length; true -> Length-M end, - copy_opened_int(Source, Dest, NewLength, Copied+M) + copy_opened_int(Source, Dest, NewLength, Copied+M, + DTraceUtag) end; {error, _} = Error -> Error @@ -841,6 +885,8 @@ copy_opened_int(Source, Dest, Length, Copied) -> ipread_s32bu_p32bu(File, Pos, MaxSize) when is_pid(File) -> ipread_s32bu_p32bu_int(File, Pos, MaxSize); +ipread_s32bu_p32bu(#file_descriptor{module = prim_file = Module} = Handle, Pos, MaxSize) -> + Module:ipread_s32bu_p32bu(Handle, Pos, MaxSize, get_dtrace_utag()); ipread_s32bu_p32bu(#file_descriptor{module = Module} = Handle, Pos, MaxSize) -> Module:ipread_s32bu_p32bu(Handle, Pos, MaxSize); ipread_s32bu_p32bu(_, _, _) -> @@ -1456,3 +1502,6 @@ wait_file_reply(From, Ref) -> %% receive {'EXIT', From, _} -> ok after 0 -> ok end, {error, terminated} end. + +get_dtrace_utag() -> + prim_file:get_dtrace_utag(). diff --git a/lib/kernel/src/file_io_server.erl b/lib/kernel/src/file_io_server.erl index 14da9c1a55..cc0343031b 100644 --- a/lib/kernel/src/file_io_server.erl +++ b/lib/kernel/src/file_io_server.erl @@ -21,7 +21,7 @@ %% A simple file server for io to one file instance per server instance. -export([format_error/1]). --export([start/3, start_link/3]). +-export([start/4, start_link/4]). -export([count_and_find/3]). @@ -43,18 +43,18 @@ format_error({_Line, Mod, Reason}) -> format_error(ErrorId) -> erl_posix_msg:message(ErrorId). -start(Owner, FileName, ModeList) +start(Owner, FileName, ModeList, DTraceUtag) when is_pid(Owner), (is_list(FileName) orelse is_binary(FileName)), is_list(ModeList) -> - do_start(spawn, Owner, FileName, ModeList). + do_start(spawn, Owner, FileName, ModeList, DTraceUtag). -start_link(Owner, FileName, ModeList) +start_link(Owner, FileName, ModeList, DTraceUtag) when is_pid(Owner), (is_list(FileName) orelse is_binary(FileName)), is_list(ModeList) -> - do_start(spawn_link, Owner, FileName, ModeList). + do_start(spawn_link, Owner, FileName, ModeList, DTraceUtag). %%%----------------------------------------------------------------- %%% Server starter, dispatcher and helpers -do_start(Spawn, Owner, FileName, ModeList) -> +do_start(Spawn, Owner, FileName, ModeList, DTraceUtag) -> Self = self(), Ref = make_ref(), Pid = @@ -63,11 +63,12 @@ do_start(Spawn, Owner, FileName, ModeList) -> %% process_flag(trap_exit, true), case parse_options(ModeList) of {ReadMode, UnicodeMode, Opts} -> - case ?PRIM_FILE:open(FileName, Opts) of + case ?PRIM_FILE:open(FileName, Opts, DTraceUtag) of {error, Reason} = Error -> Self ! {Ref, Error}, exit(Reason); {ok, Handle} -> + put(dtrace_utag, DTraceUtag), % TODO: API? %% XXX must I handle R6 nodes here? M = erlang:monitor(process, Owner), Self ! {Ref, ok}, diff --git a/lib/kernel/src/file_server.erl b/lib/kernel/src/file_server.erl index fc6cd823c9..c917819508 100644 --- a/lib/kernel/src/file_server.erl +++ b/lib/kernel/src/file_server.erl @@ -76,6 +76,7 @@ stop() -> init([]) -> process_flag(trap_exit, true), + put(dtrace_utag, atom_to_list(?FILE_SERVER)), case ?PRIM_FILE:start() of {ok, Handle} -> ets:new(?FILE_IO_SERVER_TABLE, [named_table]), @@ -99,9 +100,9 @@ init([]) -> {'reply', 'eof' | 'ok' | {'error', term()} | {'ok', term()}, state()} | {'stop', 'normal', 'stopped', state()}. -handle_call({open, Name, ModeList}, {Pid, _Tag} = _From, Handle) +handle_call({open, Name, ModeList, DTraceUtag}, {Pid, _Tag} = _From, Handle) when is_list(ModeList) -> - Child = ?FILE_IO_SERVER:start_link(Pid, Name, ModeList), + Child = ?FILE_IO_SERVER:start_link(Pid, Name, ModeList, DTraceUtag), case Child of {ok, P} when is_pid(P) -> ets:insert(?FILE_IO_SERVER_TABLE, {P, Name}); @@ -110,87 +111,86 @@ handle_call({open, Name, ModeList}, {Pid, _Tag} = _From, Handle) end, {reply, Child, Handle}; -handle_call({open, _Name, _Mode}, _From, Handle) -> +handle_call({open, _Name, _Mode, _DTraceUtag}, _From, Handle) -> {reply, {error, einval}, Handle}; -handle_call({read_file, Name}, _From, Handle) -> - {reply, ?PRIM_FILE:read_file(Name), Handle}; +handle_call({read_file, Name, DTraceUtag}, _From, Handle) -> + {reply, ?PRIM_FILE:read_file(Name, DTraceUtag), Handle}; -handle_call({write_file, Name, Bin}, _From, Handle) -> - {reply, ?PRIM_FILE:write_file(Name, Bin), Handle}; +handle_call({write_file, Name, Bin, DTraceUtag}, _From, Handle) -> + {reply, ?PRIM_FILE:write_file(Name, Bin, DTraceUtag), Handle}; -handle_call({set_cwd, Name}, _From, Handle) -> - {reply, ?PRIM_FILE:set_cwd(Handle, Name), Handle}; +handle_call({set_cwd, Name, DTraceUtag}, _From, Handle) -> + {reply, ?PRIM_FILE:set_cwd(Handle, Name, DTraceUtag), Handle}; -handle_call({delete, Name}, _From, Handle) -> - {reply, ?PRIM_FILE:delete(Handle, Name), Handle}; +handle_call({delete, Name, DTraceUtag}, _From, Handle) -> + {reply, ?PRIM_FILE:delete(Handle, Name, DTraceUtag), Handle}; -handle_call({rename, Fr, To}, _From, Handle) -> - {reply, ?PRIM_FILE:rename(Handle, Fr, To), Handle}; +handle_call({rename, Fr, To, DTraceUtag}, _From, Handle) -> + {reply, ?PRIM_FILE:rename(Handle, Fr, To, DTraceUtag), Handle}; -handle_call({make_dir, Name}, _From, Handle) -> - {reply, ?PRIM_FILE:make_dir(Handle, Name), Handle}; +handle_call({make_dir, Name, DTraceUtag}, _From, Handle) -> + {reply, ?PRIM_FILE:make_dir(Handle, Name, DTraceUtag), Handle}; -handle_call({del_dir, Name}, _From, Handle) -> - {reply, ?PRIM_FILE:del_dir(Handle, Name), Handle}; +handle_call({del_dir, Name, DTraceUtag}, _From, Handle) -> + {reply, ?PRIM_FILE:del_dir(Handle, Name, DTraceUtag), Handle}; -handle_call({list_dir, Name}, _From, Handle) -> - {reply, ?PRIM_FILE:list_dir(Handle, Name), Handle}; +handle_call({list_dir, Name, DTraceUtag}, _From, Handle) -> + {reply, ?PRIM_FILE:list_dir(Handle, Name, DTraceUtag), Handle}; handle_call(get_cwd, _From, Handle) -> - {reply, ?PRIM_FILE:get_cwd(Handle), Handle}; -handle_call({get_cwd}, _From, Handle) -> - {reply, ?PRIM_FILE:get_cwd(Handle), Handle}; -handle_call({get_cwd, Name}, _From, Handle) -> - {reply, ?PRIM_FILE:get_cwd(Handle, Name), Handle}; + {reply, ?PRIM_FILE:get_cwd(Handle, no_drive, "TODO-fixme"), Handle}; +handle_call({get_cwd, no_drive, DTraceUtag}, _From, Handle) -> + {reply, ?PRIM_FILE:get_cwd(Handle, no_drive, DTraceUtag), Handle}; +handle_call({get_cwd, Name, DTraceUtag}, _From, Handle) -> + {reply, ?PRIM_FILE:get_cwd(Handle, Name, DTraceUtag), Handle}; -handle_call({read_file_info, Name}, _From, Handle) -> - {reply, ?PRIM_FILE:read_file_info(Handle, Name), Handle}; +handle_call({read_file_info, Name, DTraceUtag}, _From, Handle) -> + {reply, ?PRIM_FILE:read_file_info(Handle, Name, DTraceUtag), Handle}; +handle_call({read_file_info, Name, Opts, DTraceUtag}, _From, Handle) -> + {reply, ?PRIM_FILE:read_file_info(Handle, Name, Opts, DTraceUtag), Handle}; -handle_call({read_file_info, Name, Opts}, _From, Handle) -> - {reply, ?PRIM_FILE:read_file_info(Handle, Name, Opts), Handle}; +handle_call({altname, Name, DTraceUtag}, _From, Handle) -> + {reply, ?PRIM_FILE:altname(Handle, Name, DTraceUtag), Handle}; -handle_call({altname, Name}, _From, Handle) -> - {reply, ?PRIM_FILE:altname(Handle, Name), Handle}; +handle_call({write_file_info, Name, Info, DTraceUtag}, _From, Handle) -> + {reply, ?PRIM_FILE:write_file_info(Handle, Name, Info, DTraceUtag), Handle}; +handle_call({write_file_info, Name, Info, Opts, DTraceUtag}, _From, Handle) -> + {reply, ?PRIM_FILE:write_file_info(Handle, Name, Info, Opts, DTraceUtag), Handle}; -handle_call({write_file_info, Name, Info}, _From, Handle) -> - {reply, ?PRIM_FILE:write_file_info(Handle, Name, Info), Handle}; +handle_call({read_link_info, Name, DTraceUtag}, _From, Handle) -> + {reply, ?PRIM_FILE:read_link_info(Handle, Name, DTraceUtag), Handle}; +handle_call({read_link_info, Name, Opts, DTraceUtag}, _From, Handle) -> + {reply, ?PRIM_FILE:read_link_info(Handle, Name, Opts, DTraceUtag), Handle}; -handle_call({write_file_info, Name, Info, Opts}, _From, Handle) -> - {reply, ?PRIM_FILE:write_file_info(Handle, Name, Info, Opts), Handle}; +handle_call({read_link, Name, DTraceUtag}, _From, Handle) -> + {reply, ?PRIM_FILE:read_link(Handle, Name, DTraceUtag), Handle}; -handle_call({read_link_info, Name}, _From, Handle) -> - {reply, ?PRIM_FILE:read_link_info(Handle, Name), Handle}; +handle_call({make_link, Old, New, DTraceUtag}, _From, Handle) -> + {reply, ?PRIM_FILE:make_link(Handle, Old, New, DTraceUtag), Handle}; -handle_call({read_link_info, Name, Opts}, _From, Handle) -> - {reply, ?PRIM_FILE:read_link_info(Handle, Name, Opts), Handle}; +handle_call({make_symlink, Old, New, DTraceUtag}, _From, Handle) -> + {reply, ?PRIM_FILE:make_symlink(Handle, Old, New, DTraceUtag), Handle}; -handle_call({read_link, Name}, _From, Handle) -> - {reply, ?PRIM_FILE:read_link(Handle, Name), Handle}; - -handle_call({make_link, Old, New}, _From, Handle) -> - {reply, ?PRIM_FILE:make_link(Handle, Old, New), Handle}; - -handle_call({make_symlink, Old, New}, _From, Handle) -> - {reply, ?PRIM_FILE:make_symlink(Handle, Old, New), Handle}; - -handle_call({copy, SourceName, SourceOpts, DestName, DestOpts, Length}, +handle_call({copy, SourceName, SourceOpts, DestName, DestOpts, Length, DTraceUtag}, _From, Handle) -> Reply = - case ?PRIM_FILE:open(SourceName, [read, binary | SourceOpts]) of + case ?PRIM_FILE:open(SourceName, [read, binary | SourceOpts], + DTraceUtag) of {ok, Source} -> SourceReply = case ?PRIM_FILE:open(DestName, - [write, binary | DestOpts]) of + [write, binary | DestOpts], + DTraceUtag) of {ok, Dest} -> DestReply = - ?PRIM_FILE:copy(Source, Dest, Length), - ?PRIM_FILE:close(Dest), + ?PRIM_FILE:copy(Source, Dest, Length, DTraceUtag), + ?PRIM_FILE:close(Dest, DTraceUtag), DestReply; {error, _} = Error -> Error end, - ?PRIM_FILE:close(Source), + ?PRIM_FILE:close(Source, DTraceUtag), SourceReply; {error, _} = Error -> Error diff --git a/lib/kernel/test/prim_file_SUITE.erl b/lib/kernel/test/prim_file_SUITE.erl index 3e2202922c..9575762b12 100644 --- a/lib/kernel/test/prim_file_SUITE.erl +++ b/lib/kernel/test/prim_file_SUITE.erl @@ -70,7 +70,7 @@ %% compile time. -define(PRIM_FILE_call(F, H, A), case H of - [] -> apply(?PRIM_FILE, F, A); + [] -> apply(?PRIM_FILE, F, A -- ["utag"]); _ -> apply(?PRIM_FILE, F, [H | A]) end). @@ -255,31 +255,31 @@ make_del_dir(Config, Handle, Suffix) -> ?line NewDir = filename:join(RootDir, atom_to_list(?MODULE) ++"_mk-dir"++Suffix), - ?line ok = ?PRIM_FILE_call(make_dir, Handle, [NewDir]), - ?line {error, eexist} = ?PRIM_FILE_call(make_dir, Handle, [NewDir]), - ?line ok = ?PRIM_FILE_call(del_dir, Handle, [NewDir]), - ?line {error, enoent} = ?PRIM_FILE_call(del_dir, Handle, [NewDir]), + ?line ok = ?PRIM_FILE_call(make_dir, Handle, [NewDir, "utag"]), + ?line {error, eexist} = ?PRIM_FILE_call(make_dir, Handle, [NewDir, "utag"]), + ?line ok = ?PRIM_FILE_call(del_dir, Handle, [NewDir, "utag"]), + ?line {error, enoent} = ?PRIM_FILE_call(del_dir, Handle, [NewDir, "utag"]), % Make sure we are not in a directory directly under test_server % as that would result in eacess errors when trying to delere '..', % because there are processes having that directory as current. - ?line ok = ?PRIM_FILE_call(make_dir, Handle, [NewDir]), + ?line ok = ?PRIM_FILE_call(make_dir, Handle, [NewDir, "utag"]), ?line {ok, CurrentDir} = ?PRIM_FILE_call(get_cwd, Handle, []), - ?line ok = ?PRIM_FILE_call(set_cwd, Handle, [NewDir]), + ?line ok = ?PRIM_FILE_call(set_cwd, Handle, [NewDir, "utag"]), try %% Check that we get an error when trying to create... %% a deep directory ?line NewDir2 = filename:join(RootDir, atom_to_list(?MODULE) ++"_mk-dir-noexist/foo"), - ?line {error, enoent} = ?PRIM_FILE_call(make_dir, Handle, [NewDir2]), + ?line {error, enoent} = ?PRIM_FILE_call(make_dir, Handle, [NewDir2, "utag"]), %% a nameless directory - ?line {error, enoent} = ?PRIM_FILE_call(make_dir, Handle, [""]), + ?line {error, enoent} = ?PRIM_FILE_call(make_dir, Handle, ["", "utag"]), %% a directory with illegal name - ?line {error, badarg} = ?PRIM_FILE_call(make_dir, Handle, ['mk-dir']), + ?line {error, badarg} = ?PRIM_FILE_call(make_dir, Handle, ['mk-dir', "utag"]), %% a directory with illegal name, even if it's a (bad) list - ?line {error, badarg} = ?PRIM_FILE_call(make_dir, Handle, [[1,2,3,{}]]), + ?line {error, badarg} = ?PRIM_FILE_call(make_dir, Handle, [[1,2,3,{}], "utag"]), %% Maybe this isn't an error, exactly, but worth mentioning anyway: %% ok = ?PRIM_FILE:make_dir([$f,$o,$o,0,$b,$a,$r])), @@ -292,17 +292,17 @@ make_del_dir(Config, Handle, Suffix) -> %% Try deleting some bad directories %% Deleting the parent directory to the current, sounds dangerous, huh? %% Don't worry ;-) the parent directory should never be empty, right? - ?line case ?PRIM_FILE_call(del_dir, Handle, [".."]) of + ?line case ?PRIM_FILE_call(del_dir, Handle, ["..", "utag"]) of {error, eexist} -> ok; {error, eacces} -> ok; %OpenBSD {error, einval} -> ok %FreeBSD end, - ?line {error, enoent} = ?PRIM_FILE_call(del_dir, Handle, [""]), - ?line {error, badarg} = ?PRIM_FILE_call(del_dir, Handle, [[3,2,1,{}]]), + ?line {error, enoent} = ?PRIM_FILE_call(del_dir, Handle, ["", "utag"]), + ?line {error, badarg} = ?PRIM_FILE_call(del_dir, Handle, [[3,2,1,{}], "utag"]), ?line test_server:timetrap_cancel(Dog) after - ?line ok = ?PRIM_FILE_call(set_cwd, Handle, [CurrentDir]) + ?line ok = ?PRIM_FILE_call(set_cwd, Handle, [CurrentDir, "utag"]) end, ok. @@ -324,7 +324,7 @@ cur_dir_0(Config, Handle) -> %% Find out the current dir, and cd to it ;-) ?line {ok,BaseDir} = ?PRIM_FILE_call(get_cwd, Handle, []), ?line Dir1 = BaseDir ++ "", %% Check that it's a string - ?line ok = ?PRIM_FILE_call(set_cwd, Handle, [Dir1]), + ?line ok = ?PRIM_FILE_call(set_cwd, Handle, [Dir1, "utag"]), ?line DirName = atom_to_list(?MODULE) ++ case Handle of [] -> @@ -336,40 +336,40 @@ cur_dir_0(Config, Handle) -> %% Make a new dir, and cd to that ?line RootDir = ?config(priv_dir,Config), ?line NewDir = filename:join(RootDir, DirName), - ?line ok = ?PRIM_FILE_call(make_dir, Handle, [NewDir]), + ?line ok = ?PRIM_FILE_call(make_dir, Handle, [NewDir, "utag"]), ?line io:format("cd to ~s",[NewDir]), - ?line ok = ?PRIM_FILE_call(set_cwd, Handle, [NewDir]), + ?line ok = ?PRIM_FILE_call(set_cwd, Handle, [NewDir, "utag"]), %% Create a file in the new current directory, and check that it %% really is created there ?line UncommonName = "uncommon.fil", ?line {ok,Fd} = ?PRIM_FILE:open(UncommonName, [read, write]), ?line ok = ?PRIM_FILE:close(Fd), - ?line {ok,NewDirFiles} = ?PRIM_FILE_call(list_dir, Handle, ["."]), + ?line {ok,NewDirFiles} = ?PRIM_FILE_call(list_dir, Handle, [".", "utag"]), ?line true = lists:member(UncommonName,NewDirFiles), %% Delete the directory and return to the old current directory %% and check that the created file isn't there (too!) ?line expect({error, einval}, {error, eacces}, {error, eexist}, - ?PRIM_FILE_call(del_dir, Handle, [NewDir])), - ?line ?PRIM_FILE_call(delete, Handle, [UncommonName]), - ?line {ok,[]} = ?PRIM_FILE_call(list_dir, Handle, ["."]), - ?line ok = ?PRIM_FILE_call(set_cwd, Handle, [Dir1]), + ?PRIM_FILE_call(del_dir, Handle, [NewDir, "utag"])), + ?line ?PRIM_FILE_call(delete, Handle, [UncommonName, "utag"]), + ?line {ok,[]} = ?PRIM_FILE_call(list_dir, Handle, [".", "utag"]), + ?line ok = ?PRIM_FILE_call(set_cwd, Handle, [Dir1, "utag"]), ?line io:format("cd back to ~s",[Dir1]), - ?line ok = ?PRIM_FILE_call(del_dir, Handle, [NewDir]), - ?line {error, enoent} = ?PRIM_FILE_call(set_cwd, Handle, [NewDir]), - ?line ok = ?PRIM_FILE_call(set_cwd, Handle, [Dir1]), + ?line ok = ?PRIM_FILE_call(del_dir, Handle, [NewDir, "utag"]), + ?line {error, enoent} = ?PRIM_FILE_call(set_cwd, Handle, [NewDir, "utag"]), + ?line ok = ?PRIM_FILE_call(set_cwd, Handle, [Dir1, "utag"]), ?line io:format("cd back to ~s",[Dir1]), - ?line {ok,OldDirFiles} = ?PRIM_FILE_call(list_dir, Handle, ["."]), + ?line {ok,OldDirFiles} = ?PRIM_FILE_call(list_dir, Handle, [".", "utag"]), ?line false = lists:member(UncommonName,OldDirFiles), %% Try doing some bad things ?line {error, badarg} = - ?PRIM_FILE_call(set_cwd, Handle, [{foo,bar}]), + ?PRIM_FILE_call(set_cwd, Handle, [{foo,bar}, "utag"]), ?line {error, enoent} = - ?PRIM_FILE_call(set_cwd, Handle, [""]), + ?PRIM_FILE_call(set_cwd, Handle, ["", "utag"]), ?line {error, enoent} = - ?PRIM_FILE_call(set_cwd, Handle, [".......a......"]), + ?PRIM_FILE_call(set_cwd, Handle, [".......a......", "utag"]), ?line {ok,BaseDir} = ?PRIM_FILE_call(get_cwd, Handle, []), %% Still there? @@ -405,10 +405,10 @@ cur_dir_1(Config, Handle) -> ?line case os:type() of {unix, _} -> ?line {error, enotsup} = - ?PRIM_FILE_call(get_cwd, Handle, ["d:"]); + ?PRIM_FILE_call(get_cwd, Handle, ["d:", "utag"]); vxworks -> ?line {error, enotsup} = - ?PRIM_FILE_call(get_cwd, Handle, ["d:"]); + ?PRIM_FILE_call(get_cwd, Handle, ["d:", "utag"]); {win32, _} -> win_cur_dir_1(Config, Handle) end, @@ -422,7 +422,7 @@ win_cur_dir_1(_Config, Handle) -> %% and try to get current directory for that drive. ?line [Drive, $:|_] = BaseDir, - ?line {ok, BaseDir} = ?PRIM_FILE_call(get_cwd, Handle, [[Drive, $:]]), + ?line {ok, BaseDir} = ?PRIM_FILE_call(get_cwd, Handle, [[Drive, $:], "utag"]), io:format("BaseDir = ~s\n", [BaseDir]), %% Unfortunately, there is no way to move away from the @@ -1027,7 +1027,7 @@ file_write_file_info(Config, Handle, Suffix) -> ?line ok = ?PRIM_FILE:write_file(Name, "hello"), ?line Time = {{1997, 01, 02}, {12, 35, 42}}, ?line Info = #file_info{mode=8#400, atime=Time, mtime=Time, ctime=Time}, - ?line ok = ?PRIM_FILE_call(write_file_info, Handle, [Name, Info]), + ?line ok = ?PRIM_FILE_call(write_file_info, Handle, [Name, Info, "utag"]), %% Read back the times. @@ -1050,12 +1050,12 @@ file_write_file_info(Config, Handle, Suffix) -> %% Make the file writable again. ?line ?PRIM_FILE_call(write_file_info, Handle, - [Name, #file_info{mode=8#600}]), + [Name, #file_info{mode=8#600}, "utag"]), ?line ok = ?PRIM_FILE:write_file(Name, "hello again"), %% And unwritable. ?line ?PRIM_FILE_call(write_file_info, Handle, - [Name, #file_info{mode=8#400}]), + [Name, #file_info{mode=8#400}, "utag"]), ?line {error, eacces} = ?PRIM_FILE:write_file(Name, "hello again"), %% Write the times again. @@ -1063,7 +1063,7 @@ file_write_file_info(Config, Handle, Suffix) -> ?line NewTime = {{1997, 02, 15}, {13, 18, 20}}, ?line NewInfo = #file_info{atime=NewTime, mtime=NewTime, ctime=NewTime}, - ?line ok = ?PRIM_FILE_call(write_file_info, Handle, [Name, NewInfo]), + ?line ok = ?PRIM_FILE_call(write_file_info, Handle, [Name, NewInfo, "utag"]), ?line {ok, ActualInfo2} = ?PRIM_FILE_call(read_file_info, Handle, [Name]), ?line #file_info{atime=NewActAtime, mtime=NewTime, @@ -1081,7 +1081,7 @@ file_write_file_info(Config, Handle, Suffix) -> %% Make the file writeable again, so that we can remove the %% test suites ... :-) ?line ?PRIM_FILE_call(write_file_info, Handle, - [Name, #file_info{mode=8#600}]), + [Name, #file_info{mode=8#600}, "utag"]), ?line test_server:timetrap_cancel(Dog), ok. @@ -1390,11 +1390,11 @@ delete(Config, Handle, Suffix) -> %% Check that the file is readable ?line {ok, Fd2} = ?PRIM_FILE:open(Name, [read]), ?line ok = ?PRIM_FILE:close(Fd2), - ?line ok = ?PRIM_FILE_call(delete, Handle, [Name]), + ?line ok = ?PRIM_FILE_call(delete, Handle, [Name, "utag"]), %% Check that the file is not readable anymore ?line {error, _} = ?PRIM_FILE:open(Name, [read]), %% Try deleting a nonexistent file - ?line {error, enoent} = ?PRIM_FILE_call(delete, Handle, [Name]), + ?line {error, enoent} = ?PRIM_FILE_call(delete, Handle, [Name, "utag"]), ?line test_server:timetrap_cancel(Dog), ok. @@ -1895,14 +1895,14 @@ make_link(Config, Handle, Suffix) -> ?line NewDir = filename:join(RootDir, atom_to_list(?MODULE) ++"_make_link"++Suffix), - ?line ok = ?PRIM_FILE_call(make_dir, Handle, [NewDir]), + ?line ok = ?PRIM_FILE_call(make_dir, Handle, [NewDir, "utag"]), ?line Name = filename:join(NewDir, "a_file"), ?line ok = ?PRIM_FILE:write_file(Name, "some contents\n"), ?line Alias = filename:join(NewDir, "an_alias"), ?line Result = - case ?PRIM_FILE_call(make_link, Handle, [Name, Alias]) of + case ?PRIM_FILE_call(make_link, Handle, [Name, Alias, "utag"]) of {error, enotsup} -> {skipped, "Links not supported on this platform"}; ok -> @@ -1913,12 +1913,12 @@ make_link(Config, Handle, Suffix) -> %% since they are not used on symbolic links. ?line {ok, Info} = - ?PRIM_FILE_call(read_link_info, Handle, [Name]), + ?PRIM_FILE_call(read_link_info, Handle, [Name, "utag"]), ?line {ok, Info} = - ?PRIM_FILE_call(read_link_info, Handle, [Alias]), + ?PRIM_FILE_call(read_link_info, Handle, [Alias, "utag"]), ?line #file_info{links = 2, type = regular} = Info, ?line {error, eexist} = - ?PRIM_FILE_call(make_link, Handle, [Name, Alias]), + ?PRIM_FILE_call(make_link, Handle, [Name, Alias, "utag"]), ok end, @@ -1956,30 +1956,30 @@ symlinks(Config, Handle, Suffix) -> ?line NewDir = filename:join(RootDir, atom_to_list(?MODULE) ++"_make_symlink"++Suffix), - ?line ok = ?PRIM_FILE_call(make_dir, Handle, [NewDir]), + ?line ok = ?PRIM_FILE_call(make_dir, Handle, [NewDir, "utag"]), ?line Name = filename:join(NewDir, "a_plain_file"), ?line ok = ?PRIM_FILE:write_file(Name, "some stupid content\n"), ?line Alias = filename:join(NewDir, "a_symlink_alias"), ?line Result = - case ?PRIM_FILE_call(make_symlink, Handle, [Name, Alias]) of + case ?PRIM_FILE_call(make_symlink, Handle, [Name, Alias, "utag"]) of {error, enotsup} -> {skipped, "Links not supported on this platform"}; ok -> ?line {ok, Info1} = - ?PRIM_FILE_call(read_file_info, Handle, [Name]), + ?PRIM_FILE_call(read_file_info, Handle, [Name, "utag"]), ?line {ok, Info1} = - ?PRIM_FILE_call(read_file_info, Handle, [Alias]), + ?PRIM_FILE_call(read_file_info, Handle, [Alias, "utag"]), ?line {ok, Info1} = - ?PRIM_FILE_call(read_link_info, Handle, [Name]), + ?PRIM_FILE_call(read_link_info, Handle, [Name, "utag"]), ?line #file_info{links = 1, type = regular} = Info1, ?line {ok, Info2} = - ?PRIM_FILE_call(read_link_info, Handle, [Alias]), + ?PRIM_FILE_call(read_link_info, Handle, [Alias, "utag"]), ?line #file_info{links=1, type=symlink} = Info2, ?line {ok, Name} = - ?PRIM_FILE_call(read_link, Handle, [Alias]), + ?PRIM_FILE_call(read_link, Handle, [Alias, "utag"]), ok end, @@ -2003,7 +2003,7 @@ list_dir_limit(Config) when is_list(Config) -> ?line NewDir = filename:join(RootDir, atom_to_list(?MODULE)++"_list_dir_limit"), ?line {ok, Handle1} = ?PRIM_FILE:start(), - ?line ok = ?PRIM_FILE_call(make_dir, Handle1, [NewDir]), + ?line ok = ?PRIM_FILE_call(make_dir, Handle1, [NewDir, "utag"]), Ref = erlang:start_timer(MaxTime*1000, self(), []), ?line Result = list_dir_limit_loop(NewDir, Handle1, Ref, MaxNumber, 0), ?line Time = case erlang:cancel_timer(Ref) of @@ -2054,7 +2054,7 @@ list_dir_limit_loop(Dir, Handle, Ref, N, Cnt) -> end. list_dir_check(Dir, Handle, Cnt) -> - case ?PRIM_FILE:list_dir(Handle, Dir) of + case ?PRIM_FILE:list_dir(Handle, Dir, "utag") of {ok, ListDir} -> case length(ListDir) of Cnt -> -- cgit v1.2.3 From 0fd4e39abeea3fc87b78eec8495109f9245b5ac8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn-Egil=20Dahlberg?= Date: Tue, 7 Feb 2012 19:19:27 +0100 Subject: Update dtrace for changes in R15 --- lib/dtrace/c_src/Makefile | 2 +- lib/dtrace/c_src/Makefile.in | 15 ++++++------- lib/dtrace/c_src/dtrace.c | 16 +++++--------- lib/dtrace/examples/dist.d | 14 ++++++------ lib/dtrace/examples/port1.d | 8 ++++--- lib/dtrace/examples/process-scheduling.d | 2 +- lib/dtrace/src/dtrace.erl | 38 +++++++++++++++++++++++++++----- lib/kernel/src/file.erl | 8 +++---- lib/kernel/src/file_server.erl | 6 ++--- 9 files changed, 66 insertions(+), 43 deletions(-) (limited to 'lib') diff --git a/lib/dtrace/c_src/Makefile b/lib/dtrace/c_src/Makefile index f3320bb766..a65491d45d 100644 --- a/lib/dtrace/c_src/Makefile +++ b/lib/dtrace/c_src/Makefile @@ -1,4 +1,4 @@ # -# Invoke with GNU make or clearmake -C gnu. +# Invoke with GNU make # include $(ERL_TOP)/make/run_make.mk diff --git a/lib/dtrace/c_src/Makefile.in b/lib/dtrace/c_src/Makefile.in index ed13684a95..831ce5ce75 100644 --- a/lib/dtrace/c_src/Makefile.in +++ b/lib/dtrace/c_src/Makefile.in @@ -72,7 +72,7 @@ RELSYSDIR = $(RELEASE_PATH)/lib/dtrace-$(VSN) # ---------------------------------------------------- # Misc Macros # ---------------------------------------------------- -OBJS = $(OBJDIR)/dtrace$(TYPEMARKER).o +before_DTrace_OBJS = $(OBJDIR)/dtrace$(TYPEMARKER).o ## NIF_MAKEFILE = $(PRIVDIR)/Makefile # Higher-level makefiles says that we can only compile on UNIX flavors @@ -100,18 +100,17 @@ else DTRACE_USER_HEADER= endif +DTRACE_OBJS = ifdef DTRACE_ENABLED_2STEP -OBJS += $(OBJDIR)/dtrace_user.o -$(OBJDIR)/dtrace_user.o: $(OBJS) $(OBJDIR)/dtrace_user.h - touch $(OBJDIR)/erlang_dtrace.c - $(CC) $(CFLAGS) -c -o $@ $(OBJDIR)/erlang_dtrace.c - # The object file created above is immediately clobbered below. - # But creating it above avoids chicken-and-egg problem with OBJS +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 $@ $(OBJS) + -o $@ $(before_DTrace_OBJS) endif +OBJS = $(before_DTrace_OBJS) $(DTRACE_OBJS) + $(OBJDIR): -@mkdir -p $(OBJDIR) diff --git a/lib/dtrace/c_src/dtrace.c b/lib/dtrace/c_src/dtrace.c index c9d25ece9c..90bb39a4b8 100644 --- a/lib/dtrace/c_src/dtrace.c +++ b/lib/dtrace/c_src/dtrace.c @@ -25,7 +25,6 @@ #include "erl_nif.h" #include "config.h" #include "sys.h" -#define DTRACE_DRIVER_SKIP_FUNC_DECLARATIONS #include "dtrace-wrapper.h" #ifdef HAVE_DTRACE #include "dtrace_user.h" @@ -144,8 +143,7 @@ static ERL_NIF_TERM user_trace_i4s4(ErlNifEnv* env, int argc, const ERL_NIF_TERM if (DTRACE_ENABLED(user_trace_i4s4)) { dtrace_nifenv_str(env, procbuf); - get_string_maybe(env, argv[0], &utbuf, - user_tagbuf, sizeof(user_tagbuf)-1); + get_string_maybe(env, argv[0], &utbuf, user_tagbuf, MESSAGE_BUFSIZ); if (! enif_get_int64(env, argv[1], &i1)) i1 = 0; if (! enif_get_int64(env, argv[2], &i2)) @@ -154,14 +152,10 @@ static ERL_NIF_TERM user_trace_i4s4(ErlNifEnv* env, int argc, const ERL_NIF_TERM i3 = 0; if (! enif_get_int64(env, argv[4], &i4)) i4 = 0; - get_string_maybe(env, argv[5], &mbuf1, - messagebuf1, sizeof(messagebuf1)-1); - get_string_maybe(env, argv[6], &mbuf2, - messagebuf2, sizeof(messagebuf2)-1); - get_string_maybe(env, argv[7], &mbuf3, - messagebuf3, sizeof(messagebuf3)-1); - get_string_maybe(env, argv[8], &mbuf4, - messagebuf4, sizeof(messagebuf4)-1); + get_string_maybe(env, argv[5], &mbuf1, messagebuf1, MESSAGE_BUFSIZ); + get_string_maybe(env, argv[6], &mbuf2, messagebuf2, MESSAGE_BUFSIZ); + get_string_maybe(env, argv[7], &mbuf3, messagebuf3, MESSAGE_BUFSIZ); + get_string_maybe(env, argv[8], &mbuf4, messagebuf4, MESSAGE_BUFSIZ); DTRACE10(user_trace_i4s4, procbuf, utbuf, i1, i2, i3, i4, mbuf1, mbuf2, mbuf3, mbuf4); return atom_true; diff --git a/lib/dtrace/examples/dist.d b/lib/dtrace/examples/dist.d index f37c827f14..550e10d363 100644 --- a/lib/dtrace/examples/dist.d +++ b/lib/dtrace/examples/dist.d @@ -30,13 +30,13 @@ 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)); - blocked_procs[copyinstr(arg3)] = timestamp; -} - -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; } diff --git a/lib/dtrace/examples/port1.d b/lib/dtrace/examples/port1.d index b82e783a14..204abbd3b8 100644 --- a/lib/dtrace/examples/port1.d +++ b/lib/dtrace/examples/port1.d @@ -99,10 +99,12 @@ erlang*:::port-command erlang*:::port-control { - cmd = driver_map[copyinstr(arg2), arg3]; - cmd_str = (cmd == 0) ? "unknown" : cmd; + /* 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, cmd_str); + copyinstr(arg0), copyinstr(arg1), copyinstr(arg2), arg3, + this->cmd_str); } /* port-exit is fired as a result of port_close() or exit signal */ diff --git a/lib/dtrace/examples/process-scheduling.d b/lib/dtrace/examples/process-scheduling.d index 9e31da2774..79e9cc598c 100644 --- a/lib/dtrace/examples/process-scheduling.d +++ b/lib/dtrace/examples/process-scheduling.d @@ -31,5 +31,5 @@ erlang*:::process-unscheduled erlang*:::process-hibernate { printf(" Hibernate pid %s resume mfa %s\n", - copyinstr(arg0), copyinstr(arg1)); + copyinstr(arg0), copyinstr(arg1)); } diff --git a/lib/dtrace/src/dtrace.erl b/lib/dtrace/src/dtrace.erl index 45addafc53..6951c03215 100644 --- a/lib/dtrace/src/dtrace.erl +++ b/lib/dtrace/src/dtrace.erl @@ -14,8 +14,8 @@ %%% four integer arguments and four string arguments; the integer %%% argument(s) must come before any string argument. For example: %%% ``` -%%% 1> put(dtrace_utag, "GGOOOAAALL!!!!!"). -%%% undefined +%%% 1> dtrace:put_tag("GGOOOAAALL!!!!!"). +%%% true %%% 2> dtrace:init(). %%% ok %%% @@ -35,9 +35,13 @@ %%% then the driver will ignore the user's input and use a default %%% value of 0 or NULL, respectively. +-define(DTRACE_UT_KEY, '_dtrace_utag_@_@'). % Match prim_file:get_dtrace_utag()! + -export([init/0, 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]). +-export([put_utag/1, get_utag/0]). + -export([scaff/0]). % Development only -export([user_trace_i4s4/9]). % Know what you're doing! @@ -68,7 +72,7 @@ available() -> -spec user_trace_s1(iolist()) -> true | false | error | badarg. -user_trace_s1(Message) -> +user_trace_s1(_Message) -> erlang:nif_error(nif_not_loaded). -spec user_trace_i4s4(iolist(), @@ -176,8 +180,32 @@ p(I1, I2, I3, I4, S1, S2, S3, S4) when is_integer(I1), is_integer(I2), is_intege true | false | error | badarg. user_trace_int(I1, I2, I3, I4, S1, S2, S3, S4) -> - UTag = prim_file:get_dtrace_utag(), - user_trace_i4s4(UTag, I1, I2, I3, I4, S1, S2, S3, S4). + UTag = get_utag(), + try + user_trace_i4s4(UTag, I1, I2, I3, I4, S1, S2, S3, S4) + catch + error:nif_not_loaded -> + false + end. + +-spec put_utag(undefined | iolist()) -> ok. + +put_utag(undefined) -> + put_utag(<<>>); +put_utag(T) when is_binary(T) -> + put(?DTRACE_UT_KEY, T), + ok; +put_utag(T) when is_list(T) -> + put(?DTRACE_UT_KEY, list_to_binary(T)), + ok. + +get_utag() -> + case get(?DTRACE_UT_KEY) of + undefined -> + <<>>; + X -> + X + end. %% Scaffolding to write tedious code: quick brute force and not 100% correct. diff --git a/lib/kernel/src/file.erl b/lib/kernel/src/file.erl index a2e0d261ee..aecb9f7923 100644 --- a/lib/kernel/src/file.erl +++ b/lib/kernel/src/file.erl @@ -227,7 +227,7 @@ read_file_info(Name) -> Reason :: posix() | badarg. read_file_info(Name, Opts) when is_list(Opts) -> - check_and_call(read_file_info, [file_name(Name), Opts]). + check_and_call(read_file_info, [file_name(Name), Opts, get_dtrace_utag()]). -spec altname(Name :: name()) -> any(). @@ -249,7 +249,7 @@ read_link_info(Name) -> Reason :: posix() | badarg. read_link_info(Name, Opts) when is_list(Opts) -> - check_and_call(read_link_info, [file_name(Name),Opts]). + check_and_call(read_link_info, [file_name(Name),Opts, get_dtrace_utag()]). -spec read_link(Name) -> {ok, Filename} | {error, Reason} when @@ -275,7 +275,7 @@ write_file_info(Name, Info = #file_info{}) -> Reason :: posix() | badarg. write_file_info(Name, Info = #file_info{}, Opts) when is_list(Opts) -> - check_and_call(write_file_info, [file_name(Name), Info, Opts]). + check_and_call(write_file_info, [file_name(Name), Info, Opts, get_dtrace_utag()]). -spec list_dir(Dir) -> {ok, Filenames} | {error, Reason} when Dir :: name(), @@ -1504,4 +1504,4 @@ wait_file_reply(From, Ref) -> end. get_dtrace_utag() -> - prim_file:get_dtrace_utag(). + dtrace:get_utag(). diff --git a/lib/kernel/src/file_server.erl b/lib/kernel/src/file_server.erl index c917819508..82adc45795 100644 --- a/lib/kernel/src/file_server.erl +++ b/lib/kernel/src/file_server.erl @@ -146,7 +146,7 @@ handle_call({get_cwd, Name, DTraceUtag}, _From, Handle) -> {reply, ?PRIM_FILE:get_cwd(Handle, Name, DTraceUtag), Handle}; handle_call({read_file_info, Name, DTraceUtag}, _From, Handle) -> - {reply, ?PRIM_FILE:read_file_info(Handle, Name, DTraceUtag), Handle}; + {reply, ?PRIM_FILE:read_file_info(Handle, Name, [], DTraceUtag), Handle}; handle_call({read_file_info, Name, Opts, DTraceUtag}, _From, Handle) -> {reply, ?PRIM_FILE:read_file_info(Handle, Name, Opts, DTraceUtag), Handle}; @@ -154,12 +154,12 @@ handle_call({altname, Name, DTraceUtag}, _From, Handle) -> {reply, ?PRIM_FILE:altname(Handle, Name, DTraceUtag), Handle}; handle_call({write_file_info, Name, Info, DTraceUtag}, _From, Handle) -> - {reply, ?PRIM_FILE:write_file_info(Handle, Name, Info, DTraceUtag), Handle}; + {reply, ?PRIM_FILE:write_file_info(Handle, Name, Info, [], DTraceUtag), Handle}; handle_call({write_file_info, Name, Info, Opts, DTraceUtag}, _From, Handle) -> {reply, ?PRIM_FILE:write_file_info(Handle, Name, Info, Opts, DTraceUtag), Handle}; handle_call({read_link_info, Name, DTraceUtag}, _From, Handle) -> - {reply, ?PRIM_FILE:read_link_info(Handle, Name, DTraceUtag), Handle}; + {reply, ?PRIM_FILE:read_link_info(Handle, Name, [], DTraceUtag), Handle}; handle_call({read_link_info, Name, Opts, DTraceUtag}, _From, Handle) -> {reply, ?PRIM_FILE:read_link_info(Handle, Name, Opts, DTraceUtag), Handle}; -- cgit v1.2.3 From c15f94e7922040b63f3abf8680cd77d5548fecf3 Mon Sep 17 00:00:00 2001 From: Patrik Nyblom Date: Mon, 13 Feb 2012 20:13:37 +0100 Subject: Add user tag spreading functionality to VM and use in file User tags in a dynamic trace enabled VM are spread throughout the system in the same way as seq_trace tokens. This is used by the file module and various other modules to get hold of the tag from the user process without changing the protocol. --- lib/dtrace/c_src/Makefile.in | 10 +-- lib/dtrace/examples/efile_drv.d | 3 +- lib/dtrace/src/dtrace.erl | 41 ++++----- lib/hipe/cerl/erl_bif_types.erl | 35 ++++++++ lib/kernel/src/file.erl | 160 +++++++++++++----------------------- lib/kernel/src/file_io_server.erl | 15 ++-- lib/kernel/src/file_server.erl | 106 ++++++++++++------------ lib/kernel/test/prim_file_SUITE.erl | 108 ++++++++++++------------ 8 files changed, 235 insertions(+), 243 deletions(-) (limited to 'lib') diff --git a/lib/dtrace/c_src/Makefile.in b/lib/dtrace/c_src/Makefile.in index 831ce5ce75..4d5f59a63d 100644 --- a/lib/dtrace/c_src/Makefile.in +++ b/lib/dtrace/c_src/Makefile.in @@ -76,7 +76,7 @@ before_DTrace_OBJS = $(OBJDIR)/dtrace$(TYPEMARKER).o ## NIF_MAKEFILE = $(PRIVDIR)/Makefile # Higher-level makefiles says that we can only compile on UNIX flavors -NIF_LIB = $(LIBDIR)/dtrace$(TYPEMARKER).so +NIF_LIB = $(LIBDIR)/dtrace$(TYPEMARKER).@DED_EXT@ ifeq ($(HOST_OS),) HOST_OS := $(shell $(ERL_TOP)/erts/autoconf/config.guess) @@ -121,14 +121,14 @@ $(OBJDIR)/%$(TYPEMARKER).o: %.c $(DTRACE_USER_HEADER) $(INSTALL_DIR) $(OBJDIR) $(CC) -c -o $@ $(ALL_CFLAGS) $< -$(LIBDIR)/dtrace$(TYPEMARKER).so: $(OBJS) +$(NIF_LIB): $(OBJS) $(INSTALL_DIR) $(LIBDIR) $(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS) clean: - rm -f $(LIBDIR)/dtrace.so - rm -f $(LIBDIR)/dtrace.debug.so - rm -f $(LIBDIR)/dtrace.valgrind.so + rm -f $(LIBDIR)/dtrace.@DED_EXT@ + rm -f $(LIBDIR)/dtrace.debug.@DED_EXT@ + rm -f $(LIBDIR)/dtrace.valgrind.@DED_EXT@ rm -f $(OBJDIR)/dtrace.o rm -f $(OBJDIR)/dtrace.debug.o rm -f $(OBJDIR)/dtrace.valgrind.o diff --git a/lib/dtrace/examples/efile_drv.d b/lib/dtrace/examples/efile_drv.d index c9c8080dba..085995ce58 100644 --- a/lib/dtrace/examples/efile_drv.d +++ b/lib/dtrace/examples/efile_drv.d @@ -71,7 +71,8 @@ erlang*:::efile_drv-entry arg4 == NULL ? "" : copyinstr(arg4), arg5 == NULL ? "" : copyinstr(arg5), arg6, arg7, /* NOTE: port name in args[10] is experimental */ - copyinstr((user_addr_t) args[10])) + (args[10] == NULL) ? + "?" : copyinstr((user_addr_t) args[10])); } erlang*:::efile_drv-int* diff --git a/lib/dtrace/src/dtrace.erl b/lib/dtrace/src/dtrace.erl index 6951c03215..71a1a3480e 100644 --- a/lib/dtrace/src/dtrace.erl +++ b/lib/dtrace/src/dtrace.erl @@ -35,12 +35,10 @@ %%% then the driver will ignore the user's input and use a default %%% value of 0 or NULL, respectively. --define(DTRACE_UT_KEY, '_dtrace_utag_@_@'). % Match prim_file:get_dtrace_utag()! - -export([init/0, 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]). --export([put_utag/1, get_utag/0]). +-export([put_utag/1, get_utag/0, get_utag_data/0, spread_utag/1, restore_utag/1]). -export([scaff/0]). % Development only -export([user_trace_i4s4/9]). % Know what you're doing! @@ -188,24 +186,29 @@ user_trace_int(I1, I2, I3, I4, S1, S2, S3, S4) -> false end. --spec put_utag(undefined | iolist()) -> ok. - -put_utag(undefined) -> - put_utag(<<>>); -put_utag(T) when is_binary(T) -> - put(?DTRACE_UT_KEY, T), - ok; -put_utag(T) when is_list(T) -> - put(?DTRACE_UT_KEY, list_to_binary(T)), - ok. +-spec put_utag(undefined | iodata()) -> binary() | undefined. +put_utag(Data) -> + erlang:put_utag(unicode:characters_to_binary(Data)). +-spec get_utag() -> binary() | undefined. get_utag() -> - case get(?DTRACE_UT_KEY) of - undefined -> - <<>>; - X -> - X - end. + erlang:get_utag(). + +-spec get_utag_data() -> binary() | undefined. +%% Gets utag if set, otherwise the spread utag data from last incoming message +get_utag_data() -> + erlang:get_utag_data(). + +-spec spread_utag(boolean()) -> true | {non_neg_integer(), binary() | []}. +%% Makes the utag behave as a sequential trace token, will spread with messages to be picked up by someone using +%% get_utag_data or get_drv_utag_data. +spread_utag(B) -> + erlang:spread_utag(B). + +-spec restore_utag(true | {non_neg_integer(), binary() | []}) -> true. +restore_utag(T) -> + erlang:restore_utag(T). + %% Scaffolding to write tedious code: quick brute force and not 100% correct. diff --git a/lib/hipe/cerl/erl_bif_types.erl b/lib/hipe/cerl/erl_bif_types.erl index a7ce17eb53..260f216725 100644 --- a/lib/hipe/cerl/erl_bif_types.erl +++ b/lib/hipe/cerl/erl_bif_types.erl @@ -614,6 +614,10 @@ type(erlang, adler32_combine, 3, Xs) -> type(erlang, append, 2, Xs) -> type(erlang, '++', 2, Xs); % alias type(erlang, append_element, 2, Xs) -> strict(arg_types(erlang, append_element, 2), Xs, fun (_) -> t_tuple() end); +type(erlang, append_vm_utag_data, 1, Xs) -> + strict(arg_types(erlang, append_vm_utag_data, 1), + Xs, + fun(_) -> t_iodata() end); type(erlang, apply, 2, Xs) -> Fun = fun ([X, _Y]) -> case t_is_fun(X) of @@ -800,6 +804,10 @@ type(erlang, get_module_info, 2, Xs) -> type(erlang, get_stacktrace, 0, _) -> t_list(t_tuple([t_atom(), t_atom(), t_sup([t_arity(), t_list()]), t_list()])); +type(erlang, get_utag, 0, _) -> + t_sup(t_binary(), t_atom('undefined')); +type(erlang, get_utag_data, 0, _) -> + t_sup(t_binary(), t_atom('undefined')); type(erlang, group_leader, 0, _) -> t_pid(); type(erlang, group_leader, 2, Xs) -> strict(arg_types(erlang, group_leader, 2), Xs, @@ -1186,6 +1194,10 @@ type(erlang, port_set_data, 2, Xs) -> strict(arg_types(erlang, port_set_data, 2), Xs, fun (_) -> t_atom('true') end); type(erlang, pre_loaded, 0, _) -> t_list(t_atom()); +type(erlang, prepend_vm_utag_data, 1, Xs) -> + strict(arg_types(erlang, prepend_vm_utag_data, 1), + Xs, + fun(_) -> t_iodata() end); type(erlang, process_display, 2, _) -> t_atom('true'); type(erlang, process_flag, 2, Xs) -> T_process_flag_returns = t_sup([t_boolean(), t_atom(), t_non_neg_integer()]), @@ -1303,6 +1315,9 @@ type(erlang, purge_module, 1, Xs) -> fun (_) -> t_atom('true') end); type(erlang, put, 2, Xs) -> strict(arg_types(erlang, put, 2), Xs, fun (_) -> t_any() end); +type(erlang, put_utag, 1, Xs) -> + strict(arg_types(erlang, put_utag, 1), Xs, + fun(_) -> t_sup(t_binary(), t_atom('undefined')) end); type(erlang, raise, 3, _) -> t_none(); type(erlang, read_timer, 1, Xs) -> strict(arg_types(erlang, read_timer, 1), Xs, @@ -1312,6 +1327,8 @@ type(erlang, ref_to_list, 1, Xs) -> type(erlang, register, 2, Xs) -> strict(arg_types(erlang, register, 2), Xs, fun (_) -> t_atom('true') end); type(erlang, registered, 0, _) -> t_list(t_atom()); +type(erlang, restore_utag, 1, Xs) -> + strict(arg_types(erlang, restore_utag, 1), Xs, fun(_) -> t_atom('true') end); type(erlang, resume_process, 1, Xs) -> strict(arg_types(erlang, resume_process, 1), Xs, fun (_) -> t_any() end); %% TODO: overapproximation -- fix this @@ -1426,6 +1443,10 @@ type(erlang, spawn_opt, 4, Xs) -> type(erlang, split_binary, 2, Xs) -> strict(arg_types(erlang, split_binary, 2), Xs, fun (_) -> t_tuple([t_binary(), t_binary()]) end); +type(erlang, spread_utag, 1, Xs) -> + strict(arg_types(erlang, spread_utag, 1), Xs, + fun(_) -> t_sup(t_tuple([t_non_neg_integer(), t_sup(t_binary(), t_nil())]), + t_atom('true')) end); type(erlang, start_timer, 3, Xs) -> strict(arg_types(erlang, start_timer, 3), Xs, fun (_) -> t_reference() end); type(erlang, statistics, 1, Xs) -> @@ -3422,6 +3443,8 @@ arg_types(erlang, append, 2) -> arg_types(erlang, '++', 2); arg_types(erlang, append_element, 2) -> [t_tuple(), t_any()]; +arg_types(erlang, append_vm_utag_data, 1) -> + [t_iodata()]; arg_types(erlang, apply, 2) -> [t_sup(t_tuple([t_module(), t_atom()]), @@ -3547,6 +3570,10 @@ arg_types(erlang, get_module_info, 1) -> [t_atom()]; arg_types(erlang, get_module_info, 2) -> [t_atom(), t_module_info_2()]; +arg_types(erlang, get_utag, 0) -> + []; +arg_types(erlang, get_utag_data, 0) -> + []; arg_types(erlang, group_leader, 0) -> []; arg_types(erlang, group_leader, 2) -> @@ -3763,6 +3790,8 @@ arg_types(erlang, port_set_data, 2) -> [t_sup(t_port(), t_atom()), t_any()]; arg_types(erlang, pre_loaded, 0) -> []; +arg_types(erlang, prepend_vm_utag_data, 1) -> + [t_iodata()]; arg_types(erlang, process_display, 2) -> [t_pid(), t_atom('backtrace')]; arg_types(erlang, process_flag, 2) -> @@ -3789,6 +3818,8 @@ arg_types(erlang, purge_module, 1) -> [t_atom()]; arg_types(erlang, put, 2) -> [t_any(), t_any()]; +arg_types(erlang, put_utag, 1) -> + [t_sup(t_binary(), t_atom('undefined'))]; arg_types(erlang, raise, 3) -> OldStyleType = t_list(t_tuple([t_atom(), t_atom(), t_sup([t_arity(), t_list()])])), @@ -3802,6 +3833,8 @@ arg_types(erlang, register, 2) -> [t_atom(), t_sup(t_port(), t_pid())]; arg_types(erlang, registered, 0) -> []; +arg_types(erlang, restore_utag, 1) -> + [t_sup(t_tuple([t_non_neg_integer(), t_sup(t_binary(), t_nil())]), t_atom('true'))]; arg_types(erlang, resume_process, 1) -> [t_pid()]; % intended for debugging only arg_types(erlang, round, 1) -> @@ -3860,6 +3893,8 @@ arg_types(erlang, spawn_opt, 4) -> [t_node(), t_atom(), t_list(), t_list(t_spawn_options())]; arg_types(erlang, split_binary, 2) -> [t_binary(), t_non_neg_integer()]; +arg_types(erlang, spread_utag, 1) -> + [t_boolean()]; arg_types(erlang, start_timer, 3) -> [t_non_neg_integer(), t_sup(t_pid(), t_atom()), t_any()]; arg_types(erlang, statistics, 1) -> diff --git a/lib/kernel/src/file.erl b/lib/kernel/src/file.erl index aecb9f7923..3a618976f5 100644 --- a/lib/kernel/src/file.erl +++ b/lib/kernel/src/file.erl @@ -39,7 +39,7 @@ -export([ipread_s32bu_p32bu/3]). %% Generic file contents. -export([open/2, close/1, advise/4, - read/2, write/2, + read/2, write/2, pread/2, pread/3, pwrite/2, pwrite/3, read_line/1, position/2, truncate/1, datasync/1, sync/1, @@ -62,7 +62,7 @@ %% Internal export to prim_file and ram_file until they implement %% an efficient copy themselves. --export([copy_opened/4]). +-export([copy_opened/3]). -export([ipread_s32bu_p32bu_int/3]). @@ -166,7 +166,7 @@ pid2name(Pid) when is_pid(Pid) -> Reason :: posix(). get_cwd() -> - call(get_cwd, [no_drive, get_dtrace_utag()]). + call(get_cwd, []). -spec get_cwd(Drive) -> {ok, Dir} | {error, Reason} when Drive :: string(), @@ -174,21 +174,21 @@ get_cwd() -> Reason :: posix() | badarg. get_cwd(Drive) -> - check_and_call(get_cwd, [file_name(Drive), get_dtrace_utag()]). + check_and_call(get_cwd, [file_name(Drive)]). -spec set_cwd(Dir) -> ok | {error, Reason} when Dir :: name(), Reason :: posix() | badarg. set_cwd(Dirname) -> - check_and_call(set_cwd, [file_name(Dirname), get_dtrace_utag()]). + check_and_call(set_cwd, [file_name(Dirname)]). -spec delete(Filename) -> ok | {error, Reason} when Filename :: name(), Reason :: posix() | badarg. delete(Name) -> - check_and_call(delete, [file_name(Name), get_dtrace_utag()]). + check_and_call(delete, [file_name(Name)]). -spec rename(Source, Destination) -> ok | {error, Reason} when Source :: name(), @@ -196,21 +196,21 @@ delete(Name) -> Reason :: posix() | badarg. rename(From, To) -> - check_and_call(rename, [file_name(From), file_name(To), get_dtrace_utag()]). + check_and_call(rename, [file_name(From), file_name(To)]). -spec make_dir(Dir) -> ok | {error, Reason} when Dir :: name(), Reason :: posix() | badarg. make_dir(Name) -> - check_and_call(make_dir, [file_name(Name), get_dtrace_utag()]). + check_and_call(make_dir, [file_name(Name)]). -spec del_dir(Dir) -> ok | {error, Reason} when Dir :: name(), Reason :: posix() | badarg. del_dir(Name) -> - check_and_call(del_dir, [file_name(Name), get_dtrace_utag()]). + check_and_call(del_dir, [file_name(Name)]). -spec read_file_info(Filename) -> {ok, FileInfo} | {error, Reason} when Filename :: name(), @@ -218,7 +218,7 @@ del_dir(Name) -> Reason :: posix() | badarg. read_file_info(Name) -> - check_and_call(read_file_info, [file_name(Name), get_dtrace_utag()]). + check_and_call(read_file_info, [file_name(Name)]). -spec read_file_info(Filename, Opts) -> {ok, FileInfo} | {error, Reason} when Filename :: name(), @@ -227,12 +227,12 @@ read_file_info(Name) -> Reason :: posix() | badarg. read_file_info(Name, Opts) when is_list(Opts) -> - check_and_call(read_file_info, [file_name(Name), Opts, get_dtrace_utag()]). + check_and_call(read_file_info, [file_name(Name), Opts]). -spec altname(Name :: name()) -> any(). altname(Name) -> - check_and_call(altname, [file_name(Name), get_dtrace_utag()]). + check_and_call(altname, [file_name(Name)]). -spec read_link_info(Name) -> {ok, FileInfo} | {error, Reason} when Name :: name(), @@ -240,7 +240,7 @@ altname(Name) -> Reason :: posix() | badarg. read_link_info(Name) -> - check_and_call(read_link_info, [file_name(Name), get_dtrace_utag()]). + check_and_call(read_link_info, [file_name(Name)]). -spec read_link_info(Name, Opts) -> {ok, FileInfo} | {error, Reason} when Name :: name(), @@ -249,7 +249,7 @@ read_link_info(Name) -> Reason :: posix() | badarg. read_link_info(Name, Opts) when is_list(Opts) -> - check_and_call(read_link_info, [file_name(Name),Opts, get_dtrace_utag()]). + check_and_call(read_link_info, [file_name(Name),Opts]). -spec read_link(Name) -> {ok, Filename} | {error, Reason} when @@ -258,7 +258,7 @@ read_link_info(Name, Opts) when is_list(Opts) -> Reason :: posix() | badarg. read_link(Name) -> - check_and_call(read_link, [file_name(Name), get_dtrace_utag()]). + check_and_call(read_link, [file_name(Name)]). -spec write_file_info(Filename, FileInfo) -> ok | {error, Reason} when Filename :: name(), @@ -266,7 +266,7 @@ read_link(Name) -> Reason :: posix() | badarg. write_file_info(Name, Info = #file_info{}) -> - check_and_call(write_file_info, [file_name(Name), Info, get_dtrace_utag()]). + check_and_call(write_file_info, [file_name(Name), Info]). -spec write_file_info(Filename, FileInfo, Opts) -> ok | {error, Reason} when Filename :: name(), @@ -275,7 +275,7 @@ write_file_info(Name, Info = #file_info{}) -> Reason :: posix() | badarg. write_file_info(Name, Info = #file_info{}, Opts) when is_list(Opts) -> - check_and_call(write_file_info, [file_name(Name), Info, Opts, get_dtrace_utag()]). + check_and_call(write_file_info, [file_name(Name), Info, Opts]). -spec list_dir(Dir) -> {ok, Filenames} | {error, Reason} when Dir :: name(), @@ -283,7 +283,7 @@ write_file_info(Name, Info = #file_info{}, Opts) when is_list(Opts) -> Reason :: posix() | badarg. list_dir(Name) -> - check_and_call(list_dir, [file_name(Name), get_dtrace_utag()]). + check_and_call(list_dir, [file_name(Name)]). -spec read_file(Filename) -> {ok, Binary} | {error, Reason} when Filename :: name(), @@ -291,7 +291,7 @@ list_dir(Name) -> Reason :: posix() | badarg | terminated | system_limit. read_file(Name) -> - check_and_call(read_file, [file_name(Name), get_dtrace_utag()]). + check_and_call(read_file, [file_name(Name)]). -spec make_link(Existing, New) -> ok | {error, Reason} when Existing :: name(), @@ -299,7 +299,7 @@ read_file(Name) -> Reason :: posix() | badarg. make_link(Old, New) -> - check_and_call(make_link, [file_name(Old), file_name(New), get_dtrace_utag()]). + check_and_call(make_link, [file_name(Old), file_name(New)]). -spec make_symlink(Existing, New) -> ok | {error, Reason} when Existing :: name(), @@ -307,7 +307,7 @@ make_link(Old, New) -> Reason :: posix() | badarg. make_symlink(Old, New) -> - check_and_call(make_symlink, [file_name(Old), file_name(New), get_dtrace_utag()]). + check_and_call(make_symlink, [file_name(Old), file_name(New)]). -spec write_file(Filename, Bytes) -> ok | {error, Reason} when Filename :: name(), @@ -315,7 +315,7 @@ make_symlink(Old, New) -> Reason :: posix() | badarg | terminated | system_limit. write_file(Name, Bin) -> - check_and_call(write_file, [file_name(Name), make_binary(Bin), get_dtrace_utag()]). + check_and_call(write_file, [file_name(Name), make_binary(Bin)]). %% This whole operation should be moved to the file_server and prim_file %% when it is time to change file server protocol again. @@ -367,7 +367,7 @@ raw_write_file_info(Name, #file_info{} = Info) -> case check_args(Args) of ok -> [FileName] = Args, - ?PRIM_FILE:write_file_info(FileName, Info, get_dtrace_utag()); + ?PRIM_FILE:write_file_info(FileName, Info); Error -> Error end. @@ -400,7 +400,7 @@ open(Item, ModeList) when is_list(ModeList) -> [FileName | _] = Args, %% We rely on the returned Handle (in {ok, Handle}) %% being a pid() or a #file_descriptor{} - ?PRIM_FILE:open(FileName, ModeList, get_dtrace_utag()); + ?PRIM_FILE:open(FileName, ModeList); Error -> Error end @@ -421,7 +421,7 @@ open(Item, ModeList) when is_list(ModeList) -> case check_args(Args) of ok -> [FileName | _] = Args, - call(open, [FileName, ModeList, get_dtrace_utag()]); + call(open, [FileName, ModeList]); Error -> Error end @@ -466,10 +466,7 @@ close(_) -> advise(File, Offset, Length, Advise) when is_pid(File) -> R = file_request(File, {advise, Offset, Length, Advise}), wait_file_reply(File, R); -advise(#file_descriptor{module = prim_file = Module} = Handle, Offset, Length, Advise) -> - Module:advise(Handle, Offset, Length, Advise, get_dtrace_utag()); advise(#file_descriptor{module = Module} = Handle, Offset, Length, Advise) -> - %% DTrace TODO: ram_file and other file drivers not yet DTrace'ified. Module:advise(Handle, Offset, Length, Advise); advise(_, _, _, _) -> {error, badarg}. @@ -480,25 +477,17 @@ advise(_, _, _, _) -> Data :: string() | binary(), Reason :: posix() | badarg | terminated. -read(File, Sz) -> - read(File, Sz, get_dtrace_utag()). - -read(File, Sz, _DTraceUtag) - when (is_pid(File) orelse is_atom(File)), is_integer(Sz), Sz >= 0 -> +read(File, Sz) when (is_pid(File) orelse is_atom(File)), is_integer(Sz), Sz >= 0 -> case io:request(File, {get_chars, '', Sz}) of Data when is_list(Data); is_binary(Data) -> {ok, Data}; Other -> Other end; -read(#file_descriptor{module = prim_file = Module} = Handle, Sz, DTraceUtag) - when is_integer(Sz), Sz >= 0 -> - Module:read(Handle, Sz, DTraceUtag); -read(#file_descriptor{module = Module} = Handle, Sz, _DTraceUtag) +read(#file_descriptor{module = Module} = Handle, Sz) when is_integer(Sz), Sz >= 0 -> - %% DTrace TODO: ram_file and other file drivers not yet DTrace'ified. Module:read(Handle, Sz); -read(_, _, _) -> +read(_, _) -> {error, badarg}. -spec read_line(IoDevice) -> {ok, Data} | eof | {error, Reason} when @@ -513,10 +502,7 @@ read_line(File) when (is_pid(File) orelse is_atom(File)) -> Other -> Other end; -read_line(#file_descriptor{module = prim_file = Module} = Handle) -> - Module:read_line(Handle, get_dtrace_utag()); read_line(#file_descriptor{module = Module} = Handle) -> - %% DTrace TODO: ram_file and other file drivers not yet DTrace'ified. Module:read_line(Handle); read_line(_) -> {error, badarg}. @@ -530,10 +516,7 @@ read_line(_) -> pread(File, L) when is_pid(File), is_list(L) -> pread_int(File, L, []); -pread(#file_descriptor{module = prim_file = Module} = Handle, L) when is_list(L) -> - Module:pread(Handle, L, get_dtrace_utag()); pread(#file_descriptor{module = Module} = Handle, L) when is_list(L) -> - %% DTrace TODO: ram_file and other file drivers not yet DTrace'ified. Module:pread(Handle, L); pread(_, _) -> {error, badarg}. @@ -565,7 +548,6 @@ pread(File, At, Sz) when is_pid(File), is_integer(Sz), Sz >= 0 -> wait_file_reply(File, R); pread(#file_descriptor{module = Module} = Handle, Offs, Sz) when is_integer(Sz), Sz >= 0 -> - %% DTrace TODO: ram_file and other file drivers not yet DTrace'ified. Module:pread(Handle, Offs, Sz); pread(_, _, _) -> {error, badarg}. @@ -575,22 +557,16 @@ pread(_, _, _) -> Bytes :: iodata(), Reason :: posix() | badarg | terminated. -write(File, Bytes) -> - write(File, Bytes, get_dtrace_utag()). - -write(File, Bytes, _DTraceUtag) when (is_pid(File) orelse is_atom(File)) -> +write(File, Bytes) when (is_pid(File) orelse is_atom(File)) -> case make_binary(Bytes) of Bin when is_binary(Bin) -> io:request(File, {put_chars,Bin}); Error -> Error end; -write(#file_descriptor{module = prim_file = Module} = Handle, Bytes, DTraceUtag) -> - Module:write(Handle, Bytes, DTraceUtag); -write(#file_descriptor{module = Module} = Handle, Bytes, _DTraceUtag) -> - %% DTrace TODO: ram_file and other file drivers not yet DTrace'ified. +write(#file_descriptor{module = Module} = Handle, Bytes) -> Module:write(Handle, Bytes); -write(_, _, _) -> +write(_, _) -> {error, badarg}. -spec pwrite(IoDevice, LocBytes) -> ok | {error, {N, Reason}} when @@ -601,10 +577,7 @@ write(_, _, _) -> pwrite(File, L) when is_pid(File), is_list(L) -> pwrite_int(File, L, 0); -pwrite(#file_descriptor{module = prim_file = Module} = Handle, L) when is_list(L) -> - Module:pwrite(Handle, L, get_dtrace_utag()); pwrite(#file_descriptor{module = Module} = Handle, L) when is_list(L) -> - %% DTrace TODO: ram_file and other file drivers not yet DTrace'ified. Module:pwrite(Handle, L); pwrite(_, _) -> {error, badarg}. @@ -631,7 +604,6 @@ pwrite(File, At, Bytes) when is_pid(File) -> R = file_request(File, {pwrite, At, Bytes}), wait_file_reply(File, R); pwrite(#file_descriptor{module = Module} = Handle, Offs, Bytes) -> - %% DTrace TODO: ram_file and other file drivers not yet DTrace'ified. Module:pwrite(Handle, Offs, Bytes); pwrite(_, _, _) -> {error, badarg}. @@ -643,10 +615,7 @@ pwrite(_, _, _) -> datasync(File) when is_pid(File) -> R = file_request(File, datasync), wait_file_reply(File, R); -datasync(#file_descriptor{module = prim_file = Module} = Handle) -> - Module:datasync(Handle, get_dtrace_utag()); datasync(#file_descriptor{module = Module} = Handle) -> - %% DTrace TODO: ram_file and other file drivers not yet DTrace'ified. Module:datasync(Handle); datasync(_) -> {error, badarg}. @@ -658,10 +627,7 @@ datasync(_) -> sync(File) when is_pid(File) -> R = file_request(File, sync), wait_file_reply(File, R); -sync(#file_descriptor{module = prim_file = Module} = Handle) -> - Module:sync(Handle, get_dtrace_utag()); sync(#file_descriptor{module = Module} = Handle) -> - %% DTrace TODO: ram_file and other file drivers not yet DTrace'ified. Module:sync(Handle); sync(_) -> {error, badarg}. @@ -675,10 +641,7 @@ sync(_) -> position(File, At) when is_pid(File) -> R = file_request(File, {position,At}), wait_file_reply(File, R); -position(#file_descriptor{module = prim_file = Module} = Handle, At) -> - Module:position(Handle, At, get_dtrace_utag()); position(#file_descriptor{module = Module} = Handle, At) -> - %% DTrace TODO: ram_file and other file drivers not yet DTrace'ified. Module:position(Handle, At); position(_, _) -> {error, badarg}. @@ -690,10 +653,7 @@ position(_, _) -> truncate(File) when is_pid(File) -> R = file_request(File, truncate), wait_file_reply(File, R); -truncate(#file_descriptor{module = prim_file = Module} = Handle) -> - Module:truncate(Handle, get_dtrace_utag()); truncate(#file_descriptor{module = Module} = Handle) -> - %% DTrace TODO: ram_file and other file drivers not yet DTrace'ified. Module:truncate(Handle); truncate(_) -> {error, badarg}. @@ -734,7 +694,7 @@ copy_int(Source, Dest, Length) when is_pid(Source), is_pid(Dest); is_pid(Source), is_record(Dest, file_descriptor); is_record(Source, file_descriptor), is_pid(Dest) -> - copy_opened_int(Source, Dest, Length, get_dtrace_utag()); + copy_opened_int(Source, Dest, Length, 0); %% Copy between open raw files, both handled by the same module copy_int(#file_descriptor{module = Module} = Source, #file_descriptor{module = Module} = Dest, @@ -743,14 +703,14 @@ copy_int(#file_descriptor{module = Module} = Source, %% Copy between open raw files of different modules copy_int(#file_descriptor{} = Source, #file_descriptor{} = Dest, Length) -> - copy_opened_int(Source, Dest, Length, get_dtrace_utag()); + copy_opened_int(Source, Dest, Length, 0); %% Copy between filenames, let the server do the copy copy_int({SourceName, SourceOpts}, {DestName, DestOpts}, Length) when is_list(SourceOpts), is_list(DestOpts) -> check_and_call(copy, [file_name(SourceName), SourceOpts, file_name(DestName), DestOpts, - Length, get_dtrace_utag()]); + Length]); %% Filename -> open file; must open Source and do client copy copy_int({SourceName, SourceOpts}, Dest, Length) when is_list(SourceOpts), is_pid(Dest); @@ -761,8 +721,7 @@ copy_int({SourceName, SourceOpts}, Dest, Length) Source -> case open(Source, [read | SourceOpts]) of {ok, Handle} -> - Result = copy_opened_int(Handle, Dest, Length, - get_dtrace_utag()), + Result = copy_opened_int(Handle, Dest, Length, 0), close(Handle), Result; {error, _} = Error -> @@ -779,8 +738,7 @@ copy_int(Source, {DestName, DestOpts}, Length) Dest -> case open(Dest, [write | DestOpts]) of {ok, Handle} -> - Result = copy_opened_int(Source, Handle, Length, - get_dtrace_utag()), + Result = copy_opened_int(Source, Handle, Length, 0), close(Handle), Result; {error, _} = Error -> @@ -815,46 +773,45 @@ copy_int(Source, Dest, Length) -> -copy_opened(Source, Dest, Length, DTraceUtag) +copy_opened(Source, Dest, Length) when is_integer(Length), Length >= 0; is_atom(Length) -> - copy_opened_int(Source, Dest, Length, DTraceUtag); -copy_opened(_, _, _, _) -> + copy_opened_int(Source, Dest, Length); +copy_opened(_, _, _) -> {error, badarg}. %% Here we know that Length is either an atom or an integer >= 0 %% (by the way, atoms > integers) -copy_opened_int(Source, Dest, Length, DTraceUtag) +copy_opened_int(Source, Dest, Length) when is_pid(Source), is_pid(Dest) -> - copy_opened_int(Source, Dest, Length, 0, DTraceUtag); -copy_opened_int(Source, Dest, Length, DTraceUtag) + copy_opened_int(Source, Dest, Length, 0); +copy_opened_int(Source, Dest, Length) when is_pid(Source), is_record(Dest, file_descriptor) -> - copy_opened_int(Source, Dest, Length, 0, DTraceUtag); -copy_opened_int(Source, Dest, Length, DTraceUtag) + copy_opened_int(Source, Dest, Length, 0); +copy_opened_int(Source, Dest, Length) when is_record(Source, file_descriptor), is_pid(Dest) -> - copy_opened_int(Source, Dest, Length, 0, DTraceUtag); -copy_opened_int(Source, Dest, Length, DTraceUtag) + copy_opened_int(Source, Dest, Length, 0); +copy_opened_int(Source, Dest, Length) when is_record(Source, file_descriptor), is_record(Dest, file_descriptor) -> - copy_opened_int(Source, Dest, Length, 0, DTraceUtag); -copy_opened_int(_, _, _, _) -> + copy_opened_int(Source, Dest, Length, 0); +copy_opened_int(_, _, _) -> {error, badarg}. %% Here we know that Source and Dest are handles to open files, Length is %% as above, and Copied is an integer >= 0 %% Copy loop in client process -copy_opened_int(_, _, Length, Copied, _DTraceUtag) - when Length =< 0 -> % atom() > integer() +copy_opened_int(_, _, Length, Copied) when Length =< 0 -> % atom() > integer() {ok, Copied}; -copy_opened_int(Source, Dest, Length, Copied, DTraceUtag) -> +copy_opened_int(Source, Dest, Length, Copied) -> N = if Length > 65536 -> 65536; true -> Length end, % atom() > integer() ! - case read(Source, N, DTraceUtag) of + case read(Source, N) of {ok, Data} -> M = if is_binary(Data) -> byte_size(Data); is_list(Data) -> length(Data) end, - case write(Dest, Data, DTraceUtag) of + case write(Dest, Data) of ok -> if M < N -> %% Got less than asked for - must be end of file @@ -864,8 +821,7 @@ copy_opened_int(Source, Dest, Length, Copied, DTraceUtag) -> NewLength = if is_atom(Length) -> Length; true -> Length-M end, - copy_opened_int(Source, Dest, NewLength, Copied+M, - DTraceUtag) + copy_opened_int(Source, Dest, NewLength, Copied+M) end; {error, _} = Error -> Error @@ -885,8 +841,6 @@ copy_opened_int(Source, Dest, Length, Copied, DTraceUtag) -> ipread_s32bu_p32bu(File, Pos, MaxSize) when is_pid(File) -> ipread_s32bu_p32bu_int(File, Pos, MaxSize); -ipread_s32bu_p32bu(#file_descriptor{module = prim_file = Module} = Handle, Pos, MaxSize) -> - Module:ipread_s32bu_p32bu(Handle, Pos, MaxSize, get_dtrace_utag()); ipread_s32bu_p32bu(#file_descriptor{module = Module} = Handle, Pos, MaxSize) -> Module:ipread_s32bu_p32bu(Handle, Pos, MaxSize); ipread_s32bu_p32bu(_, _, _) -> @@ -1467,7 +1421,10 @@ call(Command, Args) when is_list(Args) -> check_and_call(Command, Args) when is_list(Args) -> case check_args(Args) of ok -> - call(Command, Args); + X = erlang:spread_utag(true), + Y = call(Command, Args), + erlang:restore_utag(X), + Y; Error -> Error end. @@ -1502,6 +1459,3 @@ wait_file_reply(From, Ref) -> %% receive {'EXIT', From, _} -> ok after 0 -> ok end, {error, terminated} end. - -get_dtrace_utag() -> - dtrace:get_utag(). diff --git a/lib/kernel/src/file_io_server.erl b/lib/kernel/src/file_io_server.erl index cc0343031b..14da9c1a55 100644 --- a/lib/kernel/src/file_io_server.erl +++ b/lib/kernel/src/file_io_server.erl @@ -21,7 +21,7 @@ %% A simple file server for io to one file instance per server instance. -export([format_error/1]). --export([start/4, start_link/4]). +-export([start/3, start_link/3]). -export([count_and_find/3]). @@ -43,18 +43,18 @@ format_error({_Line, Mod, Reason}) -> format_error(ErrorId) -> erl_posix_msg:message(ErrorId). -start(Owner, FileName, ModeList, DTraceUtag) +start(Owner, FileName, ModeList) when is_pid(Owner), (is_list(FileName) orelse is_binary(FileName)), is_list(ModeList) -> - do_start(spawn, Owner, FileName, ModeList, DTraceUtag). + do_start(spawn, Owner, FileName, ModeList). -start_link(Owner, FileName, ModeList, DTraceUtag) +start_link(Owner, FileName, ModeList) when is_pid(Owner), (is_list(FileName) orelse is_binary(FileName)), is_list(ModeList) -> - do_start(spawn_link, Owner, FileName, ModeList, DTraceUtag). + do_start(spawn_link, Owner, FileName, ModeList). %%%----------------------------------------------------------------- %%% Server starter, dispatcher and helpers -do_start(Spawn, Owner, FileName, ModeList, DTraceUtag) -> +do_start(Spawn, Owner, FileName, ModeList) -> Self = self(), Ref = make_ref(), Pid = @@ -63,12 +63,11 @@ do_start(Spawn, Owner, FileName, ModeList, DTraceUtag) -> %% process_flag(trap_exit, true), case parse_options(ModeList) of {ReadMode, UnicodeMode, Opts} -> - case ?PRIM_FILE:open(FileName, Opts, DTraceUtag) of + case ?PRIM_FILE:open(FileName, Opts) of {error, Reason} = Error -> Self ! {Ref, Error}, exit(Reason); {ok, Handle} -> - put(dtrace_utag, DTraceUtag), % TODO: API? %% XXX must I handle R6 nodes here? M = erlang:monitor(process, Owner), Self ! {Ref, ok}, diff --git a/lib/kernel/src/file_server.erl b/lib/kernel/src/file_server.erl index 82adc45795..fc6cd823c9 100644 --- a/lib/kernel/src/file_server.erl +++ b/lib/kernel/src/file_server.erl @@ -76,7 +76,6 @@ stop() -> init([]) -> process_flag(trap_exit, true), - put(dtrace_utag, atom_to_list(?FILE_SERVER)), case ?PRIM_FILE:start() of {ok, Handle} -> ets:new(?FILE_IO_SERVER_TABLE, [named_table]), @@ -100,9 +99,9 @@ init([]) -> {'reply', 'eof' | 'ok' | {'error', term()} | {'ok', term()}, state()} | {'stop', 'normal', 'stopped', state()}. -handle_call({open, Name, ModeList, DTraceUtag}, {Pid, _Tag} = _From, Handle) +handle_call({open, Name, ModeList}, {Pid, _Tag} = _From, Handle) when is_list(ModeList) -> - Child = ?FILE_IO_SERVER:start_link(Pid, Name, ModeList, DTraceUtag), + Child = ?FILE_IO_SERVER:start_link(Pid, Name, ModeList), case Child of {ok, P} when is_pid(P) -> ets:insert(?FILE_IO_SERVER_TABLE, {P, Name}); @@ -111,86 +110,87 @@ handle_call({open, Name, ModeList, DTraceUtag}, {Pid, _Tag} = _From, Handle) end, {reply, Child, Handle}; -handle_call({open, _Name, _Mode, _DTraceUtag}, _From, Handle) -> +handle_call({open, _Name, _Mode}, _From, Handle) -> {reply, {error, einval}, Handle}; -handle_call({read_file, Name, DTraceUtag}, _From, Handle) -> - {reply, ?PRIM_FILE:read_file(Name, DTraceUtag), Handle}; +handle_call({read_file, Name}, _From, Handle) -> + {reply, ?PRIM_FILE:read_file(Name), Handle}; -handle_call({write_file, Name, Bin, DTraceUtag}, _From, Handle) -> - {reply, ?PRIM_FILE:write_file(Name, Bin, DTraceUtag), Handle}; +handle_call({write_file, Name, Bin}, _From, Handle) -> + {reply, ?PRIM_FILE:write_file(Name, Bin), Handle}; -handle_call({set_cwd, Name, DTraceUtag}, _From, Handle) -> - {reply, ?PRIM_FILE:set_cwd(Handle, Name, DTraceUtag), Handle}; +handle_call({set_cwd, Name}, _From, Handle) -> + {reply, ?PRIM_FILE:set_cwd(Handle, Name), Handle}; -handle_call({delete, Name, DTraceUtag}, _From, Handle) -> - {reply, ?PRIM_FILE:delete(Handle, Name, DTraceUtag), Handle}; +handle_call({delete, Name}, _From, Handle) -> + {reply, ?PRIM_FILE:delete(Handle, Name), Handle}; -handle_call({rename, Fr, To, DTraceUtag}, _From, Handle) -> - {reply, ?PRIM_FILE:rename(Handle, Fr, To, DTraceUtag), Handle}; +handle_call({rename, Fr, To}, _From, Handle) -> + {reply, ?PRIM_FILE:rename(Handle, Fr, To), Handle}; -handle_call({make_dir, Name, DTraceUtag}, _From, Handle) -> - {reply, ?PRIM_FILE:make_dir(Handle, Name, DTraceUtag), Handle}; +handle_call({make_dir, Name}, _From, Handle) -> + {reply, ?PRIM_FILE:make_dir(Handle, Name), Handle}; -handle_call({del_dir, Name, DTraceUtag}, _From, Handle) -> - {reply, ?PRIM_FILE:del_dir(Handle, Name, DTraceUtag), Handle}; +handle_call({del_dir, Name}, _From, Handle) -> + {reply, ?PRIM_FILE:del_dir(Handle, Name), Handle}; -handle_call({list_dir, Name, DTraceUtag}, _From, Handle) -> - {reply, ?PRIM_FILE:list_dir(Handle, Name, DTraceUtag), Handle}; +handle_call({list_dir, Name}, _From, Handle) -> + {reply, ?PRIM_FILE:list_dir(Handle, Name), Handle}; handle_call(get_cwd, _From, Handle) -> - {reply, ?PRIM_FILE:get_cwd(Handle, no_drive, "TODO-fixme"), Handle}; -handle_call({get_cwd, no_drive, DTraceUtag}, _From, Handle) -> - {reply, ?PRIM_FILE:get_cwd(Handle, no_drive, DTraceUtag), Handle}; -handle_call({get_cwd, Name, DTraceUtag}, _From, Handle) -> - {reply, ?PRIM_FILE:get_cwd(Handle, Name, DTraceUtag), Handle}; + {reply, ?PRIM_FILE:get_cwd(Handle), Handle}; +handle_call({get_cwd}, _From, Handle) -> + {reply, ?PRIM_FILE:get_cwd(Handle), Handle}; +handle_call({get_cwd, Name}, _From, Handle) -> + {reply, ?PRIM_FILE:get_cwd(Handle, Name), Handle}; -handle_call({read_file_info, Name, DTraceUtag}, _From, Handle) -> - {reply, ?PRIM_FILE:read_file_info(Handle, Name, [], DTraceUtag), Handle}; -handle_call({read_file_info, Name, Opts, DTraceUtag}, _From, Handle) -> - {reply, ?PRIM_FILE:read_file_info(Handle, Name, Opts, DTraceUtag), Handle}; +handle_call({read_file_info, Name}, _From, Handle) -> + {reply, ?PRIM_FILE:read_file_info(Handle, Name), Handle}; -handle_call({altname, Name, DTraceUtag}, _From, Handle) -> - {reply, ?PRIM_FILE:altname(Handle, Name, DTraceUtag), Handle}; +handle_call({read_file_info, Name, Opts}, _From, Handle) -> + {reply, ?PRIM_FILE:read_file_info(Handle, Name, Opts), Handle}; -handle_call({write_file_info, Name, Info, DTraceUtag}, _From, Handle) -> - {reply, ?PRIM_FILE:write_file_info(Handle, Name, Info, [], DTraceUtag), Handle}; -handle_call({write_file_info, Name, Info, Opts, DTraceUtag}, _From, Handle) -> - {reply, ?PRIM_FILE:write_file_info(Handle, Name, Info, Opts, DTraceUtag), Handle}; +handle_call({altname, Name}, _From, Handle) -> + {reply, ?PRIM_FILE:altname(Handle, Name), Handle}; -handle_call({read_link_info, Name, DTraceUtag}, _From, Handle) -> - {reply, ?PRIM_FILE:read_link_info(Handle, Name, [], DTraceUtag), Handle}; -handle_call({read_link_info, Name, Opts, DTraceUtag}, _From, Handle) -> - {reply, ?PRIM_FILE:read_link_info(Handle, Name, Opts, DTraceUtag), Handle}; +handle_call({write_file_info, Name, Info}, _From, Handle) -> + {reply, ?PRIM_FILE:write_file_info(Handle, Name, Info), Handle}; -handle_call({read_link, Name, DTraceUtag}, _From, Handle) -> - {reply, ?PRIM_FILE:read_link(Handle, Name, DTraceUtag), Handle}; +handle_call({write_file_info, Name, Info, Opts}, _From, Handle) -> + {reply, ?PRIM_FILE:write_file_info(Handle, Name, Info, Opts), Handle}; -handle_call({make_link, Old, New, DTraceUtag}, _From, Handle) -> - {reply, ?PRIM_FILE:make_link(Handle, Old, New, DTraceUtag), Handle}; +handle_call({read_link_info, Name}, _From, Handle) -> + {reply, ?PRIM_FILE:read_link_info(Handle, Name), Handle}; -handle_call({make_symlink, Old, New, DTraceUtag}, _From, Handle) -> - {reply, ?PRIM_FILE:make_symlink(Handle, Old, New, DTraceUtag), Handle}; +handle_call({read_link_info, Name, Opts}, _From, Handle) -> + {reply, ?PRIM_FILE:read_link_info(Handle, Name, Opts), Handle}; -handle_call({copy, SourceName, SourceOpts, DestName, DestOpts, Length, DTraceUtag}, +handle_call({read_link, Name}, _From, Handle) -> + {reply, ?PRIM_FILE:read_link(Handle, Name), Handle}; + +handle_call({make_link, Old, New}, _From, Handle) -> + {reply, ?PRIM_FILE:make_link(Handle, Old, New), Handle}; + +handle_call({make_symlink, Old, New}, _From, Handle) -> + {reply, ?PRIM_FILE:make_symlink(Handle, Old, New), Handle}; + +handle_call({copy, SourceName, SourceOpts, DestName, DestOpts, Length}, _From, Handle) -> Reply = - case ?PRIM_FILE:open(SourceName, [read, binary | SourceOpts], - DTraceUtag) of + case ?PRIM_FILE:open(SourceName, [read, binary | SourceOpts]) of {ok, Source} -> SourceReply = case ?PRIM_FILE:open(DestName, - [write, binary | DestOpts], - DTraceUtag) of + [write, binary | DestOpts]) of {ok, Dest} -> DestReply = - ?PRIM_FILE:copy(Source, Dest, Length, DTraceUtag), - ?PRIM_FILE:close(Dest, DTraceUtag), + ?PRIM_FILE:copy(Source, Dest, Length), + ?PRIM_FILE:close(Dest), DestReply; {error, _} = Error -> Error end, - ?PRIM_FILE:close(Source, DTraceUtag), + ?PRIM_FILE:close(Source), SourceReply; {error, _} = Error -> Error diff --git a/lib/kernel/test/prim_file_SUITE.erl b/lib/kernel/test/prim_file_SUITE.erl index 9575762b12..3e2202922c 100644 --- a/lib/kernel/test/prim_file_SUITE.erl +++ b/lib/kernel/test/prim_file_SUITE.erl @@ -70,7 +70,7 @@ %% compile time. -define(PRIM_FILE_call(F, H, A), case H of - [] -> apply(?PRIM_FILE, F, A -- ["utag"]); + [] -> apply(?PRIM_FILE, F, A); _ -> apply(?PRIM_FILE, F, [H | A]) end). @@ -255,31 +255,31 @@ make_del_dir(Config, Handle, Suffix) -> ?line NewDir = filename:join(RootDir, atom_to_list(?MODULE) ++"_mk-dir"++Suffix), - ?line ok = ?PRIM_FILE_call(make_dir, Handle, [NewDir, "utag"]), - ?line {error, eexist} = ?PRIM_FILE_call(make_dir, Handle, [NewDir, "utag"]), - ?line ok = ?PRIM_FILE_call(del_dir, Handle, [NewDir, "utag"]), - ?line {error, enoent} = ?PRIM_FILE_call(del_dir, Handle, [NewDir, "utag"]), + ?line ok = ?PRIM_FILE_call(make_dir, Handle, [NewDir]), + ?line {error, eexist} = ?PRIM_FILE_call(make_dir, Handle, [NewDir]), + ?line ok = ?PRIM_FILE_call(del_dir, Handle, [NewDir]), + ?line {error, enoent} = ?PRIM_FILE_call(del_dir, Handle, [NewDir]), % Make sure we are not in a directory directly under test_server % as that would result in eacess errors when trying to delere '..', % because there are processes having that directory as current. - ?line ok = ?PRIM_FILE_call(make_dir, Handle, [NewDir, "utag"]), + ?line ok = ?PRIM_FILE_call(make_dir, Handle, [NewDir]), ?line {ok, CurrentDir} = ?PRIM_FILE_call(get_cwd, Handle, []), - ?line ok = ?PRIM_FILE_call(set_cwd, Handle, [NewDir, "utag"]), + ?line ok = ?PRIM_FILE_call(set_cwd, Handle, [NewDir]), try %% Check that we get an error when trying to create... %% a deep directory ?line NewDir2 = filename:join(RootDir, atom_to_list(?MODULE) ++"_mk-dir-noexist/foo"), - ?line {error, enoent} = ?PRIM_FILE_call(make_dir, Handle, [NewDir2, "utag"]), + ?line {error, enoent} = ?PRIM_FILE_call(make_dir, Handle, [NewDir2]), %% a nameless directory - ?line {error, enoent} = ?PRIM_FILE_call(make_dir, Handle, ["", "utag"]), + ?line {error, enoent} = ?PRIM_FILE_call(make_dir, Handle, [""]), %% a directory with illegal name - ?line {error, badarg} = ?PRIM_FILE_call(make_dir, Handle, ['mk-dir', "utag"]), + ?line {error, badarg} = ?PRIM_FILE_call(make_dir, Handle, ['mk-dir']), %% a directory with illegal name, even if it's a (bad) list - ?line {error, badarg} = ?PRIM_FILE_call(make_dir, Handle, [[1,2,3,{}], "utag"]), + ?line {error, badarg} = ?PRIM_FILE_call(make_dir, Handle, [[1,2,3,{}]]), %% Maybe this isn't an error, exactly, but worth mentioning anyway: %% ok = ?PRIM_FILE:make_dir([$f,$o,$o,0,$b,$a,$r])), @@ -292,17 +292,17 @@ make_del_dir(Config, Handle, Suffix) -> %% Try deleting some bad directories %% Deleting the parent directory to the current, sounds dangerous, huh? %% Don't worry ;-) the parent directory should never be empty, right? - ?line case ?PRIM_FILE_call(del_dir, Handle, ["..", "utag"]) of + ?line case ?PRIM_FILE_call(del_dir, Handle, [".."]) of {error, eexist} -> ok; {error, eacces} -> ok; %OpenBSD {error, einval} -> ok %FreeBSD end, - ?line {error, enoent} = ?PRIM_FILE_call(del_dir, Handle, ["", "utag"]), - ?line {error, badarg} = ?PRIM_FILE_call(del_dir, Handle, [[3,2,1,{}], "utag"]), + ?line {error, enoent} = ?PRIM_FILE_call(del_dir, Handle, [""]), + ?line {error, badarg} = ?PRIM_FILE_call(del_dir, Handle, [[3,2,1,{}]]), ?line test_server:timetrap_cancel(Dog) after - ?line ok = ?PRIM_FILE_call(set_cwd, Handle, [CurrentDir, "utag"]) + ?line ok = ?PRIM_FILE_call(set_cwd, Handle, [CurrentDir]) end, ok. @@ -324,7 +324,7 @@ cur_dir_0(Config, Handle) -> %% Find out the current dir, and cd to it ;-) ?line {ok,BaseDir} = ?PRIM_FILE_call(get_cwd, Handle, []), ?line Dir1 = BaseDir ++ "", %% Check that it's a string - ?line ok = ?PRIM_FILE_call(set_cwd, Handle, [Dir1, "utag"]), + ?line ok = ?PRIM_FILE_call(set_cwd, Handle, [Dir1]), ?line DirName = atom_to_list(?MODULE) ++ case Handle of [] -> @@ -336,40 +336,40 @@ cur_dir_0(Config, Handle) -> %% Make a new dir, and cd to that ?line RootDir = ?config(priv_dir,Config), ?line NewDir = filename:join(RootDir, DirName), - ?line ok = ?PRIM_FILE_call(make_dir, Handle, [NewDir, "utag"]), + ?line ok = ?PRIM_FILE_call(make_dir, Handle, [NewDir]), ?line io:format("cd to ~s",[NewDir]), - ?line ok = ?PRIM_FILE_call(set_cwd, Handle, [NewDir, "utag"]), + ?line ok = ?PRIM_FILE_call(set_cwd, Handle, [NewDir]), %% Create a file in the new current directory, and check that it %% really is created there ?line UncommonName = "uncommon.fil", ?line {ok,Fd} = ?PRIM_FILE:open(UncommonName, [read, write]), ?line ok = ?PRIM_FILE:close(Fd), - ?line {ok,NewDirFiles} = ?PRIM_FILE_call(list_dir, Handle, [".", "utag"]), + ?line {ok,NewDirFiles} = ?PRIM_FILE_call(list_dir, Handle, ["."]), ?line true = lists:member(UncommonName,NewDirFiles), %% Delete the directory and return to the old current directory %% and check that the created file isn't there (too!) ?line expect({error, einval}, {error, eacces}, {error, eexist}, - ?PRIM_FILE_call(del_dir, Handle, [NewDir, "utag"])), - ?line ?PRIM_FILE_call(delete, Handle, [UncommonName, "utag"]), - ?line {ok,[]} = ?PRIM_FILE_call(list_dir, Handle, [".", "utag"]), - ?line ok = ?PRIM_FILE_call(set_cwd, Handle, [Dir1, "utag"]), + ?PRIM_FILE_call(del_dir, Handle, [NewDir])), + ?line ?PRIM_FILE_call(delete, Handle, [UncommonName]), + ?line {ok,[]} = ?PRIM_FILE_call(list_dir, Handle, ["."]), + ?line ok = ?PRIM_FILE_call(set_cwd, Handle, [Dir1]), ?line io:format("cd back to ~s",[Dir1]), - ?line ok = ?PRIM_FILE_call(del_dir, Handle, [NewDir, "utag"]), - ?line {error, enoent} = ?PRIM_FILE_call(set_cwd, Handle, [NewDir, "utag"]), - ?line ok = ?PRIM_FILE_call(set_cwd, Handle, [Dir1, "utag"]), + ?line ok = ?PRIM_FILE_call(del_dir, Handle, [NewDir]), + ?line {error, enoent} = ?PRIM_FILE_call(set_cwd, Handle, [NewDir]), + ?line ok = ?PRIM_FILE_call(set_cwd, Handle, [Dir1]), ?line io:format("cd back to ~s",[Dir1]), - ?line {ok,OldDirFiles} = ?PRIM_FILE_call(list_dir, Handle, [".", "utag"]), + ?line {ok,OldDirFiles} = ?PRIM_FILE_call(list_dir, Handle, ["."]), ?line false = lists:member(UncommonName,OldDirFiles), %% Try doing some bad things ?line {error, badarg} = - ?PRIM_FILE_call(set_cwd, Handle, [{foo,bar}, "utag"]), + ?PRIM_FILE_call(set_cwd, Handle, [{foo,bar}]), ?line {error, enoent} = - ?PRIM_FILE_call(set_cwd, Handle, ["", "utag"]), + ?PRIM_FILE_call(set_cwd, Handle, [""]), ?line {error, enoent} = - ?PRIM_FILE_call(set_cwd, Handle, [".......a......", "utag"]), + ?PRIM_FILE_call(set_cwd, Handle, [".......a......"]), ?line {ok,BaseDir} = ?PRIM_FILE_call(get_cwd, Handle, []), %% Still there? @@ -405,10 +405,10 @@ cur_dir_1(Config, Handle) -> ?line case os:type() of {unix, _} -> ?line {error, enotsup} = - ?PRIM_FILE_call(get_cwd, Handle, ["d:", "utag"]); + ?PRIM_FILE_call(get_cwd, Handle, ["d:"]); vxworks -> ?line {error, enotsup} = - ?PRIM_FILE_call(get_cwd, Handle, ["d:", "utag"]); + ?PRIM_FILE_call(get_cwd, Handle, ["d:"]); {win32, _} -> win_cur_dir_1(Config, Handle) end, @@ -422,7 +422,7 @@ win_cur_dir_1(_Config, Handle) -> %% and try to get current directory for that drive. ?line [Drive, $:|_] = BaseDir, - ?line {ok, BaseDir} = ?PRIM_FILE_call(get_cwd, Handle, [[Drive, $:], "utag"]), + ?line {ok, BaseDir} = ?PRIM_FILE_call(get_cwd, Handle, [[Drive, $:]]), io:format("BaseDir = ~s\n", [BaseDir]), %% Unfortunately, there is no way to move away from the @@ -1027,7 +1027,7 @@ file_write_file_info(Config, Handle, Suffix) -> ?line ok = ?PRIM_FILE:write_file(Name, "hello"), ?line Time = {{1997, 01, 02}, {12, 35, 42}}, ?line Info = #file_info{mode=8#400, atime=Time, mtime=Time, ctime=Time}, - ?line ok = ?PRIM_FILE_call(write_file_info, Handle, [Name, Info, "utag"]), + ?line ok = ?PRIM_FILE_call(write_file_info, Handle, [Name, Info]), %% Read back the times. @@ -1050,12 +1050,12 @@ file_write_file_info(Config, Handle, Suffix) -> %% Make the file writable again. ?line ?PRIM_FILE_call(write_file_info, Handle, - [Name, #file_info{mode=8#600}, "utag"]), + [Name, #file_info{mode=8#600}]), ?line ok = ?PRIM_FILE:write_file(Name, "hello again"), %% And unwritable. ?line ?PRIM_FILE_call(write_file_info, Handle, - [Name, #file_info{mode=8#400}, "utag"]), + [Name, #file_info{mode=8#400}]), ?line {error, eacces} = ?PRIM_FILE:write_file(Name, "hello again"), %% Write the times again. @@ -1063,7 +1063,7 @@ file_write_file_info(Config, Handle, Suffix) -> ?line NewTime = {{1997, 02, 15}, {13, 18, 20}}, ?line NewInfo = #file_info{atime=NewTime, mtime=NewTime, ctime=NewTime}, - ?line ok = ?PRIM_FILE_call(write_file_info, Handle, [Name, NewInfo, "utag"]), + ?line ok = ?PRIM_FILE_call(write_file_info, Handle, [Name, NewInfo]), ?line {ok, ActualInfo2} = ?PRIM_FILE_call(read_file_info, Handle, [Name]), ?line #file_info{atime=NewActAtime, mtime=NewTime, @@ -1081,7 +1081,7 @@ file_write_file_info(Config, Handle, Suffix) -> %% Make the file writeable again, so that we can remove the %% test suites ... :-) ?line ?PRIM_FILE_call(write_file_info, Handle, - [Name, #file_info{mode=8#600}, "utag"]), + [Name, #file_info{mode=8#600}]), ?line test_server:timetrap_cancel(Dog), ok. @@ -1390,11 +1390,11 @@ delete(Config, Handle, Suffix) -> %% Check that the file is readable ?line {ok, Fd2} = ?PRIM_FILE:open(Name, [read]), ?line ok = ?PRIM_FILE:close(Fd2), - ?line ok = ?PRIM_FILE_call(delete, Handle, [Name, "utag"]), + ?line ok = ?PRIM_FILE_call(delete, Handle, [Name]), %% Check that the file is not readable anymore ?line {error, _} = ?PRIM_FILE:open(Name, [read]), %% Try deleting a nonexistent file - ?line {error, enoent} = ?PRIM_FILE_call(delete, Handle, [Name, "utag"]), + ?line {error, enoent} = ?PRIM_FILE_call(delete, Handle, [Name]), ?line test_server:timetrap_cancel(Dog), ok. @@ -1895,14 +1895,14 @@ make_link(Config, Handle, Suffix) -> ?line NewDir = filename:join(RootDir, atom_to_list(?MODULE) ++"_make_link"++Suffix), - ?line ok = ?PRIM_FILE_call(make_dir, Handle, [NewDir, "utag"]), + ?line ok = ?PRIM_FILE_call(make_dir, Handle, [NewDir]), ?line Name = filename:join(NewDir, "a_file"), ?line ok = ?PRIM_FILE:write_file(Name, "some contents\n"), ?line Alias = filename:join(NewDir, "an_alias"), ?line Result = - case ?PRIM_FILE_call(make_link, Handle, [Name, Alias, "utag"]) of + case ?PRIM_FILE_call(make_link, Handle, [Name, Alias]) of {error, enotsup} -> {skipped, "Links not supported on this platform"}; ok -> @@ -1913,12 +1913,12 @@ make_link(Config, Handle, Suffix) -> %% since they are not used on symbolic links. ?line {ok, Info} = - ?PRIM_FILE_call(read_link_info, Handle, [Name, "utag"]), + ?PRIM_FILE_call(read_link_info, Handle, [Name]), ?line {ok, Info} = - ?PRIM_FILE_call(read_link_info, Handle, [Alias, "utag"]), + ?PRIM_FILE_call(read_link_info, Handle, [Alias]), ?line #file_info{links = 2, type = regular} = Info, ?line {error, eexist} = - ?PRIM_FILE_call(make_link, Handle, [Name, Alias, "utag"]), + ?PRIM_FILE_call(make_link, Handle, [Name, Alias]), ok end, @@ -1956,30 +1956,30 @@ symlinks(Config, Handle, Suffix) -> ?line NewDir = filename:join(RootDir, atom_to_list(?MODULE) ++"_make_symlink"++Suffix), - ?line ok = ?PRIM_FILE_call(make_dir, Handle, [NewDir, "utag"]), + ?line ok = ?PRIM_FILE_call(make_dir, Handle, [NewDir]), ?line Name = filename:join(NewDir, "a_plain_file"), ?line ok = ?PRIM_FILE:write_file(Name, "some stupid content\n"), ?line Alias = filename:join(NewDir, "a_symlink_alias"), ?line Result = - case ?PRIM_FILE_call(make_symlink, Handle, [Name, Alias, "utag"]) of + case ?PRIM_FILE_call(make_symlink, Handle, [Name, Alias]) of {error, enotsup} -> {skipped, "Links not supported on this platform"}; ok -> ?line {ok, Info1} = - ?PRIM_FILE_call(read_file_info, Handle, [Name, "utag"]), + ?PRIM_FILE_call(read_file_info, Handle, [Name]), ?line {ok, Info1} = - ?PRIM_FILE_call(read_file_info, Handle, [Alias, "utag"]), + ?PRIM_FILE_call(read_file_info, Handle, [Alias]), ?line {ok, Info1} = - ?PRIM_FILE_call(read_link_info, Handle, [Name, "utag"]), + ?PRIM_FILE_call(read_link_info, Handle, [Name]), ?line #file_info{links = 1, type = regular} = Info1, ?line {ok, Info2} = - ?PRIM_FILE_call(read_link_info, Handle, [Alias, "utag"]), + ?PRIM_FILE_call(read_link_info, Handle, [Alias]), ?line #file_info{links=1, type=symlink} = Info2, ?line {ok, Name} = - ?PRIM_FILE_call(read_link, Handle, [Alias, "utag"]), + ?PRIM_FILE_call(read_link, Handle, [Alias]), ok end, @@ -2003,7 +2003,7 @@ list_dir_limit(Config) when is_list(Config) -> ?line NewDir = filename:join(RootDir, atom_to_list(?MODULE)++"_list_dir_limit"), ?line {ok, Handle1} = ?PRIM_FILE:start(), - ?line ok = ?PRIM_FILE_call(make_dir, Handle1, [NewDir, "utag"]), + ?line ok = ?PRIM_FILE_call(make_dir, Handle1, [NewDir]), Ref = erlang:start_timer(MaxTime*1000, self(), []), ?line Result = list_dir_limit_loop(NewDir, Handle1, Ref, MaxNumber, 0), ?line Time = case erlang:cancel_timer(Ref) of @@ -2054,7 +2054,7 @@ list_dir_limit_loop(Dir, Handle, Ref, N, Cnt) -> end. list_dir_check(Dir, Handle, Cnt) -> - case ?PRIM_FILE:list_dir(Handle, Dir, "utag") of + case ?PRIM_FILE:list_dir(Handle, Dir) of {ok, ListDir} -> case length(ListDir) of Cnt -> -- cgit v1.2.3 From db4ddca4d9709965121fba9a1f9cc68226f35a0c Mon Sep 17 00:00:00 2001 From: Patrik Nyblom Date: Mon, 5 Mar 2012 17:29:03 +0100 Subject: Correct some errors in the user tag spreading --- lib/dtrace/examples/user-probe.systemtap | 4 ++-- lib/kernel/src/file.erl | 11 ++++++----- lib/kernel/src/file_io_server.erl | 3 +++ 3 files changed, 11 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/dtrace/examples/user-probe.systemtap b/lib/dtrace/examples/user-probe.systemtap index c80bf94697..84a45709e8 100644 --- a/lib/dtrace/examples/user-probe.systemtap +++ b/lib/dtrace/examples/user-probe.systemtap @@ -28,12 +28,12 @@ * environment. */ -probe process("dtrace.so").mark("user_trace-s1") +probe process("dyntrace.so").mark("user_trace-s1") { printf("%s\n", user_string($arg1)); } -probe process("dtrace.so").mark("user_trace-i4s4") +probe process("dyntrace.so").mark("user_trace-i4s4") { printf("%s %s %d %d %d %d '%s' '%s' '%s' '%s'\n", user_string($arg1), diff --git a/lib/kernel/src/file.erl b/lib/kernel/src/file.erl index 3a618976f5..b281151778 100644 --- a/lib/kernel/src/file.erl +++ b/lib/kernel/src/file.erl @@ -1416,15 +1416,16 @@ mode_list(_) -> %% Functions for communicating with the file server call(Command, Args) when is_list(Args) -> - gen_server:call(?FILE_SERVER, list_to_tuple([Command | Args]), infinity). + X = erlang:spread_utag(true), + Y = gen_server:call(?FILE_SERVER, list_to_tuple([Command | Args]), + infinity), + erlang:restore_utag(X), + Y. check_and_call(Command, Args) when is_list(Args) -> case check_args(Args) of ok -> - X = erlang:spread_utag(true), - Y = call(Command, Args), - erlang:restore_utag(X), - Y; + call(Command, Args); Error -> Error end. diff --git a/lib/kernel/src/file_io_server.erl b/lib/kernel/src/file_io_server.erl index 14da9c1a55..6369a5250c 100644 --- a/lib/kernel/src/file_io_server.erl +++ b/lib/kernel/src/file_io_server.erl @@ -57,9 +57,11 @@ start_link(Owner, FileName, ModeList) do_start(Spawn, Owner, FileName, ModeList) -> Self = self(), Ref = make_ref(), + Utag = erlang:spread_utag(true), Pid = erlang:Spawn( fun() -> + erlang:restore_utag(Utag), %% process_flag(trap_exit, true), case parse_options(ModeList) of {ReadMode, UnicodeMode, Opts} -> @@ -84,6 +86,7 @@ do_start(Spawn, Owner, FileName, ModeList) -> exit(Reason1) end end), + erlang:restore_utag(Utag), Mref = erlang:monitor(process, Pid), receive {Ref, {error, _Reason} = Error} -> -- cgit v1.2.3 From 0889c9860f5d07fc87db6bfc287b9a3ddc764aa1 Mon Sep 17 00:00:00 2001 From: Patrik Nyblom Date: Thu, 8 Mar 2012 16:05:16 +0100 Subject: Move dtrace erlang code and NIF into runtime_tools Also make dyntrace NIF's load in on_load instead of init/0 --- lib/Makefile | 2 +- lib/dtrace/Makefile | 36 --- lib/dtrace/c_src/Makefile | 4 - lib/dtrace/c_src/Makefile.in | 151 ----------- lib/dtrace/c_src/dtrace.c | 168 ------------- lib/dtrace/c_src/dtrace_user.d | 53 ---- lib/dtrace/ebin/.placeholder | 0 lib/dtrace/examples/dist.d | 62 ----- lib/dtrace/examples/dist.systemtap | 76 ------ lib/dtrace/examples/driver1.d | 114 --------- lib/dtrace/examples/driver1.systemtap | 125 --------- lib/dtrace/examples/efile_drv.d | 104 -------- lib/dtrace/examples/efile_drv.systemtap | 112 --------- lib/dtrace/examples/function-calls.d | 51 ---- lib/dtrace/examples/function-calls.systemtap | 61 ----- lib/dtrace/examples/garbage-collection.d | 39 --- lib/dtrace/examples/garbage-collection.systemtap | 49 ---- lib/dtrace/examples/memory1.d | 41 --- lib/dtrace/examples/memory1.systemtap | 51 ---- lib/dtrace/examples/messages.d | 94 ------- lib/dtrace/examples/messages.systemtap | 87 ------- lib/dtrace/examples/port1.d | 142 ----------- lib/dtrace/examples/port1.systemtap | 152 ----------- lib/dtrace/examples/process-scheduling.d | 35 --- lib/dtrace/examples/process-scheduling.systemtap | 45 ---- lib/dtrace/examples/spawn-exit.d | 41 --- lib/dtrace/examples/spawn-exit.systemtap | 51 ---- lib/dtrace/examples/user-probe.d | 36 --- lib/dtrace/examples/user-probe.systemtap | 46 ---- lib/dtrace/src/Makefile | 102 -------- lib/dtrace/src/dtrace.app.src | 27 -- lib/dtrace/src/dtrace.appup.src | 19 -- lib/dtrace/src/dtrace.erl | 247 ------------------ lib/dtrace/vsn.mk | 1 - lib/runtime_tools/c_src/Makefile.in | 79 +++++- lib/runtime_tools/c_src/dtrace_user.d | 53 ++++ lib/runtime_tools/c_src/dyntrace.c | 172 +++++++++++++ lib/runtime_tools/examples/dist.d | 62 +++++ lib/runtime_tools/examples/dist.systemtap | 76 ++++++ lib/runtime_tools/examples/driver1.d | 114 +++++++++ lib/runtime_tools/examples/driver1.systemtap | 125 +++++++++ lib/runtime_tools/examples/efile_drv.d | 104 ++++++++ lib/runtime_tools/examples/efile_drv.systemtap | 112 +++++++++ lib/runtime_tools/examples/function-calls.d | 51 ++++ .../examples/function-calls.systemtap | 61 +++++ lib/runtime_tools/examples/garbage-collection.d | 39 +++ .../examples/garbage-collection.systemtap | 49 ++++ lib/runtime_tools/examples/memory1.d | 41 +++ lib/runtime_tools/examples/memory1.systemtap | 51 ++++ lib/runtime_tools/examples/messages.d | 94 +++++++ lib/runtime_tools/examples/messages.systemtap | 87 +++++++ lib/runtime_tools/examples/port1.d | 142 +++++++++++ lib/runtime_tools/examples/port1.systemtap | 152 +++++++++++ lib/runtime_tools/examples/process-scheduling.d | 35 +++ .../examples/process-scheduling.systemtap | 45 ++++ lib/runtime_tools/examples/spawn-exit.d | 41 +++ lib/runtime_tools/examples/spawn-exit.systemtap | 51 ++++ lib/runtime_tools/examples/user-probe.d | 36 +++ lib/runtime_tools/examples/user-probe.systemtap | 46 ++++ lib/runtime_tools/src/Makefile | 10 +- lib/runtime_tools/src/dyntrace.erl | 279 +++++++++++++++++++++ lib/runtime_tools/src/runtime_tools.app.src | 2 +- 62 files changed, 2202 insertions(+), 2431 deletions(-) delete mode 100644 lib/dtrace/Makefile delete mode 100644 lib/dtrace/c_src/Makefile delete mode 100644 lib/dtrace/c_src/Makefile.in delete mode 100644 lib/dtrace/c_src/dtrace.c delete mode 100644 lib/dtrace/c_src/dtrace_user.d delete mode 100644 lib/dtrace/ebin/.placeholder delete mode 100644 lib/dtrace/examples/dist.d delete mode 100644 lib/dtrace/examples/dist.systemtap delete mode 100644 lib/dtrace/examples/driver1.d delete mode 100644 lib/dtrace/examples/driver1.systemtap delete mode 100644 lib/dtrace/examples/efile_drv.d delete mode 100644 lib/dtrace/examples/efile_drv.systemtap delete mode 100644 lib/dtrace/examples/function-calls.d delete mode 100644 lib/dtrace/examples/function-calls.systemtap delete mode 100644 lib/dtrace/examples/garbage-collection.d delete mode 100644 lib/dtrace/examples/garbage-collection.systemtap delete mode 100644 lib/dtrace/examples/memory1.d delete mode 100644 lib/dtrace/examples/memory1.systemtap delete mode 100644 lib/dtrace/examples/messages.d delete mode 100644 lib/dtrace/examples/messages.systemtap delete mode 100644 lib/dtrace/examples/port1.d delete mode 100644 lib/dtrace/examples/port1.systemtap delete mode 100644 lib/dtrace/examples/process-scheduling.d delete mode 100644 lib/dtrace/examples/process-scheduling.systemtap delete mode 100644 lib/dtrace/examples/spawn-exit.d delete mode 100644 lib/dtrace/examples/spawn-exit.systemtap delete mode 100644 lib/dtrace/examples/user-probe.d delete mode 100644 lib/dtrace/examples/user-probe.systemtap delete mode 100644 lib/dtrace/src/Makefile delete mode 100644 lib/dtrace/src/dtrace.app.src delete mode 100644 lib/dtrace/src/dtrace.appup.src delete mode 100644 lib/dtrace/src/dtrace.erl delete mode 100644 lib/dtrace/vsn.mk create mode 100644 lib/runtime_tools/c_src/dtrace_user.d create mode 100644 lib/runtime_tools/c_src/dyntrace.c create mode 100644 lib/runtime_tools/examples/dist.d create mode 100644 lib/runtime_tools/examples/dist.systemtap create mode 100644 lib/runtime_tools/examples/driver1.d create mode 100644 lib/runtime_tools/examples/driver1.systemtap create mode 100644 lib/runtime_tools/examples/efile_drv.d create mode 100644 lib/runtime_tools/examples/efile_drv.systemtap create mode 100644 lib/runtime_tools/examples/function-calls.d create mode 100644 lib/runtime_tools/examples/function-calls.systemtap create mode 100644 lib/runtime_tools/examples/garbage-collection.d create mode 100644 lib/runtime_tools/examples/garbage-collection.systemtap create mode 100644 lib/runtime_tools/examples/memory1.d create mode 100644 lib/runtime_tools/examples/memory1.systemtap create mode 100644 lib/runtime_tools/examples/messages.d create mode 100644 lib/runtime_tools/examples/messages.systemtap create mode 100644 lib/runtime_tools/examples/port1.d create mode 100644 lib/runtime_tools/examples/port1.systemtap create mode 100644 lib/runtime_tools/examples/process-scheduling.d create mode 100644 lib/runtime_tools/examples/process-scheduling.systemtap create mode 100644 lib/runtime_tools/examples/spawn-exit.d create mode 100644 lib/runtime_tools/examples/spawn-exit.systemtap create mode 100644 lib/runtime_tools/examples/user-probe.d create mode 100644 lib/runtime_tools/examples/user-probe.systemtap create mode 100644 lib/runtime_tools/src/dyntrace.erl (limited to 'lib') diff --git a/lib/Makefile b/lib/Makefile index 96ce2d1315..aa4e074830 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -31,7 +31,7 @@ ifdef BUILD_ALL cosTransactions cosEvent cosTime cosNotification \ cosProperty cosFileTransfer cosEventDomain et megaco webtool \ xmerl edoc eunit ssh inviso typer erl_docgen \ - percept dialyzer dtrace hipe + percept dialyzer hipe EXTRA_FILE := $(wildcard EXTRA-APPLICATIONS) EXTRA_APPLICATIONS := $(if $(EXTRA_FILE),$(shell cat $(EXTRA_FILE))) endif diff --git a/lib/dtrace/Makefile b/lib/dtrace/Makefile deleted file mode 100644 index 29d463aab1..0000000000 --- a/lib/dtrace/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -# -# %CopyrightBegin% -# -# Copyright Ericsson AB 2002-2009. 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% -# -include $(ERL_TOP)/make/target.mk -include $(ERL_TOP)/make/$(TARGET)/otp.mk - -# -# Macros -# - -SUB_DIRECTORIES = src c_src - -include vsn.mk -VSN = $(DTRACE_VSN) - -SPECIAL_TARGETS = - -# -# Default Subdir Targets -# -include $(ERL_TOP)/make/otp_subdir.mk diff --git a/lib/dtrace/c_src/Makefile b/lib/dtrace/c_src/Makefile deleted file mode 100644 index a65491d45d..0000000000 --- a/lib/dtrace/c_src/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -# -# Invoke with GNU make -# -include $(ERL_TOP)/make/run_make.mk diff --git a/lib/dtrace/c_src/Makefile.in b/lib/dtrace/c_src/Makefile.in deleted file mode 100644 index 4d5f59a63d..0000000000 --- a/lib/dtrace/c_src/Makefile.in +++ /dev/null @@ -1,151 +0,0 @@ -# -# %CopyrightBegin% -# -# Copyright Scott Lystig Fritchie 2011. 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% -# -include $(ERL_TOP)/make/target.mk -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 -VSN=$(DTRACE_VSN) - -# ---------------------------------------------------- -# The following variables differ between systems. -# Set by configure. -# ---------------------------------------------------- -CC = $(DED_CC) -LD = $(DED_LD) -SHELL = /bin/sh -LIBS = $(DED_LIBS) -LDFLAGS += $(DED_LDFLAGS) -CFLAGS = $(DED_CFLAGS) - -DTRACE_LIBNAME = dtrace - - -INCLUDES = $(DED_INCLUDES) - -ifeq ($(TYPE),debug) -TYPEMARKER = .debug -TYPE_FLAGS = $(subst -O3,,$(subst -O2,,$(CFLAGS))) -DDEBUG -else -ifeq ($(TYPE),valgrind) -TYPEMARKER = .valgrind -TYPE_FLAGS = $(subst -O3,,$(subst -O2,,$(CFLAGS))) -DVALGRIND -else -TYPEMARKER = -TYPE_FLAGS = $(CFLAGS) -endif -endif - -ALL_CFLAGS = $(TYPE_FLAGS) $(INCLUDES) -I$(OBJDIR) \ - -I$(ERL_TOP)/erts/emulator/$(TARGET) - -# ---------------------------------------------------- -# Release directory specification -# ---------------------------------------------------- -RELSYSDIR = $(RELEASE_PATH)/lib/dtrace-$(VSN) - -# ---------------------------------------------------- -# Misc Macros -# ---------------------------------------------------- -before_DTrace_OBJS = $(OBJDIR)/dtrace$(TYPEMARKER).o -## NIF_MAKEFILE = $(PRIVDIR)/Makefile - -# Higher-level makefiles says that we can only compile on UNIX flavors -NIF_LIB = $(LIBDIR)/dtrace$(TYPEMARKER).@DED_EXT@ - -ifeq ($(HOST_OS),) -HOST_OS := $(shell $(ERL_TOP)/erts/autoconf/config.guess) -endif - -# ---------------------------------------------------- -# Targets -# ---------------------------------------------------- - -debug opt valgrind: $(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 - -OBJS = $(before_DTrace_OBJS) $(DTRACE_OBJS) - -$(OBJDIR): - -@mkdir -p $(OBJDIR) - -$(LIBDIR): - -@mkdir -p $(LIBDIR) - -$(OBJDIR)/%$(TYPEMARKER).o: %.c $(DTRACE_USER_HEADER) - $(INSTALL_DIR) $(OBJDIR) - $(CC) -c -o $@ $(ALL_CFLAGS) $< - -$(NIF_LIB): $(OBJS) - $(INSTALL_DIR) $(LIBDIR) - $(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS) - -clean: - rm -f $(LIBDIR)/dtrace.@DED_EXT@ - rm -f $(LIBDIR)/dtrace.debug.@DED_EXT@ - rm -f $(LIBDIR)/dtrace.valgrind.@DED_EXT@ - rm -f $(OBJDIR)/dtrace.o - rm -f $(OBJDIR)/dtrace.debug.o - rm -f $(OBJDIR)/dtrace.valgrind.o - rm -f core *~ - -docs: - -# ---------------------------------------------------- -# Release Target -# ---------------------------------------------------- -include $(ERL_TOP)/make/otp_release_targets.mk - -release_spec: opt - $(INSTALL_DIR) $(RELSYSDIR)/priv/obj - $(INSTALL_DIR) $(RELSYSDIR)/priv/lib - # $(INSTALL_DATA) $(NIF_MAKEFILE) $(RELSYSDIR)/priv/obj - $(INSTALL_PROGRAM) $(OBJS) $(RELSYSDIR)/priv/obj - $(INSTALL_PROGRAM) $(NIF_LIB) $(RELSYSDIR)/priv/lib - -release_docs_spec: diff --git a/lib/dtrace/c_src/dtrace.c b/lib/dtrace/c_src/dtrace.c deleted file mode 100644 index 90bb39a4b8..0000000000 --- a/lib/dtrace/c_src/dtrace.c +++ /dev/null @@ -1,168 +0,0 @@ -/* - * %CopyrightBegin% - * - * Copyright Scott Lystig Fritchie 2011. 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" -#ifdef HAVE_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 VALGRIND - # include -#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 ErlNifFunc nif_funcs[] = { - {"available", 0, available}, - {"user_trace_s1", 1, user_trace_s1}, - {"user_trace_i4s4", 9, user_trace_i4s4} -}; - -ERL_NIF_INIT(dtrace, 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_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_DTRACE - ErlNifBinary message_bin; - DTRACE_CHARBUF(messagebuf, MESSAGE_BUFSIZ + 1); - - if (DTRACE_ENABLED(user_trace_s1)) { - if (!enif_inspect_iolist_as_binary(env, argv[0], &message_bin) || - message_bin.size > MESSAGE_BUFSIZ) { - return atom_badarg; - } - memcpy(messagebuf, (char *) message_bin.data, message_bin.size); - messagebuf[message_bin.size] = '\0'; - DTRACE1(user_trace_s1, messagebuf); - return atom_true; - } else { - return atom_false; - } -#else - return atom_error; -#endif -} - -void -get_string_maybe(ErlNifEnv *env, - const ERL_NIF_TERM term, char **ptr, char *buf, int bufsiz) -{ - ErlNifBinary str_bin; - - if (!enif_inspect_iolist_as_binary(env, term, &str_bin) || - str_bin.size > bufsiz) { - *ptr = NULL; - } else { - memcpy(buf, (char *) str_bin.data, str_bin.size); - buf[str_bin.size] = '\0'; - *ptr = buf; - } -} - -static ERL_NIF_TERM user_trace_i4s4(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) -{ -#ifdef HAVE_DTRACE - DTRACE_CHARBUF(procbuf, 32 + 1); - DTRACE_CHARBUF(user_tagbuf, MESSAGE_BUFSIZ + 1); - char *utbuf = NULL; - ErlNifSInt64 i1, i2, i3, i4; - DTRACE_CHARBUF(messagebuf1, MESSAGE_BUFSIZ + 1); - DTRACE_CHARBUF(messagebuf2, MESSAGE_BUFSIZ + 1); - DTRACE_CHARBUF(messagebuf3, MESSAGE_BUFSIZ + 1); - DTRACE_CHARBUF(messagebuf4, MESSAGE_BUFSIZ + 1); - char *mbuf1 = NULL, *mbuf2 = NULL, *mbuf3 = NULL, *mbuf4 = NULL; - - if (DTRACE_ENABLED(user_trace_i4s4)) { - dtrace_nifenv_str(env, procbuf); - get_string_maybe(env, argv[0], &utbuf, user_tagbuf, MESSAGE_BUFSIZ); - if (! enif_get_int64(env, argv[1], &i1)) - i1 = 0; - if (! enif_get_int64(env, argv[2], &i2)) - i2 = 0; - if (! enif_get_int64(env, argv[3], &i3)) - i3 = 0; - if (! enif_get_int64(env, argv[4], &i4)) - i4 = 0; - get_string_maybe(env, argv[5], &mbuf1, messagebuf1, MESSAGE_BUFSIZ); - get_string_maybe(env, argv[6], &mbuf2, messagebuf2, MESSAGE_BUFSIZ); - get_string_maybe(env, argv[7], &mbuf3, messagebuf3, MESSAGE_BUFSIZ); - get_string_maybe(env, argv[8], &mbuf4, messagebuf4, MESSAGE_BUFSIZ); - DTRACE10(user_trace_i4s4, procbuf, utbuf, - i1, i2, i3, i4, mbuf1, mbuf2, mbuf3, mbuf4); - return atom_true; - } else { - return atom_false; - } -#else - return atom_error; -#endif -} diff --git a/lib/dtrace/c_src/dtrace_user.d b/lib/dtrace/c_src/dtrace_user.d deleted file mode 100644 index 45d3ef3b66..0000000000 --- a/lib/dtrace/c_src/dtrace_user.d +++ /dev/null @@ -1,53 +0,0 @@ -/* - * %CopyrightBegin% - * - * Copyright Scott Lystig Fritchie 2011. - * 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 { - /** - * Send a single string to a probe. - * - * @param NUL-terminated string - */ - probe user_trace__s1(char* message); - - /** - * Multi-purpose probe: up to 4 NUL-terminated strings and 4 - * 64-bit integer arguments. - * - * @param proc, the PID (string form) of the sending process - * @param user_tag, the user tag of the sender - * @param i1, integer - * @param i2, integer - * @param i3, integer - * @param i4, integer - * @param s1, string/iolist. D's arg6 is NULL if not given by Erlang - * @param s2, string/iolist. D's arg7 is NULL if not given by Erlang - * @param s3, string/iolist. D's arg8 is NULL if not given by Erlang - * @param s4, string/iolist. D's arg9 is NULL if not given by Erlang - */ - probe user_trace__i4s4(char *proc, char *user_tag, - int i1, int i2, int i3, int i4, - char *s1, char *s2, char *s3, char *s4); -}; - -#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/dtrace/ebin/.placeholder b/lib/dtrace/ebin/.placeholder deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/lib/dtrace/examples/dist.d b/lib/dtrace/examples/dist.d deleted file mode 100644 index 550e10d363..0000000000 --- a/lib/dtrace/examples/dist.d +++ /dev/null @@ -1,62 +0,0 @@ -/* example usage: dtrace -q -s /path/to/dist.d */ -/* - * %CopyrightBegin% - * - * Copyright Scott Lystig Fritchie 2011. 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/dtrace/examples/dist.systemtap b/lib/dtrace/examples/dist.systemtap deleted file mode 100644 index af27b2cab6..0000000000 --- a/lib/dtrace/examples/dist.systemtap +++ /dev/null @@ -1,76 +0,0 @@ -/* example usage: stap /path/to/dist.systemtap -x */ -/* - * %CopyrightBegin% - * - * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011. 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/dtrace/examples/driver1.d b/lib/dtrace/examples/driver1.d deleted file mode 100644 index 9f53ffeb2a..0000000000 --- a/lib/dtrace/examples/driver1.d +++ /dev/null @@ -1,114 +0,0 @@ -/* example usage: dtrace -q -s /path/to/driver1.d */ -/* - * %CopyrightBegin% - * - * Copyright Scott Lystig Fritchie 2011. 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/dtrace/examples/driver1.systemtap b/lib/dtrace/examples/driver1.systemtap deleted file mode 100644 index 8b99e465b7..0000000000 --- a/lib/dtrace/examples/driver1.systemtap +++ /dev/null @@ -1,125 +0,0 @@ -/* example usage: stap /path/to/driver1.systemtap -x */ -/* - * %CopyrightBegin% - * - * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011. 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/dtrace/examples/efile_drv.d b/lib/dtrace/examples/efile_drv.d deleted file mode 100644 index 085995ce58..0000000000 --- a/lib/dtrace/examples/efile_drv.d +++ /dev/null @@ -1,104 +0,0 @@ -/* example usage: dtrace -q -s /path/to/efile_drv.d */ -/* - * %CopyrightBegin% - * - * Copyright Scott Lystig Fritchie 2011. 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/dtrace/examples/efile_drv.systemtap b/lib/dtrace/examples/efile_drv.systemtap deleted file mode 100644 index 5a47b3e22b..0000000000 --- a/lib/dtrace/examples/efile_drv.systemtap +++ /dev/null @@ -1,112 +0,0 @@ -/* - * %CopyrightBegin% - * - * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011. 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/dtrace/examples/function-calls.d b/lib/dtrace/examples/function-calls.d deleted file mode 100644 index 238c5211ac..0000000000 --- a/lib/dtrace/examples/function-calls.d +++ /dev/null @@ -1,51 +0,0 @@ -/* example usage: dtrace -q -s /path/to/function-calls.d */ -/* - * %CopyrightBegin% - * - * Copyright Scott Lystig Fritchie 2011. 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*:::function-entry -{ - printf("pid %s enter %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/dtrace/examples/function-calls.systemtap b/lib/dtrace/examples/function-calls.systemtap deleted file mode 100644 index 8fc4375135..0000000000 --- a/lib/dtrace/examples/function-calls.systemtap +++ /dev/null @@ -1,61 +0,0 @@ -/* - * %CopyrightBegin% - * - * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011. 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("function-entry") -{ - printf("pid %s enter %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/dtrace/examples/garbage-collection.d b/lib/dtrace/examples/garbage-collection.d deleted file mode 100644 index f234e7d4db..0000000000 --- a/lib/dtrace/examples/garbage-collection.d +++ /dev/null @@ -1,39 +0,0 @@ -/* example usage: dtrace -q -s /path/to/garbage-collection.d */ -/* - * %CopyrightBegin% - * - * Copyright Scott Lystig Fritchie 2011. 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/dtrace/examples/garbage-collection.systemtap b/lib/dtrace/examples/garbage-collection.systemtap deleted file mode 100644 index 64d69c6fbd..0000000000 --- a/lib/dtrace/examples/garbage-collection.systemtap +++ /dev/null @@ -1,49 +0,0 @@ -/* - * %CopyrightBegin% - * - * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011. 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/dtrace/examples/memory1.d b/lib/dtrace/examples/memory1.d deleted file mode 100644 index c2e16e0779..0000000000 --- a/lib/dtrace/examples/memory1.d +++ /dev/null @@ -1,41 +0,0 @@ -/* example usage: dtrace -q -s /path/to/memory1.d */ -/* - * %CopyrightBegin% - * - * Copyright Scott Lystig Fritchie 2011. 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/dtrace/examples/memory1.systemtap b/lib/dtrace/examples/memory1.systemtap deleted file mode 100644 index 9723f2d02d..0000000000 --- a/lib/dtrace/examples/memory1.systemtap +++ /dev/null @@ -1,51 +0,0 @@ -/* - * %CopyrightBegin% - * - * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011. 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/dtrace/examples/messages.d b/lib/dtrace/examples/messages.d deleted file mode 100644 index 6361f3a220..0000000000 --- a/lib/dtrace/examples/messages.d +++ /dev/null @@ -1,94 +0,0 @@ -/* example usage: dtrace -q -s /path/to/messages.d */ -/* - * %CopyrightBegin% - * - * Copyright Scott Lystig Fritchie 2011. 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/dtrace/examples/messages.systemtap b/lib/dtrace/examples/messages.systemtap deleted file mode 100644 index ff8f4076b1..0000000000 --- a/lib/dtrace/examples/messages.systemtap +++ /dev/null @@ -1,87 +0,0 @@ -/* - * %CopyrightBegin% - * - * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011. 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/dtrace/examples/port1.d b/lib/dtrace/examples/port1.d deleted file mode 100644 index 204abbd3b8..0000000000 --- a/lib/dtrace/examples/port1.d +++ /dev/null @@ -1,142 +0,0 @@ -/* example usage: dtrace -q -s /path/to/port1.d */ -/* - * %CopyrightBegin% - * - * Copyright Scott Lystig Fritchie 2011. 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/dtrace/examples/port1.systemtap b/lib/dtrace/examples/port1.systemtap deleted file mode 100644 index a63d9b670c..0000000000 --- a/lib/dtrace/examples/port1.systemtap +++ /dev/null @@ -1,152 +0,0 @@ -/* - * %CopyrightBegin% - * - * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011. 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/dtrace/examples/process-scheduling.d b/lib/dtrace/examples/process-scheduling.d deleted file mode 100644 index 79e9cc598c..0000000000 --- a/lib/dtrace/examples/process-scheduling.d +++ /dev/null @@ -1,35 +0,0 @@ -/* example usage: dtrace -q -s /path/to/process-scheduling.d */ -/* - * %CopyrightBegin% - * - * Copyright Scott Lystig Fritchie 2011. 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/dtrace/examples/process-scheduling.systemtap b/lib/dtrace/examples/process-scheduling.systemtap deleted file mode 100644 index c8cee60a07..0000000000 --- a/lib/dtrace/examples/process-scheduling.systemtap +++ /dev/null @@ -1,45 +0,0 @@ -/* - * %CopyrightBegin% - * - * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011. 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/dtrace/examples/spawn-exit.d b/lib/dtrace/examples/spawn-exit.d deleted file mode 100644 index 7310f3343d..0000000000 --- a/lib/dtrace/examples/spawn-exit.d +++ /dev/null @@ -1,41 +0,0 @@ -/* example usage: dtrace -q -s /path/to/spawn-exit.d */ -/* - * %CopyrightBegin% - * - * Copyright Scott Lystig Fritchie 2011. 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/dtrace/examples/spawn-exit.systemtap b/lib/dtrace/examples/spawn-exit.systemtap deleted file mode 100644 index 5e3be9fc1b..0000000000 --- a/lib/dtrace/examples/spawn-exit.systemtap +++ /dev/null @@ -1,51 +0,0 @@ -/* - * %CopyrightBegin% - * - * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011. 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/dtrace/examples/user-probe.d b/lib/dtrace/examples/user-probe.d deleted file mode 100644 index 13baff6a32..0000000000 --- a/lib/dtrace/examples/user-probe.d +++ /dev/null @@ -1,36 +0,0 @@ -/* example usage: dtrace -q -s /path/to/user-probe.d */ -/* - * %CopyrightBegin% - * - * Copyright Scott Lystig Fritchie 2011. 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/dtrace/examples/user-probe.systemtap b/lib/dtrace/examples/user-probe.systemtap deleted file mode 100644 index 84a45709e8..0000000000 --- a/lib/dtrace/examples/user-probe.systemtap +++ /dev/null @@ -1,46 +0,0 @@ -/* - * %CopyrightBegin% - * - * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011. 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("dyntrace.so").mark("user_trace-s1") -{ - printf("%s\n", user_string($arg1)); -} - -probe process("dyntrace.so").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/dtrace/src/Makefile b/lib/dtrace/src/Makefile deleted file mode 100644 index d613402a63..0000000000 --- a/lib/dtrace/src/Makefile +++ /dev/null @@ -1,102 +0,0 @@ -# -# %CopyrightBegin% -# -# Copyright Ericsson AB 2002-2011. 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% -# -include $(ERL_TOP)/make/target.mk -include $(ERL_TOP)/make/$(TARGET)/otp.mk - -# ---------------------------------------------------- -# Application version -# ---------------------------------------------------- -include ../vsn.mk -VSN=$(DTRACE_VSN) - -# ---------------------------------------------------- -# Release directory specification -# ---------------------------------------------------- -RELSYSDIR = $(RELEASE_PATH)/lib/dtrace-$(VSN) - -# ---------------------------------------------------- -# Common Macros -# ---------------------------------------------------- - -MODULES= \ - dtrace - -HRL_FILES= \ - -INTERNAL_HRL_FILES= \ - -ERL_FILES= $(MODULES:%=%.erl) -EXAMPLE_FILES= \ - ../examples/* - -TARGET_FILES= $(MODULES:%=$(EBIN)/%.$(EMULATOR)) $(APP_TARGET) $(APPUP_TARGET) - -EXECUTABLES= \ - -APP_FILE= dtrace.app - -APP_SRC= $(APP_FILE).src -APP_TARGET= $(EBIN)/$(APP_FILE) - -APPUP_FILE= dtrace.appup - -APPUP_SRC= $(APPUP_FILE).src -APPUP_TARGET= $(EBIN)/$(APPUP_FILE) - -# ---------------------------------------------------- -# FLAGS -# ---------------------------------------------------- -ERL_COMPILE_FLAGS += \ - -I../include \ - -I ../../et/include \ - -I ../../../libraries/et/include - -# ---------------------------------------------------- -# Targets -# ---------------------------------------------------- - -debug opt: $(TARGET_FILES) - -clean: - rm -f $(TARGET_FILES) - rm -f errs core *~ - -$(APP_TARGET): $(APP_SRC) ../vsn.mk - sed -e 's;%VSN%;$(VSN);' $< > $@ - -$(APPUP_TARGET): $(APPUP_SRC) ../vsn.mk - sed -e 's;%VSN%;$(VSN);' $< > $@ - -docs: - -# ---------------------------------------------------- -# Release Target -# ---------------------------------------------------- -include $(ERL_TOP)/make/otp_release_targets.mk - -release_spec: opt - $(INSTALL_DIR) $(RELSYSDIR)/src - $(INSTALL_DATA) $(ERL_FILES) $(RELSYSDIR)/src - # $(INSTALL_DATA) $(INTERNAL_HRL_FILES) $(RELSYSDIR)/src - $(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/dtrace/src/dtrace.app.src b/lib/dtrace/src/dtrace.app.src deleted file mode 100644 index 764e863559..0000000000 --- a/lib/dtrace/src/dtrace.app.src +++ /dev/null @@ -1,27 +0,0 @@ -%% -%% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2002-2009. 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% -%% -{application, dtrace, - [{description, "DTRACE version 1"}, - {vsn, "%VSN%"}, - {modules, [ - dtrace - ]}, - {registered, []}, - {applications, [kernel, stdlib]}, - {env, []}]}. diff --git a/lib/dtrace/src/dtrace.appup.src b/lib/dtrace/src/dtrace.appup.src deleted file mode 100644 index f730a2f8df..0000000000 --- a/lib/dtrace/src/dtrace.appup.src +++ /dev/null @@ -1,19 +0,0 @@ -%% -%% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2002-2009. 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% -%% -{"%VSN%",[],[]}. diff --git a/lib/dtrace/src/dtrace.erl b/lib/dtrace/src/dtrace.erl deleted file mode 100644 index 71a1a3480e..0000000000 --- a/lib/dtrace/src/dtrace.erl +++ /dev/null @@ -1,247 +0,0 @@ --module(dtrace). - -%%% @doc The DTrace interface module -%%% -%%% This DTrace interface module, with the corresponding NIFs, should -%%% work on any operating system platform where user-space DTrace -%%% probes are supported. -%%% -%%% Use the `dtrace:init()' function to load the NIF shared library and -%%% to initialize library's private state. -%%% -%%% It is recommended that you use the `dtrace:p()' function to add -%%% DTrace 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. For example: -%%% ``` -%%% 1> dtrace:put_tag("GGOOOAAALL!!!!!"). -%%% true -%%% 2> dtrace:init(). -%%% ok -%%% -%%% % % % Enable the DTrace probe using the 'dtrace' command. -%%% -%%% 3> dtrace: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([init/0, 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]). --export([put_utag/1, get_utag/0, get_utag_data/0, spread_utag/1, restore_utag/1]). - --export([scaff/0]). % Development only --export([user_trace_i4s4/9]). % Know what you're doing! - --type probe_arg() :: integer() | iolist(). --type int_p_arg() :: integer() | iolist() | undef. -%% 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(). - --spec init() -> ok | {error, {term(), term()}}. - -init() -> - PrivDir = code:priv_dir(dtrace), - Lib = filename:join([PrivDir, "lib", "dtrace"]), - erlang:load_nif(Lib, 0). - -%%% -%%% 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). - -%%% -%%% 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_utag(), - try - user_trace_i4s4(UTag, I1, I2, I3, I4, S1, S2, S3, S4) - catch - error:nif_not_loaded -> - false - end. - --spec put_utag(undefined | iodata()) -> binary() | undefined. -put_utag(Data) -> - erlang:put_utag(unicode:characters_to_binary(Data)). - --spec get_utag() -> binary() | undefined. -get_utag() -> - erlang:get_utag(). - --spec get_utag_data() -> binary() | undefined. -%% Gets utag if set, otherwise the spread utag data from last incoming message -get_utag_data() -> - erlang:get_utag_data(). - --spec spread_utag(boolean()) -> true | {non_neg_integer(), binary() | []}. -%% Makes the utag behave as a sequential trace token, will spread with messages to be picked up by someone using -%% get_utag_data or get_drv_utag_data. -spread_utag(B) -> - erlang:spread_utag(B). - --spec restore_utag(true | {non_neg_integer(), binary() | []}) -> true. -restore_utag(T) -> - erlang:restore_utag(T). - - -%% Scaffolding to write tedious code: quick brute force and not 100% correct. - -scaff_int_args(N) -> - L = lists:sublist(["I1", "I2", "I3", "I4"], N), - [string:join(L, ", ")]. - -scaff_int_guards(N) -> - L = lists:sublist(["is_integer(I1)", "is_integer(I2)", "is_integer(I3)", - "is_integer(I4)"], N), - lists:flatten(string:join(L, ", ")). - -scaff_char_args(N) -> - L = lists:sublist(["S1", "S2", "S3", "S4"], N), - [string:join(L, ", ")]. - -scaff_fill(N) -> - [string:join(lists:duplicate(N, "undef"), ", ")]. - -scaff() -> - L = [begin - IntArgs = scaff_int_args(N_int), - IntGuards = scaff_int_guards(N_int), - IntFill = scaff_fill(4 - N_int), - CharArgs = scaff_char_args(N_char), - CharFill = scaff_fill(4 - N_char), - InArgs = string:join(IntArgs ++ CharArgs, ", "), - OutArgs = string:join(IntArgs ++ IntFill ++ CharArgs ++ CharFill, - ", "), - {N_int + N_char, - lists:flatten([io_lib:format("p(~s) when ~s ->\n", - [InArgs, IntGuards]), - io_lib:format(" user_trace_int(~s);\n", [OutArgs]) - ])} - end || N_int <- [0,1,2,3,4], N_char <- [0,1,2,3,4]], - [io:format("%%~p\n~s", [N, Str]) || {N, Str} <- lists:sort(L)]. diff --git a/lib/dtrace/vsn.mk b/lib/dtrace/vsn.mk deleted file mode 100644 index 73bf983c00..0000000000 --- a/lib/dtrace/vsn.mk +++ /dev/null @@ -1 +0,0 @@ -DTRACE_VSN = 0.8 diff --git a/lib/runtime_tools/c_src/Makefile.in b/lib/runtime_tools/c_src/Makefile.in index 3d9a7ed69d..120f9b913f 100644 --- a/lib/runtime_tools/c_src/Makefile.in +++ b/lib/runtime_tools/c_src/Makefile.in @@ -20,6 +20,11 @@ include $(ERL_TOP)/make/target.mk 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 # ---------------------------------------------------- @@ -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/obj $(INSTALL_DIR) $(RELSYSDIR)/priv/lib - $(INSTALL_PROGRAM) $(SOLIBS) $(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..45d3ef3b66 --- /dev/null +++ b/lib/runtime_tools/c_src/dtrace_user.d @@ -0,0 +1,53 @@ +/* + * %CopyrightBegin% + * + * Copyright Scott Lystig Fritchie 2011. + * 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 { + /** + * Send a single string to a probe. + * + * @param NUL-terminated string + */ + probe user_trace__s1(char* message); + + /** + * Multi-purpose probe: up to 4 NUL-terminated strings and 4 + * 64-bit integer arguments. + * + * @param proc, the PID (string form) of the sending process + * @param user_tag, the user tag of the sender + * @param i1, integer + * @param i2, integer + * @param i3, integer + * @param i4, integer + * @param s1, string/iolist. D's arg6 is NULL if not given by Erlang + * @param s2, string/iolist. D's arg7 is NULL if not given by Erlang + * @param s3, string/iolist. D's arg8 is NULL if not given by Erlang + * @param s4, string/iolist. D's arg9 is NULL if not given by Erlang + */ + probe user_trace__i4s4(char *proc, char *user_tag, + int i1, int i2, int i3, int i4, + char *s1, char *s2, char *s3, char *s4); +}; + +#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..d94014559d --- /dev/null +++ b/lib/runtime_tools/c_src/dyntrace.c @@ -0,0 +1,172 @@ +/* + * %CopyrightBegin% + * + * Copyright Scott Lystig Fritchie 2011. 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 VALGRIND + # include +#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 ErlNifFunc nif_funcs[] = { + {"available", 0, available}, + {"user_trace_s1", 1, user_trace_s1}, + {"user_trace_i4s4", 9, user_trace_i4s4} +}; + +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 + ErlNifBinary message_bin; + DTRACE_CHARBUF(messagebuf, MESSAGE_BUFSIZ + 1); + + if (DTRACE_ENABLED(user_trace_s1)) { + if (!enif_inspect_iolist_as_binary(env, argv[0], &message_bin) || + message_bin.size > MESSAGE_BUFSIZ) { + return atom_badarg; + } + memcpy(messagebuf, (char *) message_bin.data, message_bin.size); + messagebuf[message_bin.size] = '\0'; + DTRACE1(user_trace_s1, messagebuf); + return atom_true; + } else { + return atom_false; + } +#else + return atom_error; +#endif +} + +void +get_string_maybe(ErlNifEnv *env, + const ERL_NIF_TERM term, char **ptr, char *buf, int bufsiz) +{ + ErlNifBinary str_bin; + + if (!enif_inspect_iolist_as_binary(env, term, &str_bin) || + str_bin.size > bufsiz) { + *ptr = NULL; + } else { + memcpy(buf, (char *) str_bin.data, str_bin.size); + buf[str_bin.size] = '\0'; + *ptr = buf; + } +} + +static ERL_NIF_TERM user_trace_i4s4(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) +{ +#ifdef HAVE_USE_DTRACE + DTRACE_CHARBUF(procbuf, 32 + 1); + DTRACE_CHARBUF(user_tagbuf, MESSAGE_BUFSIZ + 1); + char *utbuf = NULL; + ErlNifSInt64 i1, i2, i3, i4; + DTRACE_CHARBUF(messagebuf1, MESSAGE_BUFSIZ + 1); + DTRACE_CHARBUF(messagebuf2, MESSAGE_BUFSIZ + 1); + DTRACE_CHARBUF(messagebuf3, MESSAGE_BUFSIZ + 1); + DTRACE_CHARBUF(messagebuf4, MESSAGE_BUFSIZ + 1); + char *mbuf1 = NULL, *mbuf2 = NULL, *mbuf3 = NULL, *mbuf4 = NULL; + + if (DTRACE_ENABLED(user_trace_i4s4)) { + dtrace_nifenv_str(env, procbuf); + get_string_maybe(env, argv[0], &utbuf, user_tagbuf, MESSAGE_BUFSIZ); + if (! enif_get_int64(env, argv[1], &i1)) + i1 = 0; + if (! enif_get_int64(env, argv[2], &i2)) + i2 = 0; + if (! enif_get_int64(env, argv[3], &i3)) + i3 = 0; + if (! enif_get_int64(env, argv[4], &i4)) + i4 = 0; + get_string_maybe(env, argv[5], &mbuf1, messagebuf1, MESSAGE_BUFSIZ); + get_string_maybe(env, argv[6], &mbuf2, messagebuf2, MESSAGE_BUFSIZ); + get_string_maybe(env, argv[7], &mbuf3, messagebuf3, MESSAGE_BUFSIZ); + get_string_maybe(env, argv[8], &mbuf4, messagebuf4, MESSAGE_BUFSIZ); + DTRACE10(user_trace_i4s4, procbuf, utbuf, + i1, i2, i3, i4, mbuf1, mbuf2, mbuf3, mbuf4); + return atom_true; + } else { + return atom_false; + } +#else + return atom_error; +#endif +} diff --git a/lib/runtime_tools/examples/dist.d b/lib/runtime_tools/examples/dist.d new file mode 100644 index 0000000000..550e10d363 --- /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. 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..af27b2cab6 --- /dev/null +++ b/lib/runtime_tools/examples/dist.systemtap @@ -0,0 +1,76 @@ +/* example usage: stap /path/to/dist.systemtap -x */ +/* + * %CopyrightBegin% + * + * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011. 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..9f53ffeb2a --- /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. 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..8b99e465b7 --- /dev/null +++ b/lib/runtime_tools/examples/driver1.systemtap @@ -0,0 +1,125 @@ +/* example usage: stap /path/to/driver1.systemtap -x */ +/* + * %CopyrightBegin% + * + * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011. 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..085995ce58 --- /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. 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..5a47b3e22b --- /dev/null +++ b/lib/runtime_tools/examples/efile_drv.systemtap @@ -0,0 +1,112 @@ +/* + * %CopyrightBegin% + * + * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011. 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..238c5211ac --- /dev/null +++ b/lib/runtime_tools/examples/function-calls.d @@ -0,0 +1,51 @@ +/* example usage: dtrace -q -s /path/to/function-calls.d */ +/* + * %CopyrightBegin% + * + * Copyright Scott Lystig Fritchie 2011. 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*:::function-entry +{ + printf("pid %s enter %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..8fc4375135 --- /dev/null +++ b/lib/runtime_tools/examples/function-calls.systemtap @@ -0,0 +1,61 @@ +/* + * %CopyrightBegin% + * + * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011. 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("function-entry") +{ + printf("pid %s enter %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..f234e7d4db --- /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. 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..64d69c6fbd --- /dev/null +++ b/lib/runtime_tools/examples/garbage-collection.systemtap @@ -0,0 +1,49 @@ +/* + * %CopyrightBegin% + * + * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011. 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..c2e16e0779 --- /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. 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..9723f2d02d --- /dev/null +++ b/lib/runtime_tools/examples/memory1.systemtap @@ -0,0 +1,51 @@ +/* + * %CopyrightBegin% + * + * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011. 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..6361f3a220 --- /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. 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..ff8f4076b1 --- /dev/null +++ b/lib/runtime_tools/examples/messages.systemtap @@ -0,0 +1,87 @@ +/* + * %CopyrightBegin% + * + * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011. 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..204abbd3b8 --- /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. 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..a63d9b670c --- /dev/null +++ b/lib/runtime_tools/examples/port1.systemtap @@ -0,0 +1,152 @@ +/* + * %CopyrightBegin% + * + * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011. 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..79e9cc598c --- /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. 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..c8cee60a07 --- /dev/null +++ b/lib/runtime_tools/examples/process-scheduling.systemtap @@ -0,0 +1,45 @@ +/* + * %CopyrightBegin% + * + * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011. 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..7310f3343d --- /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. 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..5e3be9fc1b --- /dev/null +++ b/lib/runtime_tools/examples/spawn-exit.systemtap @@ -0,0 +1,51 @@ +/* + * %CopyrightBegin% + * + * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011. 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.d b/lib/runtime_tools/examples/user-probe.d new file mode 100644 index 0000000000..13baff6a32 --- /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. 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..84a45709e8 --- /dev/null +++ b/lib/runtime_tools/examples/user-probe.systemtap @@ -0,0 +1,46 @@ +/* + * %CopyrightBegin% + * + * Copyright Scott Lystig Fritchie and Andreas Schultz, 2011. 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("dyntrace.so").mark("user_trace-s1") +{ + printf("%s\n", user_string($arg1)); +} + +probe process("dyntrace.so").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..6dc89bea32 100644 --- a/lib/runtime_tools/src/Makefile +++ b/lib/runtime_tools/src/Makefile @@ -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 @@ -97,6 +103,8 @@ release_spec: opt $(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 diff --git a/lib/runtime_tools/src/dyntrace.erl b/lib/runtime_tools/src/dyntrace.erl new file mode 100644 index 0000000000..20472a2be6 --- /dev/null +++ b/lib/runtime_tools/src/dyntrace.erl @@ -0,0 +1,279 @@ +-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. +%%% +%%% Use the `dyntrace:init()' function to load the NIF shared library and +%%% to initialize library's private state. +%%% +%%% 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. For example: +%%% ``` +%%% 1> dyntrace:put_utag("GGOOOAAALL!!!!!"). +%%% true +%%% 2> dyntrace:init(). +%%% ok +%%% +%%% % % % If using dtrace, enable the Dynamic trace probe using the 'dtrace' +%%% % % % command. +%%% +%%% 3> 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]). +-export([put_utag/1, get_utag/0, get_utag_data/0, spread_utag/1, restore_utag/1]). + +-export([scaff/0]). % Development only +-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. + +%% 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). + +%%% +%%% 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_utag(), + try + user_trace_i4s4(UTag, I1, I2, I3, I4, S1, S2, S3, S4) + catch + error:nif_not_loaded -> + false + end. + +-spec put_utag(undefined | iodata()) -> binary() | undefined. +put_utag(Data) -> + erlang:put_utag(unicode:characters_to_binary(Data)). + +-spec get_utag() -> binary() | undefined. +get_utag() -> + erlang:get_utag(). + +-spec get_utag_data() -> binary() | undefined. +%% Gets utag if set, otherwise the spread utag data from last incoming message +get_utag_data() -> + erlang:get_utag_data(). + +-spec spread_utag(boolean()) -> true | {non_neg_integer(), binary() | []}. +%% Makes the utag behave as a sequential trace token, will spread with messages to be picked up by someone using +%% get_utag_data or get_drv_utag_data. +spread_utag(B) -> + erlang:spread_utag(B). + +-spec restore_utag(true | {non_neg_integer(), binary() | []}) -> true. +restore_utag(T) -> + erlang:restore_utag(T). + + +%% Scaffolding to write tedious code: quick brute force and not 100% correct. + +scaff_int_args(N) -> + L = lists:sublist(["I1", "I2", "I3", "I4"], N), + [string:join(L, ", ")]. + +scaff_int_guards(N) -> + L = lists:sublist(["is_integer(I1)", "is_integer(I2)", "is_integer(I3)", + "is_integer(I4)"], N), + lists:flatten(string:join(L, ", ")). + +scaff_char_args(N) -> + L = lists:sublist(["S1", "S2", "S3", "S4"], N), + [string:join(L, ", ")]. + +scaff_fill(N) -> + [string:join(lists:duplicate(N, "undef"), ", ")]. + +scaff() -> + L = [begin + IntArgs = scaff_int_args(N_int), + IntGuards = scaff_int_guards(N_int), + IntFill = scaff_fill(4 - N_int), + CharArgs = scaff_char_args(N_char), + CharFill = scaff_fill(4 - N_char), + InArgs = string:join(IntArgs ++ CharArgs, ", "), + OutArgs = string:join(IntArgs ++ IntFill ++ CharArgs ++ CharFill, + ", "), + {N_int + N_char, + lists:flatten([io_lib:format("p(~s) when ~s ->\n", + [InArgs, IntGuards]), + io_lib:format(" user_trace_int(~s);\n", [OutArgs]) + ])} + end || N_int <- [0,1,2,3,4], N_char <- [0,1,2,3,4]], + [io:format("%%~p\n~s", [N, Str]) || {N, Str} <- lists:sort(L)]. diff --git a/lib/runtime_tools/src/runtime_tools.app.src b/lib/runtime_tools/src/runtime_tools.app.src index 76fd998530..a9d2d68857 100644 --- a/lib/runtime_tools/src/runtime_tools.app.src +++ b/lib/runtime_tools/src/runtime_tools.app.src @@ -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}]}, -- cgit v1.2.3 From 560cea59eeee117f0170772d4edee820b6fc96d9 Mon Sep 17 00:00:00 2001 From: Patrik Nyblom Date: Wed, 21 Mar 2012 14:54:00 +0100 Subject: Rename dyntrace BIFs to more suiting names --- lib/hipe/cerl/erl_bif_types.erl | 70 +++++++++++++++++++------------------- lib/kernel/src/file.erl | 4 +-- lib/kernel/src/file_io_server.erl | 6 ++-- lib/runtime_tools/src/dyntrace.erl | 42 +++++++++++------------ 4 files changed, 61 insertions(+), 61 deletions(-) (limited to 'lib') diff --git a/lib/hipe/cerl/erl_bif_types.erl b/lib/hipe/cerl/erl_bif_types.erl index 260f216725..0c2e846010 100644 --- a/lib/hipe/cerl/erl_bif_types.erl +++ b/lib/hipe/cerl/erl_bif_types.erl @@ -614,10 +614,6 @@ type(erlang, adler32_combine, 3, Xs) -> type(erlang, append, 2, Xs) -> type(erlang, '++', 2, Xs); % alias type(erlang, append_element, 2, Xs) -> strict(arg_types(erlang, append_element, 2), Xs, fun (_) -> t_tuple() end); -type(erlang, append_vm_utag_data, 1, Xs) -> - strict(arg_types(erlang, append_vm_utag_data, 1), - Xs, - fun(_) -> t_iodata() end); type(erlang, apply, 2, Xs) -> Fun = fun ([X, _Y]) -> case t_is_fun(X) of @@ -714,6 +710,27 @@ type(erlang, display_nl, 0, _) -> t_atom('true'); type(erlang, dist_exit, 3, Xs) -> strict(arg_types(erlang, dist_exit, 3), Xs, fun (_) -> t_atom('true') end); +type(erlang, dt_append_vm_tag_data, 1, Xs) -> + strict(arg_types(erlang, dt_append_vm_tag_data, 1), + Xs, + fun(_) -> t_iodata() end); +type(erlang, dt_get_tag, 0, _) -> + t_sup(t_binary(), t_atom('undefined')); +type(erlang, dt_get_tag_data, 0, _) -> + t_sup(t_binary(), t_atom('undefined')); +type(erlang, dt_prepend_vm_tag_data, 1, Xs) -> + strict(arg_types(erlang, dt_prepend_vm_tag_data, 1), + Xs, + fun(_) -> t_iodata() end); +type(erlang, dt_put_tag, 1, Xs) -> + strict(arg_types(erlang, dt_put_tag, 1), Xs, + fun(_) -> t_sup(t_binary(), t_atom('undefined')) end); +type(erlang, dt_restore_tag, 1, Xs) -> + strict(arg_types(erlang, dt_restore_tag, 1), Xs, fun(_) -> t_atom('true') end); +type(erlang, dt_spread_tag, 1, Xs) -> + strict(arg_types(erlang, dt_spread_tag, 1), Xs, + fun(_) -> t_sup(t_tuple([t_non_neg_integer(), t_sup(t_binary(), t_nil())]), + t_atom('true')) end); type(erlang, element, 2, Xs) -> strict(arg_types(erlang, element, 2), Xs, fun ([X1, X2]) -> @@ -804,10 +821,6 @@ type(erlang, get_module_info, 2, Xs) -> type(erlang, get_stacktrace, 0, _) -> t_list(t_tuple([t_atom(), t_atom(), t_sup([t_arity(), t_list()]), t_list()])); -type(erlang, get_utag, 0, _) -> - t_sup(t_binary(), t_atom('undefined')); -type(erlang, get_utag_data, 0, _) -> - t_sup(t_binary(), t_atom('undefined')); type(erlang, group_leader, 0, _) -> t_pid(); type(erlang, group_leader, 2, Xs) -> strict(arg_types(erlang, group_leader, 2), Xs, @@ -1194,10 +1207,6 @@ type(erlang, port_set_data, 2, Xs) -> strict(arg_types(erlang, port_set_data, 2), Xs, fun (_) -> t_atom('true') end); type(erlang, pre_loaded, 0, _) -> t_list(t_atom()); -type(erlang, prepend_vm_utag_data, 1, Xs) -> - strict(arg_types(erlang, prepend_vm_utag_data, 1), - Xs, - fun(_) -> t_iodata() end); type(erlang, process_display, 2, _) -> t_atom('true'); type(erlang, process_flag, 2, Xs) -> T_process_flag_returns = t_sup([t_boolean(), t_atom(), t_non_neg_integer()]), @@ -1315,9 +1324,6 @@ type(erlang, purge_module, 1, Xs) -> fun (_) -> t_atom('true') end); type(erlang, put, 2, Xs) -> strict(arg_types(erlang, put, 2), Xs, fun (_) -> t_any() end); -type(erlang, put_utag, 1, Xs) -> - strict(arg_types(erlang, put_utag, 1), Xs, - fun(_) -> t_sup(t_binary(), t_atom('undefined')) end); type(erlang, raise, 3, _) -> t_none(); type(erlang, read_timer, 1, Xs) -> strict(arg_types(erlang, read_timer, 1), Xs, @@ -1327,8 +1333,6 @@ type(erlang, ref_to_list, 1, Xs) -> type(erlang, register, 2, Xs) -> strict(arg_types(erlang, register, 2), Xs, fun (_) -> t_atom('true') end); type(erlang, registered, 0, _) -> t_list(t_atom()); -type(erlang, restore_utag, 1, Xs) -> - strict(arg_types(erlang, restore_utag, 1), Xs, fun(_) -> t_atom('true') end); type(erlang, resume_process, 1, Xs) -> strict(arg_types(erlang, resume_process, 1), Xs, fun (_) -> t_any() end); %% TODO: overapproximation -- fix this @@ -1443,10 +1447,6 @@ type(erlang, spawn_opt, 4, Xs) -> type(erlang, split_binary, 2, Xs) -> strict(arg_types(erlang, split_binary, 2), Xs, fun (_) -> t_tuple([t_binary(), t_binary()]) end); -type(erlang, spread_utag, 1, Xs) -> - strict(arg_types(erlang, spread_utag, 1), Xs, - fun(_) -> t_sup(t_tuple([t_non_neg_integer(), t_sup(t_binary(), t_nil())]), - t_atom('true')) end); type(erlang, start_timer, 3, Xs) -> strict(arg_types(erlang, start_timer, 3), Xs, fun (_) -> t_reference() end); type(erlang, statistics, 1, Xs) -> @@ -3443,8 +3443,6 @@ arg_types(erlang, append, 2) -> arg_types(erlang, '++', 2); arg_types(erlang, append_element, 2) -> [t_tuple(), t_any()]; -arg_types(erlang, append_vm_utag_data, 1) -> - [t_iodata()]; arg_types(erlang, apply, 2) -> [t_sup(t_tuple([t_module(), t_atom()]), @@ -3518,6 +3516,20 @@ arg_types(erlang, display_string, 1) -> [t_string()]; arg_types(erlang, dist_exit, 3) -> [t_pid(), t_dist_exit(), t_sup(t_pid(), t_port())]; +arg_types(erlang, dt_append_vm_tag_data, 1) -> + [t_iodata()]; +arg_types(erlang, dt_get_tag, 0) -> + []; +arg_types(erlang, dt_get_tag_data, 0) -> + []; +arg_types(erlang, dt_prepend_vm_tag_data, 1) -> + [t_iodata()]; +arg_types(erlang, dt_put_tag, 1) -> + [t_sup(t_binary(), t_atom('undefined'))]; +arg_types(erlang, dt_restore_tag, 1) -> + [t_sup(t_tuple([t_non_neg_integer(), t_sup(t_binary(), t_nil())]), t_atom('true'))]; +arg_types(erlang, dt_spread_tag, 1) -> + [t_boolean()]; arg_types(erlang, element, 2) -> [t_pos_fixnum(), t_tuple()]; arg_types(erlang, erase, 0) -> @@ -3570,10 +3582,6 @@ arg_types(erlang, get_module_info, 1) -> [t_atom()]; arg_types(erlang, get_module_info, 2) -> [t_atom(), t_module_info_2()]; -arg_types(erlang, get_utag, 0) -> - []; -arg_types(erlang, get_utag_data, 0) -> - []; arg_types(erlang, group_leader, 0) -> []; arg_types(erlang, group_leader, 2) -> @@ -3790,8 +3798,6 @@ arg_types(erlang, port_set_data, 2) -> [t_sup(t_port(), t_atom()), t_any()]; arg_types(erlang, pre_loaded, 0) -> []; -arg_types(erlang, prepend_vm_utag_data, 1) -> - [t_iodata()]; arg_types(erlang, process_display, 2) -> [t_pid(), t_atom('backtrace')]; arg_types(erlang, process_flag, 2) -> @@ -3818,8 +3824,6 @@ arg_types(erlang, purge_module, 1) -> [t_atom()]; arg_types(erlang, put, 2) -> [t_any(), t_any()]; -arg_types(erlang, put_utag, 1) -> - [t_sup(t_binary(), t_atom('undefined'))]; arg_types(erlang, raise, 3) -> OldStyleType = t_list(t_tuple([t_atom(), t_atom(), t_sup([t_arity(), t_list()])])), @@ -3833,8 +3837,6 @@ arg_types(erlang, register, 2) -> [t_atom(), t_sup(t_port(), t_pid())]; arg_types(erlang, registered, 0) -> []; -arg_types(erlang, restore_utag, 1) -> - [t_sup(t_tuple([t_non_neg_integer(), t_sup(t_binary(), t_nil())]), t_atom('true'))]; arg_types(erlang, resume_process, 1) -> [t_pid()]; % intended for debugging only arg_types(erlang, round, 1) -> @@ -3893,8 +3895,6 @@ arg_types(erlang, spawn_opt, 4) -> [t_node(), t_atom(), t_list(), t_list(t_spawn_options())]; arg_types(erlang, split_binary, 2) -> [t_binary(), t_non_neg_integer()]; -arg_types(erlang, spread_utag, 1) -> - [t_boolean()]; arg_types(erlang, start_timer, 3) -> [t_non_neg_integer(), t_sup(t_pid(), t_atom()), t_any()]; arg_types(erlang, statistics, 1) -> diff --git a/lib/kernel/src/file.erl b/lib/kernel/src/file.erl index b281151778..e2290f6a23 100644 --- a/lib/kernel/src/file.erl +++ b/lib/kernel/src/file.erl @@ -1416,10 +1416,10 @@ mode_list(_) -> %% Functions for communicating with the file server call(Command, Args) when is_list(Args) -> - X = erlang:spread_utag(true), + X = erlang:dt_spread_tag(true), Y = gen_server:call(?FILE_SERVER, list_to_tuple([Command | Args]), infinity), - erlang:restore_utag(X), + erlang:dt_restore_tag(X), Y. check_and_call(Command, Args) when is_list(Args) -> diff --git a/lib/kernel/src/file_io_server.erl b/lib/kernel/src/file_io_server.erl index 6369a5250c..7311ad9fee 100644 --- a/lib/kernel/src/file_io_server.erl +++ b/lib/kernel/src/file_io_server.erl @@ -57,11 +57,11 @@ start_link(Owner, FileName, ModeList) do_start(Spawn, Owner, FileName, ModeList) -> Self = self(), Ref = make_ref(), - Utag = erlang:spread_utag(true), + Utag = erlang:dt_spread_tag(true), Pid = erlang:Spawn( fun() -> - erlang:restore_utag(Utag), + erlang:dt_restore_tag(Utag), %% process_flag(trap_exit, true), case parse_options(ModeList) of {ReadMode, UnicodeMode, Opts} -> @@ -86,7 +86,7 @@ do_start(Spawn, Owner, FileName, ModeList) -> exit(Reason1) end end), - erlang:restore_utag(Utag), + erlang:dt_restore_tag(Utag), Mref = erlang:monitor(process, Pid), receive {Ref, {error, _Reason} = Error} -> diff --git a/lib/runtime_tools/src/dyntrace.erl b/lib/runtime_tools/src/dyntrace.erl index 20472a2be6..388c7679b9 100644 --- a/lib/runtime_tools/src/dyntrace.erl +++ b/lib/runtime_tools/src/dyntrace.erl @@ -14,7 +14,7 @@ %%% four integer arguments and four string arguments; the integer %%% argument(s) must come before any string argument. For example: %%% ``` -%%% 1> dyntrace:put_utag("GGOOOAAALL!!!!!"). +%%% 1> dyntrace:put_tag("GGOOOAAALL!!!!!"). %%% true %%% 2> dyntrace:init(). %%% ok @@ -39,7 +39,7 @@ -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]). --export([put_utag/1, get_utag/0, get_utag_data/0, spread_utag/1, restore_utag/1]). +-export([put_tag/1, get_tag/0, get_tag_data/0, spread_tag/1, restore_tag/1]). -export([scaff/0]). % Development only -export([user_trace_i4s4/9]). % Know what you're doing! @@ -210,7 +210,7 @@ p(I1, I2, I3, I4, S1, S2, S3, S4) when is_integer(I1), is_integer(I2), is_intege true | false | error | badarg. user_trace_int(I1, I2, I3, I4, S1, S2, S3, S4) -> - UTag = get_utag(), + UTag = get_tag(), try user_trace_i4s4(UTag, I1, I2, I3, I4, S1, S2, S3, S4) catch @@ -218,28 +218,28 @@ user_trace_int(I1, I2, I3, I4, S1, S2, S3, S4) -> false end. --spec put_utag(undefined | iodata()) -> binary() | undefined. -put_utag(Data) -> - erlang:put_utag(unicode:characters_to_binary(Data)). +-spec put_tag(undefined | iodata()) -> binary() | undefined. +put_tag(Data) -> + erlang:dt_put_tag(unicode:characters_to_binary(Data)). --spec get_utag() -> binary() | undefined. -get_utag() -> - erlang:get_utag(). +-spec get_tag() -> binary() | undefined. +get_tag() -> + erlang:dt_get_tag(). --spec get_utag_data() -> binary() | undefined. -%% Gets utag if set, otherwise the spread utag data from last incoming message -get_utag_data() -> - erlang:get_utag_data(). +-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_utag(boolean()) -> true | {non_neg_integer(), binary() | []}. -%% Makes the utag behave as a sequential trace token, will spread with messages to be picked up by someone using -%% get_utag_data or get_drv_utag_data. -spread_utag(B) -> - erlang:spread_utag(B). +-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_utag(true | {non_neg_integer(), binary() | []}) -> true. -restore_utag(T) -> - erlang:restore_utag(T). +-spec restore_tag(true | {non_neg_integer(), binary() | []}) -> true. +restore_tag(T) -> + erlang:dt_restore_tag(T). %% Scaffolding to write tedious code: quick brute force and not 100% correct. -- cgit v1.2.3 From 6969ae73662f7c507977a9560a858a5964c791c4 Mon Sep 17 00:00:00 2001 From: Patrik Nyblom Date: Tue, 20 Mar 2012 18:47:03 +0100 Subject: Add documentation for dyntrace and system_info changes --- lib/runtime_tools/doc/src/Makefile | 2 +- lib/runtime_tools/doc/src/dyntrace.xml | 209 +++++++++++++++++++++++++++++++++ lib/runtime_tools/doc/src/ref_man.xml | 1 + 3 files changed, 211 insertions(+), 1 deletion(-) create mode 100644 lib/runtime_tools/doc/src/dyntrace.xml (limited to 'lib') diff --git a/lib/runtime_tools/doc/src/Makefile b/lib/runtime_tools/doc/src/Makefile index dbbae81cfe..f1dd788f80 100644 --- a/lib/runtime_tools/doc/src/Makefile +++ b/lib/runtime_tools/doc/src/Makefile @@ -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 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 @@ + + + + +
+ + 19962012 + Ericsson AB. 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. + + + + dyntrace + Patrik Nyblom + + 1 + ETX/B/SFP (Kenneth Lundin) + + 12-03-20 + A + dyntrace.xml +
+ dyntrace + Interface to dynamic tracing + +

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.

+

Should dynamic tracing be enabled in the current build, either by configuring with ./configure --with-dynamic-trace=dtrace or with ./configure --with-dynamic-trace=systemtap, the module can be used for two things:

+ + Trigger the user-probe user_trace_i4s4 in the NIF library dyntrace.so by calling dyntrace:p/{1,2,3,4,5,6,7,8}. + Set a user specified tag that will be present in the trace messages of both the efile_drv and the user-probe mentioned above. + +

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.

+

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.

+

How to write d programs or systemtap 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 examples directory of the runtime_tools application however contains comprehensive examples of both d and systemtap programs that will help you get started. Another source of information is the README.dtrace(.md) and README.systemtap(.md) files in the Erlang source top directory.

+
+ + + available() -> boolean() + Check if dynamic tracing is available + +

This function uses the NIF library to determine if dynamic + tracing is available. Usually calling erlang:system_info/1 + is a better indicator of the availability of dynamic + tracing.

+

The function will throw an exception if the dyntrace NIF library could not be loaded by the on_load function of this module.

+
+
+ + p() -> true | false | error | badarg + Trigger the user trace probe. + +

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(integer() | string()) -> true | false | error | badarg + Trigger the user trace probe. + +

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(integer() | string(), integer() | string()) -> true | false | error | badarg + Trigger the user trace probe. + +

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. p(1,"Hello") is ok, as is p(1,1) and p("Hello","Again"), but not p("Hello",1).

+
+
+ + p(integer() | string(), integer() | string(), integer() | string()) -> true | false | error | badarg + Trigger the user trace probe. + +

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 p/2.

+
+
+ + p(integer() | string(), integer() | string(), integer() | string(), integer() | string()) -> true | false | error | badarg + Trigger the user trace probe. + +

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 p/2.

+
+
+ + p(integer(), integer() | string(), integer() | string(), integer() | string(), string()) -> true | false | error | badarg + Trigger the user trace probe. + +

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 p/2.

+

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(integer(), integer(), integer() | string(), integer() | string(), string(), string()) -> true | false | error | badarg + Trigger the user trace probe. + +

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 p/2.

+

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(integer(), integer(), integer(), integer() | string(), string(), string(), string()) -> true | false | error | badarg + Trigger the user trace probe. + +

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 p/2.

+

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(integer(), integer(), integer(), integer(), string(), string(), string(), string()) -> true | false | error | badarg + Trigger the user trace probe. + +

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.

+
+
+ + get_tag() -> binary() | undefined + Get the user tag set in the process. + +

This function returns the user tag set in the current + process. If no tag is set or dynamic tracing is not available, + it returns undefined

+
+
+ + get_tag() -> binary() | undefined + Get the user tag set in the process or sent to the process. + +

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 + sequential trace + tokens are spread to other processes together with + messages. For an explanation of how user tags can be spread + together with messages, see spread_tag/1. If no tag is + found or dynamic tracing is not available, it returns + undefined

+
+
+ + + put_tag(Item) -> binary() | undefined + Set the user tag of the current process. + + Item = iodata() + + +

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.

+

The user tag is provided to the user probes triggered by calls top dyntrace:p/{1,2,3,4,5,6,7,8} as well as probes in the efile_driver. In the future, user tags might be added to more probes.

+

The old user tag (if any) is returned, or undefined if no user tag was present or dynamic tracing is not enabled.

+
+
+ + spread_tag(boolean()) -> TagData + Start or stop spreading dynamic trace user tags with the next message. + + TagData = opaque data that can be used as parameter to restore_tag/1 + + +

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.

+

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 spread_tag/1 and restore_tag/1, 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 restore_tag/1.

+

The file 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.

+

The most use of this function would be if one for example uses the io module to communicate with an I/O-server for a regular file, like in the following example:

+
+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).
+
+

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.

+
+
+ + restore_tag(TagData) -> true + Restore to a previous state of user tag spreading. + + TagData = opaque data returned by spread_tag/1 + + +

Restores the previous state of user tags and their spreading as it was before a call to spread_tag/1. 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:

+
+f() ->
+    TagData=dyntrace:spread_tag(false),
+    spawn(fun() ->
+             dyntrace:restore_tag(TagData),
+             do_something()
+          end),
+    do_something_else(),
+    dyntrace:restore_tag(TagData).
+
+

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).

+
+
+
+
+ diff --git a/lib/runtime_tools/doc/src/ref_man.xml b/lib/runtime_tools/doc/src/ref_man.xml index 579efcd969..41fa5f17c4 100644 --- a/lib/runtime_tools/doc/src/ref_man.xml +++ b/lib/runtime_tools/doc/src/ref_man.xml @@ -33,6 +33,7 @@ + -- cgit v1.2.3 From 1e653c3539423e4cfdeab1d232483bcac0e8b073 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Wed, 21 Mar 2012 14:26:47 +0100 Subject: Use distinct function-entry probes for local and global calls It seems useful to be able to filter out (for example) just the global calls. --- lib/runtime_tools/examples/function-calls.d | 10 ++++++++-- lib/runtime_tools/examples/function-calls.systemtap | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/runtime_tools/examples/function-calls.d b/lib/runtime_tools/examples/function-calls.d index 238c5211ac..3e015dc2d2 100644 --- a/lib/runtime_tools/examples/function-calls.d +++ b/lib/runtime_tools/examples/function-calls.d @@ -18,9 +18,15 @@ * %CopyrightEnd% */ -erlang*:::function-entry +erlang*:::local-function-entry { - printf("pid %s enter %s depth %d\n", + 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); } diff --git a/lib/runtime_tools/examples/function-calls.systemtap b/lib/runtime_tools/examples/function-calls.systemtap index 8fc4375135..16c9c04918 100644 --- a/lib/runtime_tools/examples/function-calls.systemtap +++ b/lib/runtime_tools/examples/function-calls.systemtap @@ -28,9 +28,15 @@ * environment. */ -probe process("beam").mark("function-entry") +probe process("beam").mark("local-function-entry") { - printf("pid %s enter %s depth %d\n", + 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); } -- cgit v1.2.3