Tracking method in and out with MetaLinks

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Tracking method in and out with MetaLinks

Manuel Leuenberger
Hi,

I stumbled upon another MetaLink scenario that I am unsure how to implement. I want to track method invocations, with receiver, arguments, selector, and return value (maybe even signaled exception). I can track the method input with a MetaLink installed on an RBMethodNode like this:

MetaLink new
    metaObject: [ :c | Transcript show: c receiver; show: c method selector; show: c arguments; cr ];
    selector: #value:;
    arguments: #(context).

and for returns with a MetaLink on RBReturnNodes like this:

MetaLink new
    metaObject: [ :v | Transcript show: v; cr ];
    selector: #value:;
    arguments: #(value)

The problem is though, that not all methods have explicit returns, and some mix explicit returns and self returns. I tried installed an #after MetaLink on a RBMethodNode, but this fails in many cases. Is there any way that I can instrument a method and track receiver, selector, arguments, and returned value (even if self) at the same time?

Cheers,
Manuel
Reply | Threaded
Open this post in threaded view
|

Re: Tracking method in and out with MetaLinks

Marcus Denker-4


> On 23 Nov 2018, at 13:40, Manuel Leuenberger <[hidden email]> wrote:
>
> Hi,
>
> I stumbled upon another MetaLink scenario that I am unsure how to implement. I want to track method invocations, with receiver, arguments, selector, and return value (maybe even signaled exception). I can track the method input with a MetaLink installed on an RBMethodNode like this:
>
> MetaLink new
>    metaObject: [ :c | Transcript show: c receiver; show: c method selector; show: c arguments; cr ];
>    selector: #value:;
>    arguments: #(context).
>
> and for returns with a MetaLink on RBReturnNodes like this:
>
> MetaLink new
>    metaObject: [ :v | Transcript show: v; cr ];
>    selector: #value:;
>    arguments: #(value)
>
> The problem is though, that not all methods have explicit returns, and some mix explicit returns and self returns. I tried installed an #after MetaLink on a RBMethodNode, but this fails in many cases. Is there any way that I can instrument a method and track receiver, selector, arguments, and returned value (even if self) at the same time?
>

I am working now on making the #after work so that one can get with #value the return of the method…

I now have a version where it works for Message Sends correctly *and* were #after on Method works better (the compilation errors should be fixed).

But  #value for #after on Method needs some more work… soon!

I will commit this intermediate step now.

        Marcus


Reply | Threaded
Open this post in threaded view
|

Re: Tracking method in and out with MetaLinks

Manuel Leuenberger
Awesome! I am looking forward to it.

Cheers,
Manuel

On 23 Nov 2018, at 14:59, Marcus Denker <[hidden email]> wrote:



On 23 Nov 2018, at 13:40, Manuel Leuenberger <[hidden email]> wrote:

Hi,

I stumbled upon another MetaLink scenario that I am unsure how to implement. I want to track method invocations, with receiver, arguments, selector, and return value (maybe even signaled exception). I can track the method input with a MetaLink installed on an RBMethodNode like this:

MetaLink new
  metaObject: [ :c | Transcript show: c receiver; show: c method selector; show: c arguments; cr ];
  selector: #value:;
  arguments: #(context).

and for returns with a MetaLink on RBReturnNodes like this:

MetaLink new
  metaObject: [ :v | Transcript show: v; cr ];
  selector: #value:;
  arguments: #(value)

The problem is though, that not all methods have explicit returns, and some mix explicit returns and self returns. I tried installed an #after MetaLink on a RBMethodNode, but this fails in many cases. Is there any way that I can instrument a method and track receiver, selector, arguments, and returned value (even if self) at the same time?


I am working now on making the #after work so that one can get with #value the return of the method… 

I now have a version where it works for Message Sends correctly *and* were #after on Method works better (the compilation errors should be fixed).

But  #value for #after on Method needs some more work… soon!

I will commit this intermediate step now.

Marcus

Reply | Threaded
Open this post in threaded view
|

Re: Tracking method in and out with MetaLinks

Marcus Denker-4
In reply to this post by Marcus Denker-4


