Skip to content

Commit

Permalink
InteractiveUtils: add minsize option to varinfo (#42116)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericphanson authored Sep 8, 2021
1 parent 3aea11e commit 62f0ccd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 6 additions & 3 deletions stdlib/InteractiveUtils/src/InteractiveUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ include("macros.jl")
include("clipboard.jl")

"""
varinfo(m::Module=Main, pattern::Regex=r""; all::Bool = false, imported::Bool = false, sortby::Symbol = :name)
varinfo(m::Module=Main, pattern::Regex=r""; all::Bool = false, imported::Bool = false, sortby::Symbol = :name, minsize::Int = 0)
Return a markdown table giving information about exported global variables in a module, optionally restricted
to those matching `pattern`.
Expand All @@ -32,8 +32,9 @@ The memory consumption estimate is an approximate lower bound on the size of the
- `imported` : also list objects explicitly imported from other modules.
- `recursive` : recursively include objects in sub-modules, observing the same settings in each.
- `sortby` : the column to sort results by. Options are `:name` (default), `:size`, and `:summary`.
- `minsize` : only includes objects with size at least `minsize` bytes. Defaults to `0`.
"""
function varinfo(m::Module=Main, pattern::Regex=r""; all::Bool = false, imported::Bool = false, sortby::Symbol = :name, recursive::Bool = false)
function varinfo(m::Module=Main, pattern::Regex=r""; all::Bool = false, imported::Bool = false, sortby::Symbol = :name, recursive::Bool = false, minsize::Int=0)
sortby in (:name, :size, :summary) || throw(ArgumentError("Unrecognized `sortby` value `:$sortby`. Possible options are `:name`, `:size`, and `:summary`"))
rows = Vector{Any}[]
workqueue = [(m, ""),]
Expand All @@ -54,7 +55,9 @@ function varinfo(m::Module=Main, pattern::Regex=r""; all::Bool = false, imported
ss = summarysize(value)
(format_bytes(ss), ss)
end
push!(rows, Any[string(prep, v), ssize_str, summary(value), ssize])
if ssize >= minsize
push!(rows, Any[string(prep, v), ssize_str, summary(value), ssize])
end
end
end
let (col, rev) = if sortby == :name
Expand Down
4 changes: 4 additions & 0 deletions stdlib/InteractiveUtils/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ end
let v = repr(varinfo(_test_varinfo_, all = true, recursive = true))
@test occursin("inner_x", v)
end
let v = repr(varinfo(_test_varinfo_, all = true, minsize = 9))
@test !occursin("x_exported", v) # excluded: 8 bytes
@test occursin("a_smaller", v)
end

# Issue 14173
module Tmp14173
Expand Down

2 comments on commit 62f0ccd

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily package evaluation, I will reply here when finished:

@nanosoldier runtests(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your package evaluation job has completed - possible new issues were detected. A full report can be found here.

Please sign in to comment.