railties 3.1.0.beta1 → 3.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/CHANGELOG +47 -1
  2. data/guides/rails_guides/generator.rb +5 -4
  3. data/guides/source/action_controller_overview.textile +26 -0
  4. data/guides/source/active_support_core_extensions.textile +10 -0
  5. data/guides/source/association_basics.textile +2 -2
  6. data/guides/source/caching_with_rails.textile +30 -1
  7. data/guides/source/configuring.textile +40 -45
  8. data/guides/source/contributing_to_ruby_on_rails.textile +20 -11
  9. data/guides/source/generators.textile +23 -24
  10. data/guides/source/getting_started.textile +4 -4
  11. data/guides/source/layout.html.erb +1 -1
  12. data/guides/source/migrations.textile +1 -1
  13. data/guides/source/performance_testing.textile +159 -84
  14. data/guides/source/rails_on_rack.textile +0 -6
  15. data/guides/source/security.textile +5 -5
  16. data/guides/source/testing.textile +3 -3
  17. data/lib/rails/application.rb +12 -7
  18. data/lib/rails/application/bootstrap.rb +2 -1
  19. data/lib/rails/application/configuration.rb +1 -1
  20. data/lib/rails/commands.rb +2 -1
  21. data/lib/rails/commands/benchmarker.rb +28 -19
  22. data/lib/rails/commands/dbconsole.rb +1 -1
  23. data/lib/rails/commands/profiler.rb +27 -43
  24. data/lib/rails/commands/runner.rb +9 -15
  25. data/lib/rails/commands/server.rb +2 -1
  26. data/lib/rails/engine.rb +9 -2
  27. data/lib/rails/engine/configuration.rb +1 -0
  28. data/lib/rails/generators.rb +2 -2
  29. data/lib/rails/generators/actions.rb +1 -1
  30. data/lib/rails/generators/app_base.rb +24 -16
  31. data/lib/rails/generators/base.rb +2 -2
  32. data/lib/rails/generators/erb/scaffold/templates/_form.html.erb +1 -1
  33. data/lib/rails/generators/erb/scaffold/templates/index.html.erb +2 -2
  34. data/lib/rails/generators/erb/scaffold/templates/show.html.erb +1 -1
  35. data/lib/rails/generators/generated_attribute.rb +7 -6
  36. data/lib/rails/generators/named_base.rb +2 -0
  37. data/lib/rails/generators/rails/app/app_generator.rb +15 -6
  38. data/lib/rails/generators/rails/app/templates/Gemfile +2 -1
  39. data/lib/rails/generators/rails/app/templates/README +10 -5
  40. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +5 -2
  41. data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +3 -1
  42. data/lib/rails/generators/rails/app/templates/config/application.rb +3 -12
  43. data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml +4 -1
  44. data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml +3 -0
  45. data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml +3 -0
  46. data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml +4 -0
  47. data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml +4 -1
  48. data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml +5 -2
  49. data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml +4 -0
  50. data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml +3 -0
  51. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +0 -1
  52. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +1 -1
  53. data/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt +2 -2
  54. data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +1 -1
  55. data/lib/rails/generators/rails/app/templates/gitignore +1 -0
  56. data/lib/rails/generators/rails/app/templates/test/performance/browsing_test.rb +4 -1
  57. data/lib/rails/generators/rails/assets/USAGE +3 -3
  58. data/lib/rails/generators/rails/assets/assets_generator.rb +4 -4
  59. data/lib/rails/generators/rails/controller/templates/controller.rb +1 -1
  60. data/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +2 -1
  61. data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +2 -2
  62. data/lib/rails/generators/test_unit/controller/templates/functional_test.rb +1 -1
  63. data/lib/rails/generators/test_unit/mailer/templates/functional_test.rb +1 -1
  64. data/lib/rails/generators/test_unit/model/templates/fixtures.yml +3 -3
  65. data/lib/rails/generators/test_unit/performance/templates/performance_test.rb +4 -1
  66. data/lib/rails/rack.rb +4 -4
  67. data/lib/rails/rack/content_length.rb +38 -0
  68. data/lib/rails/railtie.rb +1 -0
  69. data/lib/rails/tasks/framework.rake +2 -7
  70. data/lib/rails/tasks/routes.rake +1 -1
  71. data/lib/rails/version.rb +1 -1
  72. metadata +6 -6
  73. data/lib/rails/rack/static.rb +0 -5
