From 3fc46fafcaac8bb13810e652ec0ba985da4f9f10 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 ++++ src/gc.h | 1 + test/threads.jl | 6 ++++++ 3 files changed, 11 insertions(+) diff --git a/src/gc-stacks.c b/src/gc-stacks.c index 4c477dd3d4c17c..20e283afb2b862 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/src/gc.h b/src/gc.h index 1a41b05f0c8ee5..1bdd278321bddf 100644 --- a/src/gc.h +++ b/src/gc.h @@ -644,6 +644,7 @@ void gc_count_pool(void); size_t jl_array_nbytes(jl_array_t *a) JL_NOTSAFEPOINT; JL_DLLEXPORT void jl_enable_gc_logging(int enable); +JL_DLLEXPORT uint32_t jl_get_num_stack_mappings(void); void _report_gc_finished(uint64_t pause, uint64_t freed, int full, int recollect) JL_NOTSAFEPOINT; #ifdef __cplusplus diff --git a/test/threads.jl b/test/threads.jl index fb684b275e8648..1a0dbeb2d4dbfa 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