[Pharo-project] Quickly getting the method call stack depth
Dear List, I was wondering whether there is a fast way to know the method call stack depth. Something like what follows does the job: -=-=-=-=-=-=-=-=-=-=-=-= | depth running | depth := 0. running := thisContext. [ running sender notNil ] whileTrue: [ running := running sender. depth := depth + 1]. depth -=-=-=-=-=-=-=-=-=-=-=-= But it is rather slow. Anyone has a suggestion? Cheers, Alexandre -- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
Maybe you could write a plugin/primitive to do the work? On 2010-03-02, at 3:50 PM, Alexandre Bergel wrote:
Dear List,
I was wondering whether there is a fast way to know the method call stack depth. Something like what follows does the job:
-=-=-=-=-=-=-=-=-=-=-=-= | depth running | depth := 0. running := thisContext. [ running sender notNil ] whileTrue: [ running := running sender. depth := depth + 1]. depth -=-=-=-=-=-=-=-=-=-=-=-=
But it is rather slow. Anyone has a suggestion?
Cheers, Alexandre -- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
-- =========================================================================== John M. McIntosh <johnmci@smalltalkconsulting.com> Twitter: squeaker68882 Corporate Smalltalk Consulting Ltd. http://www.smalltalkconsulting.com ===========================================================================
Will it be of any use for you? If yes, then I will do it. Alexandre On 2 Mar 2010, at 21:00, John M McIntosh wrote:
Maybe you could write a plugin/primitive to do the work?
On 2010-03-02, at 3:50 PM, Alexandre Bergel wrote:
Dear List,
I was wondering whether there is a fast way to know the method call stack depth. Something like what follows does the job:
-=-=-=-=-=-=-=-=-=-=-=-= | depth running | depth := 0. running := thisContext. [ running sender notNil ] whileTrue: [ running := running sender. depth := depth + 1]. depth -=-=-=-=-=-=-=-=-=-=-=-=
But it is rather slow. Anyone has a suggestion?
Cheers, Alexandre -- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
-- = = = = = ====================================================================== John M. McIntosh <johnmci@smalltalkconsulting.com> Twitter: squeaker68882 Corporate Smalltalk Consulting Ltd. http:// www.smalltalkconsulting.com = = = = = ======================================================================
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
-- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
Well it seems rather special purpose. What are you using it for? Why is the cost impacting your work? On 2010-03-02, at 4:06 PM, Alexandre Bergel wrote:
Will it be of any use for you? If yes, then I will do it.
Alexandre
On 2 Mar 2010, at 21:00, John M McIntosh wrote:
Maybe you could write a plugin/primitive to do the work?
On 2010-03-02, at 3:50 PM, Alexandre Bergel wrote:
Dear List,
I was wondering whether there is a fast way to know the method call stack depth. Something like what follows does the job:
-=-=-=-=-=-=-=-=-=-=-=-= | depth running | depth := 0. running := thisContext. [ running sender notNil ] whileTrue: [ running := running sender. depth := depth + 1]. depth -=-=-=-=-=-=-=-=-=-=-=-=
But it is rather slow. Anyone has a suggestion?
Cheers, Alexandre -- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
-- =========================================================================== John M. McIntosh <johnmci@smalltalkconsulting.com> Twitter: squeaker68882 Corporate Smalltalk Consulting Ltd. http://www.smalltalkconsulting.com ===========================================================================
Well it seems rather special purpose. What are you using it for? Why is the cost impacting your work?
There is an excellent paper at oopsla'09 that shows the method call graph can be effectively inferred using the method call stack depth: http://www-plan.cs.colorado.edu/klipto/mytkowicz-oopsla09.pdf Executing "[ running sender notNil ] whileTrue: [ running := running sender. depth := depth + 1]" before each method execution of my application terribly slows it down. Cheers, Alexandre
On 2010-03-02, at 4:06 PM, Alexandre Bergel wrote:
Will it be of any use for you? If yes, then I will do it.
Alexandre
On 2 Mar 2010, at 21:00, John M McIntosh wrote:
Maybe you could write a plugin/primitive to do the work?
On 2010-03-02, at 3:50 PM, Alexandre Bergel wrote:
Dear List,
I was wondering whether there is a fast way to know the method call stack depth. Something like what follows does the job:
-=-=-=-=-=-=-=-=-=-=-=-= | depth running | depth := 0. running := thisContext. [ running sender notNil ] whileTrue: [ running := running sender. depth := depth + 1]. depth -=-=-=-=-=-=-=-=-=-=-=-=
But it is rather slow. Anyone has a suggestion?
Cheers, Alexandre -- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
-- = = = = = ====================================================================== John M. McIntosh <johnmci@smalltalkconsulting.com> Twitter: squeaker68882 Corporate Smalltalk Consulting Ltd. http:// www.smalltalkconsulting.com = = = = = ======================================================================
-- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
Ah, well if you can build your own VM, then it would be easy to add as a named primitive. On 2010-03-02, at 4:34 PM, Alexandre Bergel wrote:
Well it seems rather special purpose. What are you using it for? Why is the cost impacting your work?
There is an excellent paper at oopsla'09 that shows the method call graph can be effectively inferred using the method call stack depth: http://www-plan.cs.colorado.edu/klipto/mytkowicz-oopsla09.pdf
Executing "[ running sender notNil ] whileTrue: [ running := running sender. depth := depth + 1]" before each method execution of my application terribly slows it down.
Cheers, Alexandre
-- =========================================================================== John M. McIntosh <johnmci@smalltalkconsulting.com> Twitter: squeaker68882 Corporate Smalltalk Consulting Ltd. http://www.smalltalkconsulting.com ===========================================================================
On Tue, Mar 2, 2010 at 4:34 PM, Alexandre Bergel <alexandre@bergel.eu>wrote:
Well it seems rather special purpose. What are you using it for? Why is the cost impacting your work?
There is an excellent paper at oopsla'09 that shows the method call graph can be effectively inferred using the method call stack depth: http://www-plan.cs.colorado.edu/klipto/mytkowicz-oopsla09.pdf
Executing "[ running sender notNil ] whileTrue: [ running := running sender. depth := depth + 1]" before each method execution of my application terribly slows it down.
If you did your own VM you could do something like - add a stack depth counter incremented and decremented on each call/return, voided on each non-local return, terminateTo: etc - cache it in a per-process inst var and store/restore it on process switch But this will be difficult to get right (e.g. delimited continuations, coroutines). could you cache it in various activations? e.g. something like Notification subclass: StackDepthQuery defaultAction ^nil Object methodsFor: performance monitoring cachingStackDepthDo: aBlock | home cachedStackDepth | home := thisContext. ^aBlock on: StackDepthQuery do: [:ex| ex proceedWith: (cachedStackDepth ifNil: [cachedStackDepth := self computeStackDepthFrom: home)] and then have StackDepthQuery count the stack frames as it searches for a handler. This is tricky because the exception machinery defers to ContextPart to do the search. You'd have to override a few methods. But this way you'd be able to cut short the counting adding cachingStackDepthDo:'s at suitable points until profiling showed the overhead was acceptable.
Cheers, Alexandre
On 2010-03-02, at 4:06 PM, Alexandre Bergel wrote:
Will it be of any use for you? If yes, then I will do it.
Alexandre
On 2 Mar 2010, at 21:00, John M McIntosh wrote:
Maybe you could write a plugin/primitive to do the work?
On 2010-03-02, at 3:50 PM, Alexandre Bergel wrote:
Dear List,
I was wondering whether there is a fast way to know the method call stack depth. Something like what follows does the job:
-=-=-=-=-=-=-=-=-=-=-=-= | depth running | depth := 0. running := thisContext. [ running sender notNil ] whileTrue: [ running := running sender. depth := depth + 1]. depth -=-=-=-=-=-=-=-=-=-=-=-=
But it is rather slow. Anyone has a suggestion?
Cheers, Alexandre -- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
-- = = = = = ====================================================================== John M. McIntosh <johnmci@smalltalkconsulting.com> Twitter: squeaker68882 Corporate Smalltalk Consulting Ltd. http:// www.smalltalkconsulting.com = = = = = ======================================================================
-- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
On Mar 3, 2010, at 1:34 AM, Alexandre Bergel wrote:
Well it seems rather special purpose. What are you using it for? Why is the cost impacting your work?
There is an excellent paper at oopsla'09 that shows the method call graph can be effectively inferred using the method call stack depth:
can you explain it a bit?
http://www-plan.cs.colorado.edu/klipto/mytkowicz-oopsla09.pdf
Executing "[ running sender notNil ] whileTrue: [ running := running sender. depth := depth + 1]" before each method execution of my application terribly slows it down.
Cheers, Alexandre
On 2010-03-02, at 4:06 PM, Alexandre Bergel wrote:
Will it be of any use for you? If yes, then I will do it.
Alexandre
On 2 Mar 2010, at 21:00, John M McIntosh wrote:
Maybe you could write a plugin/primitive to do the work?
On 2010-03-02, at 3:50 PM, Alexandre Bergel wrote:
Dear List,
I was wondering whether there is a fast way to know the method call stack depth. Something like what follows does the job:
-=-=-=-=-=-=-=-=-=-=-=-= | depth running | depth := 0. running := thisContext. [ running sender notNil ] whileTrue: [ running := running sender. depth := depth + 1]. depth -=-=-=-=-=-=-=-=-=-=-=-=
But it is rather slow. Anyone has a suggestion?
Cheers, Alexandre -- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
-- = = = = = ====================================================================== John M. McIntosh <johnmci@smalltalkconsulting.com> Twitter: squeaker68882 Corporate Smalltalk Consulting Ltd. http:// www.smalltalkconsulting.com = = = = = ======================================================================
-- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
On Tue, 2 Mar 2010, Alexandre Bergel wrote:
Well it seems rather special purpose. What are you using it for? Why is the cost impacting your work?
There is an excellent paper at oopsla'09 that shows the method call graph can be effectively inferred using the method call stack depth: http://www-plan.cs.colorado.edu/klipto/mytkowicz-oopsla09.pdf
Executing "[ running sender notNil ] whileTrue: [ running := running sender. depth := depth + 1]" before each method execution of my application terribly slows it down.
This is more than twice as fast, though it may be still too slow for your needs: | depth running | running := thisContext. depth := 1. [ (running := running instVarAt: 1) == nil ] whileFalse: [ depth := depth + 1 ]. depth Levente
Cheers, Alexandre
On 2010-03-02, at 4:06 PM, Alexandre Bergel wrote:
Will it be of any use for you? If yes, then I will do it.
Alexandre
On 2 Mar 2010, at 21:00, John M McIntosh wrote:
Maybe you could write a plugin/primitive to do the work?
On 2010-03-02, at 3:50 PM, Alexandre Bergel wrote:
Dear List,
I was wondering whether there is a fast way to know the method call stack depth. Something like what follows does the job:
-=-=-=-=-=-=-=-=-=-=-=-= | depth running | depth := 0. running := thisContext. [ running sender notNil ] whileTrue: [ running := running sender. depth := depth + 1]. depth -=-=-=-=-=-=-=-=-=-=-=-=
But it is rather slow. Anyone has a suggestion?
Cheers, Alexandre -- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
-- = = = = = ====================================================================== John M. McIntosh <johnmci@smalltalkconsulting.com> Twitter: squeaker68882 Corporate Smalltalk Consulting Ltd. http:// www.smalltalkconsulting.com = = = = = ======================================================================
-- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Indeed. Thanks!
This is more than twice as fast, though it may be still too slow for your needs:
| depth running | running := thisContext. depth := 1. [ (running := running instVarAt: 1) == nil ] whileFalse: [ depth := depth + 1 ]. depth
[ 100000 timesRepeat: [ | depth running | running := thisContext. depth := 1. [ (running := running instVarAt: 1) == nil ] whileFalse: [ depth := depth + 1 ]. depth ] ] timeToRun => 321 [ 100000 timesRepeat: [| depth running | depth := 0. running := thisContext. [ running sender notNil ] whileTrue: [ running := running sender. depth := depth + 1]. depth] ] timeToRun => 942 -- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
On 03.03.2010 21:35, Alexandre Bergel wrote:
Indeed. Thanks!
This is more than twice as fast, though it may be still too slow for your needs:
| depth running | running := thisContext. depth := 1. [ (running := running instVarAt: 1) == nil ] whileFalse: [ depth := depth + 1 ]. depth The paper talks about using stack pointer and program counter as identifiers, I doubt stack depth as returned by such a method will provide a good enough granularity to do proper disambiguation. (not to mention the main reason for using them is that they can be gotten with virtually no overhead...)
Cheers, Henry
The paper talks about using stack pointer and program counter as identifiers, I doubt stack depth as returned by such a method will provide a good enough granularity to do proper disambiguation. (not to mention the main reason for using them is that they can be gotten with virtually no overhead...)
Not only the stack depth. But the function identity is given by the compiled method reference. Associating the stack depth with the compiled method will do the job apparently. Cheers, Alexandre -- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
On 03.03.2010 22:21, Alexandre Bergel wrote:
The paper talks about using stack pointer and program counter as identifiers, I doubt stack depth as returned by such a method will provide a good enough granularity to do proper disambiguation. (not to mention the main reason for using them is that they can be gotten with virtually no overhead...) Not only the stack depth. But the function identity is given by the compiled method reference. Associating the stack depth with the compiled method will do the job apparently.
Cheers, Alexandre
Read a little past the abstract, and you'll understand what I was trying to tell you. Cheers, Henry
participants (6)
-
Alexandre Bergel -
Eliot Miranda -
Henrik Sperre Johansen -
John M McIntosh -
Levente Uzonyi -
Stéphane Ducasse