railsbench 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,109 @@
1
+ 2007-01-14 09:07 stkaes
2
+
3
+ * CHANGELOG: updated CHANGELOG
4
+
5
+ 2007-01-14 09:02 stkaes
6
+
7
+ * test/test_helper.rb: dos2unix
8
+
9
+ 2007-01-14 09:01 stkaes
10
+
11
+ * latest_changes.txt: updated latest changes
12
+
13
+ 2007-01-14 08:59 stkaes
14
+
15
+ * INSTALL: formatting
16
+
17
+ 2007-01-14 08:56 stkaes
18
+
19
+ * install.rb: automatically detect RAILS_ROOT in railsbench install
20
+
21
+ 2007-01-14 08:56 stkaes
22
+
23
+ * INSTALL: mention generate_benchmarks in file INSTALL
24
+
25
+ 2007-01-14 08:40 stkaes
26
+
27
+ * script/perf_diff, script/perf_diff_gc, script/perf_run,
28
+ script/perf_run_gc, script/run_urls: display help when call with
29
+ string 'help' as first argument
30
+
31
+ 2007-01-14 08:39 stkaes
32
+
33
+ * bin/railsbench: automatically set RAILS_ROOT when invoked from a
34
+ Rails app's top level directory
35
+
36
+ 2007-01-14 07:57 stkaes
37
+
38
+ * README: updated README
39
+
40
+ 2007-01-13 23:51 stkaes
41
+
42
+ * script/generate_benchmarks: keep generated controller benchmarks
43
+ sorted. output non generated benchmarks at the end of
44
+ benchmarks.yml
45
+
46
+ 2007-01-13 10:19 stkaes
47
+
48
+ * latest_changes.txt: updated latest changes
49
+
50
+ 2007-01-13 10:05 stkaes
51
+
52
+ * script/generate_benchmarks: enable deletion of benchmarks for
53
+ ignored controllers/actions
54
+
55
+ 2007-01-13 10:04 stkaes
56
+
57
+ * bin/railsbench: support help
58
+
59
+ 2007-01-13 06:46 stkaes
60
+
61
+ * script/generate_benchmarks: improved benchmark generator
62
+
63
+ 2007-01-07 15:28 stkaes
64
+
65
+ * Manifest.txt, latest_changes.txt, script/generate_benchmarks:
66
+ added generate benchmarks command
67
+
68
+ 2007-01-07 15:27 stkaes
69
+
70
+ * install.rb: fixed install problems
71
+
72
+ 2007-01-07 15:27 stkaes
73
+
74
+ * lib/railsbench/perf_info.rb: fixed problems with unpatched GC
75
+ -This line, and those below, will be ignored--
76
+
77
+ M perf_info.rb
78
+
79
+ 2007-01-07 14:15 stkaes
80
+
81
+ * lib/railsbench/gc_info.rb, lib/railsbench/perf_info.rb,
82
+ lib/railsbench/perf_utils.rb, lib/railsbench/railsbenchmark.rb,
83
+ script/perf_bench, script/perf_comp, script/perf_comp_gc,
84
+ script/perf_diff, script/perf_diff_gc, script/perf_html,
85
+ script/perf_plot, script/perf_plot_gc, script/perf_prof,
86
+ script/perf_run, script/perf_run_gc, script/perf_tex,
87
+ script/perf_times, script/perf_times_gc, script/run_urls: updated
88
+ copyright notice
89
+
90
+ 2007-01-07 14:06 stkaes
91
+
92
+ * install.rb: fix installation problems
93
+
94
+ 2007-01-07 13:57 stkaes
95
+
96
+ * lib/railsbench/version.rb: incremented version number
97
+
98
+ 2007-01-06 12:56 stkaes
99
+
100
+ * Rakefile, bin/railsbench, script/generate_benchmarks: added
101
+ generate_benchmarks
102
+
103
+ 2006-12-26 11:02 stkaes
104
+
105
+ * CHANGELOG: updated changelog
106
+
1
107
  2006-12-26 10:31 stkaes
2
108
 
3
109
  * INSTALL: dedription of railsbench path and railsbench postinstall
data/INSTALL CHANGED
@@ -1,8 +1,9 @@
1
- ============
2
- INSTALLATION
3
- ============
1
+ ==================================================
2
+ RAILSBENCH INSTALLATION
3
+ ==================================================
4
4
 
5
- STEP 1: installing railsbench and PATH modifcation
5
+ STEP 1: installing railsbench and PATH modification
6
+ ---------------------------------------------------
6
7
 
7
8
  If you obtained and installed railsbench as a gem, a script called
8
9
  railsbench is available in your Ruby bin directory. railsbench is a
@@ -37,6 +38,7 @@ script directory to your search path.
37
38
 
38
39
 
39
40
  STEP 2: prepare your application for benchmarking
41
+ -------------------------------------------------
40
42
 
41
43
  Manual installation:
42
44
 
@@ -55,8 +57,12 @@ Automatic installation:
55
57
  about possible results, you can call railsbench install --dry-run
56
58
  first.
57
59
 
