From 0985c73c9ab92575ecb6b297c48e38735dfba4d7 Mon Sep 17 00:00:00 2001 From: Nathan Daly Date: Wed, 20 Sep 2023 01:13:44 -0600 Subject: [PATCH] Export num_stack_mappings to track the number of in-flight stack mappings and tasks in application (#51301) --- src/gc-stacks.c | 4 ++++ test/threads.jl | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/src/gc-stacks.c b/src/gc-stacks.c index c04e48821e46f..693cb8d0eadf0 100644 --- a/src/gc-stacks.c +++ b/src/gc-stacks.c @@ -76,6 +76,10 @@ static void free_stack(void *stkbuf, size_t bufsz) } #endif +JL_DLLEXPORT uint32_t jl_get_num_stack_mappings(void) +{ + return jl_atomic_load_relaxed(&num_stack_mappings); +} const unsigned pool_sizes[] = { 128 * 1024, diff --git a/test/threads.jl b/test/threads.jl index 8189311739e31..14fe94408a050 100644 --- a/test/threads.jl +++ b/test/threads.jl @@ -327,3 +327,9 @@ end @test_throws ArgumentError @macroexpand(@threads 1) # arg isn't an Expr @test_throws ArgumentError @macroexpand(@threads if true 1 end) # arg doesn't start with for end + +@testset "num_stack_mappings metric" begin + @test @ccall(jl_get_num_stack_mappings()::Cint) >= 1 + # There must be at least two: one for the root test task and one for the async task: + @test fetch(@async(@ccall(jl_get_num_stack_mappings()::Cint))) >= 2 +end