locked
Instrument methods in dynamic assemblies RRS feed

  • Question

  • I want to instrument methods which are defined in dynamic assemblies with Reflection.Emit. David Broman explained in his article [1]: “profilers are not allowed to instrument dynamic code generated via the Reflection.Emit namespace”. Is that the case for a single DynamicMethod or is it also true for complete assemblies created with DefineDynamicAssembly?

    While the JIT-Callbacks (e.g. JITCompilationStarted) are not invoked for DynamicMethods, they are invoked for methods defined in dynamic assemblies. This makes me wonder, if it is feasible to instrument these methods with the Profiling API.

    [1] http://blogs.msdn.com/b/davbr/archive/2011/10/10/rejit-limitations-in-net-4-5.aspx

    Thursday, October 4, 2012 2:00 PM

Answers

  • Hi, Bernhard.

    Unfortunately, you cannot use the Profiling API to instrument *any* dynamic code, whether it's full assemblies generated dynamically via Ref.Emit DefineDynamicAssembly or one-off DynamicMethods.  It's all off-limits.

    Thanks,
    Dave

    Thursday, October 11, 2012 11:44 PM

All replies

  • Hi BPruegl,

    Welcome to the MSDN Forum.

    Based on your description, it seems that you want to reflect the dynamic method. Am I right?

    I will try to involve some other one into this thread. Please wait it patiently.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, October 8, 2012 6:52 AM
    Moderator
  • Hi Mike,

    Yes, I want to replace the IL code in the callback “JITCompilationStarted”.for methods in dynamic assemblies.

    Thanks, Bernhard

    Monday, October 8, 2012 7:19 AM
  • Hi Bernhard,

    From David's blog, what I understand he ment to say by "profilers are not allowed to instrument dynamic code generated via the Reflection.Emit namespace" is when you instrument dynamic code (IL), it has to be through the native layer i.e. Profiler APIs and not Reflection.Emit. So in other words, profiling API can only be used by native code. You cannot use managed code (Reflection.Emit) to do your instrumentation.

    Thanks,

    Gaurav (MSFT)

    Thursday, October 11, 2012 8:26 PM
  • Hi, Bernhard.

    Unfortunately, you cannot use the Profiling API to instrument *any* dynamic code, whether it's full assemblies generated dynamically via Ref.Emit DefineDynamicAssembly or one-off DynamicMethods.  It's all off-limits.

    Thanks,
    Dave

    Thursday, October 11, 2012 11:44 PM