Monitor a process's usage of each CPU core

后端 未结 4 1465
春和景丽
春和景丽 2021-02-13 02:01

Is there a way to query or calculate the CPU usage of a single process per each core separately?

For example,

Na

4条回答
  •  轮回少年
    2021-02-13 02:28

    Try the below (found it here)

        int coreCount = 0;
        foreach (var item in new System.Management.ManagementObjectSearcher("Select * from Win32_Processor").Get())
        {
            coreCount += int.Parse(item["NumberOfCores"].ToString());
        }
    
        PerformanceCounter[] pc = new PerformanceCounter[coreCount];
    
        for (int i = 0; i < coreCount; i++)
        {
            pc[i] = new PerformanceCounter("Processor", "% Processor Time", i.ToString());
            Console.WriteLine(pc[i].CounterName);
        }
    

提交回复
热议问题