gpt4 book ai didi

macos - 获取从 0 到 100% 范围内的 CPU 负载

转载 作者:行者123 更新时间:2023-12-03 17:50:37 25 4
gpt4 key购买 nike

我正在尝试获取运行时的CPU负载。我正在尝试this fantastic answer但这段代码给了我这样的输出:

Core: 0 Usage: 0.120000
Core: 1 Usage: 0.080000
Core: 2 Usage: 0.066667
Core: 3 Usage: 0.070000

这超出了我的需要。如何获得从 0 到 100% 范围内的负载,而与用户拥有的内核/CPU 数量无关?

好的,我可以对这些数字进行平均,但假设平均值是 0.08。这是否意味着负载为 8%?我对此不太确定。

最佳答案

如果您阅读您提供的代码,您可以看到 (@"Core: %u Usage: %f",i,inUse/Total) 可以通过简单的操作轻松转换为百分比使用中/总计*100

顺便说一句: enter image description here

关于macos - 获取从 0 到 100% 范围内的 CPU 负载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28580521/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com