(original) (raw)

Index: Modules/gcmodule.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Modules/gcmodule.c,v retrieving revision 2.80 diff -u -r2.80 gcmodule.c --- Modules/gcmodule.c 1 Nov 2004 16:39:57 -0000 2.80 +++ Modules/gcmodule.c 11 Jan 2005 17:08:54 -0000 @@ -732,6 +732,9 @@ PyGC_Head unreachable; /* non-problematic unreachable trash */ PyGC_Head finalizers; /* objects with, & reachable from, __del__ */ PyGC_Head *gc; + static PyObject *tmod = NULL; + static unsigned int show_elapsed = 1; + double t1 = 0.0; if (delstr == NULL) { delstr = PyString_InternFromString("__del__"); @@ -740,6 +743,24 @@ } if (debug & DEBUG_STATS) { + if (tmod == NULL && show_elapsed) { + tmod = PyImport_ImportModule("time"); + if (tmod == NULL) { + PySys_WriteStderr("gc: elapsed time unavailable\n"); + show_elapsed = 0; + } + } + if (show_elapsed) { + PyObject *f = PyObject_CallMethod(tmod, "time", NULL); + if (f == NULL) { + PySys_WriteStderr("gc: elapsed time unavailable\n"); + show_elapsed = 0; + } + else { + t1 = PyFloat_AsDouble(f); + Py_DECREF(f); + } + } PySys_WriteStderr("gc: collecting generation %d...\n", generation); PySys_WriteStderr("gc: objects in each generation:"); @@ -841,6 +862,18 @@ "gc: done, %ld unreachable, %ld uncollectable.\n", n+m, n); } + if (show_elapsed) { + PyObject *f = PyObject_CallMethod(tmod, "time", NULL); + if (f == NULL) { + PySys_WriteStderr("gc: elapsed time unavailable\n"); + show_elapsed = 0; + } + else { + t1 = PyFloat_AsDouble(f)-t1; + Py_DECREF(f); + PySys_WriteStderr("gc: %.4fs elapsed.\n", t1); + } + } } /* Append instances in the uncollectable set to a Python