Skip to content

Instantly share code, notes, and snippets.

@mkborregaard
Created September 11, 2017 19:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mkborregaard/c0081cd9a154018273e6b9166546d534 to your computer and use it in GitHub Desktop.
Save mkborregaard/c0081cd9a154018273e6b9166546d534 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