Class: SpaceTime

Inherits:
Object
  • Object
show all
Defined in:
lib/bud/graphs.rb

Instance Method Summary collapse

Constructor Details

#initialize(input, links = false) ⇒ SpaceTime

Returns a new instance of SpaceTime.



251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# 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

Instance Method Details

#finish(file, fmt = nil) ⇒ Object



324
325
326
327
328
329
330
331
332
333
334
335
# 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) ⇒ Object



272
273
274
275
276
277
278
279
280
# 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

#processObject



282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
# 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