174 lines
5.9 KiB
C++
Executable File
174 lines
5.9 KiB
C++
Executable File
/**
|
|
* @file SystemInfoUpdateThread.cpp
|
|
* @author jinchao
|
|
* @brief 系统信息更新线程实现
|
|
* @version 1.0
|
|
* @date 2025-03-10
|
|
*
|
|
* @copyright Copyright (c) 2025 COMAC
|
|
*
|
|
*/
|
|
#include "SystemInfoUpdateThread.h"
|
|
#include <random>
|
|
#include <QDebug>
|
|
#include "../TopicManager/TopicManager.h"
|
|
|
|
SystemInfoUpdateThread::~SystemInfoUpdateThread()
|
|
{
|
|
//注销引擎状态订阅
|
|
TopicManager::Instance()->unregisterSubscriber("XNSim::XNSimStatus::XNEngineStatus");
|
|
//注销线程状态订阅
|
|
TopicManager::Instance()->unregisterSubscriber("XNSim::XNSimStatus::XNThreadStatus");
|
|
}
|
|
|
|
void SystemInfoUpdateThread::run()
|
|
{
|
|
//周期计数
|
|
quint64 cycleCount = 0;
|
|
//线程周期计数
|
|
QMap<quint32, quint64> threadCycleCount;
|
|
while (!m_Quit) {
|
|
if (m_Active) {
|
|
QMutexLocker locker(&m_Mutex);
|
|
//获取引擎状态
|
|
XNSim::XNSimStatus::XNCoreStatus coreStatus = engineStatus.XNCoreSt();
|
|
//引擎状态更新
|
|
if (m_EngineStatusUpdate) {
|
|
//更新引擎名称
|
|
emit updateEngineName(QString::fromStdString(engineStatus.XNEngineName()));
|
|
//更新引擎ID
|
|
emit updateEngineID(engineStatus.XNEngineID());
|
|
//更新引擎状态
|
|
emit updateEngineStatus(engineStatus.XNEngineSt());
|
|
//更新亲和性
|
|
QString affinity = "";
|
|
for (int i = 0; i < sizeof(engineStatus.XNEngineAff()); i++) {
|
|
if ((engineStatus.XNEngineAff() >> i) & 1 == 1) {
|
|
affinity += QString::number(i) + ",";
|
|
}
|
|
}
|
|
affinity.remove(affinity.length() - 1, 1);
|
|
emit updateAffinity(affinity);
|
|
//更新线程数量
|
|
emit updateThreadCount(engineStatus.XNThCnt());
|
|
//更新内核状态
|
|
emit updateCoreStatus(0, coreStatus.XNFWStatus());
|
|
//更新任务管理器状态
|
|
emit updateCoreStatus(1, coreStatus.XNTMStatus());
|
|
//更新执行管理器状态
|
|
emit updateCoreStatus(2, coreStatus.XNEMStatus());
|
|
//更新数据管理器状态
|
|
emit updateCoreStatus(3, coreStatus.XNSDStatus());
|
|
//更新任务管理器状态
|
|
emit updateCoreStatus(4, coreStatus.XNThMStatus());
|
|
//更新内存管理器状态
|
|
emit updateCoreStatus(5, coreStatus.XNMMStatus());
|
|
//更新系统管理器状态
|
|
emit updateCoreStatus(6, coreStatus.XNSMStatus());
|
|
//更新调度管理器状态
|
|
emit updateCoreStatus(7, coreStatus.XNDMStatus());
|
|
//引擎状态更新标志
|
|
m_EngineStatusUpdate = false;
|
|
} else {
|
|
//更新引擎状态
|
|
emit updateEngineStatus(99);
|
|
}
|
|
|
|
//填写线程信息
|
|
for (auto &threadStatus : m_ThreadStatus) {
|
|
XNRuntimeData threadData;
|
|
//更新线程名称
|
|
threadData.m_name = QString::fromStdString(threadStatus.XNThreadName());
|
|
//更新线程周期计数
|
|
threadData.m_CycleCount = threadStatus.XNThRunCnt();
|
|
//更新线程ID
|
|
threadData.m_id = threadStatus.XNThreadID();
|
|
//更新线程亲和性掩码
|
|
threadData.m_AffinityMask = threadStatus.XNThreadAff();
|
|
//更新线程优先级
|
|
threadData.m_Priority = threadStatus.XNThreadPro();
|
|
//更新线程运行状态
|
|
if (threadCycleCount.contains(threadData.m_id)) {
|
|
if (threadCycleCount[threadData.m_id] != threadData.m_CycleCount) {
|
|
//更新线程周期计数
|
|
threadCycleCount[threadData.m_id] = threadData.m_CycleCount;
|
|
//更新线程运行状态
|
|
threadData.m_RunningState = threadStatus.XNThreadSt();
|
|
} else {
|
|
//更新线程运行状态
|
|
threadData.m_RunningState = 99;
|
|
continue;
|
|
}
|
|
} else {
|
|
//更新线程周期计数
|
|
threadCycleCount[threadData.m_id] = threadData.m_CycleCount;
|
|
//更新线程运行状态
|
|
threadData.m_RunningState = threadStatus.XNThreadSt();
|
|
}
|
|
//更新线程设定频率
|
|
threadData.m_SetFrequency = threadStatus.XNThSetFreq();
|
|
//更新线程当前频率
|
|
double currectFrequency = threadStatus.XNThCurFreq();
|
|
threadData.m_CurrentFrequency.push_back(currectFrequency);
|
|
//更新线程当前周期
|
|
threadData.m_CurrentPeriod.push_back(1000.0 / currectFrequency);
|
|
//更新线程最小频率
|
|
threadData.m_MinFrequency = currectFrequency;
|
|
//更新线程最大频率
|
|
threadData.m_MaxFrequency = currectFrequency;
|
|
//更新线程平均频率
|
|
threadData.m_AvgFrequency = currectFrequency;
|
|
//更新线程最小周期
|
|
threadData.m_MinPeriod = 1000.0 / currectFrequency;
|
|
//更新线程最大周期
|
|
threadData.m_MaxPeriod = 1000.0 / currectFrequency;
|
|
//更新线程平均周期
|
|
threadData.m_AvgPeriod = 1000.0 / currectFrequency;
|
|
//更新线程设定周期
|
|
threadData.m_SetPeriod = 1000.0 / threadStatus.XNThSetFreq();
|
|
//更新线程信息
|
|
emit updateThreadInfo(threadData);
|
|
}
|
|
}
|
|
//休眠
|
|
QThread::msleep(m_SleepTime);
|
|
}
|
|
}
|
|
|
|
void SystemInfoUpdateThread::onChangeSleepTime(const unsigned int newSleepTime)
|
|
{
|
|
m_SleepTime = newSleepTime;
|
|
}
|
|
|
|
void SystemInfoUpdateThread::onThreadController(const bool &isActive)
|
|
{
|
|
m_Active = isActive;
|
|
}
|
|
|
|
void SystemInfoUpdateThread::Initialize()
|
|
{
|
|
//注册引擎状态订阅
|
|
TopicManager::Instance()->registerSubscriber<XNSim::XNSimStatus::XNEngineStatusPubSubType>(
|
|
"XNSim::XNSimStatus::XNEngineStatus",
|
|
std::bind(&SystemInfoUpdateThread::EngineStatusListener, this, std::placeholders::_1));
|
|
//注册线程状态订阅
|
|
TopicManager::Instance()->registerSubscriber<XNSim::XNSimStatus::XNThreadStatusPubSubType>(
|
|
"XNSim::XNSimStatus::XNThreadStatus",
|
|
std::bind(&SystemInfoUpdateThread::ThreadStatusListener, this, std::placeholders::_1));
|
|
}
|
|
|
|
void SystemInfoUpdateThread::EngineStatusListener(const XNSim::XNSimStatus::XNEngineStatus &status)
|
|
{
|
|
QMutexLocker locker(&m_Mutex);
|
|
m_EngineStatusUpdate = true;
|
|
engineStatus = status;
|
|
}
|
|
|
|
void SystemInfoUpdateThread::ThreadStatusListener(const XNSim::XNSimStatus::XNThreadStatus &status)
|
|
{
|
|
if (m_Active) {
|
|
QMutexLocker locker(&m_Mutex);
|
|
m_ThreadStatus[status.XNThreadID()] = status;
|
|
}
|
|
}
|