Tim*_*uri 13 c# performance multithreading memory-management cpu-usage
我知道如何获得进程的CPU使用率和内存使用率,但我想知道如何在每个线程级别上获取它.如果最好的解决方案是做一些P-Invoking,那也没关系.
我需要的例子:
Thread myThread = Thread.CurrentThread;
// some time later in some other function...
Console.WriteLine(GetThreadSpecificCpuUsage(myThread));
Run Code Online (Sandbox Code Playgroud)
jer*_*jvl 10
如上所述,内存使用无法回答,因为这是整个过程的一个属性,但CPU使用:
Process p = Process.GetCurrentProcess(); // getting current running process of the app
foreach (ProcessThread pt in p.Threads)
{
// use pt.Id / pt.TotalProcessorTime / pt.UserProcessorTime / pt.PrivilegedProcessorTime
}
Run Code Online (Sandbox Code Playgroud)