> On 23 Nov 2018, at 14:59, Marcus Denker <[hidden email]> wrote:
>
>
>
>> On 23 Nov 2018, at 13:40, Manuel Leuenberger <[hidden email]> wrote:
>>
>> Hi,
>>
>> I stumbled upon another MetaLink scenario that I am unsure how to implement. I want to track method invocations, with receiver, arguments, selector, and return value (maybe even signaled exception). I can track the method input with a MetaLink installed on an RBMethodNode like this:
>>
>> MetaLink new
>>   metaObject: [ :c | Transcript show: c receiver; show: c method selector; show: c arguments; cr ];
>>   selector: #value:;
>>   arguments: #(context).
>>
>> and for returns with a MetaLink on RBReturnNodes like this:
>>
>> MetaLink new
>>   metaObject: [ :v | Transcript show: v; cr ];
>>   selector: #value:;
>>   arguments: #(value)
>>
>> The problem is though, that not all methods have explicit returns, and some mix explicit returns and self returns. I tried installed an #after MetaLink on a RBMethodNode, but this fails in many cases. Is there any way that I can instrument a method and track receiver, selector, arguments, and returned value (even if self) at the same time?
>>
>
> I am working now on making the #after work so that one can get with #value the return of the method…
>
> I now have a version where it works for Message Sends correctly *and* were #after on Method works better (the compilation errors should be fixed).
>
> But  #value for #after on Method needs some more work… soon!
>
> I will commit this intermediate step now.
>

Here is the first step:

https://github.com/pharo-project/pharo/pull/2011

        • #operation for send after
        • #operation and value for {} arrays
        • #after hooks: preamble now executed before the operation
        • #after hooks: added concept of postamble, executed just before hook

Next I need to look into #value for #after on methods. This got broken because we wrap the whole method in an exception handler (as #after should be called even if
an exception happens).

But this adds too much complexity… especially how it is done now. I think I will simplify that in a next step.

        Marcus



Reply | Threaded
Open this post in threaded view
|

Re: Tracking method in and out with MetaLinks

Pharo Smalltalk Users mailing list


On 23 Nov 2018, at 15:19, Marcus Denker <[hidden email]> wrote:



On 23 Nov 2018, at 14:59, Marcus Denker <[hidden email]> wrote:



On 23 Nov 2018, at 13:40, Manuel Leuenberger <[hidden email]> wrote:

Hi,

I stumbled upon another MetaLink scenario that I am unsure how to implement. I want to track method invocations, with receiver, arguments, selector, and return value (maybe even signaled exception). I can track the method input with a MetaLink installed on an RBMethodNode like this:

MetaLink new
 metaObject: [ :c | Transcript show: c receiver; show: c method selector; show: c arguments; cr ];
 selector: #value:;
 arguments: #(context).

and for returns with a MetaLink on RBReturnNodes like this:

MetaLink new
 metaObject: [ :v | Transcript show: v; cr ];
 selector: #value:;
 arguments: #(value)

The problem is though, that not all methods have explicit returns, and some mix explicit returns and self returns. I tried installed an #after MetaLink on a RBMethodNode, but this fails in many cases. Is there any way that I can instrument a method and track receiver, selector, arguments, and returned value (even if self) at the same time?


I am working now on making the #after work so that one can get with #value the return of the method… 

I now have a version where it works for Message Sends correctly *and* were #after on Method works better (the compilation errors should be fixed).

But  #value for #after on Method needs some more work… soon!


#value for methods should now work with this PR loaded:


This is implemented by compiling a wrapped method for #after (just as we do for primitives).

Marcus

Reply | Threaded
Open this post in threaded view
|

Re: Tracking method in and out with MetaLinks

Marcus Denker-4
In reply to this post by Marcus Denker-4
>>>
>>> I am working now on making the #after work so that one can get with #value the return of the method…
>>>
>>> I now have a version where it works for Message Sends correctly *and* were #after on Method works better (the compilation errors should be fixed).
>>>
>>> But  #value for #after on Method needs some more work… soon!
>>>
>
> #value for methods should now work with this PR loaded:
>
> https://github.com/pharo-project/pharo/pull/2012
>
> This is implemented by compiling a wrapped method for #after (just as we do for primitives).
>
tests are green, so I merged it…

But I keep https://pharo.fogbugz.com/f/cases/22681/Metalink-on-message-may-break-compilation open for now:

TODO for that issue:

- test if the use case shown in this issue now works

- write a test with the meta link from this issue to make sure this will not break in the future
(the test should just apply it to an example, not  a whole package, though. For speed)

        Marcus