graphics() added clinfo support (linux)
This commit is contained in:
+80
-10
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Vendored
+1
@@ -252,6 +252,7 @@ export namespace Systeminformation {
|
||||
vendor: string;
|
||||
model: string;
|
||||
bus: string;
|
||||
busAddress?: string;
|
||||
vram: number;
|
||||
vramDynamic: boolean;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user