views:

218

answers:

2

I want to test the profile usage of an important library-class of my rails-project. It uses ActiveRecord so I need all rails dependencies to profile it.

As far as I know, I need a patched ruby (rubygc) so script/profile and script/benchmark can track memory usage. I tried to follow this official guide to patch the source code of ruby 1.8.6 (p399) and 1.8.7 (p248), but both fail with the following message:

patching file gc.c
Hunk #2 succeeded at 50 with fuzz 2 (offset 2 lines).
Hunk #3 succeeded at 87 with fuzz 2 (offset 6 lines).
Hunk #4 succeeded at 153 with fuzz 1 (offset 45 lines).
Hunk #5 succeeded at 409 with fuzz 2 (offset 274 lines).
Hunk #6 FAILED at 462.
Hunk #7 FAILED at 506.
Hunk #8 FAILED at 520.
Hunk #9 FAILED at 745.
Hunk #10 FAILED at 754.
Hunk #11 FAILED at 923.
Hunk #12 succeeded at 711 (offset 46 lines).
Hunk #13 succeeded at 730 (offset 46 lines).
Hunk #14 succeeded at 766 (offset 55 lines).
Hunk #15 succeeded at 1428 (offset 87 lines).
Hunk #16 succeeded at 1492 (offset 89 lines).
Hunk #17 FAILED at 1541.
Hunk #18 FAILED at 1551.
Hunk #19 succeeded at 1571 (offset 91 lines).
Hunk #20 succeeded at 1592 (offset 91 lines).
Hunk #21 succeeded at 1601 (offset 91 lines).
Hunk #22 succeeded at 1826 (offset 108 lines).
Hunk #23 succeeded at 1843 (offset 108 lines).
Hunk #24 succeeded at 1926 (offset 108 lines).
Hunk #25 succeeded at 2118 (offset 108 lines).
Hunk #26 succeeded at 2563 (offset 100 lines).
Hunk #27 succeeded at 2611 with fuzz 1 (offset 102 lines).
Hunk #28 succeeded at 2628 (offset 102 lines).
8 out of 28 hunks FAILED -- saving rejects to file gc.c.rej
patching file intern.h
Hunk #1 succeeded at 268 (offset 15 lines).

I also tried to use ruby-prof, but I always get the error "uninitialized constant RubyProf::Test". I don't know how to use the gem "memory" and neither "memprof" nor "bleak_house" could be installed successfully.

If I get a patched ruby running, I should be fine. But any other possibility to profile the memory of library classes are welcome. Thanks for helping!

A: 

If you are on Windows you could try Ruby Memory Validator.

You could also try th original Ruby Memory Tracking API which some of the other ones are derived from. This works for any platform - but you'll have to build Ruby yourself (and call the API from C/C++ yourself).

Stephen Kellett
+1  A: 

I too was always getting that error with ruby-prof. There is a bug in the profile_test_helper.rb. If you change line 17 to read "require 'ruby-prof/test'" it should work.

http://github.com/jeremy/ruby-prof/issues#issue/5

korinthe
Wow that was of great help! Fixed my issue.Sorry for late respond, but used a workaround with ps in the meanwhile.Thanks a lot!
Florian Pilz