Skip to content

Instantly share code, notes, and snippets.

@tenforward
Created November 10, 2011 11:43
Show Gist options
  • Save tenforward/1354677 to your computer and use it in GitHub Desktop.
Save tenforward/1354677 to your computer and use it in GitHub Desktop.
bonnie++の出力csvをgnuplotでグラフ化する
#!/usr/bin/ruby1.9 -w
# -*- coding: utf-8 -*-
#
# usage: ruby b2gp.rb [path to csv]
#
# あらかじめ複数の csv ファイルを
# for f in `ls *.csv`; do tail -n 1 $f >> all.csv; done
# みたいにして 1 ファイルにしておくこと.
require "csv"
csvpath = ARGV[0]
if csvpath.empty? then
print "usage: ruby b2gp.rb [path to csv]"
exit 0
end
# CSV ファイルを読み込み,X 軸の定義 (xtics) の生成とグラフの値の配列を生成
x = 0
xtics_labels = ""
putc_result = Array.new
block_result = Array.new
seek_result = Array.new
seqfile_result = Array.new
ranfile_result = Array.new
seqoutlat_result = Array.new
seqinlat_result = Array.new
ranseeklat_result = Array.new
seqcreatelat_result = Array.new
rancreatelat_result = Array.new
CSV.foreach(csvpath) {|row|
xtics_labels << "\"#{row[2]}\" #{x},"
putc_result << row[7].to_i
putc_result << row[13].to_i
block_result << row[9].to_i
block_result << row[11].to_i
block_result << row[15].to_i
seek_result << row[17].to_i
seqfile_result << row[24].to_i
seqfile_result << row[26].to_i
seqfile_result << row[28].to_i
ranfile_result << row[30].to_i
ranfile_result << row[32].to_i
ranfile_result << row[34].to_i
seqoutlat_result << row[36].to_i
seqoutlat_result << row[37].to_i
seqoutlat_result << row[38].to_i
seqinlat_result << row[39].to_i
seqinlat_result << row[40].to_i
seqinlat_result << row[41].to_i
seqcreatelat_result << row[42].to_i
seqcreatelat_result << row[43].to_i
seqcreatelat_result << row[44].to_i
rancreatelat_result << row[45].to_i
rancreatelat_result << row[46].to_i
rancreatelat_result << row[47].to_i
x += 1
}
# X 軸の目盛の生成
xtics_labels.chop!
xtics_def = "set xtics (#{xtics_labels}) nomirror scale 0 rotate by -45"
# Y 軸の範囲の生成 (title 文字列がグラフと重ならないように最大値の 1.2 倍まで)
putc_max = putc_result.max * 1.2
block_max = block_result.max * 1.2
seek_max = seek_result.max * 1.2
seqfile_max = seqfile_result.max * 1.2
ranfile_max = ranfile_result.max * 1.2
seqoutlat_max = seqoutlat_result.max * 1.2
seqinlat_max = seqinlat_result.max * 1.2
seqcreatelat_max = seqcreatelat_result.max * 1.2
rancreatelat_max = rancreatelat_result.max * 1.2
# gnuplot 定義の共通部分
common_def = <<"EOB"
# データファイルフォーマット
set datafile separator ","
# 棒グラフのスタイル
set boxwidth 0.2
# X 軸
#{xtics_def}
# Y 軸
set ytics nomirror
set format y "%.0f"
EOB
# Sequential Output/Input per Char のグラフの定義部分
seqchar_script =<<"EOB"
set terminal wxt 1
#{common_def}
set ylabel "Characters per sec (K/sec)"
set yrange [0:#{putc_max}]
# plot
plot '#{csvpath}' using ($0-0.1):8 axis x1y1 with boxes title "Writing Chracters sequentially(K/sec)", \\
'' using ($0+0.1):14 axis x1y1 with boxes title "Reading Chracters sequentially(K/sec)"
set terminal postscript eps font "Arial"
set style fill pattern
set output "seqChar.eps"
replot
set terminal png font "Arial"
set output "seqChar.png"
replot
#pause -1 ""
EOB
# Sequential Output/Input Block のグラフ定義部分
seqblock_script =<<"EOB"
set terminal wxt 2
#{common_def}
set ylabel "Blocks per sec (K/sec)"
set yrange [0:#{block_max}]
# plot
plot '#{csvpath}' using ($0-0.2):10 axis x1y1 with boxes title "Writing Blocks sequentially(K/sec)", \\
'' using 12 axis x1y1 with boxes title "Re-writing Blocks sequentially(K/sec)", \\
'' using ($0+0.2):16 axis x1y1 with boxes title "Reading Blocks sequentially(K/sec)"
set terminal postscript eps font "Arial"
set style fill pattern
set output "seqBlock.eps"
replot
set terminal png font "Arial"
set output "seqBlock.png"
replot
EOB
# Random Seek
seek_script =<<"EOB"
set terminal wxt 3
#{common_def}
set ylabel "Seeks (seeks/sec)
set yrange [0:#{seek_max}]
# plot
set boxwidth 0.5
set style fill solid
plot '#{csvpath}' using 18 axis x1y1 with boxes title "Seeks(seek/sec)"
set terminal postscript eps font "Arial"
set style fill pattern
set output "seeks.eps"
replot
set terminal png font "Arial"
set output "seeks.png"
replot
EOB
# Sequential Create
seqfile_script =<<"EOB"
set terminal wxt 4
#{common_def}
set ylabel "Rate (files/sec)"
set yrange [0:#{seqfile_max}]
# plot
plot '#{csvpath}' using ($0-0.2):25 axis x1y1 with boxes title "Create files sequentially(files/sec)", \\
'' using 27 axis x1y1 with boxes title "Reading files sequentially(files/sec)", \\
'' using ($0+0.2):29 axis x1y1 with boxes title "Delete files sequentially(files/sec)"
set terminal postscript eps font "Arial"
set style fill pattern
set output "seqfile.eps"
replot
set terminal png font "Arial"
set output "seqfile.png"
replot
EOB
# Random Create
ranfile_script =<<"EOB"
set terminal wxt 5
#{common_def}
set ylabel "Rate (files/sec)"
set yrange [0:#{ranfile_max}]
# plot
plot '#{csvpath}' using ($0-0.2):31 axis x1y1 with boxes title "Create Files in random order(files/sec)", \\
'' using 33 axis x1y1 with boxes title "Reading Files in random order(files/sec)", \\
'' using ($0+0.2):35 axis x1y1 with boxes title "Delete Files in random order(files/sec)"
set terminal postscript eps font "Arial"
set style fill pattern
set output "ranfile.eps"
replot
set terminal png font "Arial"
set output "ranfile.png"
replot
EOB
# Sequential Output Latency
seqoutlat_script =<<"EOB"
set terminal wxt 6
set ylabel "Latency (msec)"
set yrange [0:#{seqoutlat_max}]
plot '#{csvpath}' using ($0-0.2):37 with boxes title "Latency for output character sequentially", \\
'' using 38 with boxes title "Latency for output block sequentially", \\
'' using ($0+0.2):39 with boxes title "Latency for rewrite block sequentially"
set terminal postscript eps font "Arial"
set style fill pattern
set output "seqoutlate.eps"
replot
set terminal png font "Arial"
set output "seqoutlat.png"
replot
EOB
# Sequential input Latency
seqinlat_script =<<"EOB"
set terminal wxt 7
set ylabel "Latency (msec)"
set yrange [0:#{seqinlat_max}]
plot '#{csvpath}' using ($0-0.2):40 with boxes title "Latency for input character sequentially", \\
'' using 41 with boxes title "Latency for input block sequentially", \\
'' using ($0+0.2):42 with boxes title "Latency for random seeks"
set terminal postscript eps font "Arial"
set style fill pattern
set output "seqinputlat.eps"
replot
set terminal png font "Arial"
set output "seqinputlat.png"
replot
EOB
# Sequential create Latency
seqcreatelat_script =<<"EOB"
set terminal wxt 8
set ylabel "Latency (msec)"
set yrange [0:#{seqcreatelat_max}]
plot '#{csvpath}' using ($0-0.2):43 with boxes title "Latency for creating file sequentially", \\
'' using 44 with boxes title "Latency for reading file sequentially", \\
'' using ($0+0.2):45 with boxes title "Latency for deleting file sequentially"
set terminal postscript eps font "Arial"
set style fill pattern
set output "seqfilelat.eps"
replot
set terminal png font "Arial"
set output "seqfilelat.png"
replot
EOB
# Sequential create Latency
rancreatelat_script =<<"EOB"
set terminal wxt 9
set ylabel "Latency (msec)"
set yrange [0:#{rancreatelat_max}]
plot '#{csvpath}' using ($0-0.2):46 with boxes title "Latency for creating file in random order", \\
'' using 47 with boxes title "Latency for reading file in random order", \\
'' using ($0+0.2):48 with boxes title "Latency for deleting file in random order"
set terminal postscript eps font "Arial"
set style fill pattern
set output "ranfilelat.eps"
replot
set terminal png font "Arial"
set output "ranfilelat.png"
replot
pause -1 ""
EOB
# Sequential Output/Input per Char のグラフ生成用のスクリプトファイル出力
io = File.open("seqchar.gp", "w")
io.print(seqchar_script)
io.close
io = File.open("seqblock.gp", "w")
io.print(seqblock_script)
io.close
io = File.open("seeks.gp", "w")
io.print(seek_script)
io.close
io = File.open("seqfile.gp", "w")
io.print(seqfile_script)
io.close
io = File.open("ranfile.gp", "w")
io.print(ranfile_script)
io.close
io = File.open("seqoutlat.gp", "w")
io.print(seqoutlat_script)
io.close
io = File.open("seqinlat.gp", "w")
io.print(seqinlat_script)
io.close
io = File.open("seqcreatelat.gp", "w")
io.print(seqcreatelat_script)
io.close
io = File.open("rancreatelat.gp", "w")
io.print(rancreatelat_script)
io.close
# Sequential Output/Input per Char のグラフ表示と eps ファイル出力
exec("gnuplot seqchar.gp seqblock.gp seeks.gp seqfile.gp ranfile.gp seqoutlat.gp seqinlat.gp seqcreatelat.gp rancreatelat.gp")
#!/usr/bin/ruby -w
# -*- coding: utf-8 -*-
#
# "ms", "us" という単位が付いている csv ファイルを ms に合わせて,単位文字列は除去
#
require 'csv'
csvpath = ARGV[0]
if csvpath.empty? then
print "usage: ruby convert_latency.rb [path to csv]"
exit 0
end
CSV.foreach(csvpath) {|row|
row.length.times{|i|
if /(\w+)ms$/ =~ row[i] then
row[i] = $1
elsif /(\w+)us$/ =~ row[i] then
row[i] = (row[i].to_f / 1000).to_s
end
}
print CSV.generate_line(row), "\n"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment