Skip to content

Instantly share code, notes, and snippets.

@methane
Created September 5, 2017 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save methane/e688bb31a23bcc437defcea4b815b1eb to your computer and use it in GitHub Desktop.
Save methane/e688bb31a23bcc437defcea4b815b1eb to your computer and use it in GitHub Desktop.
diff --git a/Python/import.c b/Python/import.c
index f27b7cb010..6b3af888be 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -1562,9 +1562,30 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals,
}
}
else {
+#ifdef CLOCK_HIGHRES
+ const clockid_t clk_id = CLOCK_HIGHRES;
+#else
+ const clockid_t clk_id = CLOCK_MONOTONIC;
+#endif
+ static int import_level;
+ struct timespec t1, t2;
+
+ clock_gettime(clk_id, &t1);
+ import_level++;
+ //fprintf(stderr, "%*s+ %s\n", import_level*2, "", PyUnicode_AsUTF8(abs_name));
+
mod = _PyObject_CallMethodIdObjArgs(interp->importlib,
&PyId__find_and_load, abs_name,
interp->import_func, NULL);
+
+ clock_gettime(clk_id, &t2);
+ fprintf(stderr, "%*s- %s %.3lf [ms]\n",
+ import_level*2, "",
+ PyUnicode_AsUTF8(abs_name),
+ (t2.tv_sec - t1.tv_sec) * 1000
+ + (t2.tv_nsec - t1.tv_nsec) / 1000000.0);
+ import_level--;
+
if (mod == NULL) {
goto error;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment