diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2008-12-17 22:46:54 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2008-12-17 22:46:54 (GMT) |
commit | 73c0e65fc353cbb80cabae8d1123716dcf379a20 (patch) | |
tree | 95d23352480ad95a4a5023fe24aaf2d466af3404 /Modules | |
parent | 1a707981c8b57e5ca7c5b8aa38d3e5e6ca235dbf (diff) | |
download | cpython-73c0e65fc353cbb80cabae8d1123716dcf379a20.zip cpython-73c0e65fc353cbb80cabae8d1123716dcf379a20.tar.gz cpython-73c0e65fc353cbb80cabae8d1123716dcf379a20.tar.bz2 |
Issue #2467: gc.DEBUG_STATS reports invalid elapsed times.
Patch by Neil Schemenauer, very slightly modified.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/gcmodule.c | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c index 6f12972..c7426a5 100644 --- a/Modules/gcmodule.c +++ b/Modules/gcmodule.c @@ -740,6 +740,24 @@ clear_freelists(void) (void)PyFloat_ClearFreeList(); } +static double +get_time(void) +{ + double result = 0; + if (tmod != NULL) { + PyObject *f = PyObject_CallMethod(tmod, "time", NULL); + if (f == NULL) { + PyErr_Clear(); + } + else { + if (PyFloat_Check(f)) + result = PyFloat_AsDouble(f); + Py_DECREF(f); + } + } + return result; +} + /* This is the main function. Read this to understand how the * collection process works. */ static Py_ssize_t @@ -762,16 +780,7 @@ collect(int generation) } if (debug & DEBUG_STATS) { - if (tmod != NULL) { - PyObject *f = PyObject_CallMethod(tmod, "time", NULL); - if (f == NULL) { - PyErr_Clear(); - } - else { - t1 = PyFloat_AsDouble(f); - Py_DECREF(f); - } - } + t1 = get_time(); PySys_WriteStderr("gc: collecting generation %d...\n", generation); PySys_WriteStderr("gc: objects in each generation:"); @@ -844,17 +853,6 @@ collect(int generation) if (debug & DEBUG_COLLECTABLE) { debug_cycle("collectable", FROM_GC(gc)); } - if (tmod != NULL && (debug & DEBUG_STATS)) { - PyObject *f = PyObject_CallMethod(tmod, "time", NULL); - if (f == NULL) { - PyErr_Clear(); - } - else { - t1 = PyFloat_AsDouble(f)-t1; - Py_DECREF(f); - PySys_WriteStderr("gc: %.4fs elapsed.\n", t1); - } - } } /* Clear weakrefs and invoke callbacks as necessary. */ @@ -876,14 +874,19 @@ collect(int generation) debug_cycle("uncollectable", FROM_GC(gc)); } if (debug & DEBUG_STATS) { + double t2 = get_time(); if (m == 0 && n == 0) - PySys_WriteStderr("gc: done.\n"); + PySys_WriteStderr("gc: done"); else PySys_WriteStderr( "gc: done, " "%" PY_FORMAT_SIZE_T "d unreachable, " - "%" PY_FORMAT_SIZE_T "d uncollectable.\n", + "%" PY_FORMAT_SIZE_T "d uncollectable", n+m, n); + if (t1 && t2) { + PySys_WriteStderr(", %.4fs elapsed", t2-t1); + } + PySys_WriteStderr(".\n"); } /* Append instances in the uncollectable set to a Python |