none
CLR Profiler API RRS feed

  • Question

  • Hello, I have some questions about CLR Profiler.

    I have functionId which I get from JITCompilationStarted callback.

    1. I want to be able to understand if it is a constructor, I can get name and compare it with ".ctor".

    2. I want to get class name and the assembly name.

    3. If class derives from specific class (lets say System.Object) in specific assembly (lets say mscorlib.dll), then print.

    Can you give me directions ?

    I have read MSDN documentation but I still don't understand which interfaces should I use.

    Thanks.

    Monday, February 11, 2013 6:51 PM

All replies

  • Hi NN,

    Welcome to the MSDN Forum.

    I am afraid you cannot get this information: http://msdn.microsoft.com/en-us/library/bb384576.aspx  

    A direct mapping no longer exists between a FunctionID and the ClassID it contains. Code-sharing optimizations can enable different instantiations of a generic type to share code. You can determine the ClassID of a FunctionID only when you examine them in the context of a particular activation of the function.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, February 13, 2013 7:18 AM
    Moderator
  • I see, but when I get into callback JITCompilationStarted, can't I get ClassID ?

    I can get class name, isn't it possible to get the class hierarchy ?

    Thnaks.
    Wednesday, February 13, 2013 7:34 AM
  • Hi NN,

    >>I can get class name, isn't it possible to get the class hierarchy ?

    I am afraid not.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, February 13, 2013 3:44 PM
    Moderator
  • Maybe you have any idea how to do something similar to what I wanted ?

    Maybe I can get class hierarchy from other callback , and then use it in JITCompilationStarted callback ?

    Friday, February 15, 2013 6:34 PM
  • It seems that CLR profile doesn't concern the hierarchy. You cannot get it through callback.

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

    Monday, February 18, 2013 8:32 AM
  • What about metadata information ?
    Can't I get it there ?

    Monday, February 18, 2013 4:21 PM
  • You can get the metadata information by ImetadataImport interface.

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

    Tuesday, February 19, 2013 1:51 PM
  • You can get the metadata information by ImetadataImport interface.

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

    How I do it ?

    I want to get full class hierarchy.


    Wednesday, February 20, 2013 9:56 AM
  • Is this not valid for some reason:

    HRESULT CorProfilerCallbackImpl::JITCompilationStarted(FunctionID functionIdBOOL fIsSafeToBlock)
    {
    	ClassID classId = 0;
    	ModuleID moduleId = 0;
    	mdToken metadataToken = 0;
    	corProfilerInfo->GetFunctionInfo(functionId, &classId, &moduleId, &metadataToken);
    }
    


    Wednesday, February 20, 2013 7:21 PM
  • It is written in MSDN that it won't work with generics :(

    The ClassID of a function on a generic class might not be obtainable without more contextual information about the use of the function. In this case, pClassId will be 0. Profiler code should use ICorProfilerInfo2::GetFunctionInfo2 with a COR_PRF_FRAME_INFO value to provide more context.

    Also I don't see how I get base class and all hierarchy.

    Wednesday, February 20, 2013 8:30 PM
  • Seems profiler cannot get this.

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

    Thursday, February 28, 2013 12:34 PM
  • Micah's code above is perfectly fine.

    Yes, you can absolutely go from a FunctionID to a ClassID, and Micah's code does that well.  The MSDN article quoted here is a bit misleading.  It's trying to say that when you go FunctionID->ClassID, that some type parameter information will be unavailable due to generics sharing.  So for a function like List<string>.foo() you might get a ClassID for List<__Canon> instead of List<string>.  Not completely precise, but good enough for the purposes of displaying information to your user, or for getting more information about the ClassID.  NN's scenario above should work just fine by using Micah's code.

    Thanks,
    Dave

    Monday, April 8, 2013 4:01 PM