test/test_stackprof.rb in stackprof-0.2.17 vs test/test_stackprof.rb in stackprof-0.2.18
- old
+ new
@@ -76,13 +76,18 @@
profile = StackProf.run(mode: :cpu, interval: 500) do
math
end
assert_operator profile[:samples], :>=, 1
- offset = RUBY_VERSION >= '3' ? 1 : 0
- frame = profile[:frames].values[offset]
- assert_includes frame[:name], "StackProfTest#math"
+ if RUBY_VERSION >= '3'
+ assert profile[:frames].values.take(2).map { |f|
+ f[:name].include? "StackProfTest#math"
+ }.any?
+ else
+ frame = profile[:frames].values.first
+ assert_includes frame[:name], "StackProfTest#math"
+ end
end
def test_walltime
profile = StackProf.run(mode: :wall) do
idle
@@ -119,23 +124,37 @@
assert_equal [10, 10], frame[:lines][profile_base_line+2]
end
end
def test_raw
+ before_monotonic = Process.clock_gettime(Process::CLOCK_MONOTONIC, :microsecond)
+
profile = StackProf.run(mode: :custom, raw: true) do
10.times do
StackProf.sample
end
end
+ after_monotonic = Process.clock_gettime(Process::CLOCK_MONOTONIC, :microsecond)
+
raw = profile[:raw]
assert_equal 10, raw[-1]
assert_equal raw[0] + 2, raw.size
offset = RUBY_VERSION >= '3' ? -3 : -2
assert_includes profile[:frames][raw[offset]][:name], 'StackProfTest#test_raw'
+
+ assert_equal 10, profile[:raw_sample_timestamps].size
+ profile[:raw_sample_timestamps].each_cons(2) do |t1, t2|
+ assert_operator t1, :>, before_monotonic
+ assert_operator t2, :>=, t1
+ assert_operator t2, :<, after_monotonic
+ end
+
assert_equal 10, profile[:raw_timestamp_deltas].size
+ total_duration = after_monotonic - before_monotonic
+ assert_operator profile[:raw_timestamp_deltas].inject(&:+), :<, total_duration
end
def test_metadata
metadata = {
path: '/foo/bar',
@@ -203,10 +222,9 @@
5.times do
GC.start
end
end
- raw = profile[:raw]
gc_frame = profile[:frames].values.find{ |f| f[:name] == "(garbage collection)" }
marking_frame = profile[:frames].values.find{ |f| f[:name] == "(marking)" }
sweeping_frame = profile[:frames].values.find{ |f| f[:name] == "(sweeping)" }
assert gc_frame