Created
September 11, 2017 19:31
-
-
Save mkborregaard/c0081cd9a154018273e6b9166546d534 to your computer and use it in GitHub Desktop.
Trace trees
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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