sebhildebrandt / systeminformation

System Information Library for Node.JS
MIT License
2.76k stars 315 forks source link

Problem with GPU metrics on Windows 24H2 #914

Open TheRedfoox opened 5 months ago

TheRedfoox commented 5 months ago

Describe the bug Since the Windows 24H2 update, almost no GPU metrics (usage, temperature, power, etc.) come up. However, on another PC running Windows 23H2, the metrics come back correctly.

To Reproduce Steps to reproduce the behavior:

  1. Use the function systeminformation.graphics().
  2. Run the application
  3. Observe GPU metrics

Current Output GPU metrics (usage, temperature, power, etc.) are not available.

Expected behavior GPU metrics (usage, temperature, power, etc.) should be available, as they are on a Windows 23H2 PC.

Environment (please complete the following information):

To get all needed environment information, please run the following command:

┌─────────────────────────────────────────────────────────────────────────────────────────┐
│  SYSTEMINFORMATION                                                     Version: 5.22.11 │
└─────────────────────────────────────────────────────────────────────────────────────────┘

Operating System:
──────────────────────────────────────────────────────────────────────────────────────────
Platform         : Windows
Distro           : Microsoft Windows 11 Professionnel
Release          : 10.0.26100
Codename         : 
Kernel           : 10.0.26100
Arch             : x64
Hostname         : NZXT-DU-RENARD
Codepage         : 850
Build            : 26100
Hypervisor       : true
RemoteSession    :

System:
──────────────────────────────────────────────────────────────────────────────────────────
Manufacturer     : ASUS
Model            : System Product Name
Version          : System Version
Virtual          :

CPU:
──────────────────────────────────────────────────────────────────────────────────────────
Manufacturer     : Intel
Brand            : Gen Intel® Core™ i7-12700K
Family           : 6
Model            : 151
Stepping         : 2
Speed            : 3.61
Cores            : 20
PhysicalCores    : 12
PerformanceCores : 20
EfficiencyCores  :
Processors       : 1
Socket           : Other

Additional context This problem appeared after the Windows 24H2 update. On another PC running Windows 23H2, GPU metrics are correctly displayed.

TheRedfoox commented 5 months ago

After putting a few debuggers in the code, I realize that getNvidiaSmi() is in error

Line 397: Error: ENOTDIR: not a directory, scandir 'C:\WINDOWS\System32\DriverStore\FileRepository/a-volutenh3aposwc.inf_amd64_b9b81cb814cdca75.ini'
    at Object.readdirSync (VM262 node:fs:1527:3)
    at t.readdirSync (VM340 node_init:2:11289)
    at VM369 G:\Developer\sb-hardware-monitor\node_modules\systeminformation\lib\graphics.js:398:21
    at Array.filter (<anonymous>)
    at getNvidiaSmi (VM369 G:\Developer\sb-hardware-monitor\node_modules\systeminformation\lib\graphics.js:397:56)
    at nvidiaSmi (VM369 G:\Developer\sb-hardware-monitor\node_modules\systeminformation\lib\graphics.js:420:26)
    at nvidiaDevices (VM369 G:\Developer\sb-hardware-monitor\node_modules\systeminformation\lib\graphics.js:444:20)
    at VM369 G:\Developer\sb-hardware-monitor\node_modules\systeminformation\lib\graphics.js:837:30
    at process.processTicksAndRejections (VM225 task_queues:77:11)
TheRedfoox commented 5 months ago

With even more searching, I see that fs.readdirSync(basePath) would expect to have only directories but actually with my explorer here C:\Windows\System32\DriverStore\FileRepository I see .ini's which may have the same name as some folders.

I think that since Windows 24H2 there are files in FileRepository, which wasn't the case before and which now poses a problem.

TheRedfoox commented 5 months ago

Something like this should solve the problem by simply checking whether the element we're testing is actually a directory.

const candidateDirs = fs.readdirSync(basePath).filter(dir => {
  if (fs.statSync([basePath, dir].join('/')).isDirectory()) {
    return fs.readdirSync([basePath, dir].join('/')).includes('nvidia-smi.exe');
  }
});

I don't know if it's up to me to make a pull request or how to format it to propose this change to fix this problem on Windows 24H2. In any case, I'm available to fix this problem as soon as possible.