railsbench 0.8.4

Sign up to get free protection for your applications and to get access to all the features.
data/script/perf_html ADDED
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ unless ARGV.include?('-nocss')
4
+ puts <<'END'
5
+ <style type="text/css">
6
+ <!--
7
+ .perf_header, .perf_data, .perf_name { font-size:70%; padding-left:5px; padding-right:5px; }
8
+ .perf_header { text-align:center; vertical-align:top; font-weight:bold;}
9
+ .i { font-style:italic; }
10
+ .b { font-weight:bold; }
11
+ .c1 { background:#fff3df; }
12
+ .c2 { background:#dfedff; }
13
+ .factor { background:#efe0ef; }
14
+ .name { background:#dfdfdf; }
15
+ .perf_name { text-align:left; }
16
+ .perf_data { text-align:right; }
17
+ -->
18
+ </style>
19
+ END
20
+ end
21
+
22
+ unless ARGV.include?('-notable')
23
+ puts "<table cellspacing=1px>"
24
+ $stdin.each_line do |l|
25
+ case l
26
+ when /^garbage collection/
27
+ unless ARGV.include?('-gc')
28
+ puts "</table>"
29
+ exit
30
+ end
31
+ puts "<tr></tr><tr></tr>"
32
+ puts "<tr>"
33
+ puts "<th class='perf_header name' style='text-align:left'>GC statistics</th>"
34
+ puts "<th class='perf_header c1'>c1 total</th><th class='perf_header c2'>c2 total</th>"
35
+ puts "<th class='perf_header c1'>c1 #gc</th><th class='perf_header c2'>c2 #gc</th>"
36
+ puts "<th class='perf_header c1'>c1 gc%</th><th class='perf_header c2'>c2 #gc%</th>"
37
+ puts "<th class='perf_header factor'>c1/c2</th>"
38
+ puts "</tr>"
39
+ when /^page/
40
+ puts "<tr>"
41
+ puts "<th class='perf_header name' style='text-align:left;'>page</th>"
42
+ puts "<th class='perf_header c1'>c1 total</th><th class='perf_header c2'>c2 total</th>"
43
+ puts "<th class='perf_header c1'>c1 r/s</th><th class='perf_header c2'>c2 r/s</th>"
44
+ puts "<th class='perf_header c1'>c1 ms/r</th><th class='perf_header c2'>c2 ms/r</th>"
45
+ puts "<th class='perf_header factor'>c1/c2</th>"
46
+ puts "</tr>"
47
+ end
48
+ case l
49
+ when %r{^([A-Za-z0-9./?= ]+)\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)\s+$}
50
+ puts "<tr>"
51
+ puts "<td class='perf_name name#{" i" if $1.strip == "all requests"}'>#{$1}</td>"
52
+ puts "<td class='perf_data c1'>#{$2}</td><td class='perf_data c2'>#{$3}</td>"
53
+ puts "<td class='perf_data c1'>#{$4}</td><td class='perf_data c2'>#{$5}</td>"
54
+ puts "<td class='perf_data c1'>#{$6}</td><td class='perf_data c2'>#{$7}</td>"
55
+ puts "<td class='perf_data factor'>#{$8}</td>"
56
+ puts "</tr>"
57
+ end
58
+ end
59
+ puts "</table>"
60
+ end
61
+
62
+ __END__
63
+
64
+ ### Local Variables: ***
65
+ ### mode:ruby ***
66
+ ### End: ***
67
+
68
+ # Copyright (C) 2005, 2006 Stefan Kaes
69
+ #
70
+ # This program is free software; you can redistribute it and/or modify
71
+ # it under the terms of the GNU General Public License as published by
72
+ # the Free Software Foundation; either version 2 of the License, or
73
+ # (at your option) any later version.
74
+ #
75
+ # This program is distributed in the hope that it will be useful,
76
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
77
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
78
+ # GNU General Public License for more details.
79
+ #
80
+ # You should have received a copy of the GNU General Public License
81
+ # along with this program; if not, write to the Free Software
82
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
data/script/perf_loop ADDED
@@ -0,0 +1,38 @@
1
+ #!/bin/sh
2
+ # set -x
3
+
4
+ BINDIR=`dirname $0`
5
+ test -z $RAILS_PERF_RUNS && RAILS_PERF_RUNS=3
6
+
7
+ FILE=$RAILS_BENCHMARK_FILE
8
+ if [ "$OSTYPE" == "cygwin" ]; then
9
+ RAILS_BENCHMARK_FILE=`cygpath -m $FILE`
10
+ fi
11
+
12
+ unset RUBY_GC_STATS
13
+
14
+ echo "benchmarking $RAILS_PERF_RUNS runs with options $@"
15
+ echo "$BINDIR/perf_bench $@" >$FILE
16
+
17
+ patched_gc="no"
18
+ for arg in $@; do
19
+ case $arg in
20
+ -gc=*) patched_gc=${arg#-gc=};;
21
+ esac
22
+ done
23
+
24
+ if [ "${patched_gc}" = "no" ]; then
25
+ unset RUBY_HEAP_MIN_SLOTS RUBY_GC_MALLOC_LIMIT RUBY_HEAP_FREE_MIN
26
+ else
27
+ . $RAILS_ROOT/config/${patched_gc}.gc
28
+ export RUBY_HEAP_MIN_SLOTS RUBY_GC_MALLOC_LIMIT RUBY_HEAP_FREE_MIN
29
+ fi
30
+
31
+ i=$(( $RAILS_PERF_RUNS ))
32
+ while [ $i -gt 0 ]; do
33
+ i=$(( $i-1 ))
34
+ ruby $BINDIR/perf_bench $@ >/dev/null || exit 1
35
+ done
36
+ echo >>$FILE
37
+
38
+ # echo "performance data written to file $RAILS_BENCHMARK_FILE"
data/script/perf_plot ADDED
@@ -0,0 +1,94 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require "gruff"
5
+
6
+ $:.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib'))
7
+ require 'railsbench/perf_info'
8
+
9
+ # extract options
10
+
11
+ selection = []
12
+ title = "Performance Graph"
13
+ files = []
14
+ names = []
15
+ labels = []
16
+ perf_data = []
17
+ graph_type = Gruff::Line
18
+ graph_width = 800
19
+
20
+ ARGV.each do |arg|
21
+ case arg
22
+ when /^-only=(.*)$/
23
+ selection = $1.split(',').map{|s| s.strip.to_i}
24
+ when /^-title=(.*)$/
25
+ title = $1 unless $1.strip.empty?
26
+ when '-line'
27
+ graph_type = Gruff::Line
28
+ when '-bar'
29
+ graph_type = Gruff::Bar
30
+ when /^-width=(\d+)$/
31
+ graph_width = $1.to_i
32
+ when /^-names=(.+)$/
33
+ names = $1.split(',')
34
+ when /^-labels=(.+)$/
35
+ labels = $1.split(',')
36
+ else
37
+ files << File.open_or_die(arg)
38
+ names[files.length-1] ||= File.basename(arg)
39
+ end
40
+ end
41
+
42
+ files.length > 0 or die "usage: perf_plot [options] file1 file2 ..."
43
+
44
+ files.each do |file|
45
+ pi = PerfInfo.new(file)
46
+ iter = pi.iterations
47
+ urls = pi.requests_per_key
48
+ perf_data << pi.keys.map{ |key| iter*urls/pi.timings_mean(key) }
49
+ file.close
50
+ end
51
+
52
+ selection = (1..(perf_data.last.length)).to_a if selection.empty?
53
+ if labels.empty?
54
+ labels = selection.map{|i| i.to_s}.index_map
55
+ else
56
+ labels = labels.index_map
57
+ end
58
+ perf_data = perf_data.map{|d| d.restrict_to(selection.map{|i| i-1})}
59
+
60
+ # puts selection.inspect
61
+ # puts labels.inspect
62
+ # puts perf_data.inspect
63
+
64
+ g = graph_type.new(graph_width)
65
+ g.title = title
66
+ g.sort = false
67
+ g.minimum_value = 0
68
+ g.maximum_value = perf_data.flatten.max.ceil
69
+ g.labels = labels
70
+ perf_data.each_with_index{|d,i| g.data(names[i], d)}
71
+ g.write
72
+
73
+
74
+ __END__
75
+
76
+ ### Local Variables: ***
77
+ ### mode:ruby ***
78
+ ### End: ***
79
+
80
+ # Copyright (C) 2005, 2006 Stefan Kaes
81
+ #
82
+ # This program is free software; you can redistribute it and/or modify
83
+ # it under the terms of the GNU General Public License as published by
84
+ # the Free Software Foundation; either version 2 of the License, or
85
+ # (at your option) any later version.
86
+ #
87
+ # This program is distributed in the hope that it will be useful,
88
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
89
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
90
+ # GNU General Public License for more details.
91
+ #
92
+ # You should have received a copy of the GNU General Public License
93
+ # along with this program; if not, write to the Free Software
94
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
@@ -0,0 +1,111 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'gruff'
5
+
6
+ $:.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib'))
7
+ require 'railsbench/gc_info'
8
+
9
+ # extract options
10
+
11
+ selection = []
12
+ title = "GC Data Graph"
13
+ files = []
14
+ names = []
15
+ labels = %w()
16
+ perf_data = []
17
+ graph_type = Gruff::StackedBar
18
+ graph_width = 1400
19
+
20
+ ARGV.each do |arg|
21
+ case arg
22
+ # when '-line'
23
+ # graph_type = Gruff::Line
24
+ # when '-bar'
25
+ # graph_type = Gruff::Bar
26
+ when /^-width=(\d+)$/
27
+ graph_width = $1.to_i
28
+ # when /^-title=(.*)$/
29
+ # title = $1 unless $1.strip.empty?
30
+ # when /^-names=(.+)$/
31
+ # names = $1.split(',')
32
+ else
33
+ files << File.open_or_die(arg)
34
+ names[files.length-1] ||= File.basename(arg)
35
+ end
36
+ end
37
+
38
+ files.length > 0 or die "usage: perf_plot_gc [options] file1 file2 ..."
39
+
40
+ object_types = Set.new
41
+ gcis = []
42
+ files.each do |file|
43
+ gcis << GCInfo.new(file)
44
+ object_types.merge gcis.last.object_types
45
+ file.close
46
+ end
47
+
48
+ object_types = object_types.to_a
49
+ gc_count_max = gcis.map{|gci| gci.collections}.max
50
+ gc_max_processed = gcis.map{|gci| gci.processed_max}.max
51
+
52
+ g = graph_type.new(graph_width)
53
+
54
+ g.add_color("#FF0000")
55
+ g.add_color("#00FF00")
56
+ g.add_color("#0000FF")
57
+
58
+ g.instance_eval do
59
+ count = @colors.length
60
+ count.times{|i| add_color(@colors[i])}
61
+ end
62
+
63
+ g.title = title
64
+ g.sort = false
65
+ g.legend_font_size = 8
66
+ g.legend_box_size = 8
67
+ g.marker_font_size = 8
68
+ #g.minimum_value = 0
69
+ #g.maximum_value = gc_max_processed
70
+ g.labels = Hash[* (0...gc_count_max).map{|i| [2*i, i.to_s]}.flatten ]
71
+ puts g.labels.inspect
72
+
73
+ object_types.each do |ot|
74
+ next if ot =~ /NODE|STRING/i
75
+ data = []
76
+ gc_count_max.times do |gc_index|
77
+ for gci in gcis
78
+ map_at_this_gc = gci.freed_objects[gc_index]
79
+ data << ((map_at_this_gc && map_at_this_gc[ot]) || 0)
80
+ map_at_this_gc = gci.live_objects[gc_index]
81
+ data << ((map_at_this_gc && map_at_this_gc[ot]) || 0)
82
+ end
83
+ end
84
+ puts "#{ot}: #{data.inspect}"
85
+ g.data(ot, data)
86
+ end
87
+
88
+ g.write
89
+
90
+
91
+ __END__
92
+
93
+ ### Local Variables: ***
94
+ ### mode:ruby ***
95
+ ### End: ***
96
+
97
+ # Copyright (C) 2005, 2006 Stefan Kaes
98
+ #
99
+ # This program is free software; you can redistribute it and/or modify
100
+ # it under the terms of the GNU General Public License as published by
101
+ # the Free Software Foundation; either version 2 of the License, or
102
+ # (at your option) any later version.
103
+ #
104
+ # This program is distributed in the hope that it will be useful,
105
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
106
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
107
+ # GNU General Public License for more details.
108
+ #
109
+ # You should have received a copy of the GNU General Public License
110
+ # along with this program; if not, write to the Free Software
111
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
data/script/perf_prof ADDED
@@ -0,0 +1,51 @@
1
+ #!/bin/sh
2
+ # set -x
3
+
4
+ if [ $# -lt 2 ]; then
5
+ echo "usage: perf_prof iterations options [conf-name]"
6
+ echo "example: perf_prof 100 \"-bm=default -log\" pdata"
7
+ exit 1
8
+ fi
9
+
10
+ BINDIR=`dirname $0`
11
+
12
+ test -z "$RAILS_PERF_DATA" && RAILS_PERF_DATA=$HOME
13
+
14
+ ITER="$1"
15
+ OPT="$2"
16
+ BENCHMARK=""
17
+ RUBY_PROF_OPTS="-ruby_prof=1"
18
+ use_patched_gc="no"
19
+ warmup="-warmup "
20
+
21
+ for opt in $OPT; do
22
+ case $opt in
23
+ -bm=*) BENCHMARK=${opt#-bm=};;
24
+ -ruby_prof=*) RUBY_PROF_OPTS=${opt};;
25
+ -patched_gc) use_patched_gc="yes";;
26
+ -warmup) warmup="";;
27
+ esac
28
+ done
29
+
30
+ if [ "${use_patched_gc}" = "no" ]; then
31
+ unset RUBY_HEAP_MIN_SLOTS RUBY_GC_MALLOC_LIMIT RUBY_HEAP_FREE_MIN
32
+ fi
33
+
34
+ DATE=`date +%m-%d`
35
+ if [ $# == 3 ]; then
36
+ BENCHMARK_FILE="$RAILS_PERF_DATA/${DATE}${BENCHMARK}.$3.html"
37
+ else
38
+ BENCHMARK_FILE="$RAILS_PERF_DATA/perf_run${BENCHMARK}.html"
39
+ fi
40
+
41
+ unset RUBY_GC_STATS
42
+
43
+ PERF_OPTIONS="$ITER $OPT ${warmup}$RUBY_PROF_OPTS"
44
+ $BINDIR/run_urls $PERF_OPTIONS >/dev/null 2>$BENCHMARK_FILE
45
+
46
+ echo "profile data written to $BENCHMARK_FILE"
47
+
48
+ case "$OSTYPE" in
49
+ cygwin*) cmd /c start "`cygpath -w $BENCHMARK_FILE`";;
50
+ darwin*) open $BENCHMARK_FILE;;
51
+ esac
data/script/perf_run ADDED
@@ -0,0 +1,34 @@
1
+ #!/bin/sh
2
+ # set -x
3
+
4
+ if [ $# -lt 1 ]; then
5
+ echo "usage: perf_run iterations options [conf-name]"
6
+ echo "example: perf_run 100 \"-bm=default -log\" pdata"
7
+ exit 1
8
+ fi
9
+
10
+ BINDIR=`dirname $0`
11
+
12
+ test -z "$RAILS_PERF_DATA" && RAILS_PERF_DATA=$HOME
13
+
14
+ ITER="$1"
15
+ OPT="$2"
16
+ BENCHMARK=""
17
+ for opt in $OPT; do
18
+ case $opt in
19
+ -bm=*) BENCHMARK=${opt#-bm=};;
20
+ esac
21
+ done
22
+
23
+ DATE=`date +%m-%d`
24
+ if [ $# == 3 ]; then
25
+ RAILS_BENCHMARK_FILE="$RAILS_PERF_DATA/${DATE}.${BENCHMARK}.$3.txt"
26
+ else
27
+ RAILS_BENCHMARK_FILE="$RAILS_PERF_DATA/perf_run.${BENCHMARK}.txt"
28
+ fi
29
+ export RAILS_BENCHMARK_FILE
30
+
31
+ unset RUBY_GC_STATS
32
+
33
+ PERF_OPTIONS="$ITER $OPT"
34
+ $BINDIR/perf_loop $PERF_OPTIONS && ruby $BINDIR/perf_times $RAILS_BENCHMARK_FILE
@@ -0,0 +1,46 @@
1
+ #!/bin/sh
2
+ # set -x
3
+
4
+ if [ $# -lt 2 ]; then
5
+ echo "usage: perf_run_gc iterations options [conf-name]"
6
+ echo "example: perf_run_gc 100 \"-bm=default -log\" pdata"
7
+ exit 1
8
+ fi
9
+
10
+ BINDIR=`dirname $0`
11
+
12
+ test -z "$RAILS_PERF_DATA" && RAILS_PERF_DATA=$HOME
13
+
14
+ ITER="$1"
15
+ OPT="$2"
16
+ BENCHMARK=""
17
+ WARMUP="-warmup"
18
+ patched_gc="no"
19
+ for opt in $OPT; do
20
+ case $opt in
21
+ -bm=*) BENCHMARK=${opt#-bm=};;
22
+ -warmup) WARMUP="";;
23
+ -gc=*) patched_gc=${opt#-gc=};;
24
+ esac
25
+ done
26
+
27
+ DATE=`date +%m-%d`
28
+ if [ $# == 3 ]; then
29
+ BENCHMARK_FILE="$RAILS_PERF_DATA/${DATE}.${BENCHMARK}.$3.gc.txt"
30
+ else
31
+ BENCHMARK_FILE="$RAILS_PERF_DATA/perf_run.${BENCHMARK}.gc.txt"
32
+ fi
33
+
34
+ PERF_OPTIONS="$ITER $WARMUP $OPT"
35
+
36
+ if [ "${patched_gc}" = "no" ]; then
37
+ unset RUBY_HEAP_MIN_SLOTS RUBY_GC_MALLOC_LIMIT RUBY_HEAP_FREE_MIN
38
+ else
39
+ . $RAILS_ROOT/config/${patched_gc}.gc
40
+ export RUBY_HEAP_MIN_SLOTS RUBY_GC_MALLOC_LIMIT RUBY_HEAP_FREE_MIN
41
+ fi
42
+
43
+ unset RUBY_GC_STATS RUBY_GC_DATA_FILE
44
+
45
+ (RUBY_GC_STATS=1 RUBY_GC_DATA_FILE=$BENCHMARK_FILE ruby $BINDIR/run_urls $PERF_OPTIONS >/dev/null) &&\
46
+ ruby $BINDIR/perf_times_gc $BENCHMARK_FILE