60
+ In either case, run `railsbench generate_benchmarks'. This will create
61
+ a benchmarks.yml file with a benchmark for each controller and action.
62
+
58
63
 
59
64
  STEP 3: optional (but highly recommended)
65
+ -----------------------------------------
60
66
 
61
67
  Patch the ruby garbage collector using rubygc18{45}.patch, depending
62
68
  on your ruby version. Recompile ruby and copy the ruby binary and
data/Manifest.txt CHANGED
@@ -18,6 +18,7 @@ lib/railsbench/perf_utils.rb
18
18
  lib/railsbench/write_headers_only.rb
19
19
  lib/railsbench/railsbenchmark.rb
20
20
  lib/benchmark.rb
21
+ script/generate_benchmarks
21
22
  script/perf_bench
22
23
  script/perf_comp
23
24
  script/perf_comp_gc
data/README CHANGED
@@ -26,12 +26,14 @@ FILES
26
26
 
27
27
  config/bechmarks.yml
28
28
  - specification of urls to benchmark
29
- install into $RAILS_ROOT/config
29
+ install into $RAILS_ROOT/config using `railsbench install'
30
+ (use railsbench install)
30
31
 
31
32
  config/benchmarks.rb
32
33
  - defines constant RAILSBENCH which is used by script perf_bench
