fix(process_list): mergeSubProcCpu

Description: mergeSubProcCpu

Log: 192254引申的磁盘,处理器是否需要统一进行叠加
Task: https://172.17.50.104/task-view-178550.html
This commit is contained in:
hesisheng 2023-10-26 10:22:43 +08:00
parent 2f2e3b9d08
commit 315f64bc07
2 changed files with 36 additions and 14 deletions

View File

@ -999,6 +999,19 @@ void ProcessList::mergeSubProcNetIO(pid_t ppid, qreal &mergeBps)
mergeBps += proc.getFlowNet();
}
void ProcessList::mergeSubProcCpu(pid_t ppid, qreal &cpu)
{
auto it = m_pidPtoCMapping.find(ppid);
while (it != m_pidPtoCMapping.end() && it.key() == ppid) {
mergeSubProcCpu(it.value(), cpu);
++it;
}
const Process &proc = m_allSet[ppid];
// qDebug() << "ppid = " << ppid << "cpu of ppid = " << proc.getCpuPercent();
cpu += proc.getCpuPercent();
}
void ProcessList::scanProcess()
{
pid_t* pid_list;
@ -1083,16 +1096,6 @@ void ProcessList::scanProcess()
}
for (const pid_t &pid : appList) {
qreal mergeBps = 0;
mergeSubProcNetIO(pid, mergeBps);
m_set[pid].setFlowNet(mergeBps);
qDebug() << "ppid of gui app = " << pid << " mergedBsp = " << mergeBps;
QString addFlownetPerSec = m_set[pid].calcFlownetPerSec(mergeBps, true);
m_set[pid].setFlowNetDesc(addFlownetPerSec);
}
for(int i = 0; i < validList.size(); ++i)
{
pid_t pidCur = validList[i];
@ -1157,6 +1160,9 @@ void ProcessList::scanProcess()
sPcpu = MIN(sPcpu, proc.getProcThreads()*100);
}
proc.setCpuPercent(sPcpu);
if (m_allSet.contains(proc.pid())) {
m_allSet[proc.pid()].setCpuPercent(sPcpu);
}
}
// CPU 百分比使用 Solaris 模式工作在“Solaris 模式”,其中任务的 CPU 使用量将被除以总的 CPU 数目。否则它将工作在“Irix 模式”。
@ -1218,10 +1224,7 @@ void ProcessList::scanProcess()
proc.setProcCpuDurationTime(formatDurationForDisplay(100 * proc.getProcCpuTime() / proc.getFrequency()));
proc.setProcStatus(formatProcessState(proc.getStatus()));
// 记录所有进程数据与pid关系
if (!m_allSet.contains(proc.pid())) {
m_allSet[proc.pid()] = proc;
}
if (proc.getStatus() == GLIBTOP_PROCESS_ZOMBIE) {
if (m_set.contains(proc.pid())) {
@ -1247,6 +1250,24 @@ void ProcessList::scanProcess()
} else {
m_set[proc.pid()] = proc;
}
// 记录所有进程数据与pid关系
if (!m_allSet.contains(proc.pid())) {
m_allSet[proc.pid()] = proc;
}
}
for (const pid_t &pid : appList) {
qreal mergeBps = 0;
mergeSubProcNetIO(pid, mergeBps);
m_set[pid].setFlowNet(mergeBps);
QString addFlownetPerSec = m_set[pid].calcFlownetPerSec(mergeBps, true);
m_set[pid].setFlowNetDesc(addFlownetPerSec);
qreal ptotalCpu = 0.;
mergeSubProcCpu(pid, ptotalCpu);
m_set[pid].setCpuPercent(ptotalCpu);
}
}

View File

@ -224,6 +224,7 @@ Q_SIGNALS:
private:
void mergeSubProcNetIO(pid_t ppid, qreal &mergeBps);
void mergeSubProcCpu(pid_t ppid, qreal &cpu);
void scanProcess();
unsigned getCpuCount();
bool isScritCmdProc(QString strCmdLine);