Skip to content

Commit 62f0ccd

Browse files
authored
InteractiveUtils: add minsize option to varinfo (#42116)
1 parent 3aea11e commit 62f0ccd

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

stdlib/InteractiveUtils/src/InteractiveUtils.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ include("macros.jl")
2121
include("clipboard.jl")
2222

2323
"""
24-
varinfo(m::Module=Main, pattern::Regex=r""; all::Bool = false, imported::Bool = false, sortby::Symbol = :name)
24+
varinfo(m::Module=Main, pattern::Regex=r""; all::Bool = false, imported::Bool = false, sortby::Symbol = :name, minsize::Int = 0)
2525
2626
Return a markdown table giving information about exported global variables in a module, optionally restricted
2727
to those matching `pattern`.
@@ -32,8 +32,9 @@ The memory consumption estimate is an approximate lower bound on the size of the
3232
- `imported` : also list objects explicitly imported from other modules.
3333
- `recursive` : recursively include objects in sub-modules, observing the same settings in each.
3434
- `sortby` : the column to sort results by. Options are `:name` (default), `:size`, and `:summary`.
35+
- `minsize` : only includes objects with size at least `minsize` bytes. Defaults to `0`.
3536
"""
36-
function varinfo(m::Module=Main, pattern::Regex=r""; all::Bool = false, imported::Bool = false, sortby::Symbol = :name, recursive::Bool = false)
37+
function varinfo(m::Module=Main, pattern::Regex=r""; all::Bool = false, imported::Bool = false, sortby::Symbol = :name, recursive::Bool = false, minsize::Int=0)
3738
sortby in (:name, :size, :summary) || throw(ArgumentError("Unrecognized `sortby` value `:$sortby`. Possible options are `:name`, `:size`, and `:summary`"))
3839
rows = Vector{Any}[]
3940
workqueue = [(m, ""),]
@@ -54,7 +55,9 @@ function varinfo(m::Module=Main, pattern::Regex=r""; all::Bool = false, imported
5455
ss = summarysize(value)
5556
(format_bytes(ss), ss)
5657
end
57-
push!(rows, Any[string(prep, v), ssize_str, summary(value), ssize])
58+
if ssize >= minsize
59+
push!(rows, Any[string(prep, v), ssize_str, summary(value), ssize])
60+
end
5861
end
5962
end
6063
let (col, rev) = if sortby == :name

stdlib/InteractiveUtils/test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ end
199199
let v = repr(varinfo(_test_varinfo_, all = true, recursive = true))
200200
@test occursin("inner_x", v)
201201
end
202+
let v = repr(varinfo(_test_varinfo_, all = true, minsize = 9))
203+
@test !occursin("x_exported", v) # excluded: 8 bytes
204+
@test occursin("a_smaller", v)
205+
end
202206

203207
# Issue 14173
204208
module Tmp14173

0 commit comments

Comments
 (0)