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
8bd6e4fb2d
commit
5a9e61164b
25 files changed
+692
-587
No files matched your search
@@ -1,8 +1,10 @@
|
||||
/* Формат канального события: live/history сохраняются при передаче в GUI, битые события отбрасываются. */
|
||||
#include "../transport/gui_bridge.h"
|
||||
#include "../../../lib/debug_config.h"
|
||||
#include "../../../src/chat/chat_event.h"
|
||||
#include <QtTest>
|
||||
#include <cstring>
|
||||
#include <thread>
|
||||
|
||||
struct ReceivedMessage {
|
||||
QString channel;
|
||||
@@ -11,6 +13,13 @@ struct ReceivedMessage {
|
||||
bool guiThread;
|
||||
};
|
||||
static QList<ReceivedMessage> received;
|
||||
static QList<int> cpuLoads;
|
||||
static bool cpuOnGuiThread = true;
|
||||
|
||||
static void cpu_received(int percent) {
|
||||
cpuLoads.append(percent);
|
||||
cpuOnGuiThread &= QThread::currentThread() == qApp->thread();
|
||||
}
|
||||
|
||||
static void message_received(const char* channel, int length, uint64_t author, int initial_sync) {
|
||||
received.append({QString::fromUtf8(channel, length), author, initial_sync != 0, QThread::currentThread() == qApp->thread()});
|
||||
@@ -39,7 +48,7 @@ private slots:
|
||||
gui_bridge_init();
|
||||
gui_bridge_set_msg_received_cb(message_received);
|
||||
}
|
||||
void cleanupTestCase() { gui_bridge_set_msg_received_cb(nullptr); }
|
||||
void cleanupTestCase() { gui_bridge_set_msg_received_cb(nullptr); gui_bridge_set_cpu_load_cb(nullptr); }
|
||||
void init() { received.clear(); }
|
||||
|
||||
void liveAndHistory() {
|
||||
@@ -69,6 +78,26 @@ private slots:
|
||||
QTest::qWait(100);
|
||||
QVERIFY(received.isEmpty());
|
||||
}
|
||||
|
||||
void cpuLoadDeliveredToGuiThread() {
|
||||
cpuLoads.clear(); cpuOnGuiThread = true;
|
||||
gui_bridge_set_cpu_load_cb(cpu_received);
|
||||
std::thread worker([] {
|
||||
const uint8_t samples[][2] = {{1, 0}, {1, 50}, {1, 100}, {0, 90}, {1, 101}};
|
||||
for (const auto& sample : samples) gui_bridge_post(CHAT_EVT_CPU_LOAD, sample, sizeof(sample));
|
||||
gui_bridge_post(CHAT_EVT_CPU_LOAD, nullptr, 0);
|
||||
});
|
||||
worker.join();
|
||||
QVERIFY(cpuLoads.isEmpty()); // Worker не вызывает UI напрямую.
|
||||
QTRY_COMPARE(cpuLoads.size(), 6);
|
||||
QCOMPARE(cpuLoads, QList<int>({0, 50, 100, 0, 0, 0}));
|
||||
QVERIFY(cpuOnGuiThread);
|
||||
gui_bridge_set_cpu_load_cb(nullptr);
|
||||
const uint8_t sample[] = {1, 75};
|
||||
gui_bridge_post(CHAT_EVT_CPU_LOAD, sample, sizeof(sample));
|
||||
QCoreApplication::processEvents();
|
||||
QCOMPARE(cpuLoads.size(), 6);
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(MessageEventTest)
|
||||
|
||||
Reference in new issue
Block a user