modified .gitignore @@ -33,6 +33,9 @@ /configure src/config.in +# Built by dtrace +src/emacs-dtrace.h + # Built by 'configure'. Info.plist InfoPlist.strings modified configure.ac @@ -1294,6 +1294,7 @@ AC_DEFUN passthrough="$passthrough --with-threads=$with_threads" passthrough="$passthrough --with-rsvg=$with_rsvg" passthrough="$passthrough --with-mps=$with_mps" + passthrough="$passthrough --with-dtrace=$with_dtrace" # Now pass through some checking-related options. emacs_val="--enable-check-lisp-object-type=$enable_check_lisp_object_type" @@ -5648,7 +5649,6 @@ AC_DEFUN fi fi - if test "$REALLY_ANDROID" = "yes" && test "$with_mps" != "no"; then HAVE_MPS=no ndk_SEARCH_MODULE([mps], [MPS], [HAVE_MPS=yes]) @@ -5669,6 +5669,29 @@ AC_DEFUN AC_SUBST([LIBMPS]) AC_SUBST([IGCOBJ]) +### Use DTrace if available, unless '--with-dtrace=no'. +AC_SUBST([DTRACE]) +AC_SUBST([DTRACE_OBJ]) +AC_SUBST([HAVE_DTRACE]) +DTRACE= +DTRACE_OBJ= +HAVE_DTRACE=no +if test "${with_dtrace}" != "no"; then + AC_PATH_PROG([DTRACE], [dtrace], []) + if test "$DTRACE" = ""; then + AC_MSG_ERROR([dtrace command not found]) + fi + AC_DEFINE([HAVE_DTRACE], [1], + [Define to 1 if you have the dtrace command.]) + HAVE_DTRACE=yes + + # DTrace providers have to be linked into an application, normally, + # except on Darwin. DTRACE_OBJ is added to the object files needed + # for Emacs in src/Makefile.in. + if test "$opsys" != darwin; then + DTRACE_OBJ=emacs-dtrace.o + fi +fi dnl Check for malloc/malloc.h on darwin AC_CHECK_HEADERS_ONCE([malloc/malloc.h]) @@ -7875,6 +7898,7 @@ AC_DEFUN Does Emacs have native lisp compiler? ${HAVE_NATIVE_COMP} Does Emacs use version 2 of the X Input Extension? ${HAVE_XINPUT2} Does Emacs generate a smaller-size Japanese dictionary? ${with_small_ja_dic} + Does Emacs use dtrace? ${HAVE_DTRACE} "]) if test -n "${EMACSDATA}"; then modified src/Makefile.in @@ -366,6 +366,33 @@ LIBGPM = LIBMPS = @LIBMPS@ IGCOBJ = @IGCOBJ@ +#----------------------------------------------------------------------- +# DTrace +#----------------------------------------------------------------------- + +HAVE_DTRACE = @HAVE_DTRACE@ +DTRACE = @DTRACE@ +# Empty if linking not required by the OS. +DTRACE_OBJ = @DTRACE_OBJ@ + +ifeq ($(HAVE_DTRACE),yes) + +# Produce header file with DTrace probe macros. +$(srcdir)/emacs-dtrace.h: $(srcdir)/emacs-dtrace.d + $(DTRACE) -o $@ -h -s $< + +# Build DTrace object file (untested). This is not triggered if +# DTRACE_OBJ is empty, which it is on macOS. So we won't use the -G +# switch which doesn't exist on macOS. +emacs-dtrace.o: $(srcdir)/emacs-dtrace.d + $(DTRACE) -o $@ -G -s $< + +# Make objects that use probes dependent on the probe header. +igc.o: $(srcdir)/emacs-dtrace.h + +endif +#----------------------------------------------------------------------- + LIBSELINUX_LIBS = @LIBSELINUX_LIBS@ LIBSELINUX_CFLAGS = @LIBSELINUX_CFLAGS@ @@ -487,7 +514,7 @@ base_obj = doprnt.o intervals.o textprop.o composite.o xml.o lcms.o $(NOTIFY_OBJ) \ $(XWIDGETS_OBJ) \ profiler.o decompress.o \ - pkg.o $(IGCOBJ) \ + pkg.o $(IGCOBJ) $(DTRACE_OBJ) \ thread.o systhread.o sqlite.o treesit.o \ itree.o json.o \ $(if $(HYBRID_MALLOC),sheap.o) \ new file src/emacs-dtrace.d @@ -0,0 +1,12 @@ +/* Emacs DTrace provider. */ + +provider emacs { + probe test_probe(const char *); +}; + +/* See https://docs.oracle.com/cd/E19253-01/817-6223/chp-usdt/index.html */ +#pragma D attributes Evolving/Evolving/Common provider emacs provider +#pragma D attributes Evolving/Evolving/Common provider emacs module +#pragma D attributes Evolving/Evolving/Common provider emacs function +#pragma D attributes Evolving/Evolving/Common provider emacs name +#pragma D attributes Evolving/Evolving/Common provider emacs args modified src/igc.c @@ -5173,6 +5173,24 @@ DEFUN ("igc--remove-extra-dependency", Figc__remove_extra_dependency, return Qt; } +/*********************************************************************** + DTrace + ***********************************************************************/ + +#ifdef HAVE_DTRACE +#include "emacs-dtrace.h" + +DEFUN ("igc-test-probe", Figc_test_probe, Sigc_test_probe, 1, 1, 0, doc: /* */) + (Lisp_Object msg) +{ + CHECK_SUBR (msg); + if (EMACS_TEST_PROBE_ENABLED ()) + EMACS_TEST_PROBE (SSDATA (msg)); + return Qnil; +} + +#endif /* HAVE_DTRACE */ + /*********************************************************************** Init ***********************************************************************/ @@ -5196,6 +5214,10 @@ syms_of_igc (void) defsubr (&Sigc__set_commit_limit); defsubr (&Sigc__add_extra_dependency); defsubr (&Sigc__remove_extra_dependency); +#ifdef HAVE_DTRACE + defsubr (&Sigc_test_probe); +#endif + DEFSYM (Qambig, "ambig"); DEFSYM (Qexact, "exact"); Fprovide (intern_c_string ("mps"), Qnil);