Chrome.system.cpu API使用 [英] Chrome.system.cpu API Usage

查看:393
本文介绍了Chrome.system.cpu API使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用chrome.system.cpu api来获取当前的CPU负载?我特别想不出如何将返回的数字转换为当前总负载的百分比。



我发现了这一点,但不太清楚如何实现:调用者可以计算负载分数,方法是进行两次调用,减去次数,再除以totalTime中的差值。

https://developer.chrome.com/apps/system_cpu



Answer
获取CPU使用率的示例如下: https://github.com/beaufortfrancois/cog-chrome-app/blob/master/src/main.js

解决方案

如果要计算处理器上的负载 - 也就是非闲置的可用CPU总时间的百分比 - 我会定期进行API调用(比如说,每5秒一次),并且对于每个间隔计算di用户+内核中从开始到结束的时间间隔除以总的差值。这是该间隔的负载。然后,如果你愿意,你可以将它们绘制在一个移动的图上。



对不起,没有代码可以显示,只是我如何去做的一个草图。


Is it possible to use the chrome.system.cpu api to get the current CPU load? I specifically can't figure out how to convert the returned numbers to a percent of the total current load.

I found this, but not quite sure how to implement: "Callers can compute load fractions by making two calls, subtracting the times, and dividing by the difference in totalTime."

https://developer.chrome.com/apps/system_cpu

Answer: An example of getting CPU usage is here: https://github.com/beaufortfrancois/cog-chrome-app/blob/master/src/main.js

解决方案

If you want to compute the load on the processor(s) -- that is, the percentage of total available CPU time that's non-idle -- I would make the API call at regular intervals (say, once every 5 seconds), and, for each interval, compute difference in user + kernel from start to the end of the interval, divided by difference in total. That's the load for that interval. Then, if you like, you can plot these on a moving graph.

Sorry, no code to show, just a sketch of how I would do it.

这篇关于Chrome.system.cpu API使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