locked
Wrapper method for the original method in the profiling API. RRS feed

  • Question

  • Hi,

    I have tried successfully to instrument methods of my interest where I put custom code in the beginning and end of a function using the Profiling API.

    But there are cases where I am not able to instrument end of a function because a function can be ended in many ways (several returns, exceptions). (tried but failed)

    I was thinking if I can create a new wrapper method for the original method and add the start and end custom method along with exceptions so that I need not worry about end function scenarios. 

    Is the wrapper method approach a good one...? If so please point me to what callback functions to be used and where to use it. 

    Any examples or articles to look into would be great. 

    -Jasper


    ..JPJ..

    Thursday, October 25, 2012 7:38 AM

Answers

  • What I would try is

    1) when your module is loaded (ModuleLoadFinished) modify your target class with a new method that matches the signature of your target method

    2) when your target method is loaded (JITCompilationStarted) rewrite it to call your new injected method with whatever surrounding prolog/epilog statements you require

    3) when your injected method (JITCompilationStarted) is loaded use the IL from your target method.

    Any examples or articles to look into would be great. 

    No articles, but I do similar to this in OpenCover (source on GitHub - look for the word cuckoo)

    Tuesday, October 30, 2012 12:20 AM

All replies

  • Hi Jasper,

    Based on my known, please try thishttp://balau82.wordpress.com/2010/10/06/trace-and-profile-function-calls-with-gcc/ 

    Have a nice day.


    Ghost,
    Call me ghost for short, Thanks
    To get the better answer, it should be a better question.

    Friday, October 26, 2012 12:31 PM
  • Thank you ghost for the suggestion, (ghost is a nice way to be called.. :))

    But I was wanting to know specifically based on the .NET profiling API. The ICorProfilerCallback stuff.


    ..JPJ..

    Friday, October 26, 2012 12:37 PM
  • Hi Jasper,

    I didn't find it in MSDN document.

    Have a nice day.


    Ghost,
    Call me ghost for short, Thanks
    To get the better answer, it should be a better question.

    Monday, October 29, 2012 9:27 AM
  • What I would try is

    1) when your module is loaded (ModuleLoadFinished) modify your target class with a new method that matches the signature of your target method

    2) when your target method is loaded (JITCompilationStarted) rewrite it to call your new injected method with whatever surrounding prolog/epilog statements you require

    3) when your injected method (JITCompilationStarted) is loaded use the IL from your target method.

    Any examples or articles to look into would be great. 

    No articles, but I do similar to this in OpenCover (source on GitHub - look for the word cuckoo)

    Tuesday, October 30, 2012 12:20 AM