<commit_before>require 'rubinius/agent'

module ActiveSupport
  module Testing
    module Performance
      DEFAULTS.merge!(
        if ARGV.include?('--benchmark')
          {:metrics => [:wall_time, :memory, :objects, :gc_runs, :gc_time]}
        else
          { :metrics => [:wall_time],
            :formats => [:flat, :graph] }
        end).freeze
      
      protected
        def run_gc
          GC.run(true)
        end
      
      class Performer; end

      class Profiler < Performer        
        def run
          @profiler = Rubinius::Profiler::Instrumenter.new
          
          @profiler.profile(false) do
            full_profile_options[:runs].to_i.times { run_test(@metric, :profile) }
          end
          
          @total = @profiler.info[:runtime] / 1000 / 1000 / 1000.0 # seconds
        end
        
        def report
          super
        end
        
        def record
          if(full_profile_options[:formats].include?(:flat))
            create_path_and_open_file(:flat) do |file|
              @profiler.show(file)
            end
          end
          
          if(full_profile_options[:formats].include?(:graph))
            create_path_and_open_file(:graph) do |file|
              @profiler.show(file)
            end
          end
        end
        
        protected
          def create_path_and_open_file(printer_name)
            fname = "#{output_filename}_#{printer_name}.txt"
            FileUtils.mkdir_p(fname)
            File.open(fname, 'wb') do |file|
              yield(file)
            end
          end
      end

      module Metrics        
        class Base
          attr_reader :loopback
          
          def profile
            yield
          end

          protected
            def with_gc_stats
              @loopback = Rubinius::Agent.loopback
              GC.run(true)
              yield
            end
        end

        class WallTime < Time
          def measure
            super
          end
        end

        class Memory < DigitalInformationUnit
          def measure
            loopback.get("system.memory.counter.bytes").last
          end
        end

        class Objects < Amount
          def measure
            loopback.get("system.memory.counter.objects").last
          end
        end

        class GcRuns < Amount
          def measure
            loopback.get("system.gc.full.count").last + loopback.get("system.gc.young.count").last
          end
        end

        class GcTime < Time
          def measure
            (loopback.get("system.gc.full.wallclock").last + loopback.get("system.gc.young.wallclock").last) / 1000.0
          end
        end
      end
    end
  end
end
<commit_msg>fixed a bug where rubinius was creating the profiling files as directories<commit_after>require 'rubinius/agent'

module ActiveSupport
  module Testing
    module Performance
      DEFAULTS.merge!(
        if ARGV.include?('--benchmark')
          {:metrics => [:wall_time, :memory, :objects, :gc_runs, :gc_time]}
        else
          { :metrics => [:wall_time],
            :formats => [:flat, :graph] }
        end).freeze
      
      protected
        def run_gc
          GC.run(true)
        end
      
      class Performer; end

      class Profiler < Performer        
        def run
          @profiler = Rubinius::Profiler::Instrumenter.new
          
          @profiler.profile(false) do
            full_profile_options[:runs].to_i.times { run_test(@metric, :profile) }
          end
          
          @total = @profiler.info[:runtime] / 1000 / 1000 / 1000.0 # seconds
        end
        
        def report
          super
        end
        
        def record
          if(full_profile_options[:formats].include?(:flat))
            create_path_and_open_file(:flat) do |file|
              @profiler.show(file)
            end
          end
          
          if(full_profile_options[:formats].include?(:graph))
            create_path_and_open_file(:graph) do |file|
              @profiler.show(file)
            end
          end
        end
        
        protected
          def create_path_and_open_file(printer_name)
            fname = "#{output_filename}_#{printer_name}.txt"
            FileUtils.mkdir_p(File.dirname(fname))
            File.open(fname, 'wb') do |file|
              yield(file)
            end
          end
      end

      module Metrics        
        class Base
          attr_reader :loopback
          
          def profile
            yield
          end

          protected
            def with_gc_stats
              @loopback = Rubinius::Agent.loopback
              GC.run(true)
              yield
            end
        end

        class WallTime < Time
          def measure
            super
          end
        end

        class Memory < DigitalInformationUnit
          def measure
            loopback.get("system.memory.counter.bytes").last
          end
        end

        class Objects < Amount
          def measure
            loopback.get("system.memory.counter.objects").last
          end
        end

        class GcRuns < Amount
          def measure
            loopback.get("system.gc.full.count").last + loopback.get("system.gc.young.count").last
          end
        end

        class GcTime < Time
          def measure
            (loopback.get("system.gc.full.wallclock").last + loopback.get("system.gc.young.wallclock").last) / 1000.0
          end
        end
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.08355990574587638, 'fraction_numerical': 0.0065252854812398045, 'mean_word_length': 1.3450913727156821, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5999751', 'n_tokens_mistral': 1554, 'n_tokens_neox': 1509, 'n_words': 317}