user1258126
user1258126

Reputation: 301

Is it possible to measure a thread's execution time without including blocking/preemption time?

In C#.NET, is there a way to measure the actual CPU time of a thread/task. This time should NOT include the blocking/preemption time. I know that a StopWatch can be used to measure the total time for a task from start to finish, but this will also include the blocking time. Is there a way to exclude the blocking time?

Upvotes: 1

Views: 297

Answers (1)

Robert Harvey
Robert Harvey

Reputation: 180788

System.Diagnostics.ProcessThread.TotalProcessorTime will give you the amount of CPU time that a given thread has consumed.

Upvotes: 4

Related Questions