bpo-31415: Support PYTHONPROFILEIMPORTTIME envvar equivalent to -X importtime (#4240)

Support PYTHONPROFILEIMPORTTIME envvar equivalent to -X importtime
This commit is contained in:
Barry Warsaw 2017-11-02 16:13:36 -07:00 committed by GitHub
parent 9e33973332
commit 700d2e4755
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 7 deletions

View file

@ -1682,10 +1682,17 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals,
* _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",