]> granicus.if.org Git - python/commitdiff
Merged revisions 67832 via svnmerge from
authorAntoine Pitrou <solipsis@pitrou.net>
Wed, 17 Dec 2008 23:18:19 +0000 (23:18 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Wed, 17 Dec 2008 23:18:19 +0000 (23:18 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r67832 | antoine.pitrou | 2008-12-17 23:46:54 +0100 (mer., 17 déc. 2008) | 4 lines

  Issue #2467: gc.DEBUG_STATS reports invalid elapsed times.
  Patch by Neil Schemenauer, very slightly modified.
........

Misc/NEWS
Modules/gcmodule.c

index bbe9214a7ce2e624a2c94abb2aba357b3fa512a6..f812ce488a3f152e36594725170aa5f92ae99e82 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,10 @@ What's New in Python 3.1 alpha 0
 Core and Builtins
 -----------------
 
+- Issue #2467: gc.DEBUG_STATS reported invalid elapsed times. Also, always
+  print elapsed times, not only when some objects are uncollectable /
+  unreachable. Original patch by Neil Schemenauer.
+
 - Issue #3439: Add a bit_length method to int.
 
 - Issue #2173: When getting device encoding, check that return value of
index f7eef4dedb7ef5ed60cb81deaa6931a8b994f02d..8462ee93faa19888e5535c05ce1f2050eca3224d 100644 (file)
@@ -709,6 +709,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
@@ -731,16 +749,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:");
@@ -813,17 +822,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. */
@@ -845,14 +843,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