-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from RelationalAI-oss/nhd-rai-upstream
Upstream changes from RelationalAI:
- Loading branch information
Showing
6 changed files
with
233 additions
and
48 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "Salsa" | ||
uuid = "1fbf2c77-44e2-4d5d-8131-0fa618a5c278" | ||
authors = ["Nathan Daly <[email protected]>", "Todd J. Green <[email protected]>"] | ||
version = "1.0.0" | ||
version = "1.1.0" | ||
|
||
[deps] | ||
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,78 @@ | ||
module DebugMode | ||
module Debug | ||
|
||
export @debug_mode, DBG | ||
export @debug_mode, enable_debug, disable_debug, enable_trace_logging, disable_trace_logging | ||
|
||
# This file was modeled on the debug mode found in src/QueryEvaluator/trie_interface.jl | ||
|
||
DBG = true | ||
# `static_debug_mode` is a flag that enables/disables all debug mode checks | ||
const static_debug_mode = true | ||
|
||
|
||
""" | ||
`debug_mode` is a flag that enables/disables the debug mode for the query evaluator | ||
@debug_mode expr... | ||
Execute `expr` only when static and runtime debug modes are enabled. | ||
""" | ||
const debug_mode = true | ||
|
||
if debug_mode | ||
""" | ||
Execute only in debug mode | ||
""" | ||
macro debug_mode(instr) | ||
esc(:( | ||
if DBG != Nothing | ||
$instr | ||
macro debug_mode(instr) | ||
if static_debug_mode | ||
quote | ||
if debug_enabled() | ||
$(esc(instr)) | ||
end | ||
)) | ||
end | ||
else | ||
:() | ||
end | ||
end | ||
|
||
if static_debug_mode | ||
# Runtime debug mode controls | ||
function enable_debug() | ||
global _DBG = true | ||
end | ||
function disable_debug() | ||
global _DBG = false | ||
end | ||
debug_enabled() = _DBG | ||
_DBG = true | ||
|
||
|
||
# Runtime trace logging controls | ||
function enable_trace_logging() | ||
global _tracing = true | ||
end | ||
function disable_trace_logging() | ||
global _tracing = false | ||
end | ||
trace_logging_enabled() = _tracing | ||
_tracing = false | ||
else | ||
macro debug_mode(instr) | ||
# Runtime Debugging is disabled. | ||
_emit_debug_warning() = | ||
@warn """ | ||
Cannot enable runtime debug statements because debug is disabled statically. | ||
To enable, reload Salsa after setting `static_debug_mode = true` in: | ||
$(@__FILE__) | ||
""" | ||
|
||
enable_debug() = _emit_debug_warning() | ||
disable_debug() = _emit_debug_warning() | ||
debug_enabled() = false | ||
|
||
enable_trace_logging() = _emit_debug_warning() | ||
disable_trace_logging() = _emit_debug_warning() | ||
trace_logging_enabled() = false | ||
end | ||
|
||
macro dbg_log_trace(expr) | ||
if static_debug_mode | ||
quote | ||
if trace_logging_enabled() | ||
$(esc(expr)) | ||
end | ||
end | ||
else | ||
:() | ||
end | ||
end | ||
|
||
end # module DebugMode | ||
end # module Debug |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
module InspectSalsa | ||
using Salsa | ||
|
||
# Crude code to dump a .dot (graphviz) version of the Arroyo Node tree. | ||
# For debugging / illustration purposes - not intended to be reachable from production | ||
# code. | ||
function dump_graph(c::Salsa.AbstractComponent; module_boxes=false) | ||
println(build_graph(c; module_boxes=module_boxes)) | ||
end | ||
|
||
# There is no IdSet in julia, so we build our own from IdDict. | ||
# We need an IdSet to prevent comparing all the contents of the various maps, which is | ||
# expensive. We just want to compare via `===` which is what an IdDict does. | ||
# (Used the name _IdSet to indicate that this is internal only, and not a full-featured set) | ||
struct _IdSet{T} | ||
d::IdDict{T,Nothing} # Only using the Keys | ||
_IdSet{T}() where T = new(IdDict{T,Nothing}()) | ||
end | ||
Base.in(k, s::_IdSet) = haskey(s.d, k) | ||
Base.push!(s::_IdSet, k) = s.d[k] = nothing | ||
|
||
function build_graph(c::Salsa.AbstractComponent; module_boxes=false) | ||
rt = Salsa.get_runtime(c) | ||
io = IOBuffer() | ||
println(io, """digraph G {""") | ||
println(io, """edge [dir="back"];""") | ||
seen = _IdSet{Any}() | ||
modules_map = Dict{Module,Set}() | ||
edges = Dict{Pair, Int}() | ||
inputs = Dict{Any, String}() # Note, there might be duplicate strings, Any must be the key | ||
|
||
_build_graph(io, c, seen, modules_map, edges, inputs) | ||
|
||
if module_boxes | ||
for (m,keys) in modules_map | ||
mname = nameof(m) | ||
println(io, """subgraph cluster_$mname {""") | ||
#println(io, """node [style=filled];""") | ||
# First print non-input keys | ||
println(io, """ $(join((repr(vertex_name(k)) for k in keys | ||
if !haskey(inputs, k)), " ")) """); | ||
begin # Then print input keys all on the bottom | ||
println(io, "{") | ||
println(io, "rank=sink;") | ||
println(io, """ $(join((repr(vertex_name(k)) for k in keys | ||
if haskey(inputs, k)), " ")) """); | ||
println(io, "}") | ||
end | ||
println(io, """ label = "Module `$mname`"; """) | ||
println(io, """ fontsize = 25; """) | ||
println(io, """ color=blue; """) | ||
println(io, """}""") | ||
end | ||
end | ||
|
||
if !module_boxes | ||
println(io, "{") | ||
println(io, "rank=sink;") | ||
end | ||
for (input_key, name) in inputs | ||
println(io, """$(vertex_name(input_key)) [label="$name"]""") | ||
end | ||
if !module_boxes | ||
println(io, "}") | ||
end | ||
|
||
max_count = maximum(values(edges)) | ||
maxwidth = 10 | ||
for ((a,b), count) in edges | ||
normwidth = 1 + maxwidth * (count / max_count) | ||
println(io, """ "$(vertex_name(a))" -> "$(vertex_name(b))" [penwidth=$normwidth, weight=$normwidth]""") | ||
end | ||
@show max_count | ||
println(io, "}") | ||
return String(take!(io)) | ||
end | ||
|
||
function _build_graph(io::IO, c::Salsa.AbstractComponent, seen::_IdSet, modules_map::Dict, edges::Dict, inputs::Dict) | ||
rt = c.runtime | ||
m = typeof(c).name.module | ||
for fieldname in fieldnames(typeof(c)) | ||
f = getfield(c, fieldname) | ||
if f in seen | ||
continue | ||
else | ||
push!(seen, f) | ||
end | ||
if f isa Salsa.AbstractComponent | ||
@show typeof(f) | ||
_build_graph(io, f, seen, modules_map, edges, inputs) | ||
elseif f isa Salsa.InputTypes | ||
key = Salsa.InputKey(f) | ||
inputs[key] = "@input: $(fieldname)" | ||
push!(get!(modules_map, m, Set([])), key) | ||
end | ||
end | ||
|
||
for (derived_key,derived_map) in rt.derived_function_maps | ||
_build_graph(io, rt, derived_key, derived_map, seen, modules_map, edges) | ||
end | ||
end | ||
|
||
function vertex_name(c::Any)::String | ||
return "v$(objectid(c))" | ||
end | ||
|
||
function _build_graph(io, rt::Salsa.Runtime, derived_key::Salsa.DerivedKey{F,TT}, derived_map::Dict, | ||
seen::_IdSet{Any}, modules_map::Dict{Module,Set}, edges::Dict{Pair, Int}) where {F,TT} | ||
in(derived_key, seen) && return | ||
push!(seen, derived_key) | ||
m = methods(F.instance).mt.module | ||
push!(get!(modules_map, m, Set([])), derived_key) | ||
println(io, "$(vertex_name(derived_key)) [shape=rect,label=\"$(derived_key)\"]") | ||
#println(io, "$(vertex_name(derived_key)) [label=\"$(derived_key)\"]") | ||
for (k,v) in derived_map | ||
for d in v.dependencies | ||
edge = (derived_key) => (d.key) | ||
count = get!(edges, edge, 0) + 1 | ||
edges[edge] = count | ||
end | ||
end | ||
#_build_graph(io, s.leaf_node, seen) | ||
end | ||
|
||
end # module |
Oops, something went wrong.