@@ -87,41 +87,6 @@ bt_init(prof_bt_t *bt, void **vec)
87
87
bt -> len = 0 ;
88
88
}
89
89
90
- static void
91
- bt_destroy (prof_bt_t * bt )
92
- {
93
-
94
- cassert (config_prof );
95
-
96
- idalloc (bt );
97
- }
98
-
99
- static prof_bt_t *
100
- bt_dup (prof_bt_t * bt )
101
- {
102
- prof_bt_t * ret ;
103
-
104
- cassert (config_prof );
105
-
106
- /*
107
- * Create a single allocation that has space for vec immediately
108
- * following the prof_bt_t structure. The backtraces that get
109
- * stored in the backtrace caches are copied from stack-allocated
110
- * temporary variables, so size is known at creation time. Making this
111
- * a contiguous object improves cache locality.
112
- */
113
- ret = (prof_bt_t * )imalloc (QUANTUM_CEILING (sizeof (prof_bt_t )) +
114
- (bt -> len * sizeof (void * )));
115
- if (ret == NULL )
116
- return (NULL );
117
- ret -> vec = (void * * )((uintptr_t )ret +
118
- QUANTUM_CEILING (sizeof (prof_bt_t )));
119
- memcpy (ret -> vec , bt -> vec , bt -> len * sizeof (void * ));
120
- ret -> len = bt -> len ;
121
-
122
- return (ret );
123
- }
124
-
125
90
static inline void
126
91
prof_enter (prof_tdata_t * prof_tdata )
127
92
{
@@ -388,11 +353,16 @@ prof_ctx_mutex_choose(void)
388
353
return (& ctx_locks [(nctxs - 1 ) % PROF_NCTX_LOCKS ]);
389
354
}
390
355
391
- static void
392
- prof_ctx_init ( prof_ctx_t * ctx , prof_bt_t * bt )
356
+ static prof_ctx_t *
357
+ prof_ctx_create ( prof_bt_t * bt )
393
358
{
394
-
395
- ctx -> bt = bt ;
359
+ /*
360
+ * Create a single allocation that has space for vec of length bt->len.
361
+ */
362
+ prof_ctx_t * ctx = (prof_ctx_t * )imalloc (offsetof(prof_ctx_t , vec ) +
363
+ (bt -> len * sizeof (void * )));
364
+ if (ctx == NULL )
365
+ return (NULL );
396
366
ctx -> lock = prof_ctx_mutex_choose ();
397
367
/*
398
368
* Set nlimbo to 1, in order to avoid a race condition with
@@ -402,6 +372,11 @@ prof_ctx_init(prof_ctx_t *ctx, prof_bt_t *bt)
402
372
ql_elm_new (ctx , dump_link );
403
373
memset (& ctx -> cnt_merged , 0 , sizeof (prof_cnt_t ));
404
374
ql_new (& ctx -> cnts_ql );
375
+ /* Duplicate bt. */
376
+ memcpy (ctx -> vec , bt -> vec , bt -> len * sizeof (void * ));
377
+ ctx -> bt .vec = ctx -> vec ;
378
+ ctx -> bt .len = bt -> len ;
379
+ return (ctx );
405
380
}
406
381
407
382
static void
@@ -428,12 +403,11 @@ prof_ctx_destroy(prof_ctx_t *ctx)
428
403
assert (ctx -> cnt_merged .accumobjs == 0 );
429
404
assert (ctx -> cnt_merged .accumbytes == 0 );
430
405
/* Remove ctx from bt2ctx. */
431
- if (ckh_remove (& bt2ctx , ctx -> bt , NULL , NULL ))
406
+ if (ckh_remove (& bt2ctx , & ctx -> bt , NULL , NULL ))
432
407
not_reached ();
433
408
prof_leave (prof_tdata );
434
409
/* Destroy ctx. */
435
410
malloc_mutex_unlock (ctx -> lock );
436
- bt_destroy (ctx -> bt );
437
411
idalloc (ctx );
438
412
} else {
439
413
/*
@@ -501,22 +475,15 @@ prof_lookup_global(prof_bt_t *bt, prof_tdata_t *prof_tdata, void **p_btkey,
501
475
prof_enter (prof_tdata );
502
476
if (ckh_search (& bt2ctx , bt , & btkey .v , & ctx .v )) {
503
477
/* bt has never been seen before. Insert it. */
504
- ctx .v = imalloc ( sizeof ( prof_ctx_t ) );
478
+ ctx .p = prof_ctx_create ( bt );
505
479
if (ctx .v == NULL ) {
506
480
prof_leave (prof_tdata );
507
481
return (true);
508
482
}
509
- btkey .p = bt_dup (bt );
510
- if (btkey .v == NULL ) {
511
- prof_leave (prof_tdata );
512
- idalloc (ctx .v );
513
- return (true);
514
- }
515
- prof_ctx_init (ctx .p , btkey .p );
483
+ btkey .p = & ctx .p -> bt ;
516
484
if (ckh_insert (& bt2ctx , btkey .v , ctx .v )) {
517
485
/* OOM. */
518
486
prof_leave (prof_tdata );
519
- idalloc (btkey .v );
520
487
idalloc (ctx .v );
521
488
return (true);
522
489
}
@@ -1039,7 +1006,7 @@ prof_dump(bool propagate_err, const char *filename, bool leakcheck)
1039
1006
1040
1007
/* Dump per ctx profile stats. */
1041
1008
while ((ctx .p = ql_first (& ctx_ql )) != NULL ) {
1042
- if (prof_dump_ctx (propagate_err , ctx .p , ctx .p -> bt , & ctx_ql ))
1009
+ if (prof_dump_ctx (propagate_err , ctx .p , & ctx .p -> bt , & ctx_ql ))
1043
1010
goto label_write_error ;
1044
1011
}
1045
1012
0 commit comments