Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 621601a

Browse files
committed
Merged revisions 67832 via svnmerge from
svn+ssh://[email protected]/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. ........
1 parent 54bc1ec commit 621601a

2 files changed

Lines changed: 30 additions & 23 deletions

File tree

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ What's New in Python 3.1 alpha 0
1212
Core and Builtins
1313
-----------------
1414

15+
- Issue #2467: gc.DEBUG_STATS reported invalid elapsed times. Also, always
16+
print elapsed times, not only when some objects are uncollectable /
17+
unreachable. Original patch by Neil Schemenauer.
18+
1519
- Issue #3439: Add a bit_length method to int.
1620

1721
- Issue #2173: When getting device encoding, check that return value of

Modules/gcmodule.c

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,24 @@ clear_freelists(void)
709709
(void)PyFloat_ClearFreeList();
710710
}
711711

712+
static double
713+
get_time(void)
714+
{
715+
double result = 0;
716+
if (tmod != NULL) {
717+
PyObject *f = PyObject_CallMethod(tmod, "time", NULL);
718+
if (f == NULL) {
719+
PyErr_Clear();
720+
}
721+
else {
722+
if (PyFloat_Check(f))
723+
result = PyFloat_AsDouble(f);
724+
Py_DECREF(f);
725+
}
726+
}
727+
return result;
728+
}
729+
712730
/* This is the main function. Read this to understand how the
713731
* collection process works. */
714732
static Py_ssize_t
@@ -731,16 +749,7 @@ collect(int generation)
731749
}
732750

733751
if (debug & DEBUG_STATS) {
734-
if (tmod != NULL) {
735-
PyObject *f = PyObject_CallMethod(tmod, "time", NULL);
736-
if (f == NULL) {
737-
PyErr_Clear();
738-
}
739-
else {
740-
t1 = PyFloat_AsDouble(f);
741-
Py_DECREF(f);
742-
}
743-
}
752+
t1 = get_time();
744753
PySys_WriteStderr("gc: collecting generation %d...\n",
745754
generation);
746755
PySys_WriteStderr("gc: objects in each generation:");
@@ -813,17 +822,6 @@ collect(int generation)
813822
if (debug & DEBUG_COLLECTABLE) {
814823
debug_cycle("collectable", FROM_GC(gc));
815824
}
816-
if (tmod != NULL && (debug & DEBUG_STATS)) {
817-
PyObject *f = PyObject_CallMethod(tmod, "time", NULL);
818-
if (f == NULL) {
819-
PyErr_Clear();
820-
}
821-
else {
822-
t1 = PyFloat_AsDouble(f)-t1;
823-
Py_DECREF(f);
824-
PySys_WriteStderr("gc: %.4fs elapsed.\n", t1);
825-
}
826-
}
827825
}
828826

829827
/* Clear weakrefs and invoke callbacks as necessary. */
@@ -845,14 +843,19 @@ collect(int generation)
845843
debug_cycle("uncollectable", FROM_GC(gc));
846844
}
847845
if (debug & DEBUG_STATS) {
846+
double t2 = get_time();
848847
if (m == 0 && n == 0)
849-
PySys_WriteStderr("gc: done.\n");
848+
PySys_WriteStderr("gc: done");
850849
else
851850
PySys_WriteStderr(
852851
"gc: done, "
853852
"%" PY_FORMAT_SIZE_T "d unreachable, "
854-
"%" PY_FORMAT_SIZE_T "d uncollectable.\n",
853+
"%" PY_FORMAT_SIZE_T "d uncollectable",
855854
n+m, n);
855+
if (t1 && t2) {
856+
PySys_WriteStderr(", %.4fs elapsed", t2-t1);
857+
}
858+
PySys_WriteStderr(".\n");
856859
}
857860

858861
/* Append instances in the uncollectable set to a Python

0 commit comments

Comments
 (0)