Kouhei Sutou
null+****@clear*****
Wed Apr 2 18:59:58 JST 2014
Kouhei Sutou 2014-04-02 18:59:58 +0900 (Wed, 02 Apr 2014) New Revision: d3195c5497ec81346c665a0132e32d9ece57a147 https://github.com/droonga/drnbench/commit/d3195c5497ec81346c665a0132e32d9ece57a147 Message: Add throughput chart generation code based on gnuplot Added files: lib/drnbench/chart/gnuplot.rb lib/drnbench/reporters/throughput-reporter.rb Added: lib/drnbench/chart/gnuplot.rb (+64 -0) 100644 =================================================================== --- /dev/null +++ lib/drnbench/chart/gnuplot.rb 2014-04-02 18:59:58 +0900 (601a0b3) @@ -0,0 +1,64 @@ +# Copyright (C) 2014 Droonga Project +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +require "tempfile" + +module Drnbench + module Chart + class Gnuplot + def initialize + @input = Tempfile.new("drnbench-graph") + write(preamble) + end + + def write(data) + @input.write(data) + end + + def run + @input.close + unless system("gnuplot", @input.path) + @input.open + puts(@input.read) + @input.close + end + end + + private + def preamble + <<-PREAMBLE +set terminal pdfcairo enhanced color transparent rounded + +set key outside center top horizontal reverse Left samplen 2 +unset border +set xtics scale 0 +set ytics scale 0 +set grid ytics linewidth 1 linetype -1 + +set style line 1 lt 1 lc rgbcolor "#3465a4" lw 2.5 pt 7 ps 1 +set style line 2 lt 1 lc rgbcolor "#edd400" lw 2.5 pt 7 ps 1 +set style line 3 lt 1 lc rgbcolor "#888a85" lw 2.5 pt 5 ps 1 +set style line 4 lt 1 lc rgbcolor "#f57900" lw 2.5 pt 5 ps 1 +set style line 5 lt 1 lc rgbcolor "#ad7fa8" lw 2.5 pt 9 ps 1 +set style line 6 lt 1 lc rgbcolor "#4e9a06" lw 2.5 pt 9 ps 1 +set style line 7 lt 1 lc rgbcolor "#ef2929" lw 2.5 pt 1 ps 1 +set style line 8 lt 1 lc rgbcolor "#5c3566" lw 2.5 pt 1 ps 1 +set style line 9 lt 1 lc rgbcolor "#c17d11" lw 2.5 pt 3 ps 1 +set style line 10 lt 1 lc rgbcolor "#dce775" lw 2.5 pt 3 ps 1 + PREAMBLE + end + end + end +end Added: lib/drnbench/reporters/throughput-reporter.rb (+55 -0) 100644 =================================================================== --- /dev/null +++ lib/drnbench/reporters/throughput-reporter.rb 2014-04-02 18:59:58 +0900 (60ecb41) @@ -0,0 +1,55 @@ +# Copyright (C) 2014 Droonga Project +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +require "tempfile" +require "fileutils" + +require "drnbench/chart/gnuplot" + +module Drnbench + module Reporters + class ThroughputReporter + def initialize(label) + @label = label + @data_file = Tempfile.new("drnbench-throughput-data") + end + + def add_data(time, qps) + @data_file.puts([time, qps].join("\t")) + end + + def report(output_directory) + FileUtils.mkdir_p(output_directory) + generate_chart(output_directory) + end + + private + def generate_chart(output_directory) + @data_file.flush + gnuplot = Chart::Gnuplot.new + gnuplot.write(<<-INPUT) +set output "#{output_directory}/throughput.pdf" +set title "Throughput" + +set xlabel "Time (second)" +set ylabel "Queries per Second (qps)" +plot "#{@data_file.path}" using 1:2 with linespoints linestyle 1 \\ + title "#{@label}" + INPUT + gnuplot.run + end + end + end +end -------------- next part -------------- HTML����������������������������...Download