[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: Improvements to the profiler [Was Re: profile]

Lothar Scholz

12/1/2004 12:24:00 PM

Hello Robert,


RK> "Brian Schröder" <ruby@brian-schroeder.de> schrieb im Newsbeitrag
RK> 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
RK> there?
>> >
>> > What new features would they provide?
>> >
>>
>> Something I'm missing is to exclude certain statements and distinguish
RK> between
>> calls to the same method from different positions. If I profile any of
RK> 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.
RK> (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
RK> to tell
>> the profiler to discern between method call at line x and line y and not
RK> to
>> report method calls from line y.

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

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

Even at the moment the profiler is at a proof of concept level and absolute
unusable in programs that do a little bit more then "puts 'hello
world'". It slows down a program by at least a factor 50.

Every solution that is based on "set_trace_func" is in my opinion just
rubbish. try this with an empty proc and see how it slows down the
program and you will understand.

-----------------------------------
require "rexml/document"
$a = 0

set_trace_func proc { |event, file, line, id, binding, klass, *rest|
$a += 1
}

a = Time.new
doc = REXML::Document.new File.new( "z:/work/eiffel/agui/build.eant" )
b = Time.new

print "Time : " , b - a, "\n"
print "Calls : " , $a, "\n"
-----------------------------------

Slows down 58 times. Add something more then a siple counter to
trace_func and you get 100 times slowdown. I have a prototype for a
ruby profiler for ArachnoRuby that only slows down 30% and gives much
much more detailed measurements.


--
Best regards, emailto: scholz at scriptolutions dot com
Lothar Scholz http://www.ru...
CTO Scriptolutions Ruby, PHP, Python IDE 's




11 Answers

Robert Klemme

12/1/2004 12:48:00 PM

0


"Lothar Scholz" <mailinglists@scriptolutions.com> schrieb im Newsbeitrag
news:13616401843.20041201132350@scriptolutions.com...

> RK> - the profiler does take away some performance already and I
suspect this
> RK> feature would lead to even greater slowdown.
>
> Even at the moment the profiler is at a proof of concept level and
absolute
> unusable in programs that do a little bit more then "puts 'hello
> world'". It slows down a program by at least a factor 50.
>
> Every solution that is based on "set_trace_func" is in my opinion just
> rubbish. try this with an empty proc and see how it slows down the
> program and you will understand.

I *have* in fact used the profiler already. I would not go so far as to
call it "rubbish". It has its use although I'd readily admit that it's
limited. But it's not rubbish. Java's hprof with cpu=times has similar
bad impacts on overall performance but it is useful in certain situations.
(I admit though that I use cpu=samples most of the time :-))

Kind regards

robert

Jamis Buck

12/1/2004 2:51:00 PM

0

Lothar Scholz wrote:

> Slows down 58 times. Add something more then a siple counter to
> trace_func and you get 100 times slowdown. I have a prototype for a
> ruby profiler for ArachnoRuby that only slows down 30% and gives much
> much more detailed measurements.

Are you going to leave us in suspense, then, or are you going to tell us
how we can get our hands on this profiler of yours? :) Or is it not
available outside of ArachnoRuby?

- Jamis


--
Jamis Buck
jgb3@email.byu.edu
http://www.jamisbuck...


Stephen Kellett

12/1/2004 3:14:00 PM

0

In message <41ADDA1C.9090300@byu.edu>, Jamis Buck <jamis_buck@byu.edu>
writes
>Are you going to leave us in suspense, then, or are you going to tell
>us how we can get our hands on this profiler of yours? :) Or is it not
>available outside of ArachnoRuby?

Took me about 30 seconds to find it with Google.

http://www.ruby-ide.com/downloa...

Stephen
--
Stephen Kellett
Object Media Limited http://www.objmedia.d...
RSI Information: http://www.objmedia.d.../rsi.html

Jamis Buck

12/1/2004 3:44:00 PM

0

Stephen Kellett wrote:
> In message <41ADDA1C.9090300@byu.edu>, Jamis Buck <jamis_buck@byu.edu>
> writes
>
>> Are you going to leave us in suspense, then, or are you going to tell
>> us how we can get our hands on this profiler of yours? :) Or is it not
>> available outside of ArachnoRuby?
>
>
> Took me about 30 seconds to find it with Google.
>
> http://www.ruby-ide.com/downloa...
>

Clever, but I was looking for just the profiler, not the IDE. I was
curious as to whether the profiler was available separately.

- Jamis

--
Jamis Buck
jgb3@email.byu.edu
http://www.jamisbuck...


Charles Mills

12/1/2004 3:45:00 PM

