Top Level Namespace
Defined Under Namespace
Modules: Benchmark, Railsbench
Classes: Array, BenchmarkSpec, File, GCInfo, GCLogEntry, PerfEntry, PerfInfo, RailsBenchmark, RailsBenchmarkWithActiveRecordStore
Constant Summary
collapse
- GCAttributes =
[:processed, :live, :freelist, :freed, :time]
- GCSummaries =
[:min, :max, :mean, :stddev, :stddev_percentage]
- PerfAttributes =
[:gc_calls, :gc_time, :load_time, :total_time]
- PerfSummaries =
[:min, :max, :mean, :stddev, :stddev_percentage]
- RAILSBENCH_BINDIR =
File.expand_path(File.dirname(__FILE__) + "/../../script")
Constants included
from Benchmark
Benchmark::BENCHMARK_VERSION, Benchmark::CAPTION, Benchmark::FMTSTR, Benchmark::OUTPUT, Benchmark::SYNC
Instance Method Summary
collapse
-
#benchmark_file_name(benchmark, config_name, prefix = nil, suffix = nil) ⇒ Object
-
#determine_rails_root_or_die!(msg = nil) ⇒ Object
-
#die(msg, error_code = 1) ⇒ Object
-
#disable_gc_stats ⇒ Object
-
#enable_gc_stats(file) ⇒ Object
-
#load_gc_variables(gc_spec) ⇒ Object
-
#perf_run(script, iterations, options, raw_data_file) ⇒ Object
-
#perf_run_gc(script, iterations, options, raw_data_file) ⇒ Object
-
#quote_arguments(argv) ⇒ Object
-
#ruby ⇒ Object
-
#set_gc_variables(argv) ⇒ Object
-
#stddev_percentage(stddev, mean) ⇒ Object
-
#truncate(text, length = 32, truncate_string = "...") ⇒ Object
-
#unset_gc_variables ⇒ Object
Methods included from Benchmark
benchmark, bm, bmbm, measure, realtime, times
Instance Method Details
#benchmark_file_name(benchmark, config_name, prefix = nil, suffix = nil) ⇒ Object
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/railsbench/perf_utils.rb', line 110
def benchmark_file_name(benchmark, config_name, prefix=nil, suffix=nil)
perf_data_dir = (ENV['RAILS_PERF_DATA'] ||= ENV['HOME'])
date = Time.now.strftime '%m-%d'
suffix = ".#{suffix}" if suffix
ENV['RAILS_BENCHMARK_FILE'] =
if config_name
"#{perf_data_dir}/#{date}.#{benchmark}.#{config_name}#{suffix}.txt"
else
"#{perf_data_dir}/perf_run#{prefix}.#{benchmark}#{suffix}.txt"
end
end
|
#determine_rails_root_or_die!(msg = nil) ⇒ Object
35
36
37
38
39
40
41
42
43
|
# File 'lib/railsbench/perf_utils.rb', line 35
def determine_rails_root_or_die!(msg=nil)
unless ENV['RAILS_ROOT']
if File.directory?("config") && File.exists?("config/environment.rb")
ENV['RAILS_ROOT'] = File.expand_path(".")
else
die(msg || "#{File.basename $PROGRAM_NAME}: $RAILS_ROOT not set and could not be configured automatically")
end
end
end
|
#die(msg, error_code = 1) ⇒ Object
45
46
47
48
|
# File 'lib/railsbench/perf_utils.rb', line 45
def die(msg, error_code=1)
$stderr.puts msg
exit error_code
end
|
#disable_gc_stats ⇒ Object
84
85
86
87
|
# File 'lib/railsbench/perf_utils.rb', line 84
def disable_gc_stats
ENV.delete 'RUBY_GC_STATS'
ENV.delete 'RUBY_GC_DATA_FILE'
end
|
#enable_gc_stats(file) ⇒ Object
79
80
81
82
|
# File 'lib/railsbench/perf_utils.rb', line 79
def enable_gc_stats(file)
ENV['RUBY_GC_STATS'] = "1"
ENV['RUBY_GC_DATA_FILE'] = file
end
|
#load_gc_variables(gc_spec) ⇒ Object
93
94
95
96
97
|
# File 'lib/railsbench/perf_utils.rb', line 93
def load_gc_variables(gc_spec)
File.open_or_die("#{ENV['RAILS_ROOT']}/config/#{gc_spec}.gc").each_line do |line|
ENV[$1] = $2 if line =~ /^(?:export )?(.*)=(.*)$/
end
end
|
#perf_run(script, iterations, options, raw_data_file) ⇒ Object
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
# File 'lib/railsbench/perf_utils.rb', line 130
def perf_run(script, iterations, options, raw_data_file)
perf_runs = (ENV['RAILS_PERF_RUNS'] ||= "3").to_i
disable_gc_stats
set_gc_variables([iterations, options])
perf_options = "#{iterations} #{options}"
null = (RUBY_PLATFORM =~ /win32/i) ? 'nul' : '/dev/null'
perf_cmd = "#{ruby} #{RAILSBENCH_BINDIR}/perf_bench #{perf_options}"
print_cmd = "#{ruby} #{RAILSBENCH_BINDIR}/perf_times #{raw_data_file}"
puts "benchmarking #{perf_runs} runs with options #{perf_options}"
File.open(raw_data_file, "w"){ |f| f.puts perf_cmd }
perf_runs.times do
system("#{perf_cmd} >#{null}") || die("#{script}: #{perf_cmd} returned #{$?}")
end
File.open(raw_data_file, "a" ){|f| f.puts }
unset_gc_variables
system(print_cmd) || die("#{script}: #{print_cmd} returned #{$?}")
end
|
#perf_run_gc(script, iterations, options, raw_data_file) ⇒ Object
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
# File 'lib/railsbench/perf_utils.rb', line 154
def perf_run_gc(script, iterations, options, raw_data_file)
warmup = "-warmup"
warmup = "" if options =~ /-warmup/
enable_gc_stats(raw_data_file)
set_gc_variables([options])
perf_options = "#{iterations} #{warmup} #{options}"
null = (RUBY_PLATFORM =~ /win32/) ? 'nul' : '/dev/null'
perf_cmd = "#{ruby} #{RAILSBENCH_BINDIR}/run_urls #{perf_options} >#{null}"
print_cmd = "#{ruby} #{RAILSBENCH_BINDIR}/perf_times_gc #{raw_data_file}"
if options =~ /-leaks/
if RUBY_PLATFORM =~ /darwin9/
puts "enabling MallocStackLogging"
perf_cmd.insert(0, "MallocStackLogging=1 ")
else
die "leak debugging not supported on #{RUBY_PLATFORM}"
end
end
puts "benchmarking GC performance with options #{perf_options}"
puts
system(perf_cmd) || die("#{script}: #{perf_cmd} returned #{$?}")
disable_gc_stats
unset_gc_variables
system(print_cmd) || die("#{script}: #{print_cmd} returned #{$?}")
end
|
#quote_arguments(argv) ⇒ Object
122
123
124
|
# File 'lib/railsbench/perf_utils.rb', line 122
def quote_arguments(argv)
argv.map{|a| a.include?(' ') ? "'#{a}'" : a.to_s}.join(' ')
end
|
#ruby ⇒ Object
126
127
128
|
# File 'lib/railsbench/perf_utils.rb', line 126
def ruby
ENV['RUBY'] || "ruby"
end
|
#set_gc_variables(argv) ⇒ Object
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/railsbench/perf_utils.rb', line 99
def set_gc_variables(argv)
gc_spec = nil
argv.each{|arg| gc_spec=$1 if arg =~ /-gc=([^ ]*)/}
if gc_spec
load_gc_variables(gc_spec)
else
unset_gc_variables
end
end
|
#stddev_percentage(stddev, mean) ⇒ Object
31
32
33
|
# File 'lib/railsbench/perf_utils.rb', line 31
def stddev_percentage(stddev, mean)
stddev.zero? ? 0.0 : (stddev/mean)*100
end
|
#truncate(text, length = 32, truncate_string = "...") ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/railsbench/perf_utils.rb', line 65
def truncate(text, length = 32, truncate_string = "...")
if text.nil? then return "" end
l = truncate_string.length + 1
if RUBY_VERSION !~ /1.9/ && $KCODE == "NONE"
text.length > length ? text[0..(length - l)] + truncate_string : text
else
chars = text.split(//)
chars.length > length ? chars[0..(length - l)].join + truncate_string : text
end
end
|
#unset_gc_variables ⇒ Object
89
90
91
|
# File 'lib/railsbench/perf_utils.rb', line 89
def unset_gc_variables
%w(RUBY_HEAP_MIN_SLOTS RUBY_GC_MALLOC_LIMIT RUBY_HEAP_FREE_MIN).each{|v| ENV.delete v}
end
|