[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Van Dyk, Joe

11/30/2004 9:25:00 PM

Hi,

Still pretty new to Ruby and profiling. Are there any tools I can use to
analyze my Ruby program to see where it's spending the bulk of the CPU time?

Thanks,
Joe


11 Answers

Van Dyk, Joe

11/30/2004 9:36:00 PM

0

Joe Van Dyk wrote:
> Hi,
>
> Still pretty new to Ruby and profiling. Are there any
> tools I can use to analyze my Ruby program to see where
> it's spending the bulk of the CPU time?
>
> Thanks,
> Joe

I found the '-r profile' option. Are there any better tools out there?


Zach Dennis

11/30/2004 9:58:00 PM

0

Joe Van Dyk wrote:

> Hi,
>
> Still pretty new to Ruby and profiling. Are there any tools I can use to
> analyze my Ruby program to see where it's spending the bulk of the CPU time?
>

http://www.rubygarden.org/ruby?Rub...

zach


Brian Schröder

11/30/2004 10:04:00 PM

0

On Wed, 1 Dec 2004 06:52:47 +0900
"Joe Van Dyk" <joe.vandyk@boeing.com> wrote:

> Hi,
>
> Still pretty new to Ruby and profiling. Are there any tools I can use to
> analyze my Ruby program to see where it's spending the bulk of the CPU time?
>
> Thanks,
> Joe
>
>

ruby -rprofile -e'puts (1..200).inject(0) { | r, i | r + (-1)**i * 1.0 / i }'
-0.690653430481824
% cumulative self self total
time seconds seconds calls ms/call ms/call name
44.44 0.04 0.04 1 40.00 80.00 Range#each
22.22 0.06 0.02 200 0.10 0.10 Fixnum#**
22.22 0.08 0.02 200 0.10 0.10 Float#/
0.00 0.08 0.00 1 0.00 0.00 Fixnum#+
0.00 0.08 0.00 200 0.00 0.00 Fixnum#*
0.00 0.08 0.00 1 0.00 0.00 Kernel.puts
0.00 0.08 0.00 2 0.00 0.00 IO#write
0.00 0.08 0.00 199 0.00 0.00 Float#+
0.00 0.08 0.00 1 0.00 80.00 Enumerable.inject
0.00 0.08 0.00 1 0.00 90.00 #toplevel
0.00 0.08 0.00 1 0.00 0.00 Profiler__.start_profile
0.00 0.08 0.00 1 0.00 0.00 Float#to_s



--
Brian Schröder
http://www.brian-sch...



Florian Gross

11/30/2004 11:10:00 PM

0

Joe Van Dyk wrote:

> I found the '-r profile' option. Are there any better tools out there?

What new features would they provide?

Robert Klemme

12/1/2004 8:43:00 AM

0


"Brian Schröder" <ruby@brian-schroeder.de> schrieb im Newsbeitrag
news:20041130230416.6299104d@black.wg...
> On Wed, 1 Dec 2004 06:52:47 +0900
> "Joe Van Dyk" <joe.vandyk@boeing.com> wrote:
>
> > Hi,
> >
> > Still pretty new to Ruby and profiling. Are there any tools I can use
to
> > analyze my Ruby program to see where it's spending the bulk of the CPU
time?
> >
> > Thanks,
> > Joe
> >
> >
>
> ruby -rprofile -e'puts (1..200).inject(0) { | r, i | r + (-1)**i * 1.0
/ i }'
> -0.690653430481824
> % cumulative self self total
> time seconds seconds calls ms/call ms/call name
> 44.44 0.04 0.04 1 40.00 80.00 Range#each
> 22.22 0.06 0.02 200 0.10 0.10 Fixnum#**
> 22.22 0.08 0.02 200 0.10 0.10 Float#/
> 0.00 0.08 0.00 1 0.00 0.00 Fixnum#+
> 0.00 0.08 0.00 200 0.00 0.00 Fixnum#*
> 0.00 0.08 0.00 1 0.00 0.00 Kernel.puts
> 0.00 0.08 0.00 2 0.00 0.00 IO#write
> 0.00 0.08 0.00 199 0.00 0.00 Float#+
> 0.00 0.08 0.00 1 0.00 80.00 Enumerable.inject
> 0.00 0.08 0.00 1 0.00 90.00 #toplevel
> 0.00 0.08 0.00 1 0.00 0.00
Profiler__.start_profile
> 0.00 0.08 0.00 1 0.00 0.00 Float#to_s
>

And an example for benchmark usage:

require 'benchmark'
include Benchmark

N = 10000
sample = ("foulx" * 100).freeze

bm(20) do |b|
b.report("gsub!") do
N.times do
s = sample.dup
s.gsub!(/x/, 'u')
end
end

b.report("gsub") do
N.times do
s = sample.dup
s = s.gsub(/x/, 'u')
end
end
end


09:41:57 [robert.klemme]: ruby /c/temp/ruby/stringperf.rb
user system total real
gsub! 3.203000 0.000000 3.203000 ( 3.242000)
gsub 3.203000 0.000000 3.203000 ( 3.250000)

Regards

robert

Brian Schröder

12/1/2004 11:11:00 AM

0

On Wed, 1 Dec 2004 08:12:52 +0900
Florian Gross <flgr@ccan.de> wrote:

> Joe Van Dyk wrote:
>
> > I found the '-r profile' option. Are there any better tools out there?
>
> What new features would they provide?
>