33
- modify this to add custom argument processing
34
- install to $RAILS_ROOT/config
34
+ modify this to add custom argument processing and to put data
35
+ into the session
36
+ install to $RAILS_ROOT/config using `railsbench install'
35
37
 
36
38
  perf_bench n options
37
39
  - main ruby script to run a given benchmark
@@ -45,7 +47,7 @@ FILES
45
47
  run_urls 1 -bm=all | grep Status:
46
48
 
47
49
  switches as for perf_bench plus
48
- -warmup : run all uris once before measuring
50
+ -warmup : run all urls once before measuring
49
51
  -svlPV : run test using SVL Ruby Performance Validator
50
52
  -svlMV : run test using SVL Ruby Memory Validator
51
53
 
@@ -74,7 +76,7 @@ FILES
74
76
  - format output taken from perf_comp and produce a HTML table
75
77
  for inclusion in HTML pages. Reads from standard input.
76
78
  options:
77
- -noccs suppress css output
79
+ -noccs suppress CSS output
78
80
  -notable suppress table output
79
81
  -gc include gc statistics
80
82
 
@@ -123,132 +125,165 @@ ENVIRONMENT
123
125
  - perf_bench sends its output to this file
124
126
 
125
127
 
128
+ INVOCATION
129
+
130
+ The gem version installs a driver script called 'railsbench' into
131
+ Ruby's bin directory. Individual commands can be called by prefixing
132
+ with railsbench. If you tire of typing railsbench all the time, you
133
+ can either define an alias (alias rb="railsbench"), or you can
134
+ include railsbench's script directory into your seach path.
135
+
136
+
126
137
  USAGE
127
138
 
128
- The two main scripts are named perf_run and perf_diff.
139
+ The two main scripts are named perf_run and perf_diff.
129
140
 
130
- perf_run 100
141
+ perf_run 100
131
142
 
132
- runs the list of urls named "default" specified in benchmkarks.yml
133
- (see below), requesting each url $RAILS_PERF_RUNS * 100 times.
143
+ runs the list of urls named "default" specified in benchmkarks.yml
144
+ (see below), requesting each url $RAILS_PERF_RUNS * 100 times.
134
145
 
135
- perf_run 100 "-bm=list -aws"
146
+ perf_run 100 "-bm=list -aws"
136
147
 
137
- runs the benchmark named 'list' and passes the expanded second
138
- argument to the rails app. By processing arguments inside your
139
- environment.rb file, you can set performance affecting options. For
140
- example, you could load action web service only if -aws is passed and
141
- measure the performance effect of omitting it.
148
+ runs the benchmark named 'list' and passes the expanded second
149
+ argument to the rails app. By processing arguments inside your
150
+ environment.rb file, you can set performance affecting options. For
151
+ example, you could load action web service only if -aws is passed and
152
+ measure the performance effect of omitting it.
142
153
 
143
- Benchmark data is stored in directory $RAILS_PERF_DATA, which should
144
- be set in your environment. If not set, $HOME is used. By default,
145
- data is stored in file $RAILS_PERF_DATA/perf_run.$BENCHMARK.txt, where
146
- BENCHMARK will be set according to the -bm option.
154
+ Benchmark data is stored in directory $RAILS_PERF_DATA, which should
155
+ be set in your environment. If not set, $HOME is used. By default,
156
+ data is stored in file $RAILS_PERF_DATA/perf_run.$BENCHMARK.txt, where
157
+ BENCHMARK will be set according to the -bm option.
147
158
 
148
- perf_run 100 "-bm=index -mail" mail
159
+ perf_run 100 "-bm=index -mail" mail
149
160
 
150
- will store benchmark data in file
161
+ will store benchmark data in file
151
162
 
152
- $RAILS_PERF_DATA/`current-date�.index.mail.txt.
163
+ $RAILS_PERF_DATA/`current-date�.index.mail.txt.
153
164
 
154
- You can get nicely formatted output of benchmark data by running
165
+ You can get nicely formatted output of benchmark data by running
155
166
 
156
- perf_times file
167
+ perf_times file
157
168
 
158
- Script perf_run will automatically print the obtained data after
159
- finishing the run using perf_times.
169
+ Script perf_run will automatically print the obtained data after
170
+ finishing the run using perf_times.
160
171
 
161
- Script perf_diff runs a list of urls with two different option lists. So
172
+ Script perf_diff runs a list of urls with two different option lists. So
162
173
 
163
- perf_diff 100 "-bm=blogs -mysql_session" "-mail=0" "-mail=1" cf1 cf2
174
+ perf_diff 100 "-bm=blogs -mysql_session" "-mail=0" "-mail=1" cf1 cf2
164
175
 
165
- would run benchmark 'blogs' twice, first as
176
+ would run benchmark 'blogs' twice, first as
166
177
 
167
- perf_run 100 "-bm=blogs -mysql_session -mail=0" cf1
178
+ perf_run 100 "-bm=blogs -mysql_session -mail=0" cf1
168
179
 
169
- and then
180
+ and then
170
181
 
171
- perf_run 100 "-bm=blogs -mysql_session -mail=1" cf2
182
+ perf_run 100 "-bm=blogs -mysql_session -mail=1" cf2
172
183
 
173
- printing a comparison of the bechmark data obtained after finishing
174
- the second run. cf1 and cf2 can be omitted, in which case data is
175
- stored in $RAILS_PERF_DATA/perf_run1.$BENCHMARK.txt and
176
- $RAILS_PERF_DATA/perf_run2.$BENCHMARK.txt.
184
+ printing a comparison of the bechmark data obtained after finishing
185
+ the second run. cf1 and cf2 can be omitted, in which case data is
186
+ stored in $RAILS_PERF_DATA/perf_run1.$BENCHMARK.txt and
187
+ $RAILS_PERF_DATA/perf_run2.$BENCHMARK.txt.
177
188
 
178
- Script perf_bench can also be invoked manually to run a given
179
- benchmark like so:
189
+ Script perf_bench can also be invoked manually to run a given
190
+ benchmark like so:
180
191
 
181
- perf_bench 100 -bm=blogs -mysql_session -mail=1 >/dev/null
192
+ perf_bench 100 -bm=blogs -mysql_session -mail=1 >/dev/null
182
193
 
183
- Performance data is sent to $RAILS_BENCHMARK_FILE, HTML output ends up
184
- on stdout. If RAILS_BENCHMARK_FILE is not set, performance data is
185
- sent to stderr.
194
+ Performance data is sent to $RAILS_BENCHMARK_FILE, HTML output ends up
195
+ on stdout. If RAILS_BENCHMARK_FILE is not set, performance data is
196
+ sent to stderr.
186
197
 
187
- Scripts perf_run_gc and perf_times_gc can be used to analyse GC performance:
198
+ Scripts perf_run_gc and perf_times_gc can be used to analyse GC performance:
188
199
 
189
- perf_run_gc 100 "-bm=all -lib=stable11" gc.log
190
- perf_times_gc gc.log
200
+ perf_run_gc 100 "-bm=all -lib=stable11" gc.log
201
+ perf_times_gc gc.log
191
202
 
192
- It will produce output looking like this:
203
+ It will produce output looking like this:
193
204
 
194
- GC data file: d:/perfdata/xp/perf_run.uncached.gc.txt
205
+ GC data file: d:/perfdata/xp/perf_run.uncached.gc.txt
195
206
 
196
- collections : 40
197
- garbage total : 8188429
198
- gc time total (sec) : 4.03
199
- garbage per request : 2047.11
200
- requests per collection: 100.00
207
+ collections : 40
208
+ garbage total : 8188429
209
+ gc time total (sec) : 4.03
210
+ garbage per request : 2047.11
211
+ requests per collection: 100.00
201
212
 
202
- mean stddev% min max
203
- gc time(ms): 101.38 10.0 93.00 125.00
204
- heap slots : 400000.00 0.0 400000.00 400000.00
205
- live : 192914.31 0.2 191787.00 193197.00
206
- freed : 207085.69 0.2 206803.00 208213.00
207
- freelist : 0.00 0.0 0.00 0.00
213
+ mean stddev% min max
214
+ gc time(ms): 101.38 10.0 93.00 125.00
215
+ heap slots : 400000.00 0.0 400000.00 400000.00
216
+ live : 192914.31 0.2 191787.00 193197.00
217
+ freed : 207085.69 0.2 206803.00 208213.00
218
+ freelist : 0.00 0.0 0.00 0.00
208
219
 
209
- Note that these numbers, especially requests per collection, are only
210
- an approximation. This is due to the fact that run_urls will add one
211
- final garbage collection call at the end of the run. Of course, higher
212
- number of iterations will produce more accurate data. Also, if the
213
- benchmark lists several uris, garbage per request will not give you
214
- meaningful information.
220
+ Note that these numbers, especially requests per collection, are only
221
+ an approximation. This is due to the fact that run_urls will add one
222
+ final garbage collection call at the end of the run. Of course, higher
223
+ number of iterations will produce more accurate data. Also, if the
224
+ benchmark lists several uris, garbage per request will not give you
225
+ meaningful information.
215
226
 
216
227
 
217
228
  CONFIGURATION
218
229
 
219
- Benchmarks are configured through file benchmarks.yml. Example:
230
+ Benchmarks are configured through file benchmarks.yml. Example:
231
+
232
+ default:
233
+ index, other
220
234
 
221
- default:
222
- index, other
235
+ index:
236
+ uri: /test/index
237
+ new_session: true
223
238
 
224
- index:
225
- uri: /test/index
226
- new_session: true
239
+ other:
240
+ -
241
+ uri: /test/list
242
+ -
243
+ uri: /test/alphabetic
244
+ query_params: page=7
245
+
246
+ defines 3 benchmarks:
247
+
248
+ "other" consists of 2 urls (/test/list and /test/alphabetic)
249
+ "index" will run (/test/index)
250
+ "default" will run all urls in "index" and "other"
251
+
252
+ uri: is mandatory, query_params: and new_session: are optional.
253
+
254
+ Instead of
227
255
 
228
- other:
229
- -
230
- uri: /test/list
231
- -
232
256
  uri: /test/alphabetic
233
257
  query_params: page=7
234
258
 
235
- defines 3 benchmarks:
259
+ one could have written
260
+
261
+ uri: /test/alphabetic?page=7
236
262
 
237
- "other" consists of 2 urls (/test/list and /test/alphabetic)
238
- "index" will run (/test/index)
239
- "default" will run all urls in "index" and "other"
263
+ new_session: specifies whether a session cookie is sent with the
264
+ request (default). To make this work correctly, you need to set
265
+ session_data on the benchmarker instance. See benchmarks.rb for details.
240
266
 
241
- uri: is mandatory, query_params: and new_session: are optional.
267
+ An inital benchmark configuration file can be generated using command
268
+ generate_benchmarks.
242
269
 
243
- Instead of
270
+ generate_benchmarks -exclude_controllers=application,admin \
271
+ -exclude_actions=edit,delete,destroy
244
272
 
245
- uri: /test/alphabetic
246
- query_params: page=7
273
+ will generate a benchmark configuration file containing definitions
274
+ for the following benchmarks:
247
275
 
248
- one could have written
276
+ a) an entry for each named route
277
+ b) an entry for each route generated from by the unnamed route definitions
278
+ c) an entry for each controller, combining all actions (named xyz_controller)
279
+ d) an entry combining all controllers (all_controllers), combining all
280
+ benchmarks generated by step c.
249
281
 
250
- uri: /test/alphabetic?page=7
282
+ After generating the benchmark configuration file you will need to
283
+ edit the benchmarks and change the placeholders in urls to real
284
+ values; i.e., change something like /blog/edit/:id to /blog/edit/235.
251
285
 
252
- new_session: specifies whether a session cookie is sent with the
253
- request (default). To make this work correctly, you need to set
254
- session_data on the benchmarker instance. See benchmarks.rb for details.
286
+ generate_benchmarks can be used on an existing configuration file. It
287
+ will keep exisiting entries, which will be moved to the end of the
288
+ config file. Thus it can be used to quickly update the config file
289
+ after you've added/deleted or renamed controllers and/or actions.
data/Rakefile CHANGED
@@ -43,7 +43,7 @@ hoe = Hoe.new(GEM_NAME, VERS) do |p|
43
43
  p.clean_globs = CLEAN #An array of file patterns to delete on clean.
44
44
  p.need_zip = true
45
45
  p.spec_extras = {:has_rdoc => false}
46
- p.changes = `cat latest_changes`
46
+ p.changes = `cat latest_changes.txt`
47
47
 
48
48
  # == Optional
49
49
  #p.changes - A description of the release's latest changes.
data/bin/railsbench CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  RAILSBENCH_CMDS = %w(
4
4
  base
5
+ generate_benchmarks
6
+ help
5
7
  install
6
8
  path
7
9
  perf_comp
@@ -18,6 +20,7 @@ perf_tex
18
20
  perf_times
19
21
  perf_times_gc
20
22
  postinstall
23
+ readme
21
24
  run_urls
22
25
  ).inject({}){ |h, cmd| h[cmd] = cmd; h[cmd.sub('perf_', '')] = cmd; h}
23
26
 
@@ -25,6 +28,8 @@ cmd = ARGV.shift
25
28
  unless real_cmd = RAILSBENCH_CMDS[cmd]
26
29
  $stderr.puts "railsbench: unknown command: #{cmd}"
27
30
  $stderr.puts "use one of: #{RAILSBENCH_CMDS.keys.sort.join(', ')}"
31
+ $stderr.puts "'railsbench help' displays README"
32
+ $stderr.puts "'railsbench cmd help' displays help for given command"
28
33
  exit 1
29
34
  end
30
35
 
@@ -34,6 +39,9 @@ case real_cmd
34
39
  when 'base'
35
40
  puts "railsbench is installed in: #{RAILSBENCH_BASE}"
36
41
  exit
42
+ when 'help', 'readme'
43
+ File.open("#{RAILSBENCH_BASE}/README").each_line{|l| puts l}
44
+ exit
37
45
  when 'path'
38
46
  puts "PATH=#{RAILSBENCH_BASE}/script:$PATH"
39
47
  exit
@@ -41,7 +49,23 @@ when 'install', 'postinstall'
41
49
  load "#{RAILSBENCH_BASE}/#{real_cmd}.rb"
42
50
  else
43
51
  unless ENV['RAILS_ROOT']
44
- $stderr.puts "railsbench: RAILS_ROOT not set"
52
+ if File.exists? 'config/environment.rb'
53
+ ENV['RAILS_ROOT'] = File.expand_path '.'
54
+ else
55
+ $stderr.puts "railsbench: RAILS_ROOT not set"
56
+ exit 1
57
+ end
58
+ end
59
+ unless File.exists? "#{ENV['RAILS_ROOT']}/config/benchmarks.yml"
60
+ $stderr.puts "railsbench: benchmarks.yml missing: run `railsbench install'"
61
+ exit 1
62
+ end
63
+ unless File.exists? "#{ENV['RAILS_ROOT']}/config/benchmarks.rb"
64
+ $stderr.puts "railsbench: benchmarks.rb missing: run `railsbench install'"
65
+ exit 1
66
+ end
67
+ unless File.exists? "#{ENV['RAILS_ROOT']}/config/environments/benchmarking.rb"
68
+ $stderr.puts "railsbench: environment 'benchmarking' missing: run `railsbench install'"
45
69
  exit 1
