Skip to content

Instantly share code, notes, and snippets.

@chetan
Created November 23, 2010 21:31
Show Gist options
  • Save chetan/712578 to your computer and use it in GitHub Desktop.
Save chetan/712578 to your computer and use it in GitHub Desktop.
convert sysbench i/o test output into tsv format
#!/usr/bin/env ruby
module SysBench
class IO
attr_accessor :version, :threads, :test
attr_accessor :total_size, :block_size
attr_accessor :byte_rate, :request_rate
attr_accessor :min, :max, :avg, :top
def initialize(file)
if not File.exists? file then
puts "File '#{file}' does not exist!"
exit
end
parse(File.new(file).read)
end
def parse(str)
str.split(/\n/).each do |l|
l.strip!
if l =~ /^sysbench (.+?):/
@version = $1
elsif l =~ /^Number of threads: (\d+)$/
@threads = $1
elsif l =~ /^Doing (.+?) test$/
@test = $1
elsif l =~ /^(.+?) total file size$/
@total_size = $1
elsif l =~ /^Block size (.+?)$/
@block_size = $1
elsif l =~ /Read [\dKMGTb.]+ Written [\dKMGTb.]+ Total transferred [\dKMGTb.]+ \((.+?)\)/
@byte_rate = $1
elsif l =~ /^(.+?) Requests\/sec executed$/
@request_rate = $1
elsif l =~ /min:\s+(.+?)$/
@min = $1
elsif l =~ /max:\s+(.+?)$/
@max = $1
elsif l =~ /avg:\s+(.+?)$/
@avg = $1
elsif l =~ /approx.*?:\s+(.+?)$/
@top = $1
end
end # each
end # parse
def to_s(delim = "\t")
[@test, @threads, @total_size, @block_size, @byte_rate, @request_rate, @min, @max, @avg, @top].join("\t")
end
end
end
file = ARGV[0]
if file.nil? or file.empty? then
puts "usage: parse.rb <output file>"
exit
end
bench = SysBench::IO.new(file)
puts bench
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment