Njanderson / resmon

Displays resource utilization in the VSCode status bar.
81 stars 22 forks source link

CPU frequency #20

Closed ZenanH closed 4 years ago

ZenanH commented 4 years ago

At present, on my computer, CPU frequency shows Base speed(①) instead of speed(②). The value of Base speed will remain unchanged. image

For me, the latter is more important. I'm not sure if this is due to my setting error or if Resource Monitor doesn't support real-time display speed.

批注 2020-01-15 095124

letmaik commented 4 years ago

Yes, this should be fixed. Currently resmon uses the si.cpu API, but instead it should use si.cpuCurrentspeed.

Njanderson commented 4 years ago

On Windows, this also maxes out your CPU. WMIC (where the systeminformation get its CPU clock speed) doesn't have this information. I have spent a long time trying to figure out a real way to get the current CPU clock speed, but it's very hard to do. On my laptop, which has a max freq. of 2.11 Ghz, every field is listed as this clock speed. I'll do some hunting to see if there is something better on Windows in another node module.

On Windows, the WMIC output isn't right:

>wmic path win32_processor get CurrentClockSpeed, MaxClockSpeed, Name
CurrentClockSpeed  MaxClockSpeed  Name
1910               2112           Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz

>wmic cpu get CurrentClockSpeed, MaxClockSpeed, Name
CurrentClockSpeed  MaxClockSpeed  Name
1910               2112           Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz
Njanderson commented 4 years ago

For example, the NodeJs os.cpus():

> os.cpus()
[
  {
    model: 'Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz',
    speed: 2112,
    times: { user: 630312, nice: 0, sys: 494515, idle: 11524515, irq: 77859 }
  },
  {
    model: 'Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz',
    speed: 2112,
    times: { user: 515890, nice: 0, sys: 227203, idle: 11905750, irq: 6234 }
  },
Njanderson commented 4 years ago

Looking at other NPM modules, they also do this wrong.

Njanderson commented 4 years ago

For N=2, my desktop also does this:

> cpuCurrentSpeed
Promise {
  { min: 3.6,
    max: 3.6,
    avg: 3.6,
    cores:
     [ 3.6, 3.6, 3.6, 3.6, 3.6, 3.6, 3.6, 3.6, 3.6, 3.6, 3.6, 3.6 ] },
Njanderson commented 4 years ago

I've actually invested a ton of time and effort into figuring this out, but I haven't come to a solution that works, not even using C++ and Win32 APIs to measure it in Windows. None of the example programs actually match Task Manager, and I cannot comment on what Task Manager does.

letmaik commented 4 years ago

Ah that's a shame, I had no idea the situation was so dire. I think for now then this should be documented, also in the description text of the vs code setting. You can Markdown now, so could even apply some formatting etc.

Njanderson commented 4 years ago

For Intel processors, you can do something like this extension does, which is read an Intel CPU MSR, which gives the current CPU operating point. But you need go to to Kernel mode just to read this - and this is a VS Code extension, so I abandoned it.

Njanderson commented 4 years ago

Agreed - I actually think this works okay in Linux.

If someone can comment on whether cpuCurrentspeed (Yes, the capitalization in systeminformation is not quite camel-cased) is required for Linux, I'd appreciate it!

Njanderson commented 4 years ago

Taking an action item to document this for Windows, and leave Linux/MacOS as is.

Njanderson commented 4 years ago

For @ZenanH, I'm sorry I couldn't help more on this.

If someone comes up with a solution that works in Windows, I'd love to hear it! 👍

letmaik commented 4 years ago

I think we want cpuCurrentspeed, as si.cpu just parses the "Model name:" line of lscpu and doesn't query the current speed, except as fall-back if the number is 0. I'm personally never interested in the static/base cpu speed.

Njanderson commented 4 years ago

Moving onto cpuCurrentspeed.avg.