【问题标题】:CPU usage in .net core (at least on Windows).net 核心中的 CPU 使用率(至少在 Windows 上)
【发布时间】:2018-01-22 08:44:11
【问题描述】:

所以PerformanceCounter 在 dotnet 核心中消失了。我知道这是因为它不兼容 Linux。

这里的评论:(What is the story of Performance Counters for .NET Core?)似乎表明,如果我愿意只在 Windows 上运行它,我可以“利用 Windows 特定的功能”,但我不知道如何将其集成到dotnet 核心。

我愿意做这个变通办法的原因是为了保留 dotnet 核心代码库,这样一旦有 PerformanceCounter 的跨平台解决方案,我就不必迁移。

所以总结一下我的问题:在 Windows 上运行时,如何在 dotnet core 中运行 CPU 使用率?


我发现的其他相关帖子:

  • This solution 似乎暗示Process.GetCurrentProcess() 就足够了,我不太明白(PerformanceCounter提供了机器的完整 CPU 使用率)。

  • 循环遍历所有进程(如this other post seem to suggest?)是不可行的(它会为某些进程引发异常),而且它看起来也很慢,这对我的用例来说是个问题。

【问题讨论】:

标签: c# .net .net-core .net-standard


【解决方案1】:

从 .NET Core 3.0 开始,性能计数器 API 再次成为 BCL 的一部分,并且也支持 Linux:

【讨论】:

  • 出现异常:PlatformNotSupportedException:此平台不支持性能计数器。如果在 .NET core 3.1 中使用 PerformanceCounter 类
猜你喜欢
  • 2016-08-19
  • 1970-01-01
  • 2021-06-13
  • 2016-01-07
  • 1970-01-01
  • 1970-01-01
  • 2021-06-04
  • 2016-09-11
  • 2013-07-17
相关资源
最近更新 更多