0

On Dec 1, 2004, at 4:52 AM, Robert Klemme wrote:

>
> "Lothar Scholz" <mailinglists@scriptolutions.com> schrieb im
> Newsbeitrag
> news:13616401843.20041201132350@scriptolutions.com...
>
>> RK> - the profiler does take away some performance already and I
> suspect this
>> RK> feature would lead to even greater slowdown.
>>
>> Even at the moment the profiler is at a proof of concept level and
> absolute
>> unusable in programs that do a little bit more then "puts 'hello
>> world'". It slows down a program by at least a factor 50.
>>
>> Every solution that is based on "set_trace_func" is in my opinion just
>> rubbish. try this with an empty proc and see how it slows down the
>> program and you will understand.
>
> I *have* in fact used the profiler already. I would not go so far as
> to
> call it "rubbish". It has its use although I'd readily admit that it's
> limited. But it's not rubbish. Java's hprof with cpu=times has
> similar
> bad impacts on overall performance but it is useful in certain
> situations.
> (I admit though that I use cpu=samples most of the time :-))
>
A little while back I told someone who was looking to speed up a Ruby
script to run it with the profiler.... they thought the profiler was
broken, because it took so long :)
A 10 second script turned into 5-10 minutes. But in the end it did
work and helped us tune the program and get some very significant speed
ups... which is what matters.
On a side note, in my experience object creation and garbage collection
(something that isn't really measured by the profiler) seems to have
the biggest impact on speed. If you can reduce the number of objects
created, the GC spends less time marking and sweeping objects.

-Charlie



Robert Klemme

12/1/2004 4:00:00 PM

0


"Charles Mills" <cmills@freeshell.org> schrieb im Newsbeitrag
news:E23078B9-43AF-11D9-AA47-000A95A27A10@freeshell.org...
> On Dec 1, 2004, at 4:52 AM, Robert Klemme wrote:
>
> >
> > "Lothar Scholz" <mailinglists@scriptolutions.com> schrieb im
> > Newsbeitrag
> > news:13616401843.20041201132350@scriptolutions.com...
> >
> >> RK> - the profiler does take away some performance already and I
> > suspect this
> >> RK> feature would lead to even greater slowdown.
> >>
> >> Even at the moment the profiler is at a proof of concept level and
> > absolute
> >> unusable in programs that do a little bit more then "puts 'hello
> >> world'". It slows down a program by at least a factor 50.
> >>
> >> Every solution that is based on "set_trace_func" is in my opinion
just
> >> rubbish. try this with an empty proc and see how it slows down the
> >> program and you will understand.
> >
> > I *have* in fact used the profiler already. I would not go so far as
> > to
> > call it "rubbish". It has its use although I'd readily admit that
it's
> > limited. But it's not rubbish. Java's hprof with cpu=times has
> > similar
> > bad impacts on overall performance but it is useful in certain
> > situations.
> > (I admit though that I use cpu=samples most of the time :-))
> >
> A little while back I told someone who was looking to speed up a Ruby
> script to run it with the profiler.... they thought the profiler was
> broken, because it took so long :)

If you have suspects and the profiler slows down too much, you can even
time manually with a helper method like this:

module Kernel
private
def time(msg)
t = Time.now.to_f
begin
return yield
ensure
t = Time.now.to_f - t
$stderr.puts "#{msg} took #{t} sec"
end
end
end

>> time("print 100 x") { 100.times { print "x" } ; puts }
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxx
print 100 x took 0.00399994850158691 sec
=> nil

> A 10 second script turned into 5-10 minutes. But in the end it did
> work and helped us tune the program and get some very significant speed
> ups... which is what matters.

!

