help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-smalltalk] [PATCH] gst-profile


From: Derek Zhou
Subject: Re: [Help-smalltalk] [PATCH] gst-profile
Date: Thu, 26 Feb 2009 23:31:18 -0800
User-agent: KMail/1.9.9

On Wednesday 25 February 2009 01:16:45 am Paolo Bonzini wrote:
> This patch adds a gst-profile tool to use the profiler more easily.  Bug
> reports (Derek, can you reproduce the filein thing?) are welcome.
> 
> Paolo
> 

A few things:
1, scripts/Profile.st is not installed by default, gst-profile can not find it.

2, I highly recommending making no-separate-blocks the default. Consider the 
very common case like:
anArray do: [ :each | each doSomethingEasy ].
...
anotherArray do: [ :each | each doSomethingHard ].
The inclusive cost calculation assume each invocation cost roughly the same; 
but a do: method basically does nothing but evaluates blocks, and there can be 
huge variation and even false recursion, so if blocks are separated out the 
resulting inclusive cost calculation can be very skewed. On the other hand, if 
we lump the cost of block into the parent method it would appear that all 
blocks are inlined just like ifTrue:, etc, which is actually quite intuitive. 
Also the inclusive cost calculation would reflect the reality more. Yes, 
non-literal blocks will cause strange cost allocation but in most programs 
literal blocks outnumber non-literal block by a wide margin.    

3, this need to be done to avoid potential endless recursion:
address@hidden:~/src$ diff -u smalltalk/packages/profile/Profiler.st 
~smalltalk/packages/profile/Profiler.st
--- smalltalk/packages/profile/Profiler.st~     2009-02-26 22:10:43.000000000 
-0800
+++ smalltalk/packages/profile/Profiler.st      2009-02-26 22:32:51.000000000 
-0800
@@ -149,8 +149,9 @@
 
     totalCost [
         totalCost notNil ifTrue: [ ^totalCost ].
-       "TODO: handle loops better."
-        totalCost := calleeCounts keys inject: selfCost into: [ :old :callee |
+       "TODO: handle loops better. The assignment prevent endless recursion"
+        totalCost := selfCost.
+        totalCost := calleeCounts keys inject: totalCost into: [ :old :callee |
            old + (self costOf: callee) ].
        ^totalCost
     ]
Assignment to totalCost before diving in the call tree will make a potential 
recursive call terminate. Not the best way in the world but at least it won't 
bomb.  

4, yes, if there is fileIn inside the profiling block (which is guarantied with 
gst-profile) the 2 things I observed before still happen:
* Some methods get negative cost. I believe this is caused by somewhere inside 
fileIn the byteCounter is reset to 0. One way to work around it is do something 
like:
  MAX(_gst_bytecode_counter - _gst_saved_bytecode_counter, 0)
But it looks ugly.
* I still observed some crashes; and they disappeared if I manually invoke the 
profiler to avoid fileIns. The crashes are non-intuitive yet deterministic; 
same program will always crash the same way; and some superficial change to the 
program can make the crash to disappear or appear or move to another place. One 
workaround is to  change fileIn to always push/pop profiler around it but that 
feels ugly too.

Derek
  




reply via email to

[Prev in Thread] Current Thread [Next in Thread]