graphics() added clinfo support (linux)

This commit is contained in:
Sebastian Hildebrandt 2020-12-14 20:32:52 +01:00
parent b08ee93f67
commit bb87af23b5
6 changed files with 89 additions and 12 deletions

View File

@ -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 |

View File

@ -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]

View File

@ -83,6 +83,11 @@
</tr>
</thead>
<tbody>
<tr>
<th scope="row">4.32.0</th>
<td>2020-12-14</td>
<td><span class="code">graphics()</span> clinfo support (linux)</td>
</tr>
<tr>
<th scope="row">4.31.2</th>
<td>2020-12-14</td>

View File

@ -169,7 +169,7 @@
<img class="logo" src="assets/logo.png">
<div class="title">systeminformation</div>
<div class="subtitle"><span id="typed"></span></div>
<div class="version">Current Version: <span id="version">4.31.2</span></div>
<div class="version">Current Version: <span id="version">4.32.0</span></div>
<button class="btn btn-light" onclick="location.href='https://github.com/sebhildebrandt/systeminformation'">View on Github <i class=" fab fa-github"></i></button>
</div>
<div class="down">

View File

@ -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);
});
});
});
});

1
lib/index.d.ts vendored
View File

@ -252,6 +252,7 @@ export namespace Systeminformation {
vendor: string;
model: string;
bus: string;
busAddress?: string;
vram: number;
vramDynamic: boolean;
}