Skip to content

Commit

Permalink
display load times in graph (integrate LoadTime)
Browse files Browse the repository at this point in the history
  • Loading branch information
tfiers committed Jan 14, 2023
1 parent eb2b420 commit 95a1465
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 8 deletions.
5 changes: 5 additions & 0 deletions docs/src/ref/internals.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ default_style
depgraph_as_dotstr
```

## Measuring load time

```@docs
time_imports
```

## Post-processing of SVG files

Expand Down
22 changes: 19 additions & 3 deletions src/includes/deps-as-dot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
depgraph_as_dotstr(
pkgname;
emptymsg = "(\$pkgname has no dependencies)",
faded = is_in_stdlib,
faded = is_in_stdlib,
time = false,
kw...
)
Expand All @@ -14,21 +15,36 @@ on the result. Keyword arguments are passed on to whichever of those two
functions accepts them.
By default, packages in the Julia standard library are drawn in gray. To
disable this, pass `faded = nothing`. Note that packages in the standard
library can be filtered out entirely by passing `stdlib = false`.
disable this, pass `faded = nothing`. Note that standard library
packages can be filtered out entirely by passing `stdlib = false`
(see [`depgraph`](@ref)).
When `time` is `true`, calls [`time_imports`](@ref) and displays the
results in the graph.
"""
depgraph_as_dotstr(
pkgname;
emptymsg = "($pkgname has no dependencies)",
faded = is_in_stdlib,
time = false,
kw...
) = begin
edges = depgraph(pkgname; select(kw, depgraph)...)
if time
loadtimes = time_imports(pkgname)
nodeinfo = Dict(
pkgname => "[$time ms]"
for (pkgname, time) in loadtimes
)
else
nodeinfo = nothing
end
dotstr = to_dot_str(
edges;
select(kw, to_dot_str)...,
emptymsg,
faded,
nodeinfo,
)
end

Expand Down
20 changes: 15 additions & 5 deletions src/modules/DotString.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,40 @@ function to_dot_str(
indent = 4,
emptymsg = nothing,
faded = nothing,
nodeinfo = nothing,
)
lines = ["digraph {"] # DIrected graph
tab = " "^indent
colourscheme = dark ? darkmode : lightmode
bgcolor = "bgcolor = \"$bg\""
add(str) = push!(lines, tab * str)
for line in [bgcolor; colourscheme; style]
push!(lines, tab * line)
add(line)
end
for (m, n) in edges
if !isnothing(faded) && any(faded, [m, n])
push!(lines, tab * "$m -> $n [color=gray]")
add("$m -> $n [color=gray]")
else
push!(lines, tab * "$m -> $n")
add("$m -> $n")
end
end
if !isnothing(faded)
for node in vertices(edges)
if faded(node)
push!(lines, tab * "$node [color=gray fontcolor=gray]")
add("$node [color=gray fontcolor=gray]")
end
end
end
if !isnothing(nodeinfo)
for node in vertices(edges)
if node in keys(nodeinfo)
info = nodeinfo[node]
add("$node [label=\"$node\\n$info\"]")
end
end
end
if !isnothing(emptymsg) && isempty(edges)
push!(lines, tab * single_node(emptymsg))
add(single_node(emptymsg))
end
push!(lines, "}")
return join(lines, "\n") * "\n"
Expand Down
2 changes: 2 additions & 0 deletions src/modules/LoadTime.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Measure load times of the given package and its dependencies, by running
`@time_imports` in a new julia process, and parsing its output.
## Example:
```jldoctest; filter = r"\\d.*\$"m
julia> using PkgGraph.LoadTime
Expand All @@ -26,6 +27,7 @@ julia> loadtimes = time_imports("EzXML");
julia> last(loadtimes)
(pkgname = "EzXML", time_ms = 54.1)
```
"""
function time_imports(pkg)
code = timeimports_code(pkg)
Expand Down
6 changes: 6 additions & 0 deletions src/modules/to_dot_string.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ to_dot_str(
indent = 4,
emptymsg = nothing,
faded = nothing,
nodeinfo = nothing,
)
```

Expand Down Expand Up @@ -49,6 +50,11 @@ A function `(nodename) -> Bool` that determines whether this node -- and
its incoming and outgoing edges -- should be drawn in gray. If `nothing`
(default), no nodes are faded.

### `nodeinfo`
A mapping `nodeinfo => String`, or `nothing` (default).
For any node present in this mapping, its info is printed underneath its
name in the graph.

## Example:

```jldoctest
Expand Down

0 comments on commit 95a1465

Please sign in to comment.