> On a side note, in my experience object creation and garbage collection
> (something that isn't really measured by the profiler) seems to have
> the biggest impact on speed. If you can reduce the number of objects
> created, the GC spends less time marking and sweeping objects.

Yeah, it's the same with Java.

Kind regards

robert

Michael Neumann

12/1/2004 4:08:00 PM

0

Robert Klemme schrieb:
> "Charles Mills" <cmills@freeshell.org> schrieb im Newsbeitrag
> news:E23078B9-43AF-11D9-AA47-000A95A27A10@freeshell.org...
>
>>On Dec 1, 2004, at 4:52 AM, Robert Klemme wrote:
>>
>>
>>>"Lothar Scholz" <mailinglists@scriptolutions.com> schrieb im
>>>Newsbeitrag
>>>news:13616401843.20041201132350@scriptolutions.com...
>>>
>>>
>>>>RK> - the profiler does take away some performance already and I
>>>
>>>suspect this
>>>
>>>>RK> feature would lead to even greater slowdown.
>>>>
>>>>Even at the moment the profiler is at a proof of concept level and
>>>
>>>absolute
>>>
>>>>unusable in programs that do a little bit more then "puts 'hello
>>>>world'". It slows down a program by at least a factor 50.
>>>>
>>>>Every solution that is based on "set_trace_func" is in my opinion
>
> just
>
>>>>rubbish. try this with an empty proc and see how it slows down the
>>>>program and you will understand.
>>>
>>>I *have* in fact used the profiler already. I would not go so far as
>>>to
>>>call it "rubbish". It has its use although I'd readily admit that
>
> it's
>
>>>limited. But it's not rubbish. Java's hprof with cpu=times has
>>>similar
>>>bad impacts on overall performance but it is useful in certain
>>>situations.
>>>(I admit though that I use cpu=samples most of the time :-))
>>>
>>
>>A little while back I told someone who was looking to speed up a Ruby
>>script to run it with the profiler.... they thought the profiler was
>>broken, because it took so long :)
>
>
> If you have suspects and the profiler slows down too much, you can even
> time manually with a helper method like this:
>
> module Kernel
> private
> def time(msg)
> t = Time.now.to_f
> begin
> return yield
> ensure
> t = Time.now.to_f - t
> $stderr.puts "#{msg} took #{t} sec"
> end
> end
> end

Or just use 'benchmark' (sorry, I've currently no Ruby reference here,
look up ri Benchmark or lib/benchmark.rb for reference).

Regards,

Michael


Charles Mills

12/1/2004 4:44:00 PM

0

On Dec 1, 2004, at 8:08 AM, Michael Neumann wrote:

> Or just use 'benchmark' (sorry, I've currently no Ruby reference here,
> look up ri Benchmark or lib/benchmark.rb for reference).
>

I think benchmarking (and testing) are good way to make sure your
"speed ups" are really doing what they are suppose to do.... you can't
really do that with the profiler, because it distorts a scripts elapsed
time so much.

-Charlie



gabriele renzi

12/1/2004 7:56:00 PM

0

Jamis Buck ha scritto:
> Stephen Kellett wrote:
>
>> In message <41ADDA1C.9090300@byu.edu>, Jamis Buck <jamis_buck@byu.edu>
>> writes
>>
>>> Are you going to leave us in suspense, then, or are you going to tell
>>> us how we can get our hands on this profiler of yours? :) Or is it
>>> not available outside of ArachnoRuby?
>>
>>
>>
>> Took me about 30 seconds to find it with Google.
>>
>> http://www.ruby-ide.com/downloa...
>>
>
> Clever, but I was looking for just the profiler, not the IDE. I was
> curious as to whether the profiler was available separately.
>

IIRC there was a patch to ruby on the site from arachno ruby aimed at
speeding up debugging (maybe profiling too).
There is a little text about it on http://www.ruby-ide.com/ru...
(I have the impression that it was downloadable but I may be wrong)

Lothar Scholz

12/1/2004 8:48:00 PM

0

Hello gabriele,

gr> Jamis Buck ha scritto:
>> Stephen Kellett wrote:
>>
>>> In message <41ADDA1C.9090300@byu.edu>, Jamis Buck <jamis_buck@byu.edu>
>>> writes
>>>
>>>> Are you going to leave us in suspense, then, or are you going to tell
>>>> us how we can get our hands on this profiler of yours? :) Or is it
>>>> not available outside of ArachnoRuby?
>>>
>>>
>>>
>>> Took me about 30 seconds to find it with Google.
>>>
>>> http://www.ru.../downloa...
>>>
>>
>> Clever, but I was looking for just the profiler, not the IDE. I was
>> curious as to whether the profiler was available separately.
>>

gr> IIRC there was a patch to ruby on the site from argr> achno ruby aimed at
gr> speeding up debugging (maybe profiling too).

No profiling available at the moment. The idea is simple: just record
line number and pointer to the file name and the clock value in the C
code that calls the trace function before the binding is created
(which is the most expensive operation when executing the trace function).

This gathered data is then analysed later, when the buffer is full or
at end of the program.

The current pure ruby profiler tries to analyse the profiler data always
on the fly which reduces speed even more.

gr> There is a little text about it on
gr> http://www.ru.../ru...
gr> (I have the impression that it was downloadable but I may be wrong)

http://www.ru.../downloads/diff-against-ruby...


--
Best regards, emailto: scholz at scriptolutions dot com
Lothar Scholz http://www.ru...
CTO Scriptolutions Ruby, PHP, Python IDE 's