aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/testing/performance/ruby/yarv.rb
blob: 62095a8fe49a3a7908ce12510677961e4991b39f (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
module ActiveSupport
  module Testing
    module Performance
      module Metrics
        class Base
          protected
            # Ruby 1.9 with GC::Profiler
            if defined?(GC::Profiler)
              def with_gc_stats
                GC::Profiler.enable
                GC.start
                yield
              ensure
                GC::Profiler.disable
              end
            end
        end
        
        class Memory < DigitalInformationUnit
          # Ruby 1.9 + GCdata patch
          if GC.respond_to?(:malloc_allocated_size)
            def measure
              GC.malloc_allocated_size
            end
          end
        end
          
        class Objects < Amount
          # Ruby 1.9 + GCdata patch
          if GC.respond_to?(:malloc_allocations)
            def measure
              GC.malloc_allocations
            end
          end
        end
        
        class GcRuns < Amount
          # Ruby 1.9
          if GC.respond_to?(:count)
            def measure
              GC.count
            end
          end
        end
        
        class GcTime < Time
          # Ruby 1.9 with GC::Profiler
          if defined?(GC::Profiler) && GC::Profiler.respond_to?(:total_time)
            def measure
              GC::Profiler.total_time
            end
          end
        end
      end
    end
  end
end