From e884f2b8325cbca9ca829d93b5b11aad1c9f7346 Mon Sep 17 00:00:00 2001 From: Mike Gunderloy Date: Tue, 4 Nov 2008 10:00:40 -0600 Subject: Regenerate recently-changed guides. --- .../guides/html/debugging_rails_applications.html | 74 ++++++++-------------- 1 file changed, 25 insertions(+), 49 deletions(-) (limited to 'railties/doc/guides/html/debugging_rails_applications.html') diff --git a/railties/doc/guides/html/debugging_rails_applications.html b/railties/doc/guides/html/debugging_rails_applications.html index d3a3180842..95f5b39e4c 100644 --- a/railties/doc/guides/html/debugging_rails_applications.html +++ b/railties/doc/guides/html/debugging_rails_applications.html @@ -340,10 +340,7 @@ http://www.gnu.org/software/src-highlite -->

You'll see something like this:

-
+
--- !ruby/object:Post
 attributes:
   updated_at: 2008-09-05 22:55:47
@@ -355,8 +352,8 @@ attributes:
 attributes_cache: {}
 
 
-Title: Rails debugging guide
-
+Title: Rails debugging guide +

1.2. to_yaml

Displaying an instance variable, or any other object or method, in yaml format can be achieved this way:

@@ -373,10 +370,7 @@ http://www.gnu.org/software/src-highlite -->

The to_yaml method converts the method to YAML format leaving it more readable, and then the simple_format helper is used to render each line as in the console. This is how debug method does its magic.

As a result of this, you will have something like this in your view:

-
+
--- !ruby/object:Post
 attributes:
 updated_at: 2008-09-05 22:55:47
@@ -387,8 +381,8 @@ id: "1"
 created_at: 2008-09-05 22:55:47
 attributes_cache: {}
 
-Title: Rails debugging guide
-
+Title: Rails debugging guide +

1.3. inspect

Another useful method for displaying object values is inspect, especially when working with arrays or hashes. This will print the object value as a string. For example:

@@ -404,14 +398,11 @@ http://www.gnu.org/software/src-highlite -->

Will be rendered as follows:

-
+
[1, 2, 3, 4, 5]
 
-Title: Rails debugging guide
-
+Title: Rails debugging guide +

1.4. Debugging Javascript

Rails has built-in support to debug RJS, to active it, set ActionView::Base.debug_rjs to true, this will specify whether RJS responses should be wrapped in a try/catch block that alert()s the caught exception (and then re-raises it).

To enable it, add the following in the Rails::Initializer do |config| block inside environment.rb:

@@ -529,11 +520,8 @@ http://www.gnu.org/software/src-highlite -->

Here's an example of the log generated by this method:

-
-
Processing PostsController#create (for 127.0.0.1 at 2008-09-08 11:52:54) [POST]
+
+
Processing PostsController#create (for 127.0.0.1 at 2008-09-08 11:52:54) [POST]
   Session ID: BAh7BzoMY3NyZl9pZCIlMDY5MWU1M2I1ZDRjODBlMzkyMWI1OTg2NWQyNzViZjYiCmZsYXNoSUM6J0FjdGl
 vbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhhc2h7AAY6CkB1c2VkewA=--b18cd92fba90eacf8137e5f6b3b06c4d724596a4
   Parameters: {"commit"=>"Create", "post"=>{"title"=>"Debugging Rails",
@@ -547,8 +535,8 @@ Post should be valid: true
  'I''m learning how to print in logs!!!', 'f', '2008-09-08 14:52:54')
 The post was saved and now is the user is going to be redirected...
 Redirected to #<Post:0x20af760>
-Completed in 0.01224 (81 reqs/sec) | DB: 0.00044 (3%) | 302 Found [http://localhost/posts]
-
+Completed in 0.01224 (81 reqs/sec) | DB: 0.00044 (3%) | 302 Found [http://localhost/posts] +

Adding extra logging like this makes it easy to search for unexpected or unusual behavior in your logs. If you add extra logging, be sure to make sensible use of log levels, to avoid filling your production logs with useless trivia.

3. Debugging with ruby-debug

@@ -581,12 +569,9 @@ http://www.gnu.org/software/src-highlite -->

If you see the message in the console or logs:

-
-
***** Debugger requested, but was not available: Start server with --debugger to enable *****
-
+
+
***** Debugger requested, but was not available: Start server with --debugger to enable *****
+

Make sure you have started your web server with the option —debugger:

+
set autolist
 set forcestep
-set listsize 25
-
+set listsize 25 +

4. Debugging Memory Leaks

@@ -1046,20 +1028,14 @@ http://www.gnu.org/software/src-highlite -->

Make sure to run a couple hundred requests to get better data samples, then press CTRL-C. The server will stop and Bleak House will produce a dumpfile in /tmp:

-
+
** BleakHouse: working...
 ** BleakHouse: complete
-** Bleakhouse: run 'bleak /tmp/bleak.5979.0.dump' to analyze.
-
+** Bleakhouse: run 'bleak /tmp/bleak.5979.0.dump' to analyze. +

To analyze it, just run the listed command. The top 20 leakiest lines will be listed:

-
+
  191691 total objects
   Final heap size 191691 filled, 220961 free
   Displaying top 20 most common line/class pairs
@@ -1071,8 +1047,8 @@ http://www.gnu.org/software/src-highlite -->
    951 /opt/local//lib/ruby/site_ruby/1.8/rubygems/version.rb:111:String
    935 /opt/local//lib/ruby/site_ruby/1.8/rubygems/specification.rb:557:String
    834 /opt/local//lib/ruby/site_ruby/1.8/rubygems/version.rb:146:Array
-  ...
-
+ ... +

This way you can find where your application is leaking memory and fix it.

If BleakHouse doesn't report any heap growth but you still have memory growth, you might have a broken C extension, or real leak in the interpreter. In that case, try using Valgrind to investigate further.

4.2. Valgrind

-- cgit v1.2.3