aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/testing/performance/ruby/mri.rb
blob: d12482b58f0ac730fe2eb880cf4b21fc89eb464b (plain) (blame)
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
module ActiveSupport
  module Testing
    module Performance
      module Metrics
        class Base
          protected
            # Ruby 1.8 + ruby-prof wrapper (enable/disable stats for Benchmarker)
            if GC.respond_to?(:enable_stats)
              def with_gc_stats
                GC.enable_stats
                yield
              ensure
                GC.disable_stats
              end
            end
        end
            
        class Memory < Base
          # Ruby 1.8 + ruby-prof wrapper
          if RubyProf.respond_to?(:measure_memory)
            def measure
              RubyProf.measure_memory / 1024.0
            end
          end
        end
        
        class Amount < Base; end
          
        class Objects < Amount
          # Ruby 1.8 + ruby-prof wrapper
          if RubyProf.respond_to?(:measure_allocations)
            def measure
              RubyProf.measure_allocations
            end
          end
        end
        
        class GcRuns < Amount
          # Ruby 1.8 + ruby-prof wrapper
          if RubyProf.respond_to?(:measure_gc_runs)
            def measure
              RubyProf.measure_gc_runs
            end
          end
        end
        
        class GcTime < Time
          # Ruby 1.8 + ruby-prof wrapper
          if RubyProf.respond_to?(:measure_gc_time)
            def measure
              RubyProf.measure_gc_time / 1000
            end
          end
        end
      end
    end
  end
end