class StackProf::Report
def +(other)
def +(other) raise ArgumentError, "cannot combine #{other.class}" unless self.class == other.class raise ArgumentError, "cannot combine #{modeline} with #{other.modeline}" unless modeline == other.modeline raise ArgumentError, "cannot combine v#{version} with v#{other.version}" unless version == other.version f1, f2 = normalized_frames, other.normalized_frames frames = (f1.keys + f2.keys).uniq.inject(Hash.new) do |hash, id| if f1[id].nil? hash[id] = f2[id] elsif f2[id] hash[id] = f1[id] hash[id][:total_samples] += f2[id][:total_samples] hash[id][:samples] += f2[id][:samples] if f2[id][:edges] edges = hash[id][:edges] ||= {} f2[id][:edges].each do |edge, weight| edges[edge] ||= 0 edges[edge] += weight end end if f2[id][:lines] lines = hash[id][:lines] ||= {} f2[id][:lines].each do |line, weight| lines[line] = add_lines(lines[line], weight) end end else hash[id] = f1[id] end hash end d1, d2 = data, other.data data = { version: version, mode: d1[:mode], interval: d1[:interval], samples: d1[:samples] + d2[:samples], gc_samples: d1[:gc_samples] + d2[:gc_samples], missed_samples: d1[:missed_samples] + d2[:missed_samples], frames: frames } self.class.new(data) end