ok, I am using ThreadPool to start threads. Inside threaad code I'm trying to figure out hom much cpu time it actually used. I've read there is ProcessThread . TotalProcessorTime property for this (http://msdn.microsoft.com/en-us/library/system.diagnostics.processthread.totalprocessortime.aspx) but I just can't get to read it. So how do I get it for a current thread?
-
What do you mean by "I just can't get to read it"? – Maxim Gueivandov Jan 24 '11 at 17:57
1 Answers
A few poiints:
1)To get the correct process thread via ProcessThread . TotalProcessorTime you'll need to native thread ID
2)It sounds very much like you are comparing the managed thread ID (via Thread.CurrentThread.Name) with the native thread ID to get the current thread within the via the System.Diagnostics namespace. Remember that managed thread ID != ProcessThreadID. You'll need to use the GetCurrentThreadId Function http://msdn.microsoft.com/en-us/library/ms683183(VS.85).aspx
3) Thread pool threads can be recycled, so the TotalProcessorTime for a thread pool may be larger than what you are expecting
4)If you profiling thread usage it may be easier to use the thread profiler in Visual Studio Ultimate, or another good profiler (i.e ANTS, DotTrace, SciTech)

- 520
- 2
- 9