none
CLR Profiler - Getting stack trace of a thread RRS feed

  • Question

  • Hi,

    In my CLR profiler, i am currently getting the thread details such as threadId, thread name (id changed)and it's times.

     Additionally i would like to take the stack traces (w.r.t the threads) , which is the efficient way to get the stack trace.? Atleast to the depth of ten.

     I need to do this without having huge overhead on the running web application.

     I have come across the dostaksnapshot..! But i need to confirm if that is the rite way. Will that be an efficient solution.? (without making huge overhead or capturing the stack trace without blocking the threads).

    Wednesday, March 15, 2017 6:40 AM

Answers

All replies

  • DoStackSnapshot is the primary way of getting the stack trace, but it's not the only way. An alternative is to use the ELT and exception callbacks to maintain a shadow stack. The shadow stack may provide better performance if you need to get the stack trace frequently.

    https://blogs.msdn.microsoft.com/davbr/2005/10/06/profiler-stack-walking-basics-and-beyond/

    https://msdn.microsoft.com/en-us/library/bb384493(v=vs.110).aspx#Anchor_7

    Note: DoStackSnapshot cannot get generic type arguments, I believe generic type arguments are only available in the method 'enter' callback (or if you instrument the method).

    Wednesday, March 15, 2017 7:55 AM
  • Hi Brain,
    Thanks for your reply.

    I want to take stack traces frequently,I have profiler which builds a shadow stack by using the FunctionEnter2, FunctionLeave2, FunctionTailcall2.
    My web application(C#) have three functions. As mentioned below.

    public void CCC()
    {
     for (int i = 0; i < 5; i++)  
     {            
      for (int j = 0; j < 5000000; j++)   
       {   
             
       }       
     }  
    }  
    public void BBB()    
    {        
     CCC();
    }    
    public void AAA()    
    {        
     for (int i = 0; i < 5; i++)        
     {            
      for (int j = 0; j < 5000000; j++)            
      { }        
     }        
     BBB();    
    }

    if i have the nested for loop i can able to capture the function information in Enter,tail and leave method. If there is no for loop am not getting the callbacks.
    From the above code,I am getting enter callbacks for function AAA and CCC but not for BBB.

    Wednesday, March 22, 2017 9:39 AM
  • Sounds like BBB was inlined (inlined methods don't generate ELT callbacks). BBB looks like a good candidate for inlining, but I'm not sure why a loop in AAA would prevent BBB from being inlined.

    You can verify if it was inlined by checking the ICorProfilerCallback::JITInlining callback; this callback also gives you the option to veto the inlining, though COR_PRF_DISABLE_INLINING might be better if you intend to block all inlining.

    Wednesday, March 22, 2017 1:54 PM