Skip to content

Commit 5db0a98

Browse files
committed
Use PerfCounter instead of monotonic
1 parent 60129b6 commit 5db0a98

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

Python/gc.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "pycore_interpframe.h" // _PyFrame_GetLocalsArray()
1111
#include "pycore_object_alloc.h" // _PyObject_MallocWithType()
1212
#include "pycore_pystate.h" // _PyThreadState_GET()
13-
#include "pycore_time.h" // _PyTime_MonotonicRaw()
13+
#include "pycore_time.h" // _PyTime_PerfCounterUnchecked()
1414
#include "pycore_tuple.h" // _PyTuple_MaybeUntrack()
1515
#include "pycore_weakref.h" // _PyWeakref_ClearRef()
1616

@@ -2068,8 +2068,6 @@ _PyGC_Collect(PyThreadState *tstate, int generation, _PyGC_Reason reason)
20682068
GCState *gcstate = &tstate->interp->gc;
20692069
assert(tstate->current_frame == NULL || tstate->current_frame->stackpointer != NULL);
20702070

2071-
PyTime_t t1;
2072-
20732071
int expected = 0;
20742072
if (!_Py_atomic_compare_exchange_int(&gcstate->collecting, &expected, 1)) {
20752073
// Don't start a garbage collection if one is already in progress.
@@ -2080,9 +2078,10 @@ _PyGC_Collect(PyThreadState *tstate, int generation, _PyGC_Reason reason)
20802078
if (reason != _Py_GC_REASON_SHUTDOWN) {
20812079
invoke_gc_callback(gcstate, "start", generation, &stats);
20822080
}
2081+
PyTime_t t1 = 0; /* initialize to prevent a compiler warning */
20832082
if (gcstate->debug & _PyGC_DEBUG_STATS) {
2084-
(void)PyTime_MonotonicRaw(&t1);
20852083
PySys_WriteStderr("gc: collecting generation %d...\n", generation);
2084+
(void)PyTime_PerfCounterRaw(&t1);
20862085
show_stats_each_generations(gcstate);
20872086
}
20882087
if (PyDTrace_GC_START_ENABLED()) {
@@ -2121,8 +2120,8 @@ _PyGC_Collect(PyThreadState *tstate, int generation, _PyGC_Reason reason)
21212120
_Py_atomic_store_int(&gcstate->collecting, 0);
21222121

21232122
if (gcstate->debug & _PyGC_DEBUG_STATS) {
2124-
PyTime_t t2;
2125-
(void)PyTime_MonotonicRaw(&t2);
2123+
PyTime_t t2 = 0; /* initialize to prevent a compiler warning */
2124+
(void)PyTime_PerfCounterRaw(&t2);
21262125
double d = PyTime_AsSecondsDouble(t2 - t1);
21272126
PySys_WriteStderr(
21282127
"gc: done, %zd unreachable, %zd uncollectable, %.4fs elapsed\n",

0 commit comments

Comments
 (0)