Skip to content

Commit

Permalink
feat: 优化底层数据读取
Browse files Browse the repository at this point in the history
优化底层数据读取

Log: 优化底层数据读取
  • Loading branch information
jeffshuai authored and deepin-bot[bot] committed Aug 14, 2023
1 parent bc858e7 commit 0c9dbf7
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 13 deletions.
3 changes: 2 additions & 1 deletion deepin-system-monitor-main/process/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ class Process
void readSockInodes();

private:
QSharedDataPointer<ProcessPrivate> d;
// QSharedDataPointer<ProcessPrivate> d;
QExplicitlySharedDataPointer<ProcessPrivate> d;
};

} // namespace process
Expand Down
68 changes: 56 additions & 12 deletions deepin-system-monitor-main/process/process_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "process/process_db.h"
#include "common/common.h"
#include "wm/wm_window_list.h"
// #include "settings.h"

#include <QDebug>

Expand All @@ -33,6 +34,11 @@ ProcessSet::ProcessSet(const ProcessSet &other)
, m_pidCtoPMapping(other.m_pidCtoPMapping)
, m_pidPtoCMapping(other.m_pidPtoCMapping)
{
m_prePid.clear();
m_curPid.clear();
m_pidMyApps.clear();
m_simpleSet.clear();
// m_settings = Settings::instance();
}

void ProcessSet::mergeSubProcNetIO(pid_t ppid, qreal &recvBps, qreal &sendBps)
Expand Down Expand Up @@ -76,7 +82,7 @@ void ProcessSet::scanProcess()
procstage->uptime = iter->procuptime();
m_recentProcStage[iter->pid()] = procstage;
}

m_curPid.clear();
m_set.clear();
m_pidPtoCMapping.clear();
m_pidCtoPMapping.clear();
Expand All @@ -86,15 +92,54 @@ void ProcessSet::scanProcess()
QList<pid_t> appLst;
while (iter.hasNext()) {
Process proc = iter.next();
if (!proc.isValid())
continue;

m_set.insert(proc.pid(), proc);
m_pidPtoCMapping.insert(proc.ppid(), proc.pid());
m_pidCtoPMapping.insert(proc.pid(), proc.ppid());
if(!m_curPid.contains(proc.pid()))
m_curPid.append(proc.pid());

}

if (proc.appType() == kFilterApps && !wmwindowList->isTrayApp(proc.pid())) {
appLst << proc.pid();
if(m_prePid != m_curPid) {
for (const pid_t &pid : m_prePid) {
if(!m_curPid.contains(pid)){
m_prePid.removeAt(pid); //remove disappear process pid
if(m_simpleSet.contains(pid))
m_simpleSet.remove(pid);
if(m_pidMyApps.contains(pid))
m_pidMyApps.removeAt(pid);
}
}

for (const pid_t &pid : m_curPid) {
if(!m_prePid.contains(pid)){ //add new process pid
Process *proc = new Process(pid);
proc->readProcessSimpleInfo();
if(!m_simpleSet.contains(pid))
m_simpleSet.insert(proc->pid(), *proc);

if (proc->appType() == kFilterApps && !wmwindowList->isTrayApp(proc->pid())) {
m_pidMyApps << proc->pid();
}
}
}
m_prePid = m_curPid;
}

// const QVariant &vindex = m_settings->getOption(kSettingKeyProcessTabIndex, kFilterApps);
// int index = vindex.toInt();

for (const pid_t &pid : m_prePid) {
Process proc = m_simpleSet[pid];
// if( ((kFilterApps == index) && (proc.appType()<= kFilterApps)) ||
// ((kFilterCurrentUser == index) && (proc.appType() <= kFilterCurrentUser)) ||
// (kNoFilter == index))
{
proc.readProcessVariableInfo(); //
if (!proc.isValid())
continue;

m_set.insert(proc.pid(), proc);
m_pidPtoCMapping.insert(proc.ppid(), proc.pid());
m_pidCtoPMapping.insert(proc.pid(), proc.ppid());
}
}

Expand All @@ -110,7 +155,7 @@ void ProcessSet::scanProcess()
return b;
};

for (const pid_t &pid : appLst) {
for (const pid_t &pid : m_pidMyApps) {
qreal recvBps = 0;
qreal sendBps = 0;
mergeSubProcNetIO(pid, recvBps, sendBps);
Expand All @@ -120,7 +165,8 @@ void ProcessSet::scanProcess()
mergeSubProcCpu(pid, ptotalCpu);
m_set[pid].setCpu(ptotalCpu);

if (!wmwindowList->isGuiApp(pid)) {
if (!wmwindowList->isGuiApp(pid))
{
// only if no ancestor process is gui app we keep this process
if (m_pidCtoPMapping.contains(pid) &&
anyRootIsGuiProc(m_pidCtoPMapping[pid])) {
Expand Down Expand Up @@ -164,11 +210,9 @@ Process ProcessSet::Iterator::next()
if (m_dirent && isdigit(m_dirent->d_name[0])) {
auto pid = pid_t(atoi(m_dirent->d_name));
Process proc(pid);
proc.readProcessInfo();

advance();

if (proc.isValid())
return proc;
}

Expand Down
6 changes: 6 additions & 0 deletions deepin-system-monitor-main/process/process_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

using namespace common::alloc;

// class Settings;
namespace core {
namespace process {

Expand Down Expand Up @@ -68,11 +69,16 @@ class ProcessSet
};

private:
// Settings *m_settings = nullptr;
QMap<pid_t, Process> m_simpleSet;
QMap<pid_t, Process> m_set;
QMap<pid_t, std::shared_ptr<RecentProcStage>> m_recentProcStage {};

QMap<pid_t, pid_t> m_pidCtoPMapping {}; // child to parent pid mapping
QMultiMap<pid_t, pid_t> m_pidPtoCMapping {}; // parent to child pid mapping
QList<pid_t> m_prePid;
QList<pid_t> m_curPid;
QList<pid_t> m_pidMyApps;

friend class Iterator;
};
Expand Down

0 comments on commit 0c9dbf7

Please sign in to comment.