Skip to content

Commit d09c49a

Browse files
Revert duration because we need total duration in tests
1 parent 5da8800 commit d09c49a

3 files changed

Lines changed: 9 additions & 7 deletions

File tree

Include/internal/pycore_interp_structs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ struct gc_generation_stats {
203203

204204
Py_ssize_t objects_transitively_reachable;
205205
Py_ssize_t objects_not_transitively_reachable;
206+
207+
// Total duration of the collection in seconds:
208+
double duration;
206209
};
207210

208211
#define GC_YOUNG_STATS_SIZE 11

Modules/gcmodule.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,6 @@ gc_get_stats_impl(PyObject *module)
342342
/*[clinic end generated code: output=a8ab1d8a5d26f3ab input=1ef4ed9d17b1a470]*/
343343
{
344344
int i;
345-
double duration;
346345
struct gc_generation_stats stats[NUM_GENERATIONS], *st;
347346

348347
/* To get consistent values despite allocations while constructing
@@ -359,13 +358,12 @@ gc_get_stats_impl(PyObject *module)
359358
for (i = 0; i < NUM_GENERATIONS; i++) {
360359
PyObject *dict;
361360
st = &stats[i];
362-
duration = PyTime_AsSecondsDouble(st->ts_stop - st->ts_start);
363361
dict = Py_BuildValue("{snsnsnsnsd}",
364362
"collections", st->collections,
365363
"collected", st->collected,
366364
"uncollectable", st->uncollectable,
367365
"candidates", st->candidates,
368-
"duration", duration
366+
"duration", st->duration
369367
);
370368
if (dict == NULL)
371369
goto error;

Python/gc.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,6 +1447,8 @@ add_stats(GCState *gcstate, int gen, struct gc_generation_stats *stats)
14471447

14481448
cur_stats->objects_transitively_reachable += stats->objects_transitively_reachable;
14491449
cur_stats->objects_not_transitively_reachable += stats->objects_not_transitively_reachable;
1450+
1451+
cur_stats->duration += stats->duration;
14501452
}
14511453

14521454
static void
@@ -1929,13 +1931,12 @@ do_gc_callback(GCState *gcstate, const char *phase,
19291931
assert(PyList_CheckExact(gcstate->callbacks));
19301932
PyObject *info = NULL;
19311933
if (PyList_GET_SIZE(gcstate->callbacks) != 0) {
1932-
double duration = PyTime_AsSecondsDouble(stats->ts_stop - stats->ts_start);
19331934
info = Py_BuildValue("{sisnsnsnsd}",
19341935
"generation", generation,
19351936
"collected", stats->collected,
19361937
"uncollectable", stats->uncollectable,
19371938
"candidates", stats->candidates,
1938-
"duration", duration);
1939+
"duration", stats->duration);
19391940
if (info == NULL) {
19401941
PyErr_FormatUnraisable("Exception ignored while invoking gc callbacks");
19411942
return;
@@ -2191,6 +2192,7 @@ _PyGC_Collect(PyThreadState *tstate, int generation, _PyGC_Reason reason)
21912192
Py_UNREACHABLE();
21922193
}
21932194
(void)PyTime_PerfCounterRaw(&stats.ts_stop);
2195+
stats.duration = PyTime_AsSecondsDouble(stats.ts_stop - stats.ts_start);
21942196
add_stats(gcstate, generation, &stats);
21952197
if (PyDTrace_GC_DONE_ENABLED()) {
21962198
PyDTrace_GC_DONE(stats.uncollectable + stats.collected);
@@ -2213,10 +2215,9 @@ _PyGC_Collect(PyThreadState *tstate, int generation, _PyGC_Reason reason)
22132215
_Py_atomic_store_int(&gcstate->collecting, 0);
22142216

22152217
if (gcstate->debug & _PyGC_DEBUG_STATS) {
2216-
double duration = PyTime_AsSecondsDouble(stats.ts_stop - stats.ts_start);
22172218
PySys_WriteStderr(
22182219
"gc: done, %zd unreachable, %zd uncollectable, %.4fs elapsed\n",
2219-
stats.collected + stats.uncollectable, stats.uncollectable, duration
2220+
stats.collected + stats.uncollectable, stats.uncollectable, stats.duration
22202221
);
22212222
}
22222223

0 commit comments

Comments
 (0)