46
70
  end
47
71
  load "#{RAILSBENCH_BASE}/script/#{real_cmd}"
data/install.rb CHANGED
@@ -9,21 +9,31 @@ end
9
9
 
10
10
  require 'yaml'
11
11
 
12
- unless RAILS_ROOT = ENV['RAILS_ROOT']
13
- STDERR.puts "RAILS_ROOT must be fined in your environment"
14
- exit 1
12
+ unless ENV['RAILS_ROOT']
13
+ if File.exists? "config/environment.rb"
14
+ ENV['RAILS_ROOT'] = File.expand_path "."
15
+ else
16
+ $stderr.puts "RAILS_ROOT must be fined in your environment"
17
+ exit 1
18
+ end
15
19
  end
16
20
 
21
+ RAILS_ROOT = ENV['RAILS_ROOT']
17
22
  RAILS_CONFIG = RAILS_ROOT + "/config/"
18
23
  RAILS_ENVS = RAILS_ROOT + "/config/environments/"
24
+ RAILSBENCH_BASE = File.expand_path(File.dirname(__FILE__)) unless defined? RAILSBENCH_BASE
25
+
26
+ if ARGV.first == 'help'
27
+ File.open("#{RAILSBENCH_BASE}/INSTALL").each_line{|l| puts l}
28
+ end
19
29
 
