Skip to content

Instantly share code, notes, and snippets.

@MitsuhaMiyamizu
Forked from mkborregaard/TraceGraph.jl
Created May 22, 2023 04:34
Show Gist options
  • Save MitsuhaMiyamizu/bb9bb990b56f41fb9f3c413fc3f2ee4f to your computer and use it in GitHub Desktop.
Save MitsuhaMiyamizu/bb9bb990b56f41fb9f3c413fc3f2ee4f to your computer and use it in GitHub Desktop.
Trace trees
module TraceGraphs
import TraceCalls: Trace
import PlotRecipes: GraphPlot
using RecipesBase
type MyGraph
source::AbstractVector{Int}
destiny::AbstractVector{Int}
end
function make_tracegraph(trace::Trace)
function addedge!(g::MyGraph, m, n)
push!(g.source, m)
push!(g.destiny, n)
end
function add_subcalls!(trace, fromvert)
funcsym = Symbol(trace.func)
local_calls = Symbol[]
subcalls = trace.called
for subcall in subcalls
subsym = Symbol(subcall.func)
if ! (subsym in local_calls)
push!(functionnames, subsym)
push!(local_calls, subsym)
tovert = length(functionnames)
addedge!(g, fromvert, tovert)
add_subcalls!(subcall, tovert)
end
end
end
functionnames = Symbol[Symbol(trace.func)]
g = MyGraph(Int[], Int[])
add_subcalls!(trace, 1)
g, functionnames
end
@recipe function f(t::Trace)
graph, names = make_tracegraph(t)
names --> names
method --> :buchheim
root --> :left
ms --> 5
GraphPlot((graph.source, graph.destiny))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment