stackprof 0.2.14 → 0.2.18
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 +4 -4
- data/.github/workflows/ci.yml +43 -0
- data/.gitignore +1 -0
- data/CHANGELOG.md +13 -6
- data/README.md +57 -51
- data/Rakefile +11 -25
- data/ext/stackprof/stackprof.c +206 -70
- data/lib/stackprof/report.rb +28 -23
- data/lib/stackprof.rb +1 -1
- data/stackprof.gemspec +8 -1
- data/test/test_stackprof.rb +65 -11
- data/vendor/FlameGraph/flamegraph.pl +751 -85
- metadata +9 -7
- data/.travis.yml +0 -21
- data/Dockerfile +0 -21
- data/Gemfile.lock +0 -27
data/test/test_stackprof.rb
CHANGED
@@ -39,16 +39,30 @@ class StackProfTest < MiniTest::Test
|
|
39
39
|
end
|
40
40
|
assert_equal :object, profile[:mode]
|
41
41
|
assert_equal 1, profile[:interval]
|
42
|
-
|
42
|
+
if RUBY_VERSION >= '3'
|
43
|
+
assert_equal 4, profile[:samples]
|
44
|
+
else
|
45
|
+
assert_equal 2, profile[:samples]
|
46
|
+
end
|
43
47
|
|
44
48
|
frame = profile[:frames].values.first
|
45
49
|
assert_includes frame[:name], "StackProfTest#test_object_allocation"
|
46
50
|
assert_equal 2, frame[:samples]
|
47
51
|
assert_includes [profile_base_line - 2, profile_base_line], frame[:line]
|
48
|
-
|
49
|
-
|
52
|
+
if RUBY_VERSION >= '3'
|
53
|
+
assert_equal [2, 1], frame[:lines][profile_base_line+1]
|
54
|
+
assert_equal [2, 1], frame[:lines][profile_base_line+2]
|
55
|
+
else
|
56
|
+
assert_equal [1, 1], frame[:lines][profile_base_line+1]
|
57
|
+
assert_equal [1, 1], frame[:lines][profile_base_line+2]
|
58
|
+
end
|
50
59
|
frame = profile[:frames].values[1] if RUBY_VERSION < '2.3'
|
51
|
-
|
60
|
+
|
61
|
+
if RUBY_VERSION >= '3'
|
62
|
+
assert_equal [4, 0], frame[:lines][profile_base_line]
|
63
|
+
else
|
64
|
+
assert_equal [2, 0], frame[:lines][profile_base_line]
|
65
|
+
end
|
52
66
|
end
|
53
67
|
|
54
68
|
def test_object_allocation_interval
|
@@ -64,8 +78,14 @@ class StackProfTest < MiniTest::Test
|
|
64
78
|
end
|
65
79
|
|
66
80
|
assert_operator profile[:samples], :>=, 1
|
67
|
-
|
68
|
-
|
81
|
+
if RUBY_VERSION >= '3'
|
82
|
+
assert profile[:frames].values.take(2).map { |f|
|
83
|
+
f[:name].include? "StackProfTest#math"
|
84
|
+
}.any?
|
85
|
+
else
|
86
|
+
frame = profile[:frames].values.first
|
87
|
+
assert_includes frame[:name], "StackProfTest#math"
|
88
|
+
end
|
69
89
|
end
|
70
90
|
|
71
91
|
def test_walltime
|
@@ -74,7 +94,11 @@ class StackProfTest < MiniTest::Test
|
|
74
94
|
end
|
75
95
|
|
76
96
|
frame = profile[:frames].values.first
|
77
|
-
|
97
|
+
if RUBY_VERSION >= '3'
|
98
|
+
assert_equal "IO.select", frame[:name]
|
99
|
+
else
|
100
|
+
assert_equal "StackProfTest#idle", frame[:name]
|
101
|
+
end
|
78
102
|
assert_in_delta 200, frame[:samples], 25
|
79
103
|
end
|
80
104
|
|
@@ -89,24 +113,46 @@ class StackProfTest < MiniTest::Test
|
|
89
113
|
assert_equal :custom, profile[:mode]
|
90
114
|
assert_equal 10, profile[:samples]
|
91
115
|
|
92
|
-
|
116
|
+
offset = RUBY_VERSION >= '3' ? 1 : 0
|
117
|
+
frame = profile[:frames].values[offset]
|
93
118
|
assert_includes frame[:name], "StackProfTest#test_custom"
|
94
119
|
assert_includes [profile_base_line-2, profile_base_line+1], frame[:line]
|
95
|
-
|
120
|
+
|
121
|
+
if RUBY_VERSION >= '3'
|
122
|
+
assert_equal [10, 0], frame[:lines][profile_base_line+2]
|
123
|
+
else
|
124
|
+
assert_equal [10, 10], frame[:lines][profile_base_line+2]
|
125
|
+
end
|
96
126
|
end
|
97
127
|
|
98
128
|
def test_raw
|
129
|
+
before_monotonic = Process.clock_gettime(Process::CLOCK_MONOTONIC, :microsecond)
|
130
|
+
|
99
131
|
profile = StackProf.run(mode: :custom, raw: true) do
|
100
132
|
10.times do
|
101
133
|
StackProf.sample
|
102
134
|
end
|
103
135
|
end
|
104
136
|
|
137
|
+
after_monotonic = Process.clock_gettime(Process::CLOCK_MONOTONIC, :microsecond)
|
138
|
+
|
105
139
|
raw = profile[:raw]
|
106
140
|
assert_equal 10, raw[-1]
|
107
141
|
assert_equal raw[0] + 2, raw.size
|
108
|
-
|
142
|
+
|
143
|
+
offset = RUBY_VERSION >= '3' ? -3 : -2
|
144
|
+
assert_includes profile[:frames][raw[offset]][:name], 'StackProfTest#test_raw'
|
145
|
+
|
146
|
+
assert_equal 10, profile[:raw_sample_timestamps].size
|
147
|
+
profile[:raw_sample_timestamps].each_cons(2) do |t1, t2|
|
148
|
+
assert_operator t1, :>, before_monotonic
|
149
|
+
assert_operator t2, :>=, t1
|
150
|
+
assert_operator t2, :<, after_monotonic
|
151
|
+
end
|
152
|
+
|
109
153
|
assert_equal 10, profile[:raw_timestamp_deltas].size
|
154
|
+
total_duration = after_monotonic - before_monotonic
|
155
|
+
assert_operator profile[:raw_timestamp_deltas].inject(&:+), :<, total_duration
|
110
156
|
end
|
111
157
|
|
112
158
|
def test_metadata
|
@@ -178,7 +224,6 @@ class StackProfTest < MiniTest::Test
|
|
178
224
|
end
|
179
225
|
end
|
180
226
|
|
181
|
-
raw = profile[:raw]
|
182
227
|
gc_frame = profile[:frames].values.find{ |f| f[:name] == "(garbage collection)" }
|
183
228
|
marking_frame = profile[:frames].values.find{ |f| f[:name] == "(marking)" }
|
184
229
|
sweeping_frame = profile[:frames].values.find{ |f| f[:name] == "(sweeping)" }
|
@@ -232,6 +277,15 @@ class StackProfTest < MiniTest::Test
|
|
232
277
|
refute_empty profile[:frames]
|
233
278
|
end
|
234
279
|
|
280
|
+
def test_min_max_interval
|
281
|
+
[-1, 0, 1_000_000, 1_000_001].each do |invalid_interval|
|
282
|
+
err = assert_raises(ArgumentError, "invalid interval #{invalid_interval}") do
|
283
|
+
StackProf.run(interval: invalid_interval, debug: true) {}
|
284
|
+
end
|
285
|
+
assert_match(/microseconds/, err.message)
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
235
289
|
def math
|
236
290
|
250_000.times do
|
237
291
|
2 ** 10
|