Skip to content

Commit b8e48e0

Browse files
Profile: Fix tests when run with nthreads > 1 (for buildkite) (#42270)
1 parent e5c35e3 commit b8e48e0

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

src/signal-handling.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,14 @@ void jl_shuffle_int_array_inplace(volatile uint64_t *carray, size_t size, uint64
3737

3838
JL_DLLEXPORT int jl_profile_is_buffer_full(void)
3939
{
40+
// declare buffer full if there isn't enough room to take samples across all threads
41+
#if defined(_OS_WINDOWS_)
42+
uint64_t nthreads = 1; // windows only profiles the main thread
43+
#else
44+
uint64_t nthreads = jl_n_threads;
45+
#endif
4046
// the `+ 6` is for the two block terminators `0` plus 4 metadata entries
41-
return bt_size_cur + (JL_BT_MAX_ENTRY_SIZE + 1) + 6 > bt_size_max;
47+
return bt_size_cur + (((JL_BT_MAX_ENTRY_SIZE + 1) + 6) * nthreads) > bt_size_max;
4248
}
4349

4450
static uint64_t jl_last_sigint_trigger = 0;

stdlib/Profile/src/Profile.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ function init(; n::Union{Nothing,Integer} = nothing, delay::Union{Nothing,Real}
5555
n_cur = ccall(:jl_profile_maxlen_data, Csize_t, ())
5656
delay_cur = ccall(:jl_profile_delay_nsec, UInt64, ())/10^9
5757
if n === nothing && delay === nothing
58-
return Int(n_cur), delay_cur
58+
nthreads = Sys.iswindows() ? 1 : Threads.nthreads() # windows only profiles the main thread
59+
return round(Int, n_cur / nthreads), delay_cur
5960
end
6061
nnew = (n === nothing) ? n_cur : n
6162
delaynew = (delay === nothing) ? delay_cur : delay

stdlib/Profile/test/runtests.jl

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,27 @@ end
106106

107107
@testset "setting sample count and delay in init" begin
108108
n_, delay_ = Profile.init()
109+
n_original = n_
110+
nthreads = Sys.iswindows() ? 1 : Threads.nthreads()
111+
sample_size_bytes = sizeof(Ptr)
109112
def_n = Sys.iswindows() && Sys.WORD_SIZE == 32 ? 1_000_000 : 10_000_000
110-
@test n_ == def_n
113+
if Sys.WORD_SIZE == 32 && (def_n * nthreads * sample_size_bytes) > 2^29
114+
@test n_ * nthreads * sample_size_bytes <= 2^29
115+
else
116+
@test n_ == def_n
117+
end
118+
111119
def_delay = Sys.iswindows() && Sys.WORD_SIZE == 32 ? 0.01 : 0.001
112120
@test delay_ == def_delay
113121
Profile.init(n=1_000_001, delay=0.0005)
114122
n_, delay_ = Profile.init()
115-
@test n_ == 1_000_001
123+
if Sys.WORD_SIZE == 32 && (1_000_001 * nthreads * sample_size_bytes) > 2^29
124+
@test n_ * nthreads * sample_size_bytes <= 2^29
125+
else
126+
@test n_ == 1_000_001
127+
end
116128
@test delay_ == 0.0005
117-
Profile.init(n=def_n, delay=def_delay)
129+
Profile.init(n=n_original, delay=def_delay)
118130
end
119131

120132
@testset "warning for buffer full" begin

0 commit comments

Comments
 (0)