Class: Pwrake::GraphTracer

Inherits:
Object
  • Object
show all
Defined in:
lib/pwrake/misc/mcgp.rb

Direct Known Subclasses

GraphTracerGroup, GraphTracerNode

Instance Method Summary collapse

Constructor Details

#initialize(loc_list, weight_list) ⇒ GraphTracer

Returns a new instance of GraphTracer.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/pwrake/misc/mcgp.rb', line 50

def initialize(loc_list, weight_list)
  if loc_list.size != weight_list.size
    raise ArgumentError, "array size of args mismatch"
  end
  @loc_list = loc_list
  @weight_list = weight_list
  @n_part = @loc_list.size
  @traced = {}
  @vertex_depth = {}
  # @grviz = Grviz.new
  @group_list = @n_part.times.map do |i|
    GraphGroup.new(@loc_list[i],@weight_list[i],@vertex_depth,@grviz)
  end
end

Instance Method Details

#trace(name = "default", target = nil) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/pwrake/misc/mcgp.rb', line 65

def trace(name="default", target=nil)

  task = Rake.application[name]
  tw = task.wrapper
  group_id = tw.group_id || 0
  group = @group_list[group_id]
  #loc_list = @loc_list[group_id]
  depth = 0

  if task.class == Rake::FileTask
    tgid = (target) ? (Rake.application[target].wrapper.group_id||0) : nil

    if File.file?(name)
      if tgid == group_id
        locs = get_location(tw)
        #if locs.empty?
        #  Pwrake.application.postprocess(task)
        #  locs = get_location(tw)
        #end
        #tw.get_file_stat
        fsz = tw.file_size
        if fsz > 100000
          #puts "g=#{group_id}, task=#{name}, target=#{target}, fsz=#{fsz}, locs="+locs.join("|")
          group.push_loc_edge( locs, name, target, fsz/10000 )
        end
      else
        #puts "g=#{group_id}, task=#{name}, tgid=#{tgid}, target=#{target}"
      end
      return depth
    end

    group.push_vertex( name )
    if tgid == group_id
      #puts "g=#{group_id}, task=#{name}, target=#{target}"
      group.push_edge( name, target, nil )
    end
    target = name
  end

  if !@traced[name]
    @traced[name] = true

    task.prerequisites.each do |prereq|
      d = trace( prereq, target )
      depth = d if d and d > depth
    end

    if task.class == Rake::FileTask
      depth += 1
    end

    @vertex_depth[name] = depth
  end

  return @vertex_depth[name]
end

#write_dot(file) ⇒ Object



122
123
124
# File 'lib/pwrake/misc/mcgp.rb', line 122

def write_dot(file)
  @grviz.write(file)
end