test-prof-autopilot 0.1.0.pre.1 → 0.1.0.pre.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 55e6d41b4c30aa3390d97e550a425e92125e6ee74e4ffe6a3e2660be5f5e1795
4
- data.tar.gz: 866cc0632a7304a5e675ae78541e77f304de4eeba781f8987a6f8d0563eba3db
3
+ metadata.gz: 8ee9039d6d83bbf54010e2ebda79747d5ad7511cb7cff65eb1d1064f72561692
4
+ data.tar.gz: fc3b28fc007dcfefddf66dd4b045befb745db2aa3dc09ca591ae3a75cee45b73
5
5
  SHA512:
6
- metadata.gz: 2ffc441d899c9fa8c2fcaec24930016ee0677705153dd4528aa19e9b48637563a06a0573e001c069d2f04ef5cf4964a49f6380afaefbb263c7b66b0ae8673b19
7
- data.tar.gz: 389c5d56dbdc4553d21850f964d5880c0de8a2cde0c9938c65a390de84556b326d3abf8cdc71ad5626461e572e7021697f2272edeb8e34ac1a427f632fafa6f4
6
+ metadata.gz: 9540aa726621514223f0f48a02b27e13c1082b27596093d610b19fd0d885dcb416f6336c03e631fb4d51a10ea57a21ccbb671312b0ca9a02a36a8e73c5225412
7
+ data.tar.gz: 6d16c822426a62e6ac7ad8d8a0d747d0e61e2850e23252ec9b9753f5ec735cb9b64ff28bb5e071614359a04314ba8eff25d08eb433e4319bfbd53337562808ce
@@ -24,32 +24,53 @@ module TestProf
24
24
  end
25
25
 
26
26
  def merge(other)
27
- f1, f2 = data[:frames], other.data[:frames]
28
-
29
- frames = (f1.keys + f2.keys).uniq.each_with_object({}) do |id, hash|
30
- if f1[id].nil?
31
- hash[id] = f2[id]
32
- elsif f2[id]
33
- hash[id] = f1[id]
34
- hash[id][:total_samples] += f2[id][:total_samples]
35
- hash[id][:samples] += f2[id][:samples]
36
- if f2[id][:edges]
37
- edges = hash[id][:edges] ||= {}
38
- f2[id][:edges].each do |edge, weight|
39
- edges[edge] ||= 0
40
- edges[edge] += weight
41
- end
27
+ ids_mapping = generate_ids_mapping(data[:frames], other.data[:frames])
28
+
29
+ frames = data[:frames].dup
30
+
31
+ other.data[:frames].each do |id, new_frame|
32
+ frame =
33
+ if ids_mapping[id]
34
+ frames[ids_mapping[id]]
35
+ else
36
+ frames[id] = empty_frame_from(new_frame)
42
37
  end
43
- if f2[id][:lines]
44
- lines = hash[id][:lines] ||= {}
45
- f2[id][:lines].each do |line, weight|
46
- lines[line] = add_lines(lines[line], weight)
38
+
39
+ frame[:total_samples] += new_frame[:total_samples]
40
+ frame[:samples] += new_frame[:samples]
41
+
42
+ if new_frame[:edges]
43
+ edges = (frame[:edges] ||= {})
44
+
45
+ new_frame[:edges].each do |edge, weight|
46
+ old_edge = ids_mapping[edge]
47
+
48
+ if edges[old_edge]
49
+ edges[old_edge] += weight
50
+ else
51
+ edges[old_edge] = weight
47
52
  end
48
53
  end
49
- else
50
- hash[id] = f1[id]
51
54
  end
52
- hash
55
+
56
+ if new_frame[:lines]
57
+ lines = (frame[:lines] ||= {})
58
+
59
+ new_frame[:lines].each do |line, weight|
60
+ old_line = ids_mapping[line]
61
+
62
+ lines[old_line] =
63
+ if lines[old_line]
64
+ add_lines(lines[old_line], weight)
65
+ else
66
+ weight
67
+ end
68
+ end
69
+ end
70
+ end
71
+
72
+ converted_raw = other.data[:raw].map do |raw|
73
+ ids_mapping[raw] || raw
53
74
  end
54
75
 
55
76
  d1, d2 = data, other.data
@@ -62,12 +83,38 @@ module TestProf
62
83
  missed_samples: d1[:missed_samples] + d2[:missed_samples],
63
84
  metadata: d1[:metadata].merge(d2[:metadata]),
64
85
  frames: frames,
65
- raw: d1[:raw] + d2[:raw],
86
+ raw: d1[:raw] + converted_raw,
66
87
  raw_timestamp_deltas: d1[:raw_timestamp_deltas] + d2[:raw_timestamp_deltas]
67
88
  }
68
89
 
69
90
  self.class.new(data)
70
91
  end
92
+
93
+ def generate_ids_mapping(frames, other_frames)
94
+ old_fingerprints = frames_to_fingerprints(frames)
95
+ new_fingerprints = frames_to_fingerprints(other_frames)
96
+
97
+ new_fingerprints.each_with_object({}) do |(fingerprint, frame), hash|
98
+ next hash unless old_fingerprints[fingerprint]
99
+
100
+ hash[frame[:id]] = old_fingerprints[fingerprint][:id]
101
+ end
102
+ end
103
+
104
+ def frames_to_fingerprints(frames)
105
+ frames.each_with_object({}) do |(id, frame), hash|
106
+ fingerprint = [frame[:name], frame[:file], frame[:line]].compact.map(&:to_s).join("/")
107
+ hash[fingerprint] = frame.merge(id: id)
108
+ hash
109
+ end
110
+ end
111
+
112
+ def empty_frame_from(frame)
113
+ frame.slice(:name, :file, :line).merge(
114
+ total_samples: 0,
115
+ samples: 0
116
+ )
117
+ end
71
118
  end
72
119
  end
73
120
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module TestProf
4
4
  module Autopilot # :nodoc:
5
- VERSION = "0.1.0.pre.1"
5
+ VERSION = "0.1.0.pre.2"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test-prof-autopilot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre.1
4
+ version: 0.1.0.pre.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruslan Shakirov