Navigation Menu

Skip to content

Commit

Permalink
Add throughput chart generation code based on gnuplot
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Apr 2, 2014
1 parent a761226 commit d3195c5
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 0 deletions.
64 changes: 64 additions & 0 deletions lib/drnbench/chart/gnuplot.rb
@@ -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
55 changes: 55 additions & 0 deletions lib/drnbench/reporters/throughput-reporter.rb
@@ -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

0 comments on commit d3195c5

Please sign in to comment.