railsbench 0.8.4 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -164,15 +164,22 @@ class RailsBenchmark
164
164
 
165
165
  # support ruby-prof
166
166
  ruby_prof = nil
167
- ARGV.each{|arg| ruby_prof=$1 if arg =~ /-ruby_prof=(\d*\.?\d*)/ }
167
+ ARGV.each{|arg| ruby_prof=$1 if arg =~ /-ruby_prof=([^ ]*)/ }
168
168
  begin
169
169
  if ruby_prof
170
+ # redirect stderr
171
+ if benchmark_file = ENV['RAILS_BENCHMARK_FILE']
172
+ $stderr = File.open(benchmark_file, "w")
173
+ end
170
174
  require 'ruby-prof'
171
175
  RubyProf.clock_mode = RubyProf::WALL_TIME
172
176
  RubyProf.start
173
177
  end
174
178
  rescue LoadError
175
179
  # ruby-prof not available, do nothing
180
+ $stderr = STDERR
181
+ $stderr.puts "ruby-prof not available: giving up"
182
+ exit(-1)
176
183
  end
177
184
 
178
185
  # start profiler and trigger data collection if required
@@ -203,7 +210,7 @@ class RailsBenchmark
203
210
  result = RubyProf.stop
204
211
  # Print a flat profile to text
205
212
  printer = RubyProf::GraphHtmlPrinter.new(result)
206
- printer.print(STDERR, ruby_prof.to_f)
213
+ printer.print($stderr, ruby_prof.to_f)
207
214
  end
208
215
 
209
216
  delete_test_session
@@ -1,8 +1,8 @@
1
1
  module Railsbench #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 8
5
- TINY = 4
4
+ MINOR = 9
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/postinstall.rb ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'fileutils'
4
+ if ARGV.include?('--dry-run')
5
+ include FileUtils::DryRun
6
+ else
7
+ include FileUtils::Verbose
8
+ end
9
+
10
+ RAILSBENCH_BASE = File.expand_path(File.dirname(__FILE__)) unless defined?(RAILSBENCH_BASE)
11
+
12
+ chmod 0755, Dir["#{RAILSBENCH_BASE}/script/*"]
data/script/perf_bench CHANGED
@@ -3,7 +3,7 @@
3
3
  $:.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib'))
4
4
 
5
5
  unless ENV['RAILS_ROOT']
6
- $stderr.puts("\nOOPS: can't benchmark unless RAILS_ROOT is set")
6
+ $stderr.puts("\nperf_bench: can't benchmark unless RAILS_ROOT is set")
7
7
  $stderr.puts("\nbenchmarking aborted!")
8
8
  exit 1
9
9
  end
@@ -37,13 +37,13 @@ bm(32) do |test|
37
37
  benchmarks = YAML::load(File.open(ENV['RAILS_ROOT'] + "/config/benchmarks.yml"))
38
38
  benchmark_name = "default"
39
39
  ARGV.each{ |arg| benchmark_name = $1 if arg =~ /-bm=([a-zA-Z_0-9]+)/ }
40
-
40
+
41
41
  RAILS_BENCHMARKER.iterations = ARGV[0].to_i
42
42
  RAILS_BENCHMARKER.url_spec = benchmarks
43
43
  RAILS_BENCHMARKER.setup_test_urls(benchmark_name)
44
44
  RAILS_BENCHMARKER.establish_test_session
45
45
  RAILS_BENCHMARKER.warmup
46
-
46
+
47
47
  if ARGV.include?('-mix')
48
48
  RAILS_BENCHMARKER.run_url_mix(test)
49
49
  else
