summaryrefslogtreecommitdiff
path: root/Python/import.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/import.c')
-rw-r--r--Python/import.c31
1 files changed, 6 insertions, 25 deletions
diff --git a/Python/import.c b/Python/import.c
index fe60844ef1..fef639825c 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -1675,10 +1675,9 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals,
}
else {
/* 1 -- true, 0 -- false, -1 -- not initialized */
- static int ximporttime = -1;
+ int importtime = interp->core_config.importtime;
static int import_level;
static _PyTime_t accumulated;
- _Py_IDENTIFIER(importtime);
_PyTime_t t1 = 0, accumulated_copy = accumulated;
@@ -1687,32 +1686,14 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals,
* Anyway, importlib._find_and_load is much slower than
* _PyDict_GetItemIdWithError().
*/
- if (ximporttime < 0) {
- const char *envoption = Py_GETENV("PYTHONPROFILEIMPORTTIME");
- if (envoption != NULL && *envoption != '\0') {
- ximporttime = 1;
- }
- else {
- PyObject *xoptions = PySys_GetXOptions();
- PyObject *value = NULL;
- if (xoptions) {
- value = _PyDict_GetItemIdWithError(
- xoptions, &PyId_importtime);
- }
- if (value == NULL && PyErr_Occurred()) {
- goto error;
- }
- if (value != NULL || Py_IsInitialized()) {
- ximporttime = (value == Py_True);
- }
- }
- if (ximporttime > 0) {
+ if (importtime) {
+ static int header = 1;
+ if (header) {
fputs("import time: self [us] | cumulative | imported package\n",
stderr);
+ header = 0;
}
- }
- if (ximporttime > 0) {
import_level++;
t1 = _PyTime_GetPerfCounter();
accumulated = 0;
@@ -1731,7 +1712,7 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals,
PyDTrace_IMPORT_FIND_LOAD_DONE(PyUnicode_AsUTF8(abs_name),
mod != NULL);
- if (ximporttime > 0) {
+ if (importtime) {
_PyTime_t cum = _PyTime_GetPerfCounter() - t1;
import_level--;