Skip to content

Commit

Permalink
Remove a few of the unspeakable hacks from the viz code.
Browse files Browse the repository at this point in the history
Previously, the viz code used a bunch of ad hoc and mostly wrong rules to
determine if a table is a builtin table or not: e.g., tables with names starting
with "t_" or ending with "_tbl" were ignored in various places. That resulted in
ignoring legitimate user-defined tables with those names; it also missed builtin
tables that didn't match the pattern.

Replace that scheme with something more reasonable: Bud now builds a hash
containing the builtin collections and we just consult that hash to see if a
collection is a builtin or not.
  • Loading branch information
neilconway committed Oct 9, 2011
1 parent 6e7fb4e commit 4a6a634
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 24 deletions.
7 changes: 3 additions & 4 deletions bin/budplot
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def make_instance(mods)
end

mod_klass = eval m
puts "m = #{m}; class = #{mod_klass.class}; length = #{mods.length}"
if mod_klass.class == Class
if mods.length == 1
return mod_klass.new
Expand Down Expand Up @@ -66,10 +65,10 @@ def process(mods)
d.tables.each do |t|
tab = t[0].to_s
tabinf[tab] = t[1].class.to_s
next if d.builtin_tables.has_key? t[0]

if interfaces[tab].nil?
unless tab =~ /^t_/ or tab == "stdio" or tab == "localtick"
priv << t
end
priv << t
else
if interfaces[tab]
inp << t
Expand Down
15 changes: 11 additions & 4 deletions lib/bud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@
module Bud
attr_reader :strata, :budtime, :inbound, :options, :meta_parser, :viz, :rtracer
attr_reader :dsock
attr_reader :tables, :channels, :tc_tables, :zk_tables, :dbm_tables, :sources, :sinks
attr_reader :builtin_tables, :tables
attr_reader :channels, :tc_tables, :zk_tables, :dbm_tables, :sources, :sinks
attr_reader :stratum_first_iter, :joinstate
attr_reader :this_stratum, :this_rule, :rule_orig_src
attr_reader :running_async
Expand Down Expand Up @@ -100,8 +101,8 @@ module Bud
# * <tt>:deploy</tt> enable deployment
# * <tt>:deploy_child_opts</tt> option hash to pass to deployed instances
def initialize(options={})
@builtin_tables = {}
@tables = {}
@table_meta = []
@rewritten_strata = []
@channels = {}
@tc_tables = {}
Expand Down Expand Up @@ -737,16 +738,19 @@ def bud_clock
private

# Builtin BUD state (predefined collections). We could define this using the
# standard "state" syntax, but we want to ensure that builtin state is
# standard state block syntax, but we want to ensure that builtin state is
# initialized before user-defined state.
def builtin_state
# We expect there to be no previously-defined tables
raise BudError unless @tables.empty?

loopback :localtick, [:col1]
@stdio = terminal :stdio
readonly :signals, [:key]
scratch :halt, [:key]
@periodics = table :periodics_tbl, [:pername] => [:period]

# for Bud reflection
# For Bud reflection
table :t_rules, [:rule_id] => [:lhs, :op, :src, :orig_src]
table :t_depends, [:rule_id, :lhs, :op, :body] => [:nm]
table :t_depends_tc, [:head, :body, :via, :neg, :temporal]
Expand All @@ -756,6 +760,9 @@ def builtin_state
table :t_cycle, [:predicate, :via, :neg, :temporal]
table :t_table_info, [:tab_name, :tab_type]
table :t_table_schema, [:tab_name, :col_name, :ord, :loc]

# Identify builtin tables as such
@builtin_tables = @tables.clone
end

# Handle any inbound tuples off the wire. Received messages are placed
Expand Down
15 changes: 7 additions & 8 deletions lib/bud/graphs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class GraphGen #:nodoc: all
attr_reader :nodes

