mirror of
https://git.outfoxxed.me/quickshell/quickshell.git
synced 2026-04-10 06:11:54 +10:00
core: log gpu information in debuginfo
This commit is contained in:
parent
1123d5ab4f
commit
1b2519d9f3
7 changed files with 82 additions and 3 deletions
|
|
@ -1,3 +1,4 @@
|
|||
pkg_check_modules(libdrm REQUIRED IMPORTED_TARGET libdrm)
|
||||
qt_add_library(quickshell-core STATIC
|
||||
plugin.cpp
|
||||
shell.cpp
|
||||
|
|
@ -54,7 +55,7 @@ qt_add_qml_module(quickshell-core
|
|||
|
||||
install_qml_module(quickshell-core)
|
||||
|
||||
target_link_libraries(quickshell-core PRIVATE Qt::Quick Qt::QuickPrivate Qt::Widgets quickshell-build)
|
||||
target_link_libraries(quickshell-core PRIVATE Qt::Quick Qt::QuickPrivate Qt::Widgets quickshell-build PkgConfig::libdrm)
|
||||
|
||||
qs_module_pch(quickshell-core SET large)
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,10 @@
|
|||
#include <qfile.h>
|
||||
#include <qfloat16.h>
|
||||
#include <qhashfunctions.h>
|
||||
#include <qscopeguard.h>
|
||||
#include <qtversion.h>
|
||||
#include <unistd.h>
|
||||
#include <xf86drm.h>
|
||||
|
||||
#include "build.hpp"
|
||||
|
||||
|
|
@ -20,10 +22,82 @@ QString qsVersion() {
|
|||
|
||||
QString qtVersion() { return qVersion() % QStringLiteral(" (built against " QT_VERSION_STR ")"); }
|
||||
|
||||
QString gpuInfo() {
|
||||
auto deviceCount = drmGetDevices2(0, nullptr, 0);
|
||||
if (deviceCount < 0) return "Failed to get DRM device count: " % QString::number(deviceCount);
|
||||
auto* devices = new drmDevicePtr[deviceCount];
|
||||
auto devicesArrayGuard = qScopeGuard([&] { delete[] devices; });
|
||||
auto r = drmGetDevices2(0, devices, deviceCount);
|
||||
if (deviceCount < 0) return "Failed to get DRM devices: " % QString::number(r);
|
||||
auto devicesGuard = qScopeGuard([&] {
|
||||
for (auto i = 0; i != deviceCount; ++i) drmFreeDevice(&devices[i]); // NOLINT
|
||||
});
|
||||
|
||||
QString info;
|
||||
auto stream = QTextStream(&info);
|
||||
|
||||
for (auto i = 0; i != deviceCount; ++i) {
|
||||
auto* device = devices[i]; // NOLINT
|
||||
|
||||
int deviceNodeType = -1;
|
||||
if (device->available_nodes & (1 << DRM_NODE_RENDER)) deviceNodeType = DRM_NODE_RENDER;
|
||||
else if (device->available_nodes & (1 << DRM_NODE_PRIMARY)) deviceNodeType = DRM_NODE_PRIMARY;
|
||||
|
||||
if (deviceNodeType == -1) continue;
|
||||
|
||||
auto* deviceNode = device->nodes[DRM_NODE_RENDER]; // NOLINT
|
||||
|
||||
auto driver = [&]() -> QString {
|
||||
auto fd = open(deviceNode, O_RDWR | O_CLOEXEC);
|
||||
if (fd == -1) return "<failed to open device node>";
|
||||
auto fdGuard = qScopeGuard([&] { close(fd); });
|
||||
auto* ver = drmGetVersion(fd);
|
||||
if (!ver) return "<drmGetVersion failed>";
|
||||
auto verGuard = qScopeGuard([&] { drmFreeVersion(ver); });
|
||||
|
||||
// clang-format off
|
||||
return QString(ver->name)
|
||||
% ' ' % QString::number(ver->version_major)
|
||||
% '.' % QString::number(ver->version_minor)
|
||||
% '.' % QString::number(ver->version_patchlevel)
|
||||
% " (" % ver->desc % ')';
|
||||
// clang-format on
|
||||
}();
|
||||
|
||||
QString product = "unknown";
|
||||
QString address = "unknown";
|
||||
|
||||
auto hex = [](int num, int pad) { return QString::number(num, 16).rightJustified(pad, '0'); };
|
||||
|
||||
switch (device->bustype) {
|
||||
case DRM_BUS_PCI: {
|
||||
auto* b = device->businfo.pci;
|
||||
auto* d = device->deviceinfo.pci;
|
||||
address = "PCI " % hex(b->bus, 2) % ':' % hex(b->dev, 2) % '.' % hex(b->func, 1);
|
||||
product = hex(d->vendor_id, 4) % ':' % hex(d->device_id, 4);
|
||||
} break;
|
||||
case DRM_BUS_USB: {
|
||||
auto* b = device->businfo.usb;
|
||||
auto* d = device->deviceinfo.usb;
|
||||
address = "USB " % QString::number(b->bus) % ':' % QString::number(b->dev);
|
||||
product = hex(d->vendor, 4) % ':' % hex(d->product, 4);
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
stream << "GPU " << deviceNode << "\n Driver: " << driver << "\n Model: " << product
|
||||
<< "\n Address: " << address << '\n';
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
QString systemInfo() {
|
||||
QString info;
|
||||
auto stream = QTextStream(&info);
|
||||
|
||||
stream << gpuInfo() << '\n';
|
||||
|
||||
stream << "/etc/os-release:";
|
||||
auto osReleaseFile = QFile("/etc/os-release");
|
||||
if (osReleaseFile.open(QFile::ReadOnly)) {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ namespace qs::debuginfo {
|
|||
|
||||
QString qsVersion();
|
||||
QString qtVersion();
|
||||
QString gpuInfo();
|
||||
QString systemInfo();
|
||||
QString combinedInfo();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue