You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: perf_timings.rb
    path of file: ./repos/manageiq/tools/log_processing
    
    the code of the file until where you have to start completion: #!/usr/bin/env ruby

RAILS_ROOT = File.expand_path(File.join(__dir__, %w[.. ..]))
require 'manageiq/gems/pending'
require 'miq_logger_processor'

logfile = ARGV.shift if ARGV[0] && File.file?(ARGV[0])
logfile ||= File.join(RAILS_ROOT, "log/evm.log")
logfile = File.expand_path(logfile)

$outdir = ARGV.shift if ARGV[0] && File.directory?(ARGV[0])
$outdir ||= File.dirname(logfile)
$outdir.chomp!("/")
$outdir.chomp!("\\")
$outdir = File.expand_path($outdir)

require 'csv'

def dump_csv(type, hashes)
  output = "#{$outdir}/#{type}.csv"
  if hashes.empty?
    puts "No #{type} data points found."
    File.truncate(output, 0) if File.exist?(output)
  else
    puts "#{hashes.length} #{type} data points found."

    keys = hashes[0].keys
    keys.delete_if { |k, _v| [:time, :total_time].include?(k) }
    keys = keys.sort_by(&:to_s)
    keys = keys.unshift(:time)
    keys += [:
    
def dump_csv(type, hashes)
  output = "#{$outdir}/#{type}.csv"
  if hashes.empty?
    puts "No #{type} data points found."
    File.truncate(output, 0) if File.exist?(output)
  else
    puts "#{hashes.length} #{type} data points found."

    keys = hashes[0].keys
    keys.delete_if { |k, _v| [:time, :total_time].include?(k) }
    keys = keys.sort_by(&:to_s)
    keys = keys.unshift(:time)
    keys += [:unaccounted, :total_time]

    graph_data = []
    CSV.open(output, "w") do |csv|
      graph_data << keys[0...-1].collect(&:to_s)
      csv << keys
      hashes.each do |h|
        values = h.values_at(*keys)

        # Calculate unaccounted time
        values[-2] = values[-1].to_f - values[1...-2].inject { |sum, v| sum.to_f + v.to_f }

        graph_data << values[0...-1].collect { |v| v.kind_of?(String) ? v : (v / values[-1] * 100) }
        csv << values
      end
    end

    MiqLoggerProcessor.to_png(graph_data, :outfile => "#{$outdir}/#{type}.png", :title => type.to_s, :graph_type => :stacked)
  end