@@ -1450,14 +1450,14 @@ Two very common sources of data that are not UTF-8:
1450
1450
 
1451
1451
  h3. Changelog
1452
1452
 
1453
- * April 26, 2011: Changed migration code from +up+, +down+ pair to +change+ method "Prem Sichanugrist":"http://sikachu.com"
1454
- * April 11, 2011: Changed scaffold_controller generator to create format block for JSON instead of XML "Sebastian Martinez":http://www.wyeworks.com
1453
+ * April 26, 2011: Change migration code from +up+, +down+ pair to +change+ method by "Prem Sichanugrist":http://sikachu.com
1454
+ * April 11, 2011: Change scaffold_controller generator to create format block for JSON instead of XML by "Sebastian Martinez":http://www.wyeworks.com
1455
1455
  * August 30, 2010: Minor editing after Rails 3 release by "Joost Baaij":http://www.spacebabies.nl
1456
1456
  * July 12, 2010: Fixes, editing and updating of code samples by "Jaime Iniesta":http://jaimeiniesta.com
1457
1457
  * May 16, 2010: Added a section on configuration gotchas to address common encoding problems that people might have by "Yehuda Katz":http://www.yehudakatz.com
1458
1458
  * April 30, 2010: Fixes, editing and updating of code samples by "Rohit Arondekar":http://rohitarondekar.com
1459
- * April 25, 2010: Couple of more minor fixups "Mikel Lindsaar":credits.html#raasdnil
1460
- * April 1, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com
1459
+ * April 25, 2010: Couple of more minor fixups by "Mikel Lindsaar":credits.html#raasdnil
1460
+ * April 1, 2010: Fixed document to validate XHTML 1.0 Strict by "Jaime Iniesta":http://jaimeiniesta.com
1461
1461
  * February 8, 2010: Full re-write for Rails 3.0-beta, added helpers and before_filters, refactored code by "Mikel Lindsaar":credits.html#raasdnil
1462
1462
  * January 24, 2010: Re-write for Rails 3.0 by "Mikel Lindsaar":credits.html#raasdnil
1463
1463
  * July 18, 2009: Minor cleanup in anticipation of Rails 2.3.3 by "Mike Gunderloy":credits.html#mgunderloy
@@ -27,7 +27,7 @@
27
27
  <a href="http://rubyonrails.org/">Overview</a> |
28
28
  <a href="http://rubyonrails.org/download">Download</a> |
29
29
  <a href="http://rubyonrails.org/deploy">Deploy</a> |
30
- <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
30
+ <a href="https://github.com/rails/rails">Code</a> |
31
31
  <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
32
32
  <a href="http://rubyonrails.org/documentation">Documentation</a> |
33
33
  <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
@@ -386,7 +386,7 @@ class ExampleMigration < ActiveRecord::Migration
386
386
  end
387
387
  </ruby>
388
388
 
389
- Sometimes your migration will do something which is just plain irreversible, for example it might destroy some data. In cases like those when you can't reverse the migration you can raise +IrreversibleMigration+ from your +down+ method. If someone tries to revert your migration an error message will be displayed saying that it can't be done.
389
+ Sometimes your migration will do something which is just plain irreversible, for example it might destroy some data. In cases like those when you can't reverse the migration you can raise +ActiveRecord::IrreversibleMigration+ from your +down+ method. If someone tries to revert your migration an error message will be displayed saying that it can't be done.
390
390
 
391
391
  h3. Running Migrations
392
392
 
@@ -4,7 +4,7 @@ This guide covers the various ways of performance testing a Ruby on Rails applic
4
4
 
