Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3d2b407

Browse files
tiranambv
authored andcommitted
bpo-31574: importlib dtrace (#3749)
Importlib was instrumented with two dtrace probes to profile import timing. Signed-off-by: Christian Heimes <[email protected]>
1 parent 574562c commit 3d2b407

5 files changed

Lines changed: 28 additions & 0 deletions

File tree

Doc/howto/instrumentation.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,17 @@ Available static markers
312312
Fires when the Python interpreter finishes a garbage collection
313313
cycle. ``arg0`` is the number of collected objects.
314314

315+
.. c:function:: import__find__load__start(str modulename)
316+
317+
Fires before :mod:`importlib` attempts to find and load the module.
318+
``arg0`` is the module name.
319+
320+
.. c:function:: import__find__load__done(str modulename, int found)
321+
322+
Fires after :mod:`importlib`'s find_and_load function is called.
323+
``arg0`` is the module name, ``arg1`` indicates if module was
324+
successfully loaded.
325+
315326

316327
SystemTap Tapsets
317328
-----------------

Include/pydtrace.d

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ provider python {
1010
probe line(const char *, const char *, int);
1111
probe gc__start(int);
1212
probe gc__done(long);
13+
probe import__find__load__start(const char *);
14+
probe import__find__load__done(const char *, int);
1315
};
1416

1517
#pragma D attributes Evolving/Evolving/Common provider python provider

Include/pydtrace.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ static inline void PyDTrace_INSTANCE_NEW_START(int arg0) {}
3434
static inline void PyDTrace_INSTANCE_NEW_DONE(int arg0) {}
3535
static inline void PyDTrace_INSTANCE_DELETE_START(int arg0) {}
3636
static inline void PyDTrace_INSTANCE_DELETE_DONE(int arg0) {}
37+
static inline void PyDTrace_IMPORT_FIND_LOAD_START(const char *arg0) {}
38+
static inline void PyDTrace_IMPORT_FIND_LOAD_DONE(const char *arg0, int arg1) {}
3739

3840
static inline int PyDTrace_LINE_ENABLED(void) { return 0; }
3941
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; }
4446
static inline int PyDTrace_INSTANCE_NEW_DONE_ENABLED(void) { return 0; }
4547
static inline int PyDTrace_INSTANCE_DELETE_START_ENABLED(void) { return 0; }
4648
static inline int PyDTrace_INSTANCE_DELETE_DONE_ENABLED(void) { return 0; }
49+
static inline int PyDTrace_IMPORT_FIND_LOAD_START_ENABLED(void) { return 0; }
50+
static inline int PyDTrace_IMPORT_FIND_LOAD_DONE_ENABLED(void) { return 0; }
4751

4852
#endif /* !WITH_DTRACE */
4953

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Importlib was instrumented with two dtrace probes to profile import timing.

Python/import.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "frameobject.h"
1313
#include "osdefs.h"
1414
#include "importdl.h"
15+
#include "pydtrace.h"
1516

1617
#ifdef HAVE_FCNTL_H
1718
#include <fcntl.h>
@@ -1667,9 +1668,18 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals,
16671668
}
16681669
else {
16691670
Py_XDECREF(mod);
1671+
1672+
if (PyDTrace_IMPORT_FIND_LOAD_START_ENABLED())
1673+
PyDTrace_IMPORT_FIND_LOAD_START(PyUnicode_AsUTF8(abs_name));
1674+
16701675
mod = _PyObject_CallMethodIdObjArgs(interp->importlib,
16711676
&PyId__find_and_load, abs_name,
16721677
interp->import_func, NULL);
1678+
1679+
if (PyDTrace_IMPORT_FIND_LOAD_DONE_ENABLED())
1680+
PyDTrace_IMPORT_FIND_LOAD_DONE(PyUnicode_AsUTF8(abs_name),
1681+
mod != NULL);
1682+
16731683
if (mod == NULL) {
16741684
goto error;
16751685
}

0 commit comments

Comments
 (0)