I have a piece of code (.NET4 C#) that should run in tight loop - other threads asynchronously serve information to the thread with this loop and process it's commands. The code is in average fast enough (100 - 200 microseconds) but about once every 2 seconds it takes more, usually around 15ms.
These peaks do not much alter the average but I'd like to find in which parts of code they happen - I don't care about the average but rather about the worst-case execution time. Are there any tools to gather such info? I have tried dotTrace but with no luck, it shows just the average and I'd like to ignore most of the cases.
There is always an option to write my own profilers using stopwatch etc. but deploying these all over the code is rather clumsy.
Note: I know that I should expect some context-switches causing these peaks with busy loop but the code is ran on 24-core server dedicated to this application. Therefore, I hope I can somehow reduce them to minimum.
Did you also try ANTS? Link: http://www.red-gate.com/products/dotnet-development/ants-performance-profiler/ The figures it gives you are averaged to the selected region. However, when you select a stack-trace the green bars shown at the top of the view for the time-line show you where that stack view was executed; so you can click on each one and view the figures (timings etc) for each execution of the stack. It takes a little bit of manual comparing but it is possible.
Not sure if the profiler you tried has something similar, YourKits is also another popular profiler, again I do not know if it offers something like this.