Skip to content

Commit 62cfd55

Browse files
committed
erts: Create thread hashes for time/memory tracing on demand
Save memory in most cases, but impose extra cpu (time) when tracing.
1 parent 15c8722 commit 62cfd55

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

erts/emulator/beam/beam_bp.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,6 +1430,9 @@ int erts_is_call_break(Process *p, ErtsTraceSession *session, int is_time,
14301430

14311431
/* foreach threadspecific hash */
14321432
for (i = 0; i < bdt->nthreads; i++) {
1433+
if (!bdt->threads[i]) {
1434+
continue;
1435+
}
14331436
/* foreach hash bucket not NIL*/
14341437
for(ix = 0; ix < bdt->threads[i]->n; ix++) {
14351438
item = &(bdt->threads[i]->buckets[ix]);
@@ -1716,6 +1719,10 @@ static void bp_hash_accum(bp_trace_hash_t **hash_p,
17161719
{
17171720
bp_data_trace_bucket_t *item;
17181721

1722+
if (*hash_p == NULL) {
1723+
*hash_p = bp_hash_alloc(32);
1724+
}
1725+
17191726
item = bp_hash_get(*hash_p, sitem);
17201727
if (!item) {
17211728
bp_hash_put(hash_p, sitem);
@@ -2108,7 +2115,7 @@ static BpDataCallTrace* bp_calltrace_alloc(void)
21082115
bdt->nthreads = n;
21092116
erts_refc_init(&bdt->refc, 1);
21102117
for (Uint i = 0; i < n; i++) {
2111-
bdt->threads[i] = bp_hash_alloc(32);
2118+
bdt->threads[i] = NULL; // allocate on demand
21122119
}
21132120
return bdt;
21142121
}
@@ -2118,7 +2125,9 @@ bp_calltrace_unref(BpDataCallTrace* bdt)
21182125
{
21192126
if (erts_refc_dectest(&bdt->refc, 0) <= 0) {
21202127
for (Uint i = 0; i < bdt->nthreads; ++i) {
2121-
bp_hash_dealloc(bdt->threads[i]);
2128+
if (bdt->threads[i]) {
2129+
bp_hash_dealloc(bdt->threads[i]);
2130+
}
21222131
}
21232132
Free(bdt);
21242133
}

0 commit comments

Comments
 (0)