5
5
  * Understand the various types of benchmarking and profiling metrics
6
6
  * Generate performance and benchmarking tests
7
- * Use a GC-patched Ruby binary to measure memory usage and object allocation
7
+ * Install and use a GC-patched Ruby binary to measure memory usage and object allocation
8
8
  * Understand the benchmarking information provided by Rails inside the log files
9
9
  * Learn about various tools facilitating benchmarking and profiling
10
10
 
@@ -23,7 +23,7 @@ require 'test_helper'
23
23
  require 'rails/performance_test_help'
24
24
 
25
25
  # Profiling results for each test method are written to tmp/performance.
26
- class BrowsingTest < ActionController::PerformanceTest
26
+ class BrowsingTest < ActionDispatch::PerformanceTest
27
27
  def test_homepage
28
28
  get '/'
29
29
  end
@@ -34,10 +34,10 @@ This example is a simple performance test case for profiling a GET request to th
34
34
 
35
35
  h4. Generating Performance Tests
36
36
 
37
- Rails provides a generator called +test_unit:performance+ for creating new performance tests:
37
+ Rails provides a generator called +performance_test+ for creating new performance tests:
38
38
 
39
39
  <shell>
40
- $ rails generate test_unit:performance homepage
40
+ $ rails generate performance_test homepage
41
41
  </shell>
42
42
 
43
43
  This generates +homepage_test.rb+ in the +test/performance+ directory:
@@ -46,7 +46,7 @@ This generates +homepage_test.rb+ in the +test/performance+ directory:
46
46
  require 'test_helper'
47
47
  require 'rails/performance_test_help'
48
48
 
49
- class HomepageTest < ActionController::PerformanceTest
49
+ class HomepageTest < ActionDispatch::PerformanceTest
50
50
  # Replace this with your real tests.
51
51
  def test_homepage
52
52
  get '/'
@@ -105,7 +105,7 @@ Here's the performance test for +HomeController#dashboard+ and +PostsController#
105
105
  require 'test_helper'
106
106
  require 'rails/performance_test_help'
107
107
 
108
- class PostPerformanceTest < ActionController::PerformanceTest
108
+ class PostPerformanceTest < ActionDispatch::PerformanceTest
109
109
  def setup
110
110
  # Application requires logged-in user
111
111
  login_as(:lifo)
@@ -133,7 +133,7 @@ Performance test for +Post+ model:
133
133
  require 'test_helper'
134
134
  require 'rails/performance_test_help'
135
135
 
136
- class PostModelTest < ActionController::PerformanceTest
136
+ class PostModelTest < ActionDispatch::PerformanceTest
137
137
  def test_creation
138
138
  Post.create :body => 'still fooling you', :cost => '100'
139
139
  end
@@ -151,7 +151,7 @@ Performance tests can be run in two modes: Benchmarking and Profiling.
151
151
 
152
152
  h5. Benchmarking
153
153
 
154
- Benchmarking helps find out how fast each performance test runs. Each test case is run +4 times+ in benchmarking mode.
154
+ Benchmarking makes it easy to quickly gather a few metrics about each test tun. By default, each test case is run +4 times+ in benchmarking mode.
155
155
 
156
156
  To run performance tests in benchmarking mode:
157
157
 
@@ -161,7 +161,7 @@ $ rake test:benchmark
161
161
 
162
162
  h5. Profiling
163
163
 
164
- Profiling helps you see the details of a performance test and provide an in-depth picture of the slow and memory hungry parts. Each test case is run +1 time+ in profiling mode.
164
+ Profiling allows you to make an in-depth analysis of each of your tests by using an external profiler. Depending on your Ruby interpreter, this profiler can be native (Rubinius, JRuby) or not (MRI, which uses RubyProf). By default, each test case is run +1 time+ in profiling mode.
165
165
 
166
166
  To run performance tests in profiling mode:
167
167
 
@@ -171,43 +171,59 @@ $ rake test:profile
171
171
 
172
172
  h4. Metrics
