Detect when audio thread is taking too long

I’m working with procedural audio generation using OnAudioFilterRead(). When this method is implemented you can see a VU meter along with a measurement of processing time.

From the docs it reads “The process time of the filter is also measured and the spent milliseconds will show up next to the VU Meter (it turns red if the filter is taking up too much time, so the mixer will starve audio data)”

I want to use this measured time to detect slow downs and use cheaper methods when necessary. However, nothing seems to indicate how to read this measured time or even how to measure time manually inside the audio thread.

Either solution works for me, any help to point me in the right direction would be much appreciated!

So I finally tracked down a solution. The answer came from looking into c# a little further, specifically at Stopwatch. My only worry is that the frequency is too low on certain hardware, but it seems to be working so far. Plus, it seems to be using cycle ticks so I imagine it’s as fine grained a timer as you can get.