<commit_before>require "prof"

case ENV["RUBY_PROF_CLOCK_MODE"]
when "gettimeofday"
  Prof.clock_mode = Prof::GETTIMEOFDAY
  $stderr.puts("use gettimeofday(2) for profiling") if $VERBOSE
when "cpu"
  if ENV.key?("RUBY_PROF_CPU_FREQUENCY")
    Prof.cpu_frequency = ENV["RUBY_PROF_CPU_FREQUENCY"].to_f
  else
    begin
      open("/proc/cpuinfo") do |f|
        f.each_line do |line|
          s = line.slice(/cpu MHz\s*:\s*(.*)/, 1)
          if s
            Prof.cpu_frequency = s.to_f * 1000000
            break
          end
        end
      end
    rescue Errno::ENOENT
    end
  end
  Prof.clock_mode = Prof::CPU
  $stderr.puts("use CPU clock counter for profiling") if $VERBOSE
else
  Prof.clock_mode = Prof::CLOCK
  $stderr.puts("use clock(3) for profiling") if $VERBOSE
end

at_exit {
  result = Prof.stop
  total = result.detect { |i|
    i.method_class.nil? && i.method_id == :"#toplevel"
  }.total_time
  if total == 0.0
    total = 0.001
  end
  sum = 0
  STDERR.print("  %%   cumulative   self              self     total\n")
  STDERR.print(" time   seconds   seconds    calls  ms/call  ms/call  name\n")
  for r in result
    sum += r.self_time
    if r.method_class.nil?
      name = r.method_id.to_s
    elsif r.method_class.is_a?(Class)
      name = r.method_class.to_s + "#" + r.method_id.to_s
    else
      name = r.method_class.to_s + "." + r.method_id.to_s
    end
    STDERR.printf("%6.2f %8.3f  %8.3f %8d %8.2f %8.2f  %s\n",
                  r.self_time / total * 100, sum, r.self_time, r.count,
                  r.self_time * 1000 / r.count, r.total_time * 1000 / r.count,
                  name)
  end
}
Prof.start<commit_msg>Fixed up to use new ruby-prof.rb file.  Code has migrated to figure_clock_mode<commit_after>require "ruby-prof"

at_exit {
  result = RubyProf.stop
  printer = RubyProf::FlatPrinter.new(result)
  printer.print(STDOUT)
}
RubyProf.start
{'fraction_non_alphanumeric': 0.1253968253968254, 'fraction_numerical': 0.020634920634920634, 'mean_word_length': 2.407207207207207, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1621657', 'n_tokens_mistral': 768, 'n_tokens_neox': 720, 'n_words': 157}