20
- install("config/benchmarks.rb", RAILS_CONFIG, :mode => 0644) unless
30
+ install("#{RAILSBENCH_BASE}/config/benchmarks.rb", RAILS_CONFIG, :mode => 0644) unless
21
31
  File.exists?(RAILS_CONFIG + "benchmarks.rb")
22
32
 
23
- install("config/benchmarks.yml", RAILS_CONFIG, :mode => 0644) unless
33
+ install("#{RAILSBENCH_BASE}/config/benchmarks.yml", RAILS_CONFIG, :mode => 0644) unless
24
34
  File.exists?(RAILS_CONFIG + "benchmarks.yml")
25
35
 
26
- install("config/benchmarking.rb", RAILS_ENVS, :mode => 0644) unless
36
+ install("#{RAILSBENCH_BASE}/config/benchmarking.rb", RAILS_ENVS, :mode => 0644) unless
27
37
  File.exists?(RAILS_ENVS + "benchmarking.rb")
28
38
 
29
39
  database = YAML::load(File.open(RAILS_CONFIG + "database.yml"))
@@ -106,7 +106,7 @@ end
106
106
  ### mode:ruby ***
107
107
  ### End: ***
108
108
 
109
- # Copyright (C) 2006 Stefan Kaes
109
+ # Copyright (C) 2006, 2007 Stefan Kaes
110
110
  #
111
111
  # This program is free software; you can redistribute it and/or modify
112
112
  # it under the terms of the GNU General Public License as published by
@@ -111,6 +111,7 @@ class PerfInfo
111
111
  end
112
112
 
113
113
  PerfAttributes.each do |attr|
114
+ next if attr.to_s =~ /^gc_/ and !gc_stats?
114
115
  a = @entries.map{|e| e.send attr}
115
116
  [:min, :max, :mean].each do |method|
116
117
  instance_variable_set "@#{attr}_#{method}", (a.send method)
@@ -128,7 +129,7 @@ end
128
129
  ### mode:ruby ***
129
130
  ### End: ***
130
131
 
131
- # Copyright (C) 2006 Stefan Kaes
132
+ # Copyright (C) 2006, 2007 Stefan Kaes
132
133
  #
133
134
  # This program is free software; you can redistribute it and/or modify
134
135
  # it under the terms of the GNU General Public License as published by
@@ -162,7 +162,7 @@ end
162
162
 
163
163
  __END__
164
164
 
165
- # Copyright (C) 2005, 2006 Stefan Kaes
165
+ # Copyright (C) 2005, 2006, 2007 Stefan Kaes
166
166
  #
167
167
  # This program is free software; you can redistribute it and/or modify
168
168
  # it under the terms of the GNU General Public License as published by
@@ -387,7 +387,7 @@ end
387
387
 
388
388
  __END__
389
389
 
390
- # Copyright (C) 2005, 2006 Stefan Kaes
390
+ # Copyright (C) 2005, 2006, 2007 Stefan Kaes
391
391
  #
392
392
  # This program is free software; you can redistribute it and/or modify
393
393
  # it under the terms of the GNU General Public License as published by
