[thread_event] Add support for user events in thread events when stats are enabled

This commit is contained in:
Slobodan Predolac
2025-03-28 07:35:53 -07:00
committed by Guangli Dai
parent e6864c6075
commit 015b017973
15 changed files with 470 additions and 81 deletions

View File

@@ -1,5 +1,18 @@
#include "test/jemalloc_test.h"
static uint32_t nuser_hook_calls;
static bool is_registered = false;
static void
test_cb(bool is_alloc, uint64_t tallocated, uint64_t tdallocated) {
++nuser_hook_calls;
}
static user_hook_object_t tobj = {
.callback = &test_cb,
.interval = 10,
.is_alloc_only = false
};
TEST_BEGIN(test_next_event_fast) {
tsd_t *tsd = tsd_fetch();
te_ctx_t ctx;
@@ -9,6 +22,12 @@ TEST_BEGIN(test_next_event_fast) {
te_ctx_current_bytes_set(&ctx, TE_NEXT_EVENT_FAST_MAX - 8U);
te_ctx_next_event_set(tsd, &ctx, TE_NEXT_EVENT_FAST_MAX);
if (!is_registered) {
is_registered = 0 == te_register_user_handler(tsd_tsdn(tsd), &tobj);
}
assert_true(is_registered || !config_stats, "Register user handler");
nuser_hook_calls = 0;
uint64_t *waits = tsd_te_datap_get_unsafe(tsd)->alloc_wait;
for (size_t i = 0; i < te_alloc_count; i++) {
waits[i] = TE_NEXT_EVENT_FAST_MAX;
@@ -16,6 +35,7 @@ TEST_BEGIN(test_next_event_fast) {
/* Test next_event_fast rolling back to 0. */
void *p = malloc(16U);
assert_true(nuser_hook_calls == 1 || !config_stats, "Expected alloc call");
assert_ptr_not_null(p, "malloc() failed");
free(p);