wingo pushed a commit to branch wip-whippet
in repository guile.

commit 8a157bc616dc42407860b5da9e0b25e910ba0b47
Author: Andy Wingo <wi...@igalia.com>
AuthorDate: Fri May 16 21:57:10 2025 +0200

    Add allocation counter to prepare_gc event
    
    Adapt all users
---
 api/gc-basic-stats.h          | 5 ++++-
 api/gc-event-listener-chain.h | 7 ++++---
 api/gc-event-listener.h       | 3 ++-
 api/gc-lttng.h                | 5 +++--
 api/gc-null-event-listener.h  | 3 ++-
 src/bdw.c                     | 2 +-
 src/mmc.c                     | 2 +-
 src/pcc.c                     | 2 +-
 src/semi.c                    | 4 +++-
 9 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/api/gc-basic-stats.h b/api/gc-basic-stats.h
index 0f8c68aee..69a98cdf3 100644
--- a/api/gc-basic-stats.h
+++ b/api/gc-basic-stats.h
@@ -26,6 +26,7 @@ struct gc_basic_stats {
   size_t max_heap_size;
   size_t live_data_size;
   size_t max_live_data_size;
+  uint64_t allocation_counter_at_last_gc;
   struct gc_latency pause_times;
 };
 
@@ -68,12 +69,14 @@ static inline void gc_basic_stats_waiting_for_stop(void 
*data) {}
 static inline void gc_basic_stats_mutators_stopped(void *data) {}
 
 static inline void gc_basic_stats_prepare_gc(void *data,
-                                             enum gc_collection_kind kind) {
+                                             enum gc_collection_kind kind,
+                                             uint64_t allocation_counter) {
   struct gc_basic_stats *stats = data;
   if (kind == GC_COLLECTION_MINOR)
     stats->minor_collection_count++;
   else
     stats->major_collection_count++;
+  stats->allocation_counter_at_last_gc = allocation_counter;
 }
 
 static inline void gc_basic_stats_roots_traced(void *data) {}
diff --git a/api/gc-event-listener-chain.h b/api/gc-event-listener-chain.h
index 27b56d5c6..380439f2c 100644
--- a/api/gc-event-listener-chain.h
+++ b/api/gc-event-listener-chain.h
@@ -36,10 +36,11 @@ static inline void 
gc_event_listener_chain_mutators_stopped(void *data) {
   chain->tail.mutators_stopped(chain->tail_data);
 }
 static inline void
