最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Chrome.system.cpu API Usage - Stack Overflow

programmeradmin6浏览0评论

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 pute load fractions by making two calls, subtracting the times, and dividing by the difference in totalTime."

Answer: An example of getting CPU usage is here: .js

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 pute load fractions by making two calls, subtracting the times, and dividing by the difference in totalTime."

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

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

Share Improve this question edited Sep 25, 2014 at 23:11 Daniel Herr asked Jun 29, 2014 at 4:23 Daniel HerrDaniel Herr 20.5k9 gold badges48 silver badges65 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

If you want to pute 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, pute 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.

Yes, I believe it is possible to get the current CPU load. You may need to e up with an algorithm to find a better way to display it, and possibly refresh it using something like setInterval().

I ran this bit of code:

chrome.system.cpu.getInfo(function(info){       
   console.log(JSON.stringify(info));   
});

Here is what returns for me:

    {
   "archName":"x86_64",
   "features":[
      "mmx",
      "sse",
      "sse2",
      "sse3",
      "ssse3",
      "sse4_1",
      "sse4_2",
      "avx"
   ],
   "modelName":"Intel(R) Core(TM) i5-2410M CPU @ 2.30GHz",
   "numOfProcessors":4,
   "processors":[
      {
         "usage":{
            "idle":1651683051644,
            "kernel":78195033247,
            "total":1886069562112,
            "user":156191477221
         }
      },
      {
         "usage":{
            "idle":1829832137618,
            "kernel":16966512759,
            "total":1886065818088,
            "user":39267167711
         }
      },
      {
         "usage":{
            "idle":1651957145401,
            "kernel":60555064171,
            "total":1886064570080,
            "user":173552360508
         }
      },
      {
         "usage":{
            "idle":1854233814038,
            "kernel":9238067218,
            "total":1886063166071,
            "user":22591284815
         }
      }
   ]
}
发布评论

评论列表(0)

  1. 暂无评论