{"action":"created","issue":{"url":"https://api.github.com/repos/sebhildebrandt/systeminformation/issues/21","repository_url":"https://api.github.com/repos/sebhildebrandt/systeminformation","labels_url":"https://api.github.com/repos/sebhildebrandt/systeminformation/issues/21/labels{/name}","comments_url":"https://api.github.com/repos/sebhildebrandt/systeminformation/issues/21/comments","events_url":"https://api.github.com/repos/sebhildebrandt/systeminformation/issues/21/events","html_url":"https://github.com/sebhildebrandt/systeminformation/issues/21","id":203833707,"number":21,"title":"Race condition?","user":{"login":"paul-bell","id":12733759,"avatar_url":"https://avatars.githubusercontent.com/u/12733759?v=3","gravatar_id":"","url":"https://api.github.com/users/paul-bell","html_url":"https://github.com/paul-bell","followers_url":"https://api.github.com/users/paul-bell/followers","following_url":"https://api.github.com/users/paul-bell/following{/other_user}","gists_url":"https://api.github.com/users/paul-bell/gists{/gist_id}","starred_url":"https://api.github.com/users/paul-bell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paul-bell/subscriptions","organizations_url":"https://api.github.com/users/paul-bell/orgs","repos_url":"https://api.github.com/users/paul-bell/repos","events_url":"https://api.github.com/users/paul-bell/events{/privacy}","received_events_url":"https://api.github.com/users/paul-bell/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2017-01-28T21:48:01Z","updated_at":"2017-02-12T16:13:13Z","closed_at":null,"body":"Hi Sebastian,\r\n\r\nThis issue appears to be similar to #14 which you fixed for us last November.\r\n\r\nBut in this case it is si.processes() - and _not_ si.currentLoad() - that may prove problematic. I say \"may\" because I am always willing to allow that this problem is of my making.\r\n\r\nMy web browser client is presenting 2 d3.js plots simultaneously. In the Node.js backend this is realized as two \"overlapped\" (roughly concurrent) calls to si.processes(). I will paste in the code below.\r\n\r\nIf I display the process CPU utilization plot by itself, data values returned by si.processes() seem fine. But if I display both process CPU utilization & the process memory utilization plots at the same time, then the data returned by si.processes() assumes quite a few incorrect values. E.g., \"Infinity\", \"NaN\", and negative CPU utilizations.\r\n\r\nIn the code below, the 2 \"collector\" functions, one for CPU utilization, the other for memory, run \"concurrently\" (well, not really, but in the Node.js idiom). Each calls si.processes() and then calls function getProcessesOfInterest .\r\n\r\nThanks for your help.\r\n\r\nCordially,\r\n\r\nPaul\r\n\r\n```\r\nfunction collectorProcessCpuUtil(monSessState, publisher)\r\n{\r\n    var cmdProgress = {\r\n       entity: 'process',\r\n       cpu_util: -1,                                                                               \r\n       sid: monSessState.monSid,\r\n       timestamp: (new Date).getTime(),\r\n    };\r\n\r\n    var mo = getMetricEntryFromSubDoc(monSessState.subDoc, cmdProgress.entity + '.cpu_util');     \r\n    mo.push = true;   \r\n   \r\n    si.processes().then(data => getProcessesOfInterest('cpu_util', data, cmdProgress, publisher, false))                            \r\n\t          .catch(error => logMsg('info', 'process cpu_util si.processes error=' + error));\r\n}\r\n\r\n\r\nfunction collectorProcessMemUtil(monSessState, publisher)\r\n{\r\n    var cmdProgress = {\r\n       entity: 'process',\r\n       mem_util: -1,                                                                               \r\n       sid: monSessState.monSid,\r\n       timestamp: (new Date).getTime(),\r\n    };\r\n    \r\n    var mo = getMetricEntryFromSubDoc(monSessState.subDoc, cmdProgress.entity + '.mem_util');     \r\n    mo.push = true;   \r\n\r\n    si.processes().then(data => getProcessesOfInterest('mem_util', data, cmdProgress, publisher, false))                            \r\n\t          .catch(error => logMsg('info', 'process mem_util si.processes error=' + error));\r\n}\r\n\r\n\r\nfunction getProcessesOfInterest(cmdId, data, cmdProgress, publisher, useProcessCache) \r\n{\r\n\tvar nodeIp = app.get('localIp');\r\n\tvar monSessState = app.get(cmdProgress.sid);\r\n\t\r\n\tvar pCache = arrayToHash(data.list, 'pid'); \r\n\tvar numCores = monSessState.cpuInfo.cores;   // always 4\r\n\t\r\n\tvar mo = getMetricEntryFromSubDoc(monSessState.subDoc, 'process.' + cmdId);\r\n\tvar valAr = [];\r\n\r\n\tmo.pids.forEach(function(wantedPid){\r\n\t\tif ( pCache[wantedPid] )                                                                               // FTI we found pid that caller's interested in                                \r\n\t\t{\r\n\t\t\tvar proc = pCache[wantedPid];                                                                  // get process object given us by si.processes\r\n\t\t\t\r\n\t\t\tif ( cmdId == 'cpu_util' )\r\n\t\t\t{\t\t\t\t\r\n\t\t\t    var temp = parseFloat(numCores*proc.pcpu/100);\r\n\t\t\t    valAr.push({pid: wantedPid, util: parseFloat(numCores*proc.pcpu/100).toFixed(2)});         // ut returned by si is divided by # cores; undo that to present simpler metric\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tif ( cmdId == 'mem_util' )\r\n\t\t\t{\r\n\t\t\t    var temp = parseFloat(proc.pmem/100);\r\n\t\t\t    valAr.push({pid: wantedPid, util: parseFloat(proc.pmem/100).toFixed(2)});  \t\t\t\t\r\n\t\t\t}\r\n\t\t}\r\n\t});\r\n\r\n\tcmdProgress[cmdId] = [{time: cmdProgress.timestamp, data: valAr}];\r\n\tpublisher(cmdProgress);\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/sebhildebrandt/systeminformation/issues/comments/279228700","html_url":"https://github.com/sebhildebrandt/systeminformation/issues/21#issuecomment-279228700","issue_url":"https://api.github.com/repos/sebhildebrandt/systeminformation/issues/21","id":279228700,"user":{"login":"sebhildebrandt","id":4717960,"avatar_url":"https://avatars.githubusercontent.com/u/4717960?v=3","gravatar_id":"","url":"https://api.github.com/users/sebhildebrandt","html_url":"https://github.com/sebhildebrandt","followers_url":"https://api.github.com/users/sebhildebrandt/followers","following_url":"https://api.github.com/users/sebhildebrandt/following{/other_user}","gists_url":"https://api.github.com/users/sebhildebrandt/gists{/gist_id}","starred_url":"https://api.github.com/users/sebhildebrandt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sebhildebrandt/subscriptions","organizations_url":"https://api.github.com/users/sebhildebrandt/orgs","repos_url":"https://api.github.com/users/sebhildebrandt/repos","events_url":"https://api.github.com/users/sebhildebrandt/events{/privacy}","received_events_url":"https://api.github.com/users/sebhildebrandt/received_events","type":"User","site_admin":false},"created_at":"2017-02-12T16:13:13Z","updated_at":"2017-02-12T16:13:13Z","body":"Hi Paul,\n\nsorry for the delay … will still need some more days. I will have time next weekend and I’ll promise to release a fix on saturday.\n\n> Am 12.02.2017 um 14:28 schrieb paul-bell <notifications@github.com>:\n> \n> Hi Sebastian,\n> \n> Any progress on this?\n> \n> Cordially,\n> \n> Paul\n> \n> —\n> You are receiving this because you commented.\n> Reply to this email directly, view it on GitHub <https://github.com/sebhildebrandt/systeminformation/issues/21#issuecomment-279218597>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AEf9iEfq1cGfp11pg6uLVfkZFZ3c7EZWks5rbwkagaJpZM4LwoMk>.\n> \n\n"}}
{"actor":{"display_login":"sebhildebrandt"}}