Skip to content

Commit

Permalink
fix: 系统监视器占用资源过高优化
Browse files Browse the repository at this point in the history
系统监视器占用资源过高优化

Log: 系统监视器占用资源过高优化
  • Loading branch information
jeffshuai committed Aug 1, 2023
1 parent a07eda7 commit 392bbc4
Show file tree
Hide file tree
Showing 14 changed files with 222 additions and 38 deletions.
2 changes: 1 addition & 1 deletion deepin-system-monitor-main/compact_memory_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ CompactMemoryMonitor::CompactMemoryMonitor(QWidget *parent)
changeTheme(dAppHelper->themeType());

m_animation = new QPropertyAnimation(this, "progress", this);
m_animation->setDuration(250);
m_animation->setDuration(10);
m_animation->setEasingCurve(QEasingCurve::OutQuad);
m_animation->setStartValue(0);
m_animation->setEndValue(1.0);
Expand Down
2 changes: 1 addition & 1 deletion deepin-system-monitor-main/cpu_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ CpuMonitor::CpuMonitor(QWidget *parent)
connect(m_cpuInfomodel, &CPUInfoModel::modelUpdated, this, &CpuMonitor::updateStatus);

m_animation = new QPropertyAnimation(this, "progress", this);
m_animation->setDuration(250);
m_animation->setDuration(20);
m_animation->setStartValue(0.0);
m_animation->setEndValue(1.0);
m_animation->setEasingCurve(QEasingCurve::OutQuad);
Expand Down
2 changes: 1 addition & 1 deletion deepin-system-monitor-main/gui/animation_stackedwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ AnimationStackedWidget::AnimationStackedWidget(const AnimationOri ori, QWidget *
, m_animationOri(ori)
, m_Animation(new QPropertyAnimation(this, "offset"))
{
setDuration(250);
setDuration(20);
connect(m_Animation
, &QPropertyAnimation::finished
, this
Expand Down
2 changes: 1 addition & 1 deletion deepin-system-monitor-main/gui/animation_stackedwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class AnimationStackedWidget : public QStackedWidget
* @brief setDuration 设置动画持续时间
* @param duration 动画时间
*/
void setDuration(int duration = 500);
void setDuration(int duration = 10);
/**
* @brief IsRunning 动画是否正在运行
* @return 动画师傅正在运行
Expand Down
2 changes: 1 addition & 1 deletion deepin-system-monitor-main/memory_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ MemoryMonitor::MemoryMonitor(QWidget *parent)
m_animation = new QPropertyAnimation(this, "progress", this);
m_animation->setStartValue(0.0);
m_animation->setEndValue(1.0);
m_animation->setDuration(250);
m_animation->setDuration(10);
connect(m_animation, &QPropertyAnimation::valueChanged, this, &MemoryMonitor::onValueChanged);
connect(m_animation, &QPropertyAnimation::finished, this, &MemoryMonitor::onAnimationFinished);

Expand Down
101 changes: 98 additions & 3 deletions deepin-system-monitor-main/process/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,92 @@ timeval Process::procuptime() const
return d->uptime;
}

void Process::readProcessVariableInfo()
{
d->valid = true;

bool ok = true;
ok = ok && readStat();
// readEnviron();
readSchedStat();
ok = ok && readStatm();

readIO();
readSockInodes();

d->proc_name.refreashProcessName(this);
d->uptime = SysInfo::instance()->uptime();

CPUSet *cpuset = DeviceDB::instance()->cpuSet();
ProcessSet *procset = ProcessDB::instance()->processSet();

auto recentProcptr = procset->getRecentProcStage(d->pid);
auto validrecentPtr = recentProcptr.lock();
qreal timedelta = d->stime + d->utime;
if (validrecentPtr) {
timedelta = timedelta - validrecentPtr->ptime;
struct DiskIO io = {validrecentPtr->read_bytes, validrecentPtr->write_bytes, validrecentPtr->cancelled_write_bytes};
d->diskIOSample->addSample(new DISKIOSampleFrame(validrecentPtr->uptime, io));

d->networkIOSample->addSample(new IOSampleFrame(validrecentPtr->uptime, {0, 0}));
}
d->cpuUsageSample->addSample(new CPUUsageSampleFrame(qMax(0., timedelta) / cpuset->getUsageTotalDelta() * 100));

struct DiskIO io = {d->read_bytes, d->write_bytes, d->cancelled_write_bytes};
d->diskIOSample->addSample(new DISKIOSampleFrame(d->uptime, io));

auto pair = d->diskIOSample->recentSamplePair();
struct IOPS iops = DISKIOSampleFrame::diskiops(pair.first, pair.second);
d->diskIOSpeedSample->addSample(new IOPSSampleFrame(iops));

qulonglong sum_recv = 0;
qulonglong sum_send = 0;

for (int i = 0; i < d->sockInodes.size(); ++i) {
SockIOStat sockIOStat;
bool result = NetifMonitor::instance()->getSockIOStatByInode(d->sockInodes[i], sockIOStat);
if (result) {
sum_recv += sockIOStat->rx_bytes;
sum_send += sockIOStat->tx_bytes;
}
}
d->networkIOSample->addSample(new IOSampleFrame(d->uptime, {sum_recv, sum_send}));

auto netpair = d->networkIOSample->recentSamplePair();
struct IOPS netiops = IOSampleFrame::iops(netpair.first, netpair.second);
d->networkBandwidthSample->addSample(new IOPSSampleFrame(netiops));

d->valid = d->valid && ok;
}

void Process::readProcessSimpleInfo()
{
d->valid = true;
bool ok = true;
readEnviron();
ok = ok && readStat();
ok = ok && readStatus();
ok = ok && readCmdline();

d->usrerName = SysInfo::userName(d->uid);
d->proc_name.refreashProcessName(this);
d->proc_icon.refreashProcessIcon(this);

d->apptype = kNoFilter;
const QVariant &euid = ProcessDB::instance()->processEuid();
WMWindowList *wmwindowList = ProcessDB::instance()->windowList();

if (euid == d->uid && (wmwindowList->isGuiApp(d->pid)
|| wmwindowList->isTrayApp(d->pid)
|| wmwindowList->isDesktopEntryApp(d->pid))) {
d->apptype = kFilterApps;
} else if (euid == d->uid) {
d->apptype = kFilterCurrentUser;
}

d->valid = d->valid && ok;
}

void Process::readProcessInfo()
{
d->valid = true;
Expand Down Expand Up @@ -207,6 +293,8 @@ bool Process::readStat()

errno = 0;
sprintf(path, PROC_STAT_PATH, d->pid);
if(access(path, R_OK) != 0) return !ok; /* no such dirent (anymore) */

// open /proc/[pid]/stat
if ((fd = open(path, O_RDONLY)) < 0) {
print_errno(errno, QString("open %1 failed").arg(path));
Expand Down Expand Up @@ -281,6 +369,7 @@ bool Process::readCmdline()
char *begin, *cur, *end;

sprintf(path, PROC_CMDLINE_PATH, d->pid);
if(access(path, R_OK) != 0) return !ok; /* no such dirent (anymore) */

errno = 0;
// open /proc/[pid]/cmdline
Expand Down Expand Up @@ -328,6 +417,7 @@ void Process::readEnviron()
int fd;

sprintf(path, PROC_ENVIRON_PATH, d->pid);
if(access(path, R_OK) != 0) return; /* no such dirent (anymore) */

errno = 0;
// open /proc/[pid]/environ
Expand Down Expand Up @@ -372,6 +462,7 @@ void Process::readSchedStat()

buf.reserve(bsiz);
sprintf(path, PROC_SCHEDSTAT_PATH, d->pid);
if(access(path, R_OK) != 0) return; /* no such dirent (anymore) */

errno = 0;
// open /proc/[pid]/schedstat
Expand Down Expand Up @@ -405,6 +496,7 @@ bool Process::readStatus()

buf.reserve(bsiz);
sprintf(path, PROC_STATUS_PATH, d->pid);
if(access(path, R_OK) != 0) return !ok; /* no such dirent (anymore) */

errno = 0;
uFile fp(fopen(path, "r"));
Expand Down Expand Up @@ -453,6 +545,7 @@ bool Process::readStatm()
ssize_t nr;

sprintf(path, PROC_STATM_PATH, d->pid);
if(access(path, R_OK) != 0) return !ok; /* no such dirent (anymore) */

errno = 0;
// open /proc/[pid]/statm
Expand Down Expand Up @@ -492,6 +585,7 @@ void Process::readIO()
char path[128], buf[bsiz];

sprintf(path, PROC_IO_PATH, d->pid);
if(access(path, R_OK) != 0) return; /* no such dirent (anymore) */

errno = 0;
// open /proc/[pid]/io
Expand Down Expand Up @@ -524,6 +618,7 @@ void Process::readSockInodes()
struct stat sbuf;

sprintf(path, PROC_FD_PATH, d->pid);
if(access(path, R_OK) != 0) return; /* no such dirent (anymore) */

errno = 0;
// open /proc/[pid]/fd dir
Expand All @@ -548,9 +643,9 @@ void Process::readSockInodes()
} // ::if(stat)
} // ::if(isdigit)
} // ::while(readdir)
if (errno) {
print_errno(errno, QString("read %1 failed").arg(path));
}
// if (errno) {
// print_errno(errno, QString("read %1 failed").arg(path));
// }
}

bool Process::isValid() const
Expand Down
2 changes: 2 additions & 0 deletions deepin-system-monitor-main/process/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ class Process
qulonglong sentBytes() const;

void readProcessInfo();
void readProcessSimpleInfo();
void readProcessVariableInfo();

private:
/**
Expand Down
Loading

0 comments on commit 392bbc4

Please sign in to comment.