@@ -2,7 +2,7 @@ module Railsbench #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 9
5
- TINY = 0
5
+ TINY = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -0,0 +1,161 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "#{ENV['RAILS_ROOT']}/config/environment"
4
+ require 'application'
5
+
6
+ if ARGV.first == "help"
7
+ puts <<-"endhelp"
8
+ usage: railsbench generate_benchmarks -excluded_actions=<regexp> -excluded_controllers=<controller_list>
9
+ 1) loads your application\'s routes and generates a benchmarks.yml file
10
+ containing benchmark definitions for each route found
11
+ 2) for named routes, benchmark names are derived from the route name
12
+ 3) for routes defined via map.connect, the benchmark name is derived
13
+ from the controller and action
14
+ 4) for each controller, a benchmark consisting of all controller actions
15
+ is generated (named after the controller file name)
16
+ 5) generates a benchmark named 'all_controllers', consisting of all
17
+ benchmarks generated in step 4
18
+ endhelp
19
+ exit
20
+ end
21
+
22
+ excluded_controllers = ["application"]
23
+ excluded_actions = /delete|destroy/
24
+ ARGV.each do |arg|
25
+ excluded_controllers += $1.split(/, */).compact if arg =~ /-excluded_controllers=(.*)/
26
+ excluded_actions = Regexp.new($1.gsub(/,/, '|')) if arg =~ /-excluded_actions=(.*)/
27
+ end
28
+
29
+ benchmark_config = File.expand_path "#{RAILS_ROOT}/config/benchmarks.yml"
30
+
31
+ if File.exist? benchmark_config
32
+ benchmarks = YAML::load(File.open(benchmark_config)) || {}
33
+ else
34
+ benchmarks = {}
35
+ end
36
+
37
+ VALID_KEYS = %w(uri action controller new_session query_params)
38
+
39
+ def dump_entry(name, entry, io = $stdout)
40
+ io.puts "#{name}:"
41
+ if entry.is_a? Hash
42
+ VALID_KEYS.each do |key|
43
+ io.printf " %15-s %s\n", key + ':', entry[key] if entry.has_key? key
44
+ end
45
+ io.puts
46
+ elsif entry.is_a? String
47
+ io.printf " %s\n\n", entry
48
+ else
49
+ raise "unsupported YAML entry"
50
+ end
51
+ end
52
+
53
+ if defined? ActionController::CodeGeneration
54
+ $stderr.puts "this Rails version is not supported. please upgrade to a 1.2 variety."
55
+ exit 1
56
+ end
57
+
58
+ rs = ActionController::Routing::Routes
59
+
60
+ named_routes_map = rs.named_routes.to_a.inject({}){|h,(name,route)| h[route] = name; h}
61
+ controller_action_map = {}
62
+ has_default_route = false
63
+
64
+ out = File.open(benchmark_config, "w")
65
+
66
+ rs.routes.to_a.each do |route|
67
+ uri = route.segments.map(&:to_s).join
68
+ (has_default_route = true; next) if uri == "/:controller/:action/:id/"
69
+ controller = route.requirements[:controller].to_s
70
+ action = route.requirements[:action].to_s
71
+ controller_action = "#{controller}_#{action}"
72
+ file_name = "#{controller}_controller"
73
+ benchmark_name = (named_routes_map[route] || controller_action).to_s
74
+ entry = (benchmarks[benchmark_name] || {}).reverse_merge "uri" => uri, "controller" => controller, "action" => action
75
+ benchmarks.delete benchmark_name
76
+ if action =~ excluded_actions
77
+ $stderr.puts "ignored action: #{action}"
78
+ benchmarks[file_name] = ((benchmarks[file_name]||"").split(/, */) - [benchmark_name]).uniq.join(', ')
79
+ next
80
+ end
81
+ if excluded_controllers.include? controller
82
+ $stderr.puts "ignored controller: #{controller}"
83
+ benchmarks["all_controllers"] = ((benchmarks["all_controllers"]||"").split(/, */) - [file_name]).uniq.join(', ')
84
+ next
85
+ end
86
+ dump_entry benchmark_name, entry, out
87
+ controller_action_map[controller_action] = true
88
+ benchmarks[file_name] = ((benchmarks[file_name]||"").split(/, */) + [benchmark_name]).uniq.join(', ')
89
+ benchmarks["all_controllers"] = ((benchmarks["all_controllers"]||"").split(/, */) + [file_name]).uniq.join(', ')
90
+ end
91
+
92
+ if has_default_route
93
+ $stderr.puts "warning: you are still using the default route"
94
+ Dir["#{RAILS_ROOT}/app/controllers/*.rb"].each do |file|
95
+ file_name = File.basename(file).sub(/\.rb$/,'')
96
+ controller_name = file_name.sub(/_controller$/,'')
97
+ if excluded_controllers.include? controller_name
98
+ $stderr.puts "ignored controller: #{controller_name}"
99
+ benchmarks["all_controllers"] = ((benchmarks["all_controllers"]||"").split(/, */) - [file_name]).uniq.join(', ')
100
+ next
101
+ end
102
+ begin
103
+ controller = file_name.classify.constantize
104
+ controller.action_methods.map(&:to_s).each do |method|
105
+ benchmark_name = "#{controller_name}_#{method}"
106
+ next if controller_action_map[benchmark_name]
107
+ uri = rs.generate({:controller => controller_name ,:action => method},{})
108
+ entry = (benchmarks[benchmark_name] || {}).reverse_merge "uri" => uri, "controller" => controller_name, "action" => method
109
+ benchmarks.delete benchmark_name
110
+ if method =~ excluded_actions
111
+ $stderr.puts "ignored action: #{method}"
112
+ benchmarks[file_name] = ((benchmarks[file_name]||"").split(/, */) - [benchmark_name]).uniq.join(', ')
113
+ next
114
+ end
115
+ dump_entry benchmark_name, entry, out
116
+ benchmarks[file_name] = ((benchmarks[file_name]||"").split(/, */) + [benchmark_name]).uniq.join(', ')
117
+ benchmarks["all_controllers"] = ((benchmarks["all_controllers"]||"").split(/, */) + [file_name]).uniq.join(', ')
118
+ end
119
+ rescue MissingSourceFile, NoMethodError, ActionController::RoutingError
120
+ end
121
+ end
122
+ end
123
+
124
+ # dump remaining benchmarks
125
+ all_entry = benchmarks.delete "all_controllers"
126
+
127
+ benchmarks.delete_if do |k,v|
128
+ v.is_a?(Hash) && (v["action"].to_s =~ excluded_actions || v["controller"].to_s =~ excluded_controllers)
129
+ end
130
+
131
+ generated_controller_benchmarks, others = benchmarks.partition{|k,v| k =~ /_controller$/}
132
+
133
+ generated_controller_benchmarks.sort_by(&:first).each do |benchmark_name, entry|
134
+ dump_entry benchmark_name, entry, out
135
+ end
136
+
137
+ dump_entry "all_controllers", all_entry, out
138
+
139
+ others.each do |benchmark_name, entry|
140
+ dump_entry benchmark_name, entry, out
141
+ end
142
+
143
+ out.close unless out.nil?
144
+
145
+ __END__
146
+
147
+ # Copyright (C) 2007 Stefan Kaes
148
+ #
149
+ # This program is free software; you can redistribute it and/or modify
150
+ # it under the terms of the GNU General Public License as published by
151
+ # the Free Software Foundation; either version 2 of the License, or
152
+ # (at your option) any later version.
153
+ #
154
+ # This program is distributed in the hope that it will be useful,
155
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
156
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
157
+ # GNU General Public License for more details.
158
+ #
159
+ # You should have received a copy of the GNU General Public License
160
+ # along with this program; if not, write to the Free Software
161
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
data/script/perf_bench CHANGED
@@ -55,7 +55,7 @@ Benchmark::OUTPUT.close unless Benchmark::OUTPUT.nil? || !ENV['RAILS_BENCHMARK_F
55
55
 
56
56
  __END__
57
57
 
58
- # Copyright (C) 2005, 2006 Stefan Kaes
58
+ # Copyright (C) 2005, 2006, 2007 Stefan Kaes
59
59
  #
60
60
  # This program is free software; you can redistribute it and/or modify
61
61
  # it under the terms of the GNU General Public License as published by
data/script/perf_comp CHANGED
@@ -134,7 +134,7 @@ end
134
134
 
135
135
  __END__
136
136
 
137
- # Copyright (C) 2005, 2006 Stefan Kaes
137
+ # Copyright (C) 2005, 2006, 2007 Stefan Kaes
138
138
  #
139
139
  # This program is free software; you can redistribute it and/or modify
140
140
  # it under the terms of the GNU General Public License as published by
data/script/perf_comp_gc CHANGED
@@ -88,7 +88,7 @@ printf "freelist : #{number_format}\n",
88
88
 
89
89
  __END__
90
90
 
91
- # Copyright (C) 2005, 2006 Stefan Kaes
91
+ # Copyright (C) 2005, 2006, 2007 Stefan Kaes
92
92
  #
93
93
  # This program is free software; you can redistribute it and/or modify
94
94
  # it under the terms of the GNU General Public License as published by
data/script/perf_diff CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- if ARGV.length < 4
3
+ if ARGV.length < 4 || ARGV.first == 'help'
4
4
  $stderr.puts 'usage: perf_diff iterations common-options options1 options4 [conf-name1] [conf-name2]'
5
5
  $stderr.puts 'example: perf_diff 100 "-bm=all" "-log" "-nocache" c1 c2'
6
6
  exit 1
@@ -31,7 +31,7 @@ system("ruby #{bindir}/perf_comp -narrow -skip_urls #{file1} #{file2}")
31
31
 
32
32
  __END__
33
33
 
34
- # Copyright (C) 2005, 2006 Stefan Kaes
34
+ # Copyright (C) 2005, 2006, 2007 Stefan Kaes
35
35
  #
36
36
  # This program is free software; you can redistribute it and/or modify
37
37
  # it under the terms of the GNU General Public License as published by
data/script/perf_diff_gc CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- if ARGV.length < 4
3
+ if ARGV.length < 4 || ARGV.first == 'help'
4
4
  $stderr.puts 'usage: perf_diff_gc iterations options1 options2 [conf-name1] [conf-name2]'
5
5
  $stderr.puts 'example: perf_diff_gc 100 "-bm=default" "-log" "-nocache" c1 c2'
6
6
  exit 1
@@ -36,7 +36,7 @@ system("ruby #{bindir}/perf_comp_gc #{file1} #{file2}")
36
36
 
37
37
  __END__
38
38
 
39
- # Copyright (C) 2005, 2006 Stefan Kaes
39
+ # Copyright (C) 2005, 2006, 2007 Stefan Kaes
40
40
  #
41
41
  # This program is free software; you can redistribute it and/or modify
42
42
  # it under the terms of the GNU General Public License as published by
data/script/perf_html CHANGED
@@ -61,7 +61,7 @@ end
61
61
 
62
62
  __END__
63
63
 
64
- # Copyright (C) 2005, 2006 Stefan Kaes
64
+ # Copyright (C) 2005, 2006, 2007 Stefan Kaes
65
65
  #
66
66
  # This program is free software; you can redistribute it and/or modify
67
67
  # it under the terms of the GNU General Public License as published by
data/script/perf_plot CHANGED
@@ -73,7 +73,7 @@ g.write
73
73
 
74
74
  __END__
75
75
 
76
- # Copyright (C) 2005, 2006 Stefan Kaes
76
+ # Copyright (C) 2005, 2006, 2007 Stefan Kaes
77
77
  #
78
78
  # This program is free software; you can redistribute it and/or modify
79
79
  # it under the terms of the GNU General Public License as published by
data/script/perf_plot_gc CHANGED
@@ -93,7 +93,7 @@ g.write
93
93
 
94
94
  __END__
95
95
 
96
- # Copyright (C) 2005, 2006 Stefan Kaes
96
+ # Copyright (C) 2005, 2006, 2007 Stefan Kaes
97
97
  #
98
98
  # This program is free software; you can redistribute it and/or modify
99
99
  # it under the terms of the GNU General Public License as published by
data/script/perf_prof CHANGED
@@ -51,7 +51,7 @@ end
51
51
 
52
52
  __END__
53
53
 
54
- # Copyright (C) 2005, 2006 Stefan Kaes
54
+ # Copyright (C) 2005, 2006, 2007 Stefan Kaes
55
55
  #
56
56
  # This program is free software; you can redistribute it and/or modify
57
57
  # it under the terms of the GNU General Public License as published by
data/script/perf_run CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- if ARGV.length == 0 || ARGV.length > 3
4
- puts "usage: perf_run iterations options [conf-name]"
5
- puts "example: perf_run 100 \"-bm=default -log\" pdata"
3
+ if ARGV.length == 0 || ARGV.length > 3 || ARGV.first == 'help'
4
+ $stderr.puts "usage: perf_run iterations options [conf-name]"
5
+ $stderr.puts "example: perf_run 100 \"-bm=default -log\" pdata"
6
6
  exit 1
7
7
  end
8
8
 
@@ -22,7 +22,7 @@ perf_run("perf_run", iterations, options, benchmark_file)
22
22
 
23
23
  __END__
24
24
 
25
- # Copyright (C) 2005, 2006 Stefan Kaes
25
+ # Copyright (C) 2005, 2006, 2007 Stefan Kaes
26
26
  #
27
27
  # This program is free software; you can redistribute it and/or modify
28
28
  # it under the terms of the GNU General Public License as published by
data/script/perf_run_gc CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- if ARGV.length < 2
3
+ if ARGV.length < 2 || ARGV.first == 'help'
4
4
  $stderr.puts "usage: perf_run_gc iterations options [conf-name]"
5
5
  $stderr.puts "example: perf_run_gc 100 \"-bm=default -log\" pdata"
6
6
  exit 1
@@ -23,7 +23,7 @@ perf_run_gc("perf_run_gc", iterations, options, benchmark_file)
23
23
 
24
24
  __END__
25
25
 
26
- # Copyright (C) 2005, 2006 Stefan Kaes
26
+ # Copyright (C) 2005, 2006, 2007 Stefan Kaes
27
27
  #
28
28
  # This program is free software; you can redistribute it and/or modify
29
29
  # it under the terms of the GNU General Public License as published by
data/script/perf_tex CHANGED
@@ -41,7 +41,7 @@ end
41
41
 
42
42
  __END__
43
43
 
44
- # Copyright (C) 2005, 2006 Stefan Kaes
44
+ # Copyright (C) 2005, 2006, 2007 Stefan Kaes
45
45
  #
46
46
  # This program is free software; you can redistribute it and/or modify
47
47
  # it under the terms of the GNU General Public License as published by
data/script/perf_times CHANGED
@@ -49,7 +49,7 @@ end
49
49
 
50
50
  __END__
51
51
 
52
- # Copyright (C) 2005, 2006 Stefan Kaes
52
+ # Copyright (C) 2005, 2006, 2007 Stefan Kaes
53
53
  #
54
54
  # This program is free software; you can redistribute it and/or modify
55
55
  # it under the terms of the GNU General Public License as published by
data/script/perf_times_gc CHANGED
@@ -65,7 +65,7 @@ end
65
65
 
66
66
  __END__
67
67
 
68
- # Copyright (C) 2005, 2006 Stefan Kaes
68
+ # Copyright (C) 2005, 2006, 2007 Stefan Kaes
69
69
  #
70
70
  # This program is free software; you can redistribute it and/or modify
71
71
  # it under the terms of the GNU General Public License as published by
data/script/run_urls CHANGED
@@ -6,6 +6,12 @@ unless ENV['RAILS_ROOT']
6
6
  exit 1
7
7
  end
8
8
 
9
+ if ARGV.length == 0 || ARGV.first == 'help'
10
+ $stderr.puts "usage: run_urls iterations option_1 ... option_n"
11
+ $stderr.puts "example: run_urls 100 -bm=default -log | grep Status:"
12
+ exit 1
13
+ end
14
+
9
15
  $:.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib'))
10
16
  require 'railsbench/railsbenchmark'
11
17
  require ENV['RAILS_ROOT'] + '/config/benchmarks'
@@ -30,7 +36,7 @@ RAILS_BENCHMARKER.run_urls_without_benchmark(ENV['RUBY_GC_STATS'].to_i == 1)
30
36
 
31
37
  __END__
32
38
 
33
- # Copyright (C) 2005, 2006 Stefan Kaes
39
+ # Copyright (C) 2005, 2006, 2007 Stefan Kaes
34
40
  #
35
41
  # This program is free software; you can redistribute it and/or modify
36
42
  # it under the terms of the GNU General Public License as published by
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: railsbench
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.9.0
7
- date: 2006-12-26 00:00:00 +01:00
6
+ version: 0.9.1
7
+ date: 2007-01-14 00:00:00 +01:00
8
8
  summary: rails benchmarking tools
9
9
  require_paths:
10
10
  - lib
@@ -49,6 +49,7 @@ files:
49
49
  - lib/railsbench/write_headers_only.rb
50
50
  - lib/railsbench/railsbenchmark.rb
51
51
  - lib/benchmark.rb
52
+ - script/generate_benchmarks
52
53
  - script/perf_bench
53
54
  - script/perf_comp
54
55
  - script/perf_comp_gc