-
-
Notifications
You must be signed in to change notification settings - Fork 32.9k
gh-102567: Add -X importtime=2 for logging an importtime message for already-loaded modules #118655
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
Changes from all commits
58d07be
b081980
ee7a4a0
0226aa1
0b0c56d
f9c07ce
6d50b0c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -966,6 +966,7 @@ Beomsoo Bombs Kim | |
Derek D. Kim | ||
Gihwan Kim | ||
Jan Kim | ||
Noah Kim | ||
Taek Joo Kim | ||
Yeojin Kim | ||
Sam Kimbrel | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
:option:`-X importtime <-X>` now accepts value ``2``, which indicates that | ||
an ``importtime`` entry should also be printed if an imported module has | ||
already been loaded. | ||
Patch by Noah Kim and Adam Turner. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,6 +103,15 @@ static struct _inittab *inittab_copy = NULL; | |
#define FIND_AND_LOAD(interp) \ | ||
(interp)->imports.find_and_load | ||
|
||
#define _IMPORT_TIME_HEADER(interp) \ | ||
do { \ | ||
if (FIND_AND_LOAD((interp)).header) { \ | ||
fputs("import time: self [us] | cumulative | imported package\n", \ | ||
stderr); \ | ||
FIND_AND_LOAD((interp)).header = 0; \ | ||
} \ | ||
} while (0) | ||
|
||
|
||
/*******************/ | ||
/* the import lock */ | ||
|
@@ -246,16 +255,33 @@ import_ensure_initialized(PyInterpreterState *interp, PyObject *mod, PyObject *n | |
rc = _PyModuleSpec_IsInitializing(spec); | ||
Py_DECREF(spec); | ||
} | ||
if (rc <= 0) { | ||
if (rc == 0) { | ||
goto done; | ||
} | ||
else if (rc < 0) { | ||
return rc; | ||
} | ||
|
||
/* Wait until module is done importing. */ | ||
PyObject *value = PyObject_CallMethodOneArg( | ||
IMPORTLIB(interp), &_Py_ID(_lock_unlock_module), name); | ||
if (value == NULL) { | ||
return -1; | ||
} | ||
Py_DECREF(value); | ||
|
||
done: | ||
/* When -X importtime=2, print an import time entry even if an | ||
imported module has already been loaded. | ||
*/ | ||
if (_PyInterpreterState_GetConfig(interp)->import_time == 2) { | ||
_IMPORT_TIME_HEADER(interp); | ||
#define import_level FIND_AND_LOAD(interp).import_level | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why use a macro here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to mirror line 3652 ( |
||
fprintf(stderr, "import time: cached | cached | %*s\n", | ||
import_level*2, PyUnicode_AsUTF8(name)); | ||
#undef import_level | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
|
@@ -3686,13 +3712,7 @@ import_find_and_load(PyThreadState *tstate, PyObject *abs_name) | |
* _PyDict_GetItemIdWithError(). | ||
*/ | ||
if (import_time) { | ||
#define header FIND_AND_LOAD(interp).header | ||
if (header) { | ||
fputs("import time: self [us] | cumulative | imported package\n", | ||
stderr); | ||
header = 0; | ||
} | ||
#undef header | ||
_IMPORT_TIME_HEADER(interp); | ||
|
||
import_level++; | ||
// ignore error: don't block import if reading the clock fails | ||
|
Uh oh!
There was an error while loading. Please reload this page.