class SpaceTime

Public Class Methods

new(input, links = false) click to toggle source
# File lib/bud/graphs.rb, line 251
def initialize(input, links = false)
  @input = input
  @links = links
  processes = input.map {|i| i[1]}
  input.map{|i| processes << i[2]}
  processes.uniq!

  @queues = {}

  @g = GraphViz.new(:G, :type => :digraph, :rankdir => "LR", :outputorder => "nodesfirst", :splines => "line")#, :clusterrank => "none")
  @hdr = @g.subgraph("cluster_0")

  @subs = {}
  @head = {}
  last = nil
  processes.each_with_index do |p, i|
    @subs[p] = @g.subgraph("buster_#{i+1}")
    @head[p] = @hdr.add_nodes("process #{p}(#{i})", :group => p)#, :color => "white", :label => "")
  end
end

Public Instance Methods

finish(file, fmt=nil) click to toggle source
# File lib/bud/graphs.rb, line 324
def finish(file, fmt=nil)
  @edges.each_pair do |k, v|
    lbl = v[3] > 1 ? "#{v[2]}(#{v[3]})" : v[2]
    lbl ||= ""
    @g.add_edges(v[0], v[1], :label => lbl, :color => "red", :weight => 1)
  end
  if fmt.nil?
    @g.output(:svg => "#{file}.svg")
  else
    eval("@g.output(:#{fmt} => \"\#{file}.#{fmt}\")")
  end
end
msg_edge(f, t, l) click to toggle source
# File lib/bud/graphs.rb, line 272
def msg_edge(f, t, l)
  lbl = "#{f}#{t}#{l}"
  if @edges[lbl]
    prev = @edges[lbl]
    @edges[lbl] = [prev[0], prev[1], prev[2], prev[3] + 1]
  else
    @edges[lbl] = [f, t, l, 1]
  end
end
process() click to toggle source
# File lib/bud/graphs.rb, line 282
def process
  @edges = {}
  queues = {}
  @input.each do |i|
    queues[i[1]] ||= []
    queues[i[2]] ||= []
    queues[i[1]] << i[3]
    queues[i[2]] << i[4]
  end

  squeues = {}
  queues.each_pair do |k, v|
    squeues[k] = v.sort{|a, b| a.to_i <=> b.to_i}
  end

  # create the nodes and the timeline edges first.
  squeues.each do |k, v|
    v.each_with_index do |item, i|
      label = "#{k}-#{item}"
      params = {:label => item.to_s, :width => 0.1, :height => 0.1, :fontsize => 6, :group => k}
      if @links
        params[:URL] = "DBM_#{k}/tm_#{item}.svg"
      end
      snd = @subs[k].add_nodes(label, params)
      unless @head[k].object_id == snd.object_id
        @subs[k].add_edges(@head[k], snd, :weight => 2)
        @head[k] = snd
      end
    end
  end

  #@input.sort{|a, b| a[3] <=> b[3]}.each do |i|
  @input.each do |i|
    snd_loc = i[1]
    rcv_loc = i[2]
    snd_label = "#{snd_loc}-#{i[3]}"
    rcv_label = "#{rcv_loc}-#{i[4]}"
    #@g.add_edge(snd_label, rcv_label, :color => "red", :weight => 1, :label => i[5])
    msg_edge(snd_label, rcv_label, i[5])
  end
end