Something I'm missing is to exclude certain statements and distinguish between
calls to the same method from different positions. If I profile any of my
progams I often get a result like

44.44 0.04 0.04 1 40.00 80.00 Array#each

where I'm using different Array#each's that I don't want to have mixed. (E.g.
for setup and then for the routine I want to profile.)

I could extract this cases into some extra class, but it would be nicer to tell
the profiler to discern between method call at line x and line y and not to
report method calls from line y.

Regards,

Brian

--
Brian Schröder
http://www.brian-sch...



Robert Klemme

12/1/2004 11:28:00 AM

0


"Brian Schröder" <ruby@brian-schroeder.de> schrieb im Newsbeitrag
news:20041201121041.6a44a927@black.wg...
> On Wed, 1 Dec 2004 08:12:52 +0900
> Florian Gross <flgr@ccan.de> wrote:
>
> > Joe Van Dyk wrote:
> >
> > > I found the '-r profile' option. Are there any better tools out
there?
> >
> > What new features would they provide?
> >
>
> Something I'm missing is to exclude certain statements and distinguish
between
> calls to the same method from different positions. If I profile any of
my
> progams I often get a result like
>
> 44.44 0.04 0.04 1 40.00 80.00 Array#each
>
> where I'm using different Array#each's that I don't want to have mixed.
(E.g.
> for setup and then for the routine I want to profile.)
>
> I could extract this cases into some extra class, but it would be nicer
to tell
> the profiler to discern between method call at line x and line y and not
to
> report method calls from line y.

Although that's certainly desirable, I see these problems:

- the profiler does take away some performance already and I suspect this
feature would lead to even greater slowdown.

- usability of the profiler will degenerate, you'll have to configure the
profiler somehow and the nice and simple "-r 'profile'" will not suffice
any more (at least not for those cases where filtering / discrimination is
applied).

In the meantime you can use benchmark or Time which both are less
intrusive. Or you follow your approach to put the code you're interested
in into a special method / class.

Kind regards

robert

djberg96

12/1/2004 2:36:00 PM

0

"Robert Klemme" <bob.news@gmx.net> wrote in message news:<315o70F37s1jeU1@individual.net>...
> "Brian Schröder" <ruby@brian-schroeder.de> schrieb im Newsbeitrag
> news:20041201121041.6a44a927@black.wg...
> > On Wed, 1 Dec 2004 08:12:52 +0900
> > Florian Gross <flgr@ccan.de> wrote:
> >
> > > Joe Van Dyk wrote:
> > >
> > > > I found the '-r profile' option. Are there any better tools out
> there?
> > >
> > > What new features would they provide?

There's RbProf (from AspectR), though I don't know what it's status is these days.

Regards,

Dan

Glenn Parker

12/1/2004 5:16:00 PM

0

Brian Schröder wrote:
>
> Something I'm missing is to exclude certain statements and distinguish between
> calls to the same method from different positions. If I profile any of my
> progams I often get a result like
>
> 44.44 0.04 0.04 1 40.00 80.00 Array#each
>
> where I'm using different Array#each's that I don't want to have mixed. (E.g.
> for setup and then for the routine I want to profile.)

In Quantify, my profiler of choice from the C/C++ world (now part of
Rational PurifyPlus), you get access to a full overlapping call-graph
for every profiled function. You can find precise information about
exactly which functions call other functions, and how much time any
called function contributes to the calling functions total. Navigating
the mass of data in the Quantify GUI has point-and-click simplicity.

It's really quite nice, with a lot of information made easy to navigate.
Worth a look if you want ideas on how to improve a profiler.

Here's a link to some (slightly out-of-date) documentation that gives a
good overview:

http://bmrc.berkeley.edu/purify/docs/html/installing_and_gettingstarted/4-qua...

--
Glenn Parker | glenn.parker-AT-comcast.net | <http://www.tetrafoi...


Jonas Arvidsson

12/2/2004 8:39:00 PM

0

> Joe Van Dyk wrote:
>> Hi,
>>
>> Still pretty new to Ruby and profiling. Are there any
>> tools I can use to analyze my Ruby program to see where
>> it's spending the bulk of the CPU time?
>>
>> Thanks,
>> Joe
>
> I found the '-r profile' option. Are there any better tools out there?
>

Hello,

I felt the need for something that pinpoints which lines in
MY code are bottlenecks, so I wrote profstack.rb, which is a lot
slower than profile.rb, but presents the calling stack for each
entry in the list. Something I find useful.

Perhaps there's a smarter way to do this. Redefining Symbol#id2name
seems very costly, but at least I was able to modify the behavior
of profile.rb without modifying profile.rb.

Regards,
--Jonas

# Include stack trace in profile report.
# By requiring this file, you get profile reporting like this:
#
# % cumulative self self total
# time seconds seconds calls ms/call ms/call name
# 47.37 34.17 34.17 1 34173.00 64813.00 Range#each
# file.rb:141 each
# file.rb:141 process
# file.rb:328

require 'profile'

class Symbol
alias_method :old_id2name, :id2name

def id2name
stack = ""
c = caller()
if c.to_s =~ /profiler\.rb/ # Have we been called by the profiler?
c.each { |frame|
next if frame =~ /profiler\.rb/ # Skip internal profiler frames
stack += "\n" + (" " * 54) + frame.to_s.sub(/:in `(.*)'$/, ' \1')
}
end
old_id2name() + stack
end
end