none
x64 CLR Profiler GetModuleMetaData failing with CORPROF_E_UNSUPPORTED_CALL_SEQUENCE RRS feed

  • Question

  • I've setup a basic profiler based on the CLRProfiler45 example.  I want to record the method, class name on the enter callback, however GetModuleMetaData fails with the HRESULT of 80131363.

    I understand that this is because my call is considered asynchronous and therefore not allowed.

    http://blogs.msdn.com/davbr/archive/2008/12/23/why-we-have-corprof-e-unsupported-call-sequence.aspx

    However, this article suggests if any of the event flags are set below then the slow-path will be used and therefore GetModuleMetaData should work.


    • COR_PRF_ENABLE_STACK_SNAPSHOT:  “Slow” ensures that the CLR has an opportunity to do some housekeeping on the stack before your profiler is called so that if your profiler calls DoStackSnapshot from within the ELT hook, then the stack walk will have a marker to begin from.
    • COR_PRF_ENABLE_FUNCTION_ARGS: “Slow” gives the CLR an opportunity to gather the function’s arguments on the stack for passing to the profiler’s enter hook.
    • COR_PRF_ENABLE_FUNCTION_RETVAL: “Slow” gives the CLR an opportunity to gather the function’s return value on the stack for passing to your profiler’s leave hook.
    • COR_PRF_ENABLE_FRAME_INFO: “Slow” gives the CLR an opportunity to gather generics information into a COR_PRF_FRAME_INFO parameter to pass to your profiler.

    I have added the following flag to my event mask to force the "slow-path" but still no luck.  What do I need to do force the
    "slow-path"?

    m_dwEventMask = (DWORD)COR_PRF_ENABLE_STACK_SNAPSHOT
    | (DWORD)COR_PRF_ENABLE_FUNCTION_ARGS
    | (DWORD)COR_PRF_MONITOR_GC
    | (DWORD)COR_PRF_MONITOR_OBJECT_ALLOCATED
    | (DWORD)COR_PRF_MONITOR_ENTERLEAVE
    | (DWORD)COR_PRF_MONITOR_CLASS_LOADS
    | (DWORD)COR_PRF_MONITOR_MODULE_LOADS
    | (DWORD)COR_PRF_MONITOR_ASSEMBLY_LOADS
    | (DWORD)COR_PRF_MONITOR_APPDOMAIN_LOADS
    | (DWORD)COR_PRF_MONITOR_SUSPENDS
    | (DWORD)COR_PRF_MONITOR_THREADS

    And the code in the enter callback.

    DebugBreak();
    ///////////////////////////////////////////////////////////////////////////
    Synchronize guard(g_pCallbackObject->m_criticalSection);
    ///////////////////////////////////////////////////////////////////////////  


    HRESULT hr = E_FAIL;

    ClassID classId = 0;
    ModuleID moduleId = 0;
    mdToken funcToken = mdTypeDefNil;
    WCHAR funName[MAX_LENGTH] = L"UNKNOWN";
    IMetaDataImport *pMDImport = NULL;
    mdTypeDef classToken = mdTypeDefNil;
    DWORD methodAttr = 0;
    PCCOR_SIGNATURE sigBlob = NULL;
    WCHAR className[MAX_LENGTH] = L"UNKNOWN";
    mdToken tkExtends = NULL;

    hr = g_pCallbackObject->m_pProfilerInfo2->GetFunctionInfo2(functionID,
    0, &classId,
    &moduleId,
    &funcToken, 0, NULL, NULL);

    hr = g_pCallbackObject->m_pProfilerInfo->GetModuleMetaData(moduleId,
    ofRead, 
    IID_IMetaDataImport, 
    (LPUNKNOWN *)&pMDImport);


    Here to stay


    • Edited by Steves0 Tuesday, April 25, 2017 11:30 AM
    Tuesday, April 25, 2017 11:26 AM

Answers

  • Thanks Cole

    I managed to get the information in a different place, the function mapper event.


    Here to stay

    • Marked as answer by Steves0 Tuesday, May 2, 2017 10:22 AM
    Tuesday, May 2, 2017 10:22 AM

All replies

  • Hi Steves,

    Please check if the result of dwEventMask as your want and try to modify the code like below and check if it works for you.

     DWORD dwEventMask = COR_PRF_ENABLE_STACK_SNAPSHOT
          | COR_PRF_ENABLE_OBJECT_ALLOCATED
          | COR_PRF_MONITOR_GC //GarbageCollectionStarted, GarbageCollectionFinished, MovedReferences, SurvivingReferences, ObjectReferences, ObjectsAllocatedByClass, RootReferences, HandleCreated, HandleDestroyed, and FinalizeableObjectQueued callbacks.
          | COR_PRF_MONITOR_OBJECT_ALLOCATED // Object
          /*<Modified>*/ | COR_PRF_MONITOR_ENTERLEAVE // method enter/leave
          /*</Modified>*/
          | COR_PRF_MONITOR_CLASS_LOADS // ClassLoad and ClassUnload 
          | COR_PRF_MONITOR_MODULE_LOADS // ModuleLoad, ModuleUnload, and ModuleAttachedToAssembly callbacks.
          | COR_PRF_MONITOR_ASSEMBLY_LOADS // AssemblyLoad and AssemblyUnload callbacks
          | COR_PRF_MONITOR_APPDOMAIN_LOADS // ModuleLoad, ModuleUnload, and ModuleAttachedToAssembly callbacks.
          | COR_PRF_MONITOR_SUSPENDS //Controls the RuntimeSuspend, RuntimeResume, RuntimeThreadSuspended, and RuntimeThreadResumed callbacks.
          | COR_PRF_MONITOR_THREADS // Controls the ThreadCreated, ThreadDestroyed, ThreadAssignedToOSThread, and ThreadNameChanged callbacks
          ;
    

    For more information, please refer to:

    https://blogs.msdn.microsoft.com/calvin_hsia/2014/02/26/see-how-often-your-code-runs-and-how-much-time-it-takes/

    Best regards,

    Cole Wu


    MSDN Community Support<br/> Please remember to click &quot;Mark as Answer&quot; the responses that resolved your issue, and to click &quot;Unmark as Answer&quot; if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact <a href="mailto:MSDNFSF@microsoft.com">MSDNFSF@microsoft.com</a>.

    Friday, April 28, 2017 8:01 AM
    Moderator
  • Thanks Cole

    I managed to get the information in a different place, the function mapper event.


    Here to stay

    • Marked as answer by Steves0 Tuesday, May 2, 2017 10:22 AM
    Tuesday, May 2, 2017 10:22 AM