Showing the amount of time taken for a method in one particular thread
Published 05 December 2012
ANTS Performance Profiler's results screen has a dropdown list labeled "Thread". This allows you to choose results relative to a particular thread.
For instance, in the example code below, the same method is called from two different threads: one is called "FirstThread" and the other is called "SecondThread". Viewing the profiling results with "all threads" selected will show a hit count of "2" and a total time of "6 seconds", assuming ANTS Performance Profiler is set up to display wall-clock time.
Selecting "FirstThread" or "SecondThread" from the dropdown will show a hit count of "1" for the same method, and a total runtime of "3 seconds". The source code view will reflect the same behavior. The following is the code of the example C# application created to demonstrate this result:
using System; using System.Collections.Generic; using System.Text; using System.Threading; namespace TestThreadTimes { class Program { static void Main(string[] args) { Thread t1=new Thread(new ThreadStart(WaitThreeSeconds)); t1.Name = "FirstThread"; t1.Start(); t1.Join(); Thread t2 = new Thread(new ThreadStart(WaitThreeSeconds)); t2.Name = "SecondThread"; t2.Start(); t2.Join(); } static void WaitThreeSeconds() { Thread.Sleep(3000); } } }