title: Optimizing Stack-Walking performance
body: <p>Currently i use the <b>dbghelp</b> library to walk through the stack of some process' thread (using <b>GetThreadContext()</b> and <b>StackWalk64()</b>) and collect only the return addresses each frame contains.</p>
  
  <p>However, the overhead of doing so is too big for the systems demands - overall time is apx. 5 msec per stack walk (with 10-15 frames). This time includes the GetThreadContext() and the loop which calls StackWalk64() to get all the frames.</p>
  
  <p>Anyhow, I must find a way to do it much much faster. Anyone has any idea how can i do that?</p>
  
  <hr>
  
  <h3>Edit:</h3>
  
  <p>Does anyone know of the ETW (Event Tracing for Windows) mechanism? </p>
  
  <p>If so, how can I trace all the context switches that happened in a certain period of time?
  Is there an event provider that publishes an event on each context switch?</p>