Skip to content

Commit e42ffa6

Browse files
authored
Add GC.logging_enabled() (#51647)
1 parent 919c390 commit e42ffa6

File tree

6 files changed

+18
-0
lines changed

6 files changed

+18
-0
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ New library functions
7474
* `eachrsplit(string, pattern)` iterates split substrings right to left.
7575
* `Sys.username()` can be used to return the current user's username ([#51897]).
7676
* `wrap(Array, m::Union{MemoryRef{T}, Memory{T}}, dims)` which is the safe counterpart to `unsafe_wrap` ([#52049]).
77+
* `GC.logging_enabled()` can be used to test whether GC logging has been enabled via `GC.enable_logging` ([#51647]).
7778

7879
New library features
7980
--------------------

base/gcutils.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,13 @@ function enable_logging(on::Bool=true)
262262
ccall(:jl_enable_gc_logging, Cvoid, (Cint,), on)
263263
end
264264

265+
"""
266+
GC.logging_enabled()
267+
268+
Return whether GC logging has been enabled via [`GC.enable_logging`](@ref).
269+
"""
270+
function logging_enabled()
271+
ccall(:jl_is_gc_logging_enabled, Cint, ()) != 0
272+
end
273+
265274
end # module GC

doc/src/base/base.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ Base.GC.enable
491491
Base.GC.@preserve
492492
Base.GC.safepoint
493493
Base.GC.enable_logging
494+
Base.GC.logging_enabled
494495
Meta.lower
495496
Meta.@lower
496497
Meta.parse(::AbstractString, ::Int)

src/gc-debug.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,10 @@ JL_DLLEXPORT void jl_enable_gc_logging(int enable) {
12071207
gc_logging_enabled = enable;
12081208
}
12091209

1210+
JL_DLLEXPORT int jl_is_gc_logging_enabled(void) {
1211+
return gc_logging_enabled;
1212+
}
1213+
12101214
void _report_gc_finished(uint64_t pause, uint64_t freed, int full, int recollect, int64_t live_bytes) JL_NOTSAFEPOINT {
12111215
if (!gc_logging_enabled) {
12121216
return;

src/gc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,7 @@ void gc_count_pool(void);
726726
size_t jl_genericmemory_nbytes(jl_genericmemory_t *a) JL_NOTSAFEPOINT;
727727

728728
JL_DLLEXPORT void jl_enable_gc_logging(int enable);
729+
JL_DLLEXPORT int jl_is_gc_logging_enabled(void);
729730
JL_DLLEXPORT uint32_t jl_get_num_stack_mappings(void);
730731
void _report_gc_finished(uint64_t pause, uint64_t freed, int full, int recollect, int64_t live_bytes) JL_NOTSAFEPOINT;
731732

test/misc.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,8 +1343,10 @@ end
13431343
open(tmppath, "w") do tmpio
13441344
redirect_stderr(tmpio) do
13451345
GC.enable_logging(true)
1346+
@test GC.logging_enabled()
13461347
GC.gc()
13471348
GC.enable_logging(false)
1349+
@test !GC.logging_enabled()
13481350
end
13491351
end
13501352
@test occursin("GC: pause", read(tmppath, String))

0 commit comments

Comments
 (0)