]> granicus.if.org Git - python/commitdiff
bpo-31574: importlib dtrace (#3749)
authorChristian Heimes <christian@python.org>
Fri, 29 Sep 2017 22:53:19 +0000 (00:53 +0200)
committerŁukasz Langa <lukasz@langa.pl>
Fri, 29 Sep 2017 22:53:19 +0000 (15:53 -0700)
Importlib was instrumented with two dtrace probes to profile import timing.

Signed-off-by: Christian Heimes <christian@python.org>
Doc/howto/instrumentation.rst
Include/pydtrace.d
Include/pydtrace.h
Misc/NEWS.d/next/Core and Builtins/2017-09-25-12-35-48.bpo-31574.5yX5r5.rst [new file with mode: 0644]
Python/import.c

index 7fca9aac7b3a6ec75b13db21288841da454db5e0..2ac939c5307f46763223d41be9370d9c9f1c9ac2 100644 (file)
@@ -312,6 +312,17 @@ Available static markers
    Fires when the Python interpreter finishes a garbage collection
    cycle. ``arg0`` is the number of collected objects.
 
+.. c:function:: import__find__load__start(str modulename)
+
+   Fires before :mod:`importlib` attempts to find and load the module.
+   ``arg0`` is the module name.
+
+.. c:function:: import__find__load__done(str modulename, int found)
+
+   Fires after :mod:`importlib`'s find_and_load function is called.
+   ``arg0`` is the module name, ``arg1`` indicates if module was
+   successfully loaded.
+
 
 SystemTap Tapsets
 -----------------
index 883605566d58c0bcbbce5e25d547416ecc2c42a7..a6a5e7ec224f484c2e8887c4c0ac468f269a3386 100644 (file)
@@ -10,6 +10,8 @@ provider python {
     probe line(const char *, const char *, int);
     probe gc__start(int);
     probe gc__done(long);
+    probe import__find__load__start(const char *);
+    probe import__find__load__done(const char *, int);
 };
 
 #pragma D attributes Evolving/Evolving/Common provider python provider
index c43a253d3ccc528a5f1a8c332721353cedb8f0ae..037961d429c64c6b33721f5a3ce735e707996fc4 100644 (file)
@@ -34,6 +34,8 @@ static inline void PyDTrace_INSTANCE_NEW_START(int arg0) {}
 static inline void PyDTrace_INSTANCE_NEW_DONE(int arg0) {}
 static inline void PyDTrace_INSTANCE_DELETE_START(int arg0) {}
 static inline void PyDTrace_INSTANCE_DELETE_DONE(int arg0) {}
+static inline void PyDTrace_IMPORT_FIND_LOAD_START(const char *arg0) {}
+static inline void PyDTrace_IMPORT_FIND_LOAD_DONE(const char *arg0, int arg1) {}
 
 static inline int PyDTrace_LINE_ENABLED(void) { return 0; }
 static inline int PyDTrace_FUNCTION_ENTRY_ENABLED(void) { return 0; }
@@ -44,6 +46,8 @@ static inline int PyDTrace_INSTANCE_NEW_START_ENABLED(void) { return 0; }
 static inline int PyDTrace_INSTANCE_NEW_DONE_ENABLED(void) { return 0; }
 static inline int PyDTrace_INSTANCE_DELETE_START_ENABLED(void) { return 0; }
 static inline int PyDTrace_INSTANCE_DELETE_DONE_ENABLED(void) { return 0; }
+static inline int PyDTrace_IMPORT_FIND_LOAD_START_ENABLED(void) { return 0; }
+static inline int PyDTrace_IMPORT_FIND_LOAD_DONE_ENABLED(void) { return 0; }
 
 #endif /* !WITH_DTRACE */
 
diff --git a/Misc/NEWS.d/next/Core and Builtins/2017-09-25-12-35-48.bpo-31574.5yX5r5.rst b/Misc/NEWS.d/next/Core and Builtins/2017-09-25-12-35-48.bpo-31574.5yX5r5.rst
new file mode 100644 (file)
index 0000000..e5c8ae2
--- /dev/null
@@ -0,0 +1 @@
+Importlib was instrumented with two dtrace probes to profile import timing.
index 5e841ca782d2bca6a6ae791627d7ae90489d44a8..e50ea4d03ccf110ee1807ff46821e230992141e8 100644 (file)
@@ -12,6 +12,7 @@
 #include "frameobject.h"
 #include "osdefs.h"
 #include "importdl.h"
+#include "pydtrace.h"
 
 #ifdef HAVE_FCNTL_H
 #include <fcntl.h>
@@ -1667,9 +1668,18 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals,
     }
     else {
         Py_XDECREF(mod);
+
+        if (PyDTrace_IMPORT_FIND_LOAD_START_ENABLED())
+            PyDTrace_IMPORT_FIND_LOAD_START(PyUnicode_AsUTF8(abs_name));
+
         mod = _PyObject_CallMethodIdObjArgs(interp->importlib,
                                             &PyId__find_and_load, abs_name,
                                             interp->import_func, NULL);
+
+        if (PyDTrace_IMPORT_FIND_LOAD_DONE_ENABLED())
+            PyDTrace_IMPORT_FIND_LOAD_DONE(PyUnicode_AsUTF8(abs_name),
+                                           mod != NULL);
+
         if (mod == NULL) {
             goto error;
         }