tags:

views:

38

answers:

1

I'm working with a time sensitive desktop application that uses p/invoke extensively, and I want to make sure that the code is not wasting a lot of time on CAS stackwalks.

I have used the SuppressUnmanagedCodeSecurity attribute where I think it is necessary, but I might have missed a few places. Does anyone know if there is a way to monitor the number of CAS stackwalks that are occurring, and better yet pinpoint the source of the security demands?

A: 

You can use the Process Explorer tool (from Sysinternals) to monitor your process.

Bring up Process Explorer, select your process and right click to show "Properties". Then, on the .NET tab, select the .NET CLR Security object to monitor. Process Explorer will show counters for

  1. Total Runtime Checks
  2. # Link Time Checks
  3. % Time in RT Checks
  4. Stack Walk Depth

These are standard security performance counters described here -> http://msdn.microsoft.com/en-us/library/adcbwb64.aspx

You could also use Perfmon or write your own code to monitor these counters.

As far as I can tell, the only one that is really useful is item 1. You could keep an eye on that while you are debugging to see if it is increasing substantially. If so, you need to examine what is causing the security demands.

I don't know of any other tools that will tell you when a stackwalk is being triggered.