I have a multithreaded C# program where I need to log how many ticks each thread spends in a specific spin wait lock.
I know there are methods for doing that from C
Look into StopWatch class which is based upon *QueryPerformance** APIs is precisely for this purpose.
MSDN:
The Stopwatch class assists the manipulation of timing-related performance counters within managed code. Specifically, the Frequency field and GetTimestamp method can be used in place of the unmanaged Win32 APIs QueryPerformanceFrequency and QueryPerformanceCounter.
Also results collected by Kristof Verbiest is worth a glipse.