sebhildebrandt / systeminformation

System Information Library for Node.JS
MIT License
2.72k stars 309 forks source link

processLoad('*') hanging #929

Open imbdb opened 1 month ago

imbdb commented 1 month ago

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

  1. used function: processLoad('*')
  2. code snippet
    let si = require('systeminformation');
    si.processLoad('*').then( v => console.log(v))
  3. start app / code
  4. See output/error '....'

Current Output No output, it just keeps waiting.

Expected behavior It should return list of all the current processes

Environment (please complete the following information):

sebhildebrandt commented 1 month ago

@imbdb what linux distribution are you using?

And, what is the output of

ps -axo pid,ppid,pcpu,pmem,comm

on this machine (console)

imbdb commented 1 month ago
Operating System:
─────────────────────────────────
Platform         : linux
Distro           : Ubuntu
Release          : 22.04.4 LTS
Codename         : jammy
Kernel           : 6.5.0-1015-aws
Arch             : arm64

Truncated output of ps -axo pid,ppid,pcpu,pmem,comm

    PID    PPID %CPU %MEM COMMAND
      1       0  1.3  0.1 systemd
      2       0  0.0  0.0 kthreadd
      3       2  0.0  0.0 rcu_gp
      4       2  0.0  0.0 rcu_par_gp
      5       2  0.0  0.0 slub_flushwq
      6       2  0.0  0.0 netns
      8       2  0.0  0.0 kworker/0:0H-events_highpri
      9       2  0.0  0.0 kworker/0:1-inode_switch_wbs
     10       2  0.0  0.0 kworker/u4:0-ext4-rsv-conversion
     11       2  0.0  0.0 mm_percpu_wq
     12       2  0.0  0.0 rcu_tasks_rude_kthread
     13       2  0.0  0.0 rcu_tasks_trace_kthread
sebhildebrandt commented 1 month ago

@imbdb can you test the latest version 5.23.5?

imbdb commented 1 month ago

The function is returning a value now. For some reason, I thought it would return the process list, but it returned a single element in the array.

[
  {
    proc: '',
    pid: 0,
    pids: [
         0,    4,  
      ... 546 more items
    ],
    cpu: 99.99999999999963,
    mem: 84.50729697417735
  }
]

I think it would be better to use the processes function instead, right?

sebhildebrandt commented 1 month ago

@imbdb ... well it SHOULD return an array of all processes. I testet it on a machine running the same os:

Platform         : linux
Distro           : Ubuntu
Release          : 22.04.3 LTS
Codename         : jammy

This is the code I am running:

let si = require('systeminformation');
si.processLoad('*').then( v => console.log(v))

And here what It returns on my side (truncated):

[
  { proc: 'systemd', pid: 1, pids: [ 1 ], cpu: 0, mem: 0 },
  { proc: 'kthreadd', pid: 2, pids: [ 2 ], cpu: 0, mem: 0 },
  { proc: 'rcu_gp', pid: 3, pids: [ 3 ], cpu: 0, mem: 0 },
  { proc: 'rcu_par_gp', pid: 4, pids: [ 4 ], cpu: 0, mem: 0 },
  { proc: 'slub_flushwq', pid: 5, pids: [ 5 ], cpu: 0, mem: 0 },
  { proc: 'netns', pid: 6, pids: [ 6 ], cpu: 0, mem: 0 },
  {
    proc: 'kworker',
    pid: 3710814,
    pids: [
            8,      24,      30,      36,      42,      48,
           54,      60,      66,      72,      78,      84,
           90,      96,     102,     108,     176,     212,
          240,     256,     305,     308,     311,     314,
          316,     318,     335,     373,     445,     507,
          536,     545,     567, 2886818, 2966220, 3064270,
      3098483, 3239607, 3331446, 3360939, 3386264, 3390085,
      3476770, 3511405, 3576747, 3585047, 3598985, 3600025,
      3602953, 3611411, 3642134, 3642299, 3671666, 3678637,
      3679710, 3679727, 3690006, 3696258, 3696745, 3699178,
      3699179, 3699468, 3700659, 3704186, 3708115, 3708794,
      3709638, 3710360, 3710631, 3710814
    ],
    cpu: 0,
    mem: 0
  },
  ...
]

Hmmmm ... I reopened the ticket ...

sebhildebrandt commented 1 month ago

@imbdb is there any chance, that you can help with debugging? That would mean adding certain console.log into the systeminformation code. If yes, I would guide you, what I would need.

imbdb commented 1 month ago

Sure @sebhildebrandt

sebhildebrandt commented 1 month ago

@imbdb thank you so much!

So, if you clone the repo with

git clone https://github.com/sebhildebrandt/systeminformation.git
cd systeminformation

Then edit the lib/processes.js file. Line 1138 to 1290 is where the magic happens ;-)

SO let us have a look:

  1. line 1139 to 1166: here we first get and parse all processes and store them into the procStatsvariable (as an array). If you do a console log after line 1166 with console.log(procStats) you should the see all processes. This should be true on your machine.
  2. line 1168 to 1230: now we are going through this array and determine if we are interested in a specific process:

For some reason this last part only happens once. Here it would be interesting to check the conditions WHY this part is not called again. Looking at your result this is anyway strange as there should never be an item in the result with name = '' ... I only allow to add items to the result array if there IS a name (line 1186). Can you try to check the conditions here and post back, what you found out?

Thank you!

sebhildebrandt commented 1 month ago

@imbdb did you had time to have a look on it on your side? I tested it here on different machines and different OS versions without any issue ... so it would be interesting to see what the reason is on your machine. Thank you in advance.

imbdb commented 1 month ago

Hello @sebhildebrandt

Give me sometime (max 2 days), stuck in some issues right now.

sebhildebrandt commented 1 month ago

Hi @imbdb ... sorry I didn't wanted to stress you! Take your time ;-)