Measure uasync CPU load and display it in desktop and Android GUIs
Sample thread CPU usage without waking idle loops, expose a one-second moving average, and refresh compact GUI indicators at 3 Hz while visible on Android. Add load and bridge regression coverage, streaming notes, and task list cleanup.
This commit is contained in:
1 parent
bcfe7ca4c1
commit
71d19013c0
25 files changed
+692
-587
No files matched your search
@@ -24,6 +24,38 @@ extern "C" {
|
||||
#include "dm/dm_core.h"
|
||||
}
|
||||
|
||||
/* Секундное среднее CPU: фиксированный градиент, заполнение по проценту. */
|
||||
class CpuLoadIndicator : public QWidget {
|
||||
public:
|
||||
explicit CpuLoadIndicator(QWidget* parent) : QWidget(parent) {
|
||||
setObjectName(QStringLiteral("cpuLoadIndicator"));
|
||||
setFixedSize(60, 24);
|
||||
setAccessibleName(QStringLiteral("CPU"));
|
||||
}
|
||||
void setValue(int percent) {
|
||||
percent = qBound(0, percent, 100);
|
||||
if (m_percent == percent) return;
|
||||
m_percent = percent; update();
|
||||
}
|
||||
protected:
|
||||
void paintEvent(QPaintEvent*) override {
|
||||
QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing);
|
||||
QPainterPath path; path.addRoundedRect(QRectF(rect()), 5, 5);
|
||||
painter.setClipPath(path);
|
||||
painter.fillRect(rect(), QColor("#E4E9E6"));
|
||||
QLinearGradient gradient(0, 0, width(), 0);
|
||||
gradient.setColorAt(0, QColor("#66BB6A"));
|
||||
gradient.setColorAt(0.5, QColor("#FFCA28"));
|
||||
gradient.setColorAt(1, QColor("#EF5350"));
|
||||
painter.fillRect(QRectF(0, 0, width() * m_percent / 100.0, height()), gradient);
|
||||
painter.setPen(QColor("#172019"));
|
||||
QFont f = font(); f.setBold(true); painter.setFont(f);
|
||||
painter.drawText(rect(), Qt::AlignCenter, QString::number(m_percent) + '%');
|
||||
}
|
||||
private:
|
||||
int m_percent = 0;
|
||||
};
|
||||
|
||||
/* Пустое место и заголовки секций не сбрасывают выбор канала. */
|
||||
class ChannelListView : public QListView {
|
||||
public:
|
||||
@@ -106,7 +138,12 @@ ChannelList::ChannelList(DbManager* db, QWidget *parent)
|
||||
auto *header = new QLabel(QCoreApplication::translate("ChatGui", "Channels"), this);
|
||||
header->setAlignment(Qt::AlignCenter);
|
||||
header->setStyleSheet("font-weight: bold; padding: 8px; background: palette(window);");
|
||||
layout->addWidget(header);
|
||||
auto* headerRow = new QHBoxLayout;
|
||||
headerRow->setContentsMargins(0, 0, 8, 0);
|
||||
headerRow->addWidget(header, 1);
|
||||
m_cpuLoad = new CpuLoadIndicator(this);
|
||||
headerRow->addWidget(m_cpuLoad);
|
||||
layout->addLayout(headerRow);
|
||||
|
||||
m_listView->setModel(m_model);
|
||||
m_listView->setItemDelegate(new ChannelDelegate(this));
|
||||
@@ -266,6 +303,8 @@ void ChannelList::onDmCallRoute(const uint8_t* data, int len) {
|
||||
}
|
||||
}
|
||||
|
||||
void ChannelList::setCpuLoad(int percent) { m_cpuLoad->setValue(percent); }
|
||||
|
||||
void ChannelList::loadChannels() {
|
||||
refreshDmPresence();
|
||||
QString selectedCid;
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
class DbManager;
|
||||
class QLabel;
|
||||
class CpuLoadIndicator;
|
||||
|
||||
class ChannelList : public QWidget {
|
||||
Q_OBJECT
|
||||
@@ -25,6 +26,7 @@ public:
|
||||
void selectChannel(const QString& channelId);
|
||||
void setChannelPeersOnline(const QString& channelId, int count);
|
||||
void setAutoConnectActive(bool active);
|
||||
void setCpuLoad(int percent);
|
||||
void setChannelUnreadCount(const QString& channelId, int count);
|
||||
int getChannelUnreadCount(const QString& channelId) const;
|
||||
|
||||
@@ -49,4 +51,5 @@ private:
|
||||
bool m_autoConnectActive = false;
|
||||
QHash<QString, bool> m_dmOnline;
|
||||
QTimer* m_dmPresenceTimer;
|
||||
CpuLoadIndicator* m_cpuLoad;
|
||||
};
|
||||
@@ -171,6 +171,18 @@ MainWindow::MainWindow(QWidget *parent, DbManager* db, const QString& cfgPath,
|
||||
setupConnects();
|
||||
}
|
||||
connect(m_autoPlayTimer, &QTimer::timeout, this, &MainWindow::autoPlayTimerTick);
|
||||
m_cpuLoadTimer = new QTimer(this);
|
||||
m_cpuLoadTimer->setTimerType(Qt::PreciseTimer);
|
||||
connect(m_cpuLoadTimer, &QTimer::timeout, this, [this] {
|
||||
auto* inst = gui_bridge_get_inst();
|
||||
if (!m_node || !m_node->isRunning() || !inst || !gui_bridge_is_uasync_ready()) {
|
||||
m_cpuLoadPending = false; m_channelList->setCpuLoad(0); return;
|
||||
}
|
||||
if (m_cpuLoadPending) return;
|
||||
m_cpuLoadPending = gui_bridge_request_cpu_load() != 0;
|
||||
});
|
||||
m_cpuLoadTimer->start(333);
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_SYS, "desktop CPU indicator polling started: period=333ms");
|
||||
|
||||
#ifndef _WIN32
|
||||
std::signal(SIGINT, unixSignalHandler);
|
||||
@@ -183,6 +195,9 @@ MainWindow::MainWindow(QWidget *parent, DbManager* db, const QString& cfgPath,
|
||||
|
||||
MainWindow::~MainWindow() {
|
||||
s_mainWindow = nullptr;
|
||||
m_cpuLoadTimer->stop();
|
||||
gui_bridge_set_cpu_load_cb(nullptr);
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_SYS, "desktop CPU indicator polling stopped");
|
||||
if (m_messageNotification) m_messageNotification->dismiss("shutdown");
|
||||
m_messageNotification.reset();
|
||||
delete AvatarManager::instance();
|
||||
@@ -407,6 +422,11 @@ void MainWindow::setupSoundFromConfig() {
|
||||
|
||||
void MainWindow::setupBridgeCallbacks() {
|
||||
s_mainWindow = this;
|
||||
gui_bridge_set_cpu_load_cb([](int percent) {
|
||||
if (!s_mainWindow) return;
|
||||
s_mainWindow->m_cpuLoadPending = false;
|
||||
s_mainWindow->m_channelList->setCpuLoad(percent);
|
||||
});
|
||||
gui_bridge_set_member_files_response_cb([](const uint8_t* data, int length) {
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "member_files: GUI response route bytes=%d browser=%d",
|
||||
length, (int)(s_mainWindow && s_mainWindow->m_fileBrowser));
|
||||
@@ -554,6 +574,8 @@ void MainWindow::setupBridgeCallbacks() {
|
||||
gui_bridge_set_network_changed_cb([](int type) {
|
||||
if (!s_mainWindow) return;
|
||||
if (type == 13) {
|
||||
s_mainWindow->m_cpuLoadPending = false;
|
||||
s_mainWindow->m_channelList->setCpuLoad(0);
|
||||
s_mainWindow->m_accountList->model()->setRadioState(0, false, false);
|
||||
s_mainWindow->m_messageList->clearDmCallRoute();
|
||||
s_mainWindow->m_channelList->clearDmPresence();
|
||||
|
||||
@@ -129,6 +129,8 @@ private:
|
||||
|
||||
QQueue<AutoPlayItem> m_autoPlayQueue;
|
||||
QTimer* m_autoPlayTimer = nullptr;
|
||||
QTimer* m_cpuLoadTimer = nullptr;
|
||||
bool m_cpuLoadPending = false;
|
||||
QTimer* m_shutdownTimer = nullptr;
|
||||
QSet<int64_t> m_autoPlayDownloading; /* msgIds with download in progress */
|
||||
|
||||
|
||||
Reference in new issue
Block a user