每个线程的处理时间?

时间:2010-07-02 12:00:41

标签: c# .net performance sockets

我想计算每个线程的处理时间。 我该怎么做。? 假设我的100个线程同时执行相同的方法work(),那么如果我把下面的代码帮助我得到我想要的东西

Process thisProc = Process.GetCurrentProcess();
string procName = thisProc.ProcessName;
DateTime started = thisProc.StartTime;

int memory = thisProc.VirtualMemorySize;
int priMemory = thisProc.PrivateMemorySize;
int physMemory = thisProc.WorkingSet;

ProcessPriorityClass priClass = thisProc.PriorityClass;
TimeSpan cpuTime = thisProc.TotalProcessorTime;

Console.WriteLine(" started: {0}", started.ToString());
Console.WriteLine(" CPU time: {0}", cpuTime.ToString());

Console.WriteLine(" Virtual Memory: {0}", memory + " ; Private Memory: " + priMemory + " ; Physical Memory: " + physMemory);

1 个答案:

答案 0 :(得分:3)

GetThreadTimes()提供此信息。但是很难使用,因为它需要一个线程句柄,.NET框架不允许你这样做。简单的解决方案是在线程函数内部启动秒表,并在完成时启动Stop()。

相关问题