#!/usr/bin/env ruby

LKP_SRC = ENV['LKP_SRC'] || File.dirname(File.dirname(File.realpath($PROGRAM_NAME)))

def parse
  start_pages = 0
  end_pages = 0
  duration= 1
  $stdin.each_line do |line|
    case line
    when /start:\s+pgmigrate_success\s+(\d+)/
      start_pages = $1.to_i
    when /end:\s+pgmigrate_success\s+(\d+)/
      end_pages = $1.to_i
    when /duration:\s+(\d+)/
      duration = $1.to_i
    end
  end

  pages = end_pages - start_pages
  printf "throughput_p/s: %f\n", pages.to_f / duration
  printf "workload: %d\n", pages
end

parse