173
173
 
174
- Benchmarking and profiling run performance tests in various modes described below.
174
+ Benchmarking and profiling run performance tests and give you multiple metrics. The availability of each metric is determined by the interpreter being used—none of them support all metrics—and by the mode in use. A brief description of each metric and their availability across interpreters/modes is given below.
175
175
 
176
176
  h5. Wall Time
177
177
 
178
178
  Wall time measures the real world time elapsed during the test run. It is affected by any other processes concurrently running on the system.
179
179
 
180
- Mode: Benchmarking
181
-
182
180
  h5. Process Time
183
181
 
184
182
  Process time measures the time taken by the process. It is unaffected by any other processes running concurrently on the same system. Hence, process time is likely to be constant for any given performance test, irrespective of the machine load.
185
183
 
186
- Mode: Profiling
184
+ h5. CPU Time
185
+
186
+ Similar to process time, but leverages the more accurate CPU clock counter available on the Pentium and PowerPC platforms.
187
+
188
+ h5. User Time
189
+
190
+ User time measures the amount of time the CPU spent in user-mode, i.e. within the process. This is not affected by other processes and by the time it possibly spends blocked.
187
191
 
188
192
  h5. Memory
189
193
 
190
194
  Memory measures the amount of memory used for the performance test case.
191
195
 
192
- Mode: Benchmarking, Profiling "Requires GC Patched Ruby":#installing-gc-patched-ruby
193
-
194
196
  h5. Objects
195
197
 
196
198
  Objects measures the number of objects allocated for the performance test case.
197
199
 
198
- Mode: Benchmarking, Profiling "Requires GC Patched Ruby":#installing-gc-patched-ruby
199
-
200
200
  h5. GC Runs
201
201
 
202
202
  GC Runs measures the number of times GC was invoked for the performance test case.
203
203
 
204
- Mode: Benchmarking "Requires GC Patched Ruby":#installing-gc-patched-ruby
205
-
206
204
  h5. GC Time
207
205
 
208
206
  GC Time measures the amount of time spent in GC for the performance test case.
209
207
 
210
- Mode: Benchmarking "Requires GC Patched Ruby":#installing-gc-patched-ruby
208
+ h5. Metric Availability
209
+
210
+ h6. Benchmarking
211
+
212
+ |_.Interpreter|_.Wall Time|_.Process Time|_.CPU Time|_.User Time|_.Memory|_.Objects|_.GC Runs|_.GC Time|
213
+ |_.MRI | yes | yes | yes | no | yes | yes | yes | yes |
214
+ |_.REE | yes | yes | yes | no | yes | yes | yes | yes |
215
+ |_.Rubinius | yes | no | no | no | yes | yes | yes | yes |
216
+ |_.JRuby | yes | no | no | yes | yes | yes | yes | yes |
217
+
218
+ h6. Profiling
219
+
220
+ |_.Interpreter|_.Wall Time|_.Process Time|_.CPU Time|_.User Time|_.Memory|_.Objects|_.GC Runs|_.GC Time|
221
+ |_.MRI | yes | yes | no | no | yes | yes | yes | yes |
222
+ |_.REE | yes | yes | no | no | yes | yes | yes | yes |
223
+ |_.Rubinius | yes | no | no | no | no | no | no | no |
224
+ |_.JRuby | yes | no | no | no | no | no | no | no |
225
+
226
+ NOTE: To profile under JRuby you'll need to run +export JRUBY_OPTS="-Xlaunch.inproc=false --profile.api"+ *before* the performance tests.
211
227
 
212
228
  h4. Understanding the Output
213
229
 
@@ -215,7 +231,7 @@ Performance tests generate different outputs inside +tmp/performance+ directory
215
231
 
