Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add total file size #2

Merged
merged 3 commits into from
Dec 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@ Here's a quick demo:
julia> using PkgCacheInspector

julia> info_cachefile("Colors")
modules: Any[Colors]
68 external methods
1776 new specializations of external methods
371 external methods with new roots
5113 external targets
3796 edges
system: 2021616
isbits: 2048623
symbols: 13345
tags: 28990
relocations: 214509
gvars: 5048
fptrs: 3112
Contents of /Users/user/.julia/compiled/v1.9/Colors/NKjaT_1DCqx.ji:
modules: Any[Colors]
68 external methods
1759 new specializations of external methods (Base 50.1%, ColorTypes 29.8%, Base.Broadcast 11.3%, ...)
361 external methods with new roots
5115 external targets
3796 edges
file size: 4922032 (4.694 MiB)
Segment sizes (bytes):
system: 1971024 ( 46.65%)
isbits: 1998959 ( 47.31%)
symbols: 13360 ( 0.32%)
tags: 28804 ( 0.68%)
relocations: 213041 ( 5.04%)
gvars: 0 ( 0.00%)
fptrs: 0 ( 0.00%)
```

At the top of the display, you can see a summary of the numbers of various items:
Expand Down
33 changes: 21 additions & 12 deletions src/PkgCacheInspector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ struct PkgCacheSizes
fptrlist::Int
end

const cache_displaynames = [
"system",
"isbits",
"symbols",
"tags",
"relocations",
"gvars",
"fptrs"
]
const cache_displaynames_l = maximum(length, cache_displaynames)

function Base.show(io::IO, szs::PkgCacheSizes)
indent = get(io, :indent, 0)
nd = ntot = 0
Expand All @@ -27,20 +38,16 @@ function Base.show(io::IO, szs::PkgCacheSizes)
nd = max(nd, ndigits(nb))
ntot += nb
end
displaynames = [
"system",
"isbits",
"symbols",
"tags",
"relocations",
"gvars",
"fptrs"
]
l = maximum(length, displaynames)
println(io, " "^indent, "Segment sizes (bytes):")
for i = 1:nf
nb = getfield(szs, i)
println(io, " "^indent, rpad(displaynames[i] * ": ", l+2), lpad(string(nb), nd), " (", @sprintf("% 6.2f", 100*nb/ntot), "%)")
println(io,
" "^indent,
rpad(cache_displaynames[i] * ": ", cache_displaynames_l+2),
lpad(string(nb), nd),
" (",
@sprintf("% 6.2f", 100*nb/ntot),
"%)")
end
end

Expand All @@ -53,6 +60,7 @@ struct PkgCacheInfo
new_method_roots::Vector{Any}
external_targets::Vector{Any}
edges::Vector{Any}
filesize::Int
cachesizes::PkgCacheSizes
end

Expand All @@ -76,6 +84,7 @@ function Base.show(io::IO, info::PkgCacheInfo)
!isempty(info.new_method_roots) && println(io, " ", length(info.new_method_roots) ÷ 2, " external methods with new roots")
!isempty(info.external_targets) && println(io, " ", length(info.external_targets) ÷ 3, " external targets")
!isempty(info.edges) && println(io, " ", length(info.edges) ÷ 2, " edges")
println(io, " ", rpad("file size: ", cache_displaynames_l+2), info.filesize, " (", Base.format_bytes(info.filesize),")")
show(IOContext(io, :indent => 2), info.cachesizes)
end

Expand All @@ -96,7 +105,7 @@ function info_cachefile(path::String, depmods::Vector{Any})
if isa(sv, Exception)
throw(sv)
end
return PkgCacheInfo(path, sv[1:7]..., PkgCacheSizes(sv[8]...))
return PkgCacheInfo(path, sv[1:7]..., filesize(path), PkgCacheSizes(sv[8]...))
end

function info_cachefile(pkg::PkgId, path::String)
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ using Test
@test isa(info, PkgCacheInfo)
str = sprint(show, info)
@test occursin("relocations", str) && occursin("new specializations", str) && occursin("targets", str)
@test occursin("file size", str)
end