File 1154-erts-Create-thread-hashes-for-time-memory-tracing-on.patch of Package erlang

From 62cfd55802dcba09c6c6bfa5e253f8548c78140a Mon Sep 17 00:00:00 2001
From: Sverker Eriksson <sverker@erlang.org>
Date: Wed, 27 Aug 2025 13:01:17 +0200
Subject: [PATCH 4/7] erts: Create thread hashes for time/memory tracing on
 demand

Save memory in most cases, but impose extra cpu (time) when tracing.
---
 erts/emulator/beam/beam_bp.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/erts/emulator/beam/beam_bp.c b/erts/emulator/beam/beam_bp.c
index 7c85ab2624..097e4ee769 100644
--- a/erts/emulator/beam/beam_bp.c
+++ b/erts/emulator/beam/beam_bp.c
@@ -1430,6 +1430,9 @@ int erts_is_call_break(Process *p, ErtsTraceSession *session, int is_time,
 
     /* foreach threadspecific hash */
     for (i = 0; i < bdt->nthreads; i++) {
+        if (!bdt->threads[i]) {
+            continue;
+        }
         /* foreach hash bucket not NIL*/
         for(ix = 0; ix < bdt->threads[i]->n; ix++) {
             item = &(bdt->threads[i]->buckets[ix]);
@@ -1716,6 +1719,10 @@ static void bp_hash_accum(bp_trace_hash_t **hash_p,
 {
     bp_data_trace_bucket_t *item;
 
+    if (*hash_p == NULL) {
+        *hash_p = bp_hash_alloc(32);
+    }
+
     item = bp_hash_get(*hash_p, sitem);
     if (!item) {
         bp_hash_put(hash_p, sitem);
@@ -2108,7 +2115,7 @@ static BpDataCallTrace* bp_calltrace_alloc(void)
     bdt->nthreads = n;
     erts_refc_init(&bdt->refc, 1);
     for (Uint i = 0; i < n; i++) {
-        bdt->threads[i] = bp_hash_alloc(32);
+        bdt->threads[i] = NULL;  // allocate on demand
     }
     return bdt;
 }
@@ -2118,7 +2125,9 @@ bp_calltrace_unref(BpDataCallTrace* bdt)
 {
     if (erts_refc_dectest(&bdt->refc, 0) <= 0) {
 	for (Uint i = 0; i < bdt->nthreads; ++i) {
-	    bp_hash_dealloc(bdt->threads[i]);
+            if (bdt->threads[i]) {
+                bp_hash_dealloc(bdt->threads[i]);
+            }
 	}
 	Free(bdt);
     }
-- 
2.51.0

openSUSE Build Service is sponsored by