216
232
  h5(#output-benchmarking). Benchmarking
217
233
 
218
- In benchmarking mode, performance tests generate two types of outputs:
234
+ In benchmarking mode, performance tests generate two types of outputs.
219
235
 
220
236
  h6(#output-command-line). Command Line
221
237
 
@@ -225,7 +241,7 @@ This is the primary form of output in benchmarking mode. Example:
225
241
  BrowsingTest#test_homepage (31 ms warmup)
226
242
  wall_time: 6 ms
227
243
  memory: 437.27 KB
228
- objects: 5514
244
+ objects: 5,514
229
245
  gc_runs: 0
230
246
  gc_time: 19 ms
231
247
  </shell>
@@ -260,7 +276,7 @@ measurement,created_at,app,rails,ruby,platform
260
276
 
261
277
  h5(#output-profiling). Profiling
262
278
 
263
- In profiling mode, you can choose from four types of output.
279
+ In profiling mode, performance tests can generate multiple types of outputs. The command line output is always presented but support for the others is dependant on the interpreter in use. A brief description of each type and their availability across interpreters is given below.
264
280
 
265
281
  h6. Command Line
266
282
 
@@ -270,26 +286,67 @@ This is a very basic form of output in profiling mode:
270
286
  BrowsingTest#test_homepage (58 ms warmup)
271
287
  process_time: 63 ms
272
288
  memory: 832.13 KB
273
- objects: 7882
289
+ objects: 7,882
274
290
  </shell>
275
291
 
276
292
  h6. Flat
277
293
 
278
- Flat output shows the total amount of time spent in each method. "Check ruby prof documentation for a better explanation":http://ruby-prof.rubyforge.org/files/examples/flat_txt.html.
294
+ Flat output shows the metric—time, memory, etc—measure in each method. "Check Ruby-Prof documentation for a better explanation":http://ruby-prof.rubyforge.org/files/examples/flat_txt.html.
279
295
 
280
296
  h6. Graph
281
297
 
282
- Graph output shows how long each method takes to run, which methods call it and which methods it calls. "Check ruby prof documentation for a better explanation":http://ruby-prof.rubyforge.org/files/examples/graph_txt.html.
298
+ Graph output shows the metric measure in each method, which methods call it and which methods it calls. "Check Ruby-Prof documentation for a better explanation":http://ruby-prof.rubyforge.org/files/examples/graph_txt.html.
283
299
 
284
300
  h6. Tree
285
301
 
286
302
  Tree output is profiling information in calltree format for use by "kcachegrind":http://kcachegrind.sourceforge.net/html/Home.html and similar tools.
287
303
 
304
+ h6. Output Availability
305
+
306
+ |_. |_.Flat|_.Graph|_.Tree|
307
+ |_.MRI | yes | yes | yes |
308
+ |_.REE | yes | yes | yes |
309
+ |_.Rubinius | yes | yes | no |
310
+ |_.JRuby | yes | yes | no |
311
+
288
312
  h4. Tuning Test Runs
289
313
 
290
- By default, each performance test is run +4 times+ in benchmarking mode and +1 time+ in profiling. However, test runs can easily be configured.
314
+ Test runs can be tuned by setting the +profile_options+ class variable on your test class.
291
315
 
292
- WARNING: Performance test configurability is not yet enabled in Rails. But it will be soon.
316
+ <ruby>
317
+ require 'test_helper'
318
+ require 'rails/performance_test_help'
319
+
320
+ # Profiling results for each test method are written to tmp/performance.
321
+ class BrowsingTest < ActionDispatch::PerformanceTest
322
+ self.profile_options = { :runs => 5,
323
+ :metrics => [:wall_time, :memory] }
324
+
325
+ def test_homepage
326
+ get '/'
327
+ end
328
+ end
329
+ </ruby>
330
+
331
+ In this example, the test would run 5 times and measure wall time and memory. There are a few configurable options:
332
+
333
+ |_.Option |_.Description|_.Default|_.Mode|
334
+ |+:runs+ |Number of runs.|Benchmarking: 4, Profiling: 1|Both|
335
+ |+:output+ |Directory to use when writing the results.|+tmp/performance+|Both|
336
+ |+:metrics+ |Metrics to use.|See below.|Both|
337
+ |+:formats+ |Formats to output to.|See below.|Profiling|
338
+
339
+ Metrics and formats have different defaults depending on the interpreter in use.
340
+
341
+ |_.Interpreter|_.Mode|_.Default metrics|_.Default formats|
342
+ |/2.MRI/REE |Benchmarking|+[:wall_time, :memory, :objects, :gc_runs, :gc_time]+|N/A|
343
+ |Profiling |+[:process_time, :memory, :objects]+|+[:flat, :graph_html, :call_tree, :call_stack]+|
344
+ |/2.Rubinius|Benchmarking|+[:wall_time, :memory, :objects, :gc_runs, :gc_time]+|N/A|
345
+ |Profiling |+[:wall_time]+|+[:flat, :graph]+|
346
+ |/2.JRuby |Benchmarking|+[:wall_time, :user_time, :memory, :gc_runs, :gc_time]+|N/A|
347
+ |Profiling |+[:wall_time]+|+[:flat, :graph]+|
348
+
349
+ As you've probably noticed by now, metrics and formats are specified using a symbol array with each name "underscored.":http://api.rubyonrails.org/classes/String.html#method-i-underscore
293
350
 
294
351
  h4. Performance Test Environment
295
352
 
@@ -303,41 +360,71 @@ Rails.logger.level = ActiveSupport::BufferedLogger::INFO
303
360
 
304
361
  As +ActionController::Base.perform_caching+ is set to +true+, performance tests will behave much as they do in the +production+ environment.
305
362
 
306
- h4. Installing GC-Patched Ruby
363
+ h4. Installing GC-Patched MRI
364
+
365
+ To get the best from Rails' performance tests under MRI, you'll need to build a special Ruby binary with some super powers.
307
366
 
308
- To get the best from Rails performance tests, you need to build a special Ruby binary with some super powers - "GC patch":http://rubyforge.org/tracker/download.php/1814/7062/17676/3291/ruby186gc.patch for measuring GC Runs/Time and memory/object allocation.
367
+ The recommended patches for each MRI version are:
309
368
 
310
- The process is fairly straightforward. If you've never compiled a Ruby binary before, follow these steps to build a ruby binary inside your home directory:
369
+ |_.Version|_.Patch|
370
+ |1.8.6|ruby186gc|
371
+ |1.8.7|ruby187gc|
372
+ |1.9.2 and above|gcdata|
311
373
 
312
- h5. Installation
374
+ All of these can be found on "RVM's _patches_ directory":https://github.com/wayneeseguin/rvm/tree/master/patches/ruby under each specific interpreter version.
313
375
 
314
- Compile Ruby and apply this "GC Patch":http://rubyforge.org/tracker/download.php/1814/7062/17676/3291/ruby186gc.patch.
376
+ Concerning the installation itself, you can either do this easily by using "RVM":http://rvm.beginrescueend.com or you can build everything from source, which is a little bit harder.
315
377
 
316
- h5. Download and Extract
378
+ h5. Install Using RVM
379
+
380
+ The process of installing a patched Ruby interpreter is very easy if you let RVM do the hard work. All of the following RVM commands will provide you with a patched Ruby interpreter:
381
+
382
+ <shell>
383
+ $ rvm install 1.9.2-p180 --patch gcdata
384
+ $ rvm install 1.8.7 --patch ruby187gc
385
+ $ rvm install 1.9.2-p180 --patch ~/Downloads/downloaded_gcdata_patch.patch
386
+ </shell>
387
+
388
+ You can even keep your regular interpreter by assigning a name to the patched one:
389
+
390
+ <shell>
391
+ $ rvm install 1.9.2-p180 --patch gcdata --name gcdata
392
+ $ rvm use 1.9.2-p180 # your regular ruby
393
+ $ rvm use 1.9.2-p180-gcdata # your patched ruby
394
+ </shell>
395
+
396
+ And it's done! You have installed a patched Ruby interpreter.
397
+
398
+ h5. Install From Source
399
+
400
+ This process is a bit more complicated, but straightforward nonetheless. If you've never compiled a Ruby binary before, follow these steps to build a Ruby binary inside your home directory.
401
+
402
+ h6. Download and Extract
317
403
 
318
404
  <shell>
319
405
  $ mkdir rubygc
320
- $ wget <download the latest stable ruby from ftp://ftp.ruby-lang.org/pub/ruby>
406
+ $ wget <the version you want from ftp://ftp.ruby-lang.org/pub/ruby>
321
407
  $ tar -xzvf <ruby-version.tar.gz>
322
408
  $ cd <ruby-version>
323
409
  </shell>
324
410
 
325
- h5. Apply the Patch
411
+ h6. Apply the Patch
326
412
 
327
413
  <shell>
328
- $ curl http://rubyforge.org/tracker/download.php/1814/7062/17676/3291/ruby186gc.patch | patch -p0
414
+ $ curl http://github.com/wayneeseguin/rvm/raw/master/patches/ruby/1.9.2/p180/gcdata.patch | patch -p0 # if you're on 1.9.2!
415
+ $ curl http://github.com/wayneeseguin/rvm/raw/master/patches/ruby/1.8.7/ruby187gc.patch | patch -p0 # if you're on 1.8.7!
329
416
  </shell>
330
417
 
331
- h5. Configure and Install
418
+ h6. Configure and Install
332
419
 
333
- The following will install ruby in your home directory's +/rubygc+ directory. Make sure to replace +&lt;homedir&gt;+ with a full patch to your actual home directory.
420
+ The following will install Ruby in your home directory's +/rubygc+ directory. Make sure to replace +&lt;homedir&gt;+ with a full patch to your actual home directory.
334
421
 
335
422
  <shell>
336
423
  $ ./configure --prefix=/<homedir>/rubygc
337
424
  $ make && make install
338
425
  </shell>
339
426
 
340
- h5. Prepare Aliases
427
+ h6. Prepare Aliases
341
428
 
342
429
  For convenience, add the following lines in your +~/.profile+:
343
430
 
@@ -349,26 +436,21 @@ alias gcirb='~/rubygc/bin/irb'
349
436
  alias gcrails='~/rubygc/bin/rails'
350
437
  </shell>
351
438
 
352
- h5. Install Rubygems and Dependency Gems
439
+ Don't forget to use your aliases from now on.
353
440
 
354
- Download "Rubygems":http://rubyforge.org/projects/rubygems and install it from source. Rubygem's README file should have necessary installation instructions.
441
+ h6. Install Rubygems (1.8 only!)
355
442
 
356
- Additionally, install the following gems:
443
+ Download "Rubygems":http://rubyforge.org/projects/rubygems and install it from source. Rubygem's README file should have necessary installation instructions. Please note that this step isn't necessary if you've installed Ruby 1.9 and above.
357
444
 
358
- * +rake+
359
- * +rails+
360
- * +ruby-prof+
361
- * +rack+
362
- * +mysql+
445
+ h4. Using Ruby-Prof on MRI and REE
363
446
 
364
- If installing +mysql+ fails, you can try to install it manually:
447
+ Add Ruby-Prof to your applications' Gemfile if you want to benchmark/profile under MRI or REE:
365
448
 
366
- <shell>
367
- $ gcruby extconf.rb --with-mysql-config
368
- $ make && make install
369
- </shell>
449
+ <ruby>
450
+ gem 'ruby-prof', :path => 'git://github.com/wycats/ruby-prof.git'
451
+ </ruby>
370
452
 
371
- And you're ready to go. Don't forget to use +gcruby+ and +gcrake+ aliases when running the performance tests.
453
+ Now run +bundle install+ and you're ready to go.
372
454
 
373
455
  h3. Command Line Tools
374
456
 
@@ -376,55 +458,47 @@ Writing performance test cases could be an overkill when you are looking for one
376
458
 
377
459
  h4. +benchmarker+
378
460
 
379
- +benchmarker+ is a wrapper around Ruby's "Benchmark":http://ruby-doc.org/core/classes/Benchmark.html standard library.
380
-
381
461
  Usage:
382
462
 
383
463
  <shell>
384
- $ rails benchmarker [times] 'Person.expensive_way' 'Person.another_expensive_way' ...
385
- </shell>
386
-
387
- Examples:
388
-
389
- <shell>
390
- $ rails benchmarker 10 'Item.all' 'CouchItem.all'
464
+ Usage: rails benchmarker 'Ruby.code' 'Ruby.more_code' ... [OPTS]
465
+ -r, --runs N Number of runs.
466
+ Default: 4
467
+ -o, --output PATH Directory to use when writing the results.
468
+ Default: tmp/performance
469
+ -m, --metrics a,b,c Metrics to use.
470
+ Default: wall_time,memory,objects,gc_runs,gc_time
391
471
  </shell>
392
472
 
393
- If the +[times]+ argument is omitted, supplied methods are run just once:
473
+ Example:
394
474
 
395
475
  <shell>
396
- $ rails benchmarker 'Item.first' 'Item.last'
476
+ $ rails benchmarker 'Item.all' 'CouchItem.all' --runs 3 --metrics wall_time,memory
397
477
  </shell>
398
478
 
399
479
  h4. +profiler+
400
480
 
401
- +profiler+ is a wrapper around the "ruby-prof":http://ruby-prof.rubyforge.org gem.
402
-
403
481
  Usage:
404
482
 
405
483
  <shell>
406
- $ rails profiler 'Person.expensive_method(10)' [times] [flat|graph|graph_html]
484
+ Usage: rails benchmarker 'Ruby.code' 'Ruby.more_code' ... [OPTS]
485
+ -r, --runs N Number of runs.
486
+ Default: 1
487
+ -o, --output PATH Directory to use when writing the results.
488
+ Default: tmp/performance
489
+ --metrics a,b,c Metrics to use.
490
+ Default: process_time,memory,objects
491
+ -m, --formats x,y,z Formats to output to.
492
+ Default: flat,graph_html,call_tree
407
493
  </shell>
408
494
 
409
- Examples:
495
+ Example:
410
496
 
411
497
  <shell>
412
- $ rails profiler 'Item.all'
498
+ $ rails profiler 'Item.all' 'CouchItem.all' --runs 2 --metrics process_time --formats flat
413
499
  </shell>
414
500
 
415
- This will profile +Item.all+ in +RubyProf::WALL_TIME+ measure mode. By default, it prints flat output to the shell.
416
-
417
- <shell>
418
- $ rails profiler 'Item.all' 10 graph
419
- </shell>
420
-
421
- This will profile +10.times { Item.all }+ with +RubyProf::WALL_TIME+ measure mode and print graph output to the shell.
422
-
423
- If you want to store the output in a file:
424
-
425
- <shell>
426
- $ rails profiler 'Item.all' 10 graph 2> graph.txt
427
- </shell>
501
+ NOTE: Metrics and formats vary from interpreter to interpreter. Pass +--help+ to each tool to see the defaults for your interpreter.
428
502
 
429
503
  h3. Helper Methods
430
504
 
@@ -517,12 +591,13 @@ h4. Tutorials and Documentation
517
591
 
518
592
  h3. Commercial Products
519
593
 
520
- Rails has been lucky to have two startups dedicated to Rails specific performance tools:
594
+ Rails has been lucky to have a few companies dedicated to Rails-specific performance tools. A couple of those are:
521
595
 
522
596
  * "New Relic":http://www.newrelic.com
523
597
  * "Scout":http://scoutapp.com
524
598
 
525
599
  h3. Changelog
526
600
 
601
+ * March 30, 2011: Documented the recent improvements (multiple interpreters, options, etc) and necessary adjustments. Other minor improvements. "Gonçalo Silva":http://goncalossilva.com.
527
602
  * January 9, 2009: Complete rewrite by "Pratik":credits.html#lifo
528
603
  * September 6, 2008: Initial version by Matthew Bergman