Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-31574: importlib dtrace #3749

Merged
merged 1 commit into from
Sep 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Doc/howto/instrumentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----------------
Expand Down
2 changes: 2 additions & 0 deletions Include/pydtrace.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions Include/pydtrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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 */

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Importlib was instrumented with two dtrace probes to profile import timing.
10 changes: 10 additions & 0 deletions Python/import.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "frameobject.h"
#include "osdefs.h"
#include "importdl.h"
#include "pydtrace.h"

#ifdef HAVE_FCNTL_H
#include <fcntl.h>
Expand Down Expand Up @@ -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;
}
Expand Down