test/test_stackprof.rb in stackprof-0.2.2 vs test/test_stackprof.rb in stackprof-0.2.3
- old
+ new
@@ -1,8 +1,9 @@
$:.unshift File.expand_path('../../lib', __FILE__)
require 'stackprof'
require 'test/unit'
+require 'tempfile'
class StackProfTest < Test::Unit::TestCase
def test_info
profile = StackProf.run{}
assert_equal 1.1, profile[:version]
@@ -84,10 +85,23 @@
assert_equal "block (2 levels) in StackProfTest#test_custom", frame[:name]
assert_equal __LINE__-10, frame[:line]
assert_equal [10, 10], frame[:lines][__LINE__-10]
end
+ def test_raw
+ profile = StackProf.run(mode: :custom, raw: true) do
+ 10.times do
+ StackProf.sample
+ end
+ end
+
+ raw = profile[:raw]
+ assert_equal 10, raw[-1]
+ assert_equal raw[0] + 2, raw.size
+ assert_equal 'block (2 levels) in StackProfTest#test_raw', profile[:frames][raw[-2]][:name]
+ end
+
def test_fork
StackProf.run do
pid = fork do
exit! StackProf.running?? 1 : 0
end
@@ -105,9 +119,21 @@
end
assert_empty profile[:frames]
assert_operator profile[:gc_samples], :>, 0
assert_equal 0, profile[:missed_samples]
+ end
+
+ def test_out
+ tmpfile = Tempfile.new('stackprof-out')
+ ret = StackProf.run(mode: :custom, out: tmpfile) do
+ StackProf.sample
+ end
+
+ assert_equal tmpfile, ret
+ tmpfile.rewind
+ profile = Marshal.load(tmpfile.read)
+ assert_not_empty profile[:frames]
end
def math
250_000.times do
2 ** 10