@@ -55,12 +55,8 @@ Benchmark::OUTPUT.close unless Benchmark::OUTPUT.nil? || !ENV['RAILS_BENCHMARK_F
55
55
 
56
56
  __END__
57
57
 
58
- ### Local Variables: ***
59
- ### mode:ruby ***
60
- ### End: ***
61
-
62
58
  # Copyright (C) 2005, 2006 Stefan Kaes
63
- #
59
+ #
64
60
  # This program is free software; you can redistribute it and/or modify
65
61
  # it under the terms of the GNU General Public License as published by
66
62
  # the Free Software Foundation; either version 2 of the License, or
@@ -70,7 +66,7 @@ __END__
70
66
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
71
67
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
72
68
  # GNU General Public License for more details.
73
- #
69
+ #
74
70
  # You should have received a copy of the GNU General Public License
75
71
  # along with this program; if not, write to the Free Software
76
72
  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
data/script/perf_comp CHANGED
@@ -134,10 +134,6 @@ end
134
134
 
135
135
  __END__
136
136
 
137
- ### Local Variables: ***
138
- ### mode:ruby ***
139
- ### End: ***
140
-
141
137
  # Copyright (C) 2005, 2006 Stefan Kaes
142
138
  #
143
139
  # This program is free software; you can redistribute it and/or modify
data/script/perf_comp_gc CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  options = ""
4
4
  if ARGV.length!=2
5
- puts "usage: perf_diff_gc file1 file2"
5
+ $stderr.puts "usage: perf_diff_gc file1 file2"
6
6
  exit 1
7
7
  end
8
8
  files=[]
@@ -13,11 +13,11 @@ ARGV.each do |arg|
13
13
  if File.stat(fn).readable?
14
14
  files << File.open(fn)
15
15
  else
16
- print "file #{fn} is unreadable\n"
16
+ $stderr.print "file #{fn} is unreadable\n"
17
17
  exit 1
18
18
  end
19
19
  rescue
20
- print "file #{fn} does not exist\n"
20
+ $stderr.print "file #{fn} does not exist\n"
21
21
  exit 1
22
22
  end
23
23
  end
@@ -59,12 +59,12 @@ printf "\n %12s %12s %9s %9s %9s %9s\n",
59
59
  "c1 mean", "c2 mean", "c1 min", "c2 min", "c1 max", "c2 max"
60
60
 
61
61
  number_format = "%12.2f %12.2f %9d %9d %9d %9d"
62
-
62
+
63
63
  printf "gc time(ms): #{number_format}\n",
64
64
  gcis[0].time_mean, gcis[1].time_mean,
65
65
  gcis[0].time_min, gcis[1].time_min,
66
66
  gcis[0].time_max, gcis[1].time_max
67
-
67
+
68
68
  printf "heap slots : #{number_format}\n",
69
69
  gcis[0].processed_mean, gcis[1].processed_mean,
70
70
  gcis[0].processed_min, gcis[1].processed_min,
@@ -74,12 +74,12 @@ printf "live : #{number_format}\n",
74
74
  gcis[0].live_mean, gcis[1].live_mean,
75
75
  gcis[0].live_min, gcis[1].live_min,
76
76
  gcis[0].live_max, gcis[1].live_max
77
-
77
+
78
78
  printf "freed : #{number_format}\n",
79
79
  gcis[0].freed_mean, gcis[1].freed_mean,
80
80
  gcis[0].freed_min, gcis[1].freed_min,
81
81
  gcis[0].freed_max, gcis[1].freed_max
82
-
82
+
83
83
  printf "freelist : #{number_format}\n",
84
84
  gcis[0].freelist_mean, gcis[1].freelist_mean,
85
85
  gcis[0].freelist_min, gcis[1].freelist_min,
@@ -88,10 +88,6 @@ printf "freelist : #{number_format}\n",
88
88
 
89
89
  __END__
90
90
 
91
- ### Local Variables: ***
92
- ### mode:ruby ***
93
- ### End: ***
94
-
95
91
  # Copyright (C) 2005, 2006 Stefan Kaes
96
92
  #
97
93
  # This program is free software; you can redistribute it and/or modify
data/script/perf_diff CHANGED
@@ -1,48 +1,48 @@
1
- #!/bin/sh
2
- # set -x
1
+ #!/usr/bin/env ruby
3
2
 
4
- if [ $# -lt 4 ]; then
5
- echo "usage: perf_diff iterations common-options options1 options4 [conf-name1] [conf-name2]"
6
- echo "example: perf_diff 100 \"-bm=all\" \"-log\" \"-nocache\" c1 c2"
3
+ if ARGV.length < 4
4
+ $stderr.puts 'usage: perf_diff iterations common-options options1 options4 [conf-name1] [conf-name2]'
5
+ $stderr.puts 'example: perf_diff 100 "-bm=all" "-log" "-nocache" c1 c2'
7
6
  exit 1
8
- fi
9
-
10
- BINDIR=`dirname $0`
11
- test -z "$RAILS_PERF_DATA" && RAILS_PERF_DATA=$HOME
12
-
13
- ITER="$1"
14
- COMMON="$2"
15
- OPT1="$3"
16
- OPT2="$4"
17
- DATE=`date +%m-%d`
18
- BENCHMARK=""
19
- for opt in $COMMON; do
20
- case $opt in
21
- -bm=*) BENCHMARK=${opt#-bm=};;
22
- esac
23
- done
24
-
25
- if [ $# -gt 4 ]; then
26
- FILE1="$RAILS_PERF_DATA/${DATE}.${BENCHMARK}.$5.txt"
27
- else
28
- FILE1="$RAILS_PERF_DATA/perf_run1.${BENCHMARK}.txt"
29
- fi
30
- if [ $# -gt 5 ]; then
31
- FILE2="$RAILS_PERF_DATA/${DATE}.${BENCHMARK}.$6.txt"
32
- else
33
- FILE2="$RAILS_PERF_DATA/perf_run2.${BENCHMARK}.txt"
34
- fi
35
-
36
- unset RUBY_GC_STATS
37
-
38
- PERF_OPTIONS="$ITER $COMMON $OPT1"
39
- RAILS_BENCHMARK_FILE=$FILE1 $BINDIR/perf_loop $PERF_OPTIONS || exit 1
40
- ruby $BINDIR/perf_times $FILE1
41
- echo;echo
42
-
43
- PERF_OPTIONS="$ITER $COMMON $OPT2"
44
- RAILS_BENCHMARK_FILE=$FILE2 $BINDIR/perf_loop $PERF_OPTIONS || exit 1
45
- ruby $BINDIR/perf_times $FILE2
46
- echo;echo
47
-
48
- ruby $BINDIR/perf_comp -narrow -skip_urls $FILE1 $FILE2
7
+ end
8
+
9
+ bindir = File.dirname(__FILE__)
10
+ require "#{bindir}/../lib/railsbench/perf_utils"
11
+
12
+ die("perf_diff: RAILS_ROOT not set") unless ENV['RAILS_ROOT']
13
+
14
+ iterations = ARGV[0]
15
+ common = ARGV[1]
16
+ options1 = ARGV[2]
17
+ options2 = ARGV[3]
18
+
19
+ benchmark = "default"
20
+ benchmark = $1 if common =~ /-bm=([^ ]+)/
21
+
22
+ file1 = benchmark_file_name(benchmark, ARGV[4], 1)
23
+ perf_run("perf_diff", iterations, "#{common} #{options1}", file1)
24
+ puts;puts
25
+
26
+ file2 = benchmark_file_name(benchmark, ARGV[5], 2)
27
+ perf_run("perf_diff", iterations, "#{common} #{options2}", file2)
28
+ puts;puts
29
+
30
+ system("ruby #{bindir}/perf_comp -narrow -skip_urls #{file1} #{file2}")
31
+
32
+ __END__
33
+
34
+ # Copyright (C) 2005, 2006 Stefan Kaes
35
+ #
36
+ # This program is free software; you can redistribute it and/or modify
37
+ # it under the terms of the GNU General Public License as published by
38
+ # the Free Software Foundation; either version 2 of the License, or
39
+ # (at your option) any later version.
40
+ #
41
+ # This program is distributed in the hope that it will be useful,
42
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
43
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44
+ # GNU General Public License for more details.
45
+ #
46
+ # You should have received a copy of the GNU General Public License
47
+ # along with this program; if not, write to the Free Software
48
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
data/script/perf_diff_gc CHANGED
@@ -1,89 +1,53 @@
1
- #!/bin/sh
2
- # set -x
1
+ #!/usr/bin/env ruby
3
2
 
4
- if [ $# -lt 4 ]; then
5
- echo "usage: perf_diff_gc iterations options1 options2 [conf-name1] [conf-name2]"
6
- echo "example: perf_diff_gc 100 \"-bm=default\" \"-log\" \"-nocache\" c1 c2"
3
+ if ARGV.length < 4
4
+ $stderr.puts 'usage: perf_diff_gc iterations options1 options2 [conf-name1] [conf-name2]'
5
+ $stderr.puts 'example: perf_diff_gc 100 "-bm=default" "-log" "-nocache" c1 c2'
7
6
  exit 1
8
- fi
7
+ end
9
8
 
10
- BINDIR=`dirname $0`
11
- test -z "$RAILS_PERF_DATA" && RAILS_PERF_DATA=$HOME
9
+ bindir = File.dirname(__FILE__)
10
+ require "#{bindir}/../lib/railsbench/perf_utils"
12
11
 
13
- ITER="$1"
14
- COMMON="$2"
15
- OPT1="$3"
16
- OPT2="$4"
17
- BENCHMARK=""
18
- WARMUP="-warmup"
12
+ die("perf_diff_gc: RAILS_ROOT not set") unless ENV['RAILS_ROOT']
19
13
 
20
- DATE=`date +%m-%d`
14
+ iterations = ARGV[0]
15
+ common = ARGV[1]
16
+ options1 = ARGV[2]
17
+ options2 = ARGV[3]
21
18
 
19
+ benchmark = "default"
20
+ benchmark = $1 if common =~ /-bm=([^ ]+)/
22
21
 
23
- if [ $# -gt 4 ]; then
24
- FILE1="$RAILS_PERF_DATA/${DATE}${BENCHMARK}.$5.gc.txt"
25
- else
26
- FILE1="$RAILS_PERF_DATA/perf_run1${BENCHMARK}.gc.txt"
27
- fi
28
- if [ $# -gt 5 ]; then
29
- FILE2="$RAILS_PERF_DATA/${DATE}${BENCHMARK}.$6.gc.txt"
30
- else
31
- FILE2="$RAILS_PERF_DATA/perf_run2${BENCHMARK}.gc.txt"
32
- fi
22
+ file1 = benchmark_file_name(benchmark, ARGV[4], 1, :gc)
23
+ perf_run_gc("perf_run_gc", iterations, "#{common} #{options1}", file1)
33
24
 
34
- OLD_RUBY_HEAP_MIN_SLOTS=$RUBY_HEAP_MIN_SLOTS
35
- OLD_RUBY_GC_MALLOC_LIMIT=$RUBY_GC_MALLOC_LIMIT
36
- OLD_RUBY_HEAP_FREE_MIN=$RUBY_HEAP_FREE_MIN
25
+ puts;puts
37
26
 
38
- PERF_OPTIONS="$ITER $WARMUP $COMMON $OPT1"
27
+ file2 = benchmark_file_name(benchmark, ARGV[5], 2, :gc)
28
+ perf_run_gc("perf_run_gc", iterations, "#{common} #{options2}", file2)
39
29
 
40
- patched_gc="no"
41
- for opt in $COMMON $OPT1; do
42
- case $opt in
43
- -gc=*) patched_gc=${opt#-gc=};;
44
- esac
45
- done
30
+ puts;puts
46
31
 
47
- if [ "${patched_gc}" = "no" ]; then
48
- unset RUBY_HEAP_MIN_SLOTS RUBY_GC_MALLOC_LIMIT RUBY_HEAP_FREE_MIN
49
- else
50
- . $RAILS_ROOT/config/${patched_gc}.gc
51
- export RUBY_HEAP_MIN_SLOTS RUBY_GC_MALLOC_LIMIT RUBY_HEAP_FREE_MIN
52
- fi
32
+ puts "benchmark comparison data"
33
+ puts
53
34
 
54
- echo "benchmarking GC performance with options $PERF_OPTIONS"
55
- echo
35
+ system("ruby #{bindir}/perf_comp_gc #{file1} #{file2}")
56
36
 
57
- (RUBY_GC_STATS=1 RUBY_GC_DATA_FILE=$FILE1 ruby $BINDIR/run_urls $PERF_OPTIONS >/dev/null) \
58
- && ruby $BINDIR/perf_times_gc $FILE1
59
- echo;echo
37
+ __END__
60
38
 
61
- PERF_OPTIONS="$ITER $WARMUP $COMMON $OPT2"
62
-
63
- patched_gc="no"
64
- for opt in $COMMON $OPT2; do
65
- case $opt in
66
- -gc=*) patched_gc=${opt#-gc=};;
67
- esac
68
- done
69
-
70
- if [ "${patched_gc}" = "no" ]; then
71
- unset RUBY_HEAP_MIN_SLOTS RUBY_GC_MALLOC_LIMIT RUBY_HEAP_FREE_MIN
72
- else
73
- . $RAILS_ROOT/config/${patched_gc}.gc
74
- export RUBY_HEAP_MIN_SLOTS RUBY_GC_MALLOC_LIMIT RUBY_HEAP_FREE_MIN
75
- fi
76
-
77
- echo "benchmarking GC performance with options $PERF_OPTIONS"
78
- echo
79
-
80
- (RUBY_GC_STATS=1 RUBY_GC_DATA_FILE=$FILE2 ruby $BINDIR/run_urls $PERF_OPTIONS >/dev/null) \
81
- && ruby $BINDIR/perf_times_gc $FILE2
82
- echo;echo
83
-
84
- unset RUBY_HEAP_MIN_SLOTS RUBY_GC_MALLOC_LIMIT RUBY_HEAP_FREE_MIN
85
-
86
- echo "benchmark comparison data"
87
- echo
88
-
89
- ruby $BINDIR/perf_comp_gc $FILE1 $FILE2
39
+ # Copyright (C) 2005, 2006 Stefan Kaes
40
+ #
41
+ # This program is free software; you can redistribute it and/or modify
42
+ # it under the terms of the GNU General Public License as published by
43
+ # the Free Software Foundation; either version 2 of the License, or
44
+ # (at your option) any later version.
45
+ #
46
+ # This program is distributed in the hope that it will be useful,
47
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
48
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49
+ # GNU General Public License for more details.
50
+ #
51
+ # You should have received a copy of the GNU General Public License
52
+ # along with this program; if not, write to the Free Software
53
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
data/script/perf_html CHANGED
@@ -61,10 +61,6 @@ end
61
61
 
62
62
  __END__
63
63
 
64
- ### Local Variables: ***
65
- ### mode:ruby ***
66
- ### End: ***
67
-
68
64
  # Copyright (C) 2005, 2006 Stefan Kaes
69
65
  #
70
66
  # This program is free software; you can redistribute it and/or modify
data/script/perf_plot CHANGED
@@ -73,10 +73,6 @@ g.write
73
73
 
74
74
  __END__
75
75
 
76
- ### Local Variables: ***
77
- ### mode:ruby ***
78
- ### End: ***
79
-
80
76
  # Copyright (C) 2005, 2006 Stefan Kaes
81
77
  #
82
78
  # This program is free software; you can redistribute it and/or modify
data/script/perf_plot_gc CHANGED
@@ -16,6 +16,7 @@ labels = %w()
16
16
  perf_data = []
17
17
  graph_type = Gruff::StackedBar
18
18
  graph_width = 1400
19
+ ignored_object_types = %w(NODE STRING)
19
20
 
20
21
  ARGV.each do |arg|
21
22
  case arg
@@ -29,6 +30,8 @@ ARGV.each do |arg|
29
30
  # title = $1 unless $1.strip.empty?
30
31
  # when /^-names=(.+)$/
31
32
  # names = $1.split(',')
33
+ when /^-ignore=(.*)$/
34
+ ignored_object_types = $1.split(',').map(&:upcase)
32
35
  else
33
36
  files << File.open_or_die(arg)
34
37
  names[files.length-1] ||= File.basename(arg)
@@ -71,7 +74,7 @@ g.labels = Hash[* (0...gc_count_max).map{|i| [2*i, i.to_s]}.flatten ]
71
74
  puts g.labels.inspect
72
75
 
73
76
  object_types.each do |ot|
74
- next if ot =~ /NODE|STRING/i
77
+ next if ignored_object_types.include?(ot)
75
78
  data = []
76
79
  gc_count_max.times do |gc_index|
77
80
  for gci in gcis
@@ -81,7 +84,7 @@ object_types.each do |ot|
81
84
  data << ((map_at_this_gc && map_at_this_gc[ot]) || 0)
82
85
  end
83
86
  end
84
- puts "#{ot}: #{data.inspect}"
87
+ # puts "#{ot}: #{data.inspect}"
85
88
  g.data(ot, data)
86
89
  end
87
90
 
@@ -90,10 +93,6 @@ g.write
90
93
 
91
94
  __END__
92
95
 
93
- ### Local Variables: ***
94
- ### mode:ruby ***
95
- ### End: ***
96
-
97
96
  # Copyright (C) 2005, 2006 Stefan Kaes
98
97
  #
99
98
  # This program is free software; you can redistribute it and/or modify