commit eb883bc52d6938d965870714e513ec00d18b05b0
Author: Ronan Dunklau <ronan.dunklau@aiven.io>
Date:   Fri Dec 10 15:51:54 2021 +0100

    Add tracing to generation context

diff --git a/src/backend/utils/mmgr/generation.c b/src/backend/utils/mmgr/generation.c
index 2c98877953..b61a9c024d 100644
--- a/src/backend/utils/mmgr/generation.c
+++ b/src/backend/utils/mmgr/generation.c
@@ -41,6 +41,7 @@
 #include "lib/ilist.h"
 #include "utils/memdebug.h"
 #include "utils/memutils.h"
+#include "pg_trace.h"
 
 
 #define Generation_BLOCKHDRSZ	MAXALIGN(sizeof(GenerationBlock))
@@ -278,7 +279,7 @@ GenerationContextCreate(MemoryContext parent,
 						&GenerationMethods,
 						parent,
 						name);
-
+	TRACE_POSTGRESQL_GENERATION_ALLOC_CREATE();
 	return (MemoryContext) set;
 }
 
@@ -313,8 +314,9 @@ GenerationReset(MemoryContext context)
 #ifdef CLOBBER_FREED_MEMORY
 		wipe_mem(block, block->blksize);
 #endif
-
+		TRACE_POSTGRESQL_GENERATION_ALLOC_FREE(block->blksize);
 		free(block);
+
 	}
 
 	set->block = NULL;
@@ -335,6 +337,7 @@ GenerationDelete(MemoryContext context)
 {
 	/* Reset to release all the GenerationBlocks */
 	GenerationReset(context);
+	TRACE_POSTGRESQL_GENERATION_ALLOC_DESTROY();
 	/* And free the context header */
 	free(context);
 }
@@ -458,6 +461,7 @@ GenerationAlloc(MemoryContext context, Size size)
 			blksize <<= 1;
 
 		block = (GenerationBlock *) malloc(blksize);
+		TRACE_POSTGRESQL_GENERATION_ALLOC_MALLOC(blksize);
 
 		if (block == NULL)
 			return NULL;
@@ -596,6 +600,7 @@ GenerationFree(MemoryContext context, void *pointer)
 	dlist_delete(&block->node);
 
 	context->mem_allocated -= block->blksize;
+	TRACE_POSTGRESQL_GENERATION_ALLOC_FREE(block->blksize);
 	free(block);
 }
 
diff --git a/src/backend/utils/probes.d b/src/backend/utils/probes.d
index b0c50a3c7f..0531ff03c8 100644
--- a/src/backend/utils/probes.d
+++ b/src/backend/utils/probes.d
@@ -91,4 +91,10 @@ provider postgresql {
 	probe wal__switch();
 	probe wal__buffer__write__dirty__start();
 	probe wal__buffer__write__dirty__done();
+
+  probe generation_alloc_malloc(Size);
+  probe generation_alloc_free(Size);
+
+  probe generation_alloc_create();
+  probe generation_alloc_destroy();
 };