-gc_event_listener_chain_prepare_gc(void *data, enum gc_collection_kind kind) {
+gc_event_listener_chain_prepare_gc(void *data, enum gc_collection_kind kind,
+                                   uint64_t counter) {
   struct gc_event_listener_chain *chain = data;
-  chain->head.prepare_gc(chain->head_data, kind);
-  chain->tail.prepare_gc(chain->tail_data, kind);
+  chain->head.prepare_gc(chain->head_data, kind, counter);
+  chain->tail.prepare_gc(chain->tail_data, kind, counter);
 }
 static inline void gc_event_listener_chain_roots_traced(void *data) {
   struct gc_event_listener_chain *chain = data;
diff --git a/api/gc-event-listener.h b/api/gc-event-listener.h
index 66801a52c..da4ab5809 100644
--- a/api/gc-event-listener.h
+++ b/api/gc-event-listener.h
@@ -8,7 +8,8 @@ struct gc_event_listener {
   void (*requesting_stop)(void *data);
   void (*waiting_for_stop)(void *data);
   void (*mutators_stopped)(void *data);
-  void (*prepare_gc)(void *data, enum gc_collection_kind kind);
+  void (*prepare_gc)(void *data, enum gc_collection_kind kind,
+                     uint64_t allocation_counter);
   void (*roots_traced)(void *data);
   void (*heap_traced)(void *data);
   void (*ephemerons_traced)(void *data);
diff --git a/api/gc-lttng.h b/api/gc-lttng.h
index d192be4ed..24612f4a8 100644
--- a/api/gc-lttng.h
+++ b/api/gc-lttng.h
@@ -45,9 +45,10 @@ LTTNG_UST_TRACEPOINT_EVENT_INSTANCE(
   whippet, tracepoint, whippet, mutators_stopped, LTTNG_UST_TP_ARGS())
 LTTNG_UST_TRACEPOINT_EVENT(
   whippet, prepare_gc,
-  LTTNG_UST_TP_ARGS(int, gc_kind),
+  LTTNG_UST_TP_ARGS(int, gc_kind, uint64_t, allocation_counter),
   LTTNG_UST_TP_FIELDS(
-    lttng_ust_field_enum(whippet, gc_kind, int, gc_kind, gc_kind)))
+    lttng_ust_field_enum(whippet, gc_kind, int, gc_kind, gc_kind)
+    lttng_ust_field_integer(uint64_t, allocation_counter, allocation_counter)))
 LTTNG_UST_TRACEPOINT_EVENT_INSTANCE(
   whippet, tracepoint, whippet, roots_traced, LTTNG_UST_TP_ARGS())
 LTTNG_UST_TRACEPOINT_EVENT_INSTANCE(
diff --git a/api/gc-null-event-listener.h b/api/gc-null-event-listener.h
index 9c032ffc2..63ca29eb1 100644
--- a/api/gc-null-event-listener.h
+++ b/api/gc-null-event-listener.h
@@ -8,7 +8,8 @@ static inline void gc_null_event_listener_requesting_stop(void 
*data) {}
 static inline void gc_null_event_listener_waiting_for_stop(void *data) {}
 static inline void gc_null_event_listener_mutators_stopped(void *data) {}
 static inline void gc_null_event_listener_prepare_gc(void *data,
-                                                     enum gc_collection_kind) 
{}
+                                                     enum gc_collection_kind,
+                                                     uint64_t) {}
 static inline void gc_null_event_listener_roots_traced(void *data) {}
 static inline void gc_null_event_listener_heap_traced(void *data) {}
 static inline void gc_null_event_listener_ephemerons_traced(void *data) {}
diff --git a/src/bdw.c b/src/bdw.c
index fc228c15e..8cee58a73 100644
--- a/src/bdw.c
+++ b/src/bdw.c
@@ -505,7 +505,7 @@ static void on_collection_event(GC_EventType event) {
   }
   case GC_EVENT_MARK_START:
     HEAP_EVENT(mutators_stopped);
-    HEAP_EVENT(prepare_gc, GC_COLLECTION_MAJOR);
+    HEAP_EVENT(prepare_gc, GC_COLLECTION_MAJOR, GC_get_total_bytes());
     break;
   case GC_EVENT_MARK_END:
     HEAP_EVENT(roots_traced);
diff --git a/src/mmc.c b/src/mmc.c
index 4e79675cc..b6b83396b 100644
--- a/src/mmc.c
+++ b/src/mmc.c
@@ -792,7 +792,7 @@ collect(struct gc_mutator *mut, enum gc_collection_kind 
requested_kind) {
   enum gc_collection_kind gc_kind =
     determine_collection_kind(heap, requested_kind);
   int is_minor = gc_kind == GC_COLLECTION_MINOR;
-  HEAP_EVENT(heap, prepare_gc, gc_kind);
+  HEAP_EVENT(heap, prepare_gc, gc_kind, 
heap->total_allocated_bytes_at_last_gc);
   nofl_space_prepare_gc(nofl_space, gc_kind);
   large_object_space_start_gc(lospace, is_minor);
   gc_extern_space_start_gc(exspace, is_minor);
diff --git a/src/pcc.c b/src/pcc.c
index 6902b3412..c0aef49fd 100644
--- a/src/pcc.c
+++ b/src/pcc.c
@@ -905,11 +905,11 @@ collect(struct gc_mutator *mut, enum gc_collection_kind 
requested_kind) {
     heap->is_minor_collection =
 #endif
     GC_GENERATIONAL ? gc_kind == GC_COLLECTION_MINOR : 0;
-  HEAP_EVENT(heap, prepare_gc, gc_kind);
   uint64_t *counter_loc = &heap->total_allocated_bytes_at_last_gc;
   copy_space_add_to_allocation_counter(heap_allocation_space(heap),
                                        counter_loc);
   large_object_space_add_to_allocation_counter(lospace, counter_loc);
+  HEAP_EVENT(heap, prepare_gc, gc_kind, *counter_loc);
   copy_spaces_start_gc(heap, is_minor_gc);
   large_object_space_start_gc(lospace, is_minor_gc);
   gc_extern_space_start_gc(exspace, is_minor_gc);
diff --git a/src/semi.c b/src/semi.c
index a1526cec4..0cca01868 100644
--- a/src/semi.c
+++ b/src/semi.c
@@ -395,7 +395,6 @@ static void collect(struct gc_mutator *mut) {
   HEAP_EVENT(heap, requesting_stop);
   HEAP_EVENT(heap, waiting_for_stop);
   HEAP_EVENT(heap, mutators_stopped);
-  HEAP_EVENT(heap, prepare_gc, GC_COLLECTION_COMPACTING);
 
   struct semi_space *semi = heap_semi_space(heap);
   struct large_object_space *large = heap_large_object_space(heap);
@@ -403,6 +402,9 @@ static void collect(struct gc_mutator *mut) {
   uint64_t *counter_loc = &heap->total_allocated_bytes_at_last_gc;
   semi_space_add_to_allocation_counter(semi, counter_loc);
   large_object_space_add_to_allocation_counter(large, counter_loc);
+
+  HEAP_EVENT(heap, prepare_gc, GC_COLLECTION_COMPACTING, *counter_loc);
+
   large_object_space_start_gc(large, 0);
   gc_extern_space_start_gc(heap->extern_space, 0);
   flip(semi);

Reply via email to