bpo-31415: Support PYTHONPROFILEIMPORTTIME envvar equivalent to -X importtime (#4240)
Support PYTHONPROFILEIMPORTTIME envvar equivalent to -X importtime
diff --git a/Python/import.c b/Python/import.c
index d396b4d..7ba1842 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -1682,10 +1682,17 @@
* _PyDict_GetItemId()
*/
if (ximporttime == 0) {
- PyObject *xoptions = PySys_GetXOptions();
- if (xoptions) {
- PyObject *value = _PyDict_GetItemId(xoptions, &PyId_importtime);
- ximporttime = (value == Py_True);
+ char *envoption = Py_GETENV("PYTHONPROFILEIMPORTTIME");
+ if (envoption != NULL && strlen(envoption) > 0) {
+ ximporttime = 1;
+ }
+ else {
+ PyObject *xoptions = PySys_GetXOptions();
+ if (xoptions) {
+ PyObject *value = _PyDict_GetItemId(
+ xoptions, &PyId_importtime);
+ ximporttime = (value == Py_True);
+ }
}
if (ximporttime) {
fputs("import time: self [us] | cumulative | imported package\n",