def initialize(tableinfo, cycle, name, budtime, collapse=false, cardinalities={})
def initialize(tableinfo, builtin_tables, cycle, name, budtime, collapse=false, cardinalities={})
@graph = GraphViz.new(:G, :type => :digraph, :label => "")
@graph.node[:fontname] = "Times-Roman"
@graph.node[:fontsize] = 18
Expand All @@ -15,9 +15,9 @@ def initialize(tableinfo, cycle, name, budtime, collapse=false, cardinalities={}
@name = name
@collapse = collapse
@budtime = budtime
@internals = {'localtick' => 1, 'stdio' => 1}
@builtin_tables = builtin_tables

# map: table -> type
# map: table name -> type
@tabinf = {}
tableinfo.each do |ti|
@tabinf[ti[0].to_s] = ti[1]
Expand Down Expand Up @@ -75,8 +75,7 @@ def process(depends)
head = d[1]
body = d[3]

# hack attack
if @internals[head] or @internals[body]
if @builtin_tables.has_key?(head.to_sym) or @builtin_tables.has_key?(body.to_sym)
next
end

Expand Down Expand Up @@ -182,11 +181,11 @@ def finish(depanalysis=nil, output=nil)
@nodes["T"].penwidth = 3

@tabinf.each_pair do |k, v|
unless @nodes[name_of(k.to_s)] or k.to_s =~ /_tbl/ or @internals[k.to_s] or (k.to_s =~ /^t_/ and @budtime != 0)
addonce(k.to_s, false)
unless @nodes[name_of(k)] or @builtin_tables[k.to_sym]
addonce(k, false)
end
if v == "Bud::BudPeriodic"
addedge("S", k.to_s, false, false, false)
addedge("S", k, false, false, false)
end
end

Expand Down
14 changes: 8 additions & 6 deletions lib/bud/viz_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ def summarize(dir, schema)
end

d = "#{@dir}/tm_#{time.bud_time}"
write_graphs(@t_tabinf, @t_cycle, @t_depends, @t_rules, d, @dir, nil, false, nil, time.bud_time, card_info)
write_graphs(@t_tabinf, builtin_tables, @t_cycle, @t_depends, @t_rules, d,
@dir, nil, false, nil, time.bud_time, card_info)
end
end

end


Expand All @@ -65,12 +65,15 @@ def graph_from_instance(bud_instance, viz_name, output_base, collapse=true, fmt=
tab = t[0].to_s
tabinf[tab] = t[1].class.to_s
end
write_graphs(tabinf, bud_instance.t_cycle, bud_instance.t_depends, bud_instance.t_rules, viz_name, output_base, fmt, collapse, bud_instance.meta_parser.depanalysis)
write_graphs(tabinf, bud_instance.builtin_tables, bud_instance.t_cycle,
bud_instance.t_depends, bud_instance.t_rules, viz_name,
output_base, fmt, collapse, bud_instance.meta_parser.depanalysis)
end

def write_graphs(tabinf, cycle, depends, rules, viz_name, output_base, fmt, collapse, depanalysis=nil, budtime=-1, card_info=nil)
def write_graphs(tabinf, builtin_tables, cycle, depends, rules, viz_name,
output_base, fmt, collapse, depanalysis=nil, budtime=-1, card_info=nil)
staging = "#{viz_name}.staging"
gv = GraphGen.new(tabinf, cycle, staging, budtime, collapse, card_info)
gv = GraphGen.new(tabinf, builtin_tables, cycle, staging, budtime, collapse, card_info)
gv.process(depends)
dump(rules, output_base, gv)
gv.finish(depanalysis, fmt)
Expand Down Expand Up @@ -272,5 +275,4 @@ def write_table_content(fn, row)
stream.puts "</tr>"
stream.close
end

end
4 changes: 2 additions & 2 deletions test/tc_meta.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ def test_visualization
dir = scratch_dir

program.run_bg
program.sync_do{}
program.sync_do

write_graphs({}, program.t_cycle, program.t_depends, program.t_rules, "#{dir}/test_viz", dir, :dot, false, nil, 1, {})
write_graphs({}, program.builtin_tables, program.t_cycle, program.t_depends, program.t_rules, "#{dir}/test_viz", dir, :dot, false, nil, 1, {})
program.stop
end

Expand Down

0 comments on commit 4a6a634

Please sign in to comment.