From bb87af23b5b19791916cd937501655d71010522f Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Mon, 14 Dec 2020 20:32:52 +0100 Subject: [PATCH] graphics() added clinfo support (linux) --- CHANGELOG.md | 1 + README.md | 2 +- docs/history.html | 5 +++ docs/index.html | 2 +- lib/graphics.js | 90 +++++++++++++++++++++++++++++++++++++++++------ lib/index.d.ts | 1 + 6 files changed, 89 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21a5bbc..089d239 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ For major (breaking) changes - version 3 and 2 see end of page. | Version | Date | Comment | | -------------- | -------------- | -------- | +| 4.32.0 | 2020-12-14 | `graphics()` clinfo support (linux) | | 4.31.2 | 2020-12-14 | `graphics()` Windows 7 Graphics Fixes (Multi Monitor) | | 4.31.1 | 2020-12-11 | `inetLatency()` command injection vulnaribility fix | | 4.31.0 | 2020-12-06 | `osInfo()` added FQDN | diff --git a/README.md b/README.md index f918b26..7c9943d 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,7 @@ si.cpu() (last 7 major and minor version releases) +- Version 4.32.0: `graphics()` added clinfo support (linux) - Version 4.31.0: `osInfo()` added FQDN - Version 4.30.0: `get()` added possibility to provide parameters - Version 4.29.0: `fsSize()` correct fs type detection macOS (HFS, APFS, NFS) @@ -100,7 +101,6 @@ si.cpu() - Version 4.27.0: `observe()` added observe / watch function - Version 4.26.0: `diskLayout()` added full S.M.A.R.T data (Linux) - Version 4.25.0: `get()` added function to get partial system info -- Version 4.24.0: `networkInterfaces()` added subnet mask ip4 and ip6 - ... You can find all changes here: [detailed changelog][changelog-url] diff --git a/docs/history.html b/docs/history.html index 4622b3c..734b762 100644 --- a/docs/history.html +++ b/docs/history.html @@ -83,6 +83,11 @@ + + 4.32.0 + 2020-12-14 + graphics() clinfo support (linux) + 4.31.2 2020-12-14 diff --git a/docs/index.html b/docs/index.html index 094b8d4..4a73a1a 100644 --- a/docs/index.html +++ b/docs/index.html @@ -169,7 +169,7 @@
systeminformation
-
Current Version: 4.31.2
+
Current Version: 4.32.0
diff --git a/lib/graphics.js b/lib/graphics.js index 2a67498..c1f0a6c 100644 --- a/lib/graphics.js +++ b/lib/graphics.js @@ -202,6 +202,7 @@ function graphics(callback) { vendor: '', model: '', bus: '', + busAddress: '', vram: -1, vramDynamic: false }; @@ -235,6 +236,7 @@ function graphics(callback) { vendor: '', model: '', bus: '', + busAddress: '', vram: -1, vramDynamic: false }; @@ -242,6 +244,7 @@ function graphics(callback) { isGraphicsController = true; let endpos = lines[i].search(/\[[0-9a-f]{4}:[0-9a-f]{4}]|$/); let parts = lines[i].substr(vgapos, endpos - vgapos).split(':'); + currentController.busAddress = lines[i].substr(0, vgapos).trim(); if (parts.length > 1) { parts[1] = parts[1].trim(); if (parts[1].toLowerCase().indexOf('corporation') >= 0) { @@ -288,12 +291,72 @@ function graphics(callback) { } } } - if (currentController.vendor || currentController.model || currentController.bus || currentController.vram !== -1 || currentController.vramDynamic) { // already a controller found + if (currentController.vendor || currentController.model || currentController.bus || currentController.busAddress || currentController.vram !== -1 || currentController.vramDynamic) { // already a controller found controllers.push(currentController); } return (controllers); } + function parseLinesLinuxClinfo(controllers, lines) { + const fieldPattern = /\[([^\]]+)\]\s+(\w+)\s+(.*)/; + const devices = lines.reduce((devices, line) => { + const field = fieldPattern.exec(line.trim()); + if (field) { + if (!devices[field[1]]) { + devices[field[1]] = {}; + } + devices[field[1]][field[2]] = field[3]; + } + return devices + }, {}); + for (let deviceId in devices) { + const device = devices[deviceId] + if (device['CL_DEVICE_TYPE'] === 'CL_DEVICE_TYPE_GPU') { + let busAddress; + if (device['CL_DEVICE_TOPOLOGY_AMD']) { + const bdf = device['CL_DEVICE_TOPOLOGY_AMD'].match(/[a-zA-Z0-9]+:\d+\.\d+/); + if (bdf) { + busAddress = bdf[0]; + } + } else if (device['CL_DEVICE_PCI_BUS_ID_NV'] && device['CL_DEVICE_PCI_SLOT_ID_NV']) { + const bus = parseInt(device['CL_DEVICE_PCI_BUS_ID_NV']); + const slot = parseInt(device['CL_DEVICE_PCI_SLOT_ID_NV']); + if (!isNaN(bus) && !isNaN(slot)) { + const b = bus & 0xff; + const d = (slot >> 3) & 0xff; + const f = slot & 0x07; + busAddress = `${b.toString().padStart(2, '0')}:${d.toString().padStart(2, '0')}.${f}`; + } + } + if (busAddress) { + let controller = controllers.find(controller => controller.busAddress === busAddress); + if (!controller) { + controller = { + vendor: '', + model: '', + bus: '', + busAddress, + vram: -1, + vramDynamic: false + }; + controllers.push(controller); + } + controller.vendor = device['CL_DEVICE_VENDOR']; + if (device['CL_DEVICE_BOARD_NAME_AMD']) { + controller.model = device['CL_DEVICE_BOARD_NAME_AMD']; + } else { + controller.model = device['CL_DEVICE_NAME']; + } + const memory = parseInt(device['CL_DEVICE_GLOBAL_MEM_SIZE']); + if (!isNaN(memory)) { + controller.vram = Math.round(memory / 1024 / 1024); + } + } + } + } + return controllers + } + function parseLinesLinuxEdid(edid) { // parsen EDID // --> model @@ -530,23 +593,30 @@ function graphics(callback) { let lines = stdout.toString().split('\n'); result.controllers = parseLinesLinuxControllers(lines); } - let cmd = 'xdpyinfo 2>/dev/null | grep \'depth of root window\' | awk \'{ print $5 }\''; + let cmd = "clinfo --raw"; exec(cmd, function (error, stdout) { - let depth = 0; if (!error) { let lines = stdout.toString().split('\n'); - depth = parseInt(lines[0]) || 0; + result.controllers = parseLinesLinuxClinfo(result.controllers, lines); } - let cmd = 'xrandr --verbose 2>/dev/null'; + let cmd = 'xdpyinfo 2>/dev/null | grep \'depth of root window\' | awk \'{ print $5 }\''; exec(cmd, function (error, stdout) { + let depth = 0; if (!error) { let lines = stdout.toString().split('\n'); - result.displays = parseLinesLinuxDisplays(lines, depth); + depth = parseInt(lines[0]) || 0; } - if (callback) { - callback(result); - } - resolve(result); + let cmd = 'xrandr --verbose 2>/dev/null'; + exec(cmd, function (error, stdout) { + if (!error) { + let lines = stdout.toString().split('\n'); + result.displays = parseLinesLinuxDisplays(lines, depth); + } + if (callback) { + callback(result); + } + resolve(result); + }); }); }); }); diff --git a/lib/index.d.ts b/lib/index.d.ts index 47ba3c4..76cb327 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -252,6 +252,7 @@ export namespace Systeminformation { vendor: string; model: string; bus: string; + busAddress?: string; vram: number; vramDynamic: boolean; }