1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
#!/usr/bin/env ruby
require 'test/unit'
require 'ruby-prof'
require 'test_helper'
require 'prime'
# -- Tests ----
class MeasureModeTest < Test::Unit::TestCase
def test_process_time
RubyProf::measure_mode = RubyProf::PROCESS_TIME
assert_equal(RubyProf::PROCESS_TIME, RubyProf::measure_mode)
result = RubyProf.profile do
run_primes
end
result.threads.each do |thread_id, methods|
methods.each do |method|
check_parent_times(method)
check_parent_calls(method)
check_child_times(method)
end
end
end
def test_wall_time
RubyProf::measure_mode = RubyProf::WALL_TIME
assert_equal(RubyProf::WALL_TIME, RubyProf::measure_mode)
result = RubyProf.profile do
run_primes
end
result.threads.values.each do |methods|
methods.each do |method|
check_parent_times(method)
check_parent_calls(method)
check_child_times(method)
end
end
end
def test_cpu
return unless RubyProf.constants.include?('CPU_TIME')
RubyProf::measure_mode = RubyProf::CPU_TIME
assert_equal(RubyProf::CPU_TIME, RubyProf::measure_mode)
result = RubyProf.profile do
run_primes
end
result.threads.values.each do |methods|
methods.each do |method|
check_parent_times(method)
check_parent_calls(method)
check_child_times(method)
end
end
end
def test_allocated_objects
return if RubyProf::ALLOCATIONS.nil?
RubyProf::measure_mode = RubyProf::ALLOCATIONS
assert_equal(RubyProf::ALLOCATIONS, RubyProf::measure_mode)
result = RubyProf.profile do
Array.new
end
end
def test_invalid
assert_raise(ArgumentError) do
RubyProf::measure_mode = 7777
end
end
end
|