Skip to content

Commit

Permalink
fix: 修复平均负载展示的指标值与实际查询的值相一致
Browse files Browse the repository at this point in the history
 修复平均负载展示的指标值与实际查询的值相一致

Log:  修复平均负载展示的指标值与实际查询的值相一致

Bug: https://pms.uniontech.com/bug-view-250027.html
  • Loading branch information
jeffshuai authored and deepin-bot[bot] committed Apr 23, 2024
1 parent dc3f0c6 commit c29f67a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
29 changes: 20 additions & 9 deletions deepin-system-monitor-main/system/sys_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,15 +385,26 @@ void SysInfo::read_btime(struct timeval &btime)

void SysInfo::read_loadavg(LoadAvg &loadAvg)
{
struct sysinfo info {
};
int rc = sysinfo(&info);
if (!rc) {
loadAvg->lavg_1m = info.loads[0];
loadAvg->lavg_5m = info.loads[1];
loadAvg->lavg_15m = info.loads[2];

return;
QFile file("/proc/loadavg");
if (file.exists() && file.open(QFile::ReadOnly)) {
// 只需要读取第一行数据
QByteArray lineData = file.readLine();
file.close();
/*样例数据:
$ cat /proc/loadavg
0.41 0.46 0.36 2/2646 20183
*/

// 分割数据 取前3
QStringList cpuStatus = QString(lineData).split(" ", QString::SkipEmptyParts);

if (cpuStatus.size() > 3) {
loadAvg->lavg_1m = cpuStatus[0].toFloat();
loadAvg->lavg_5m = cpuStatus[1].toFloat();
loadAvg->lavg_15m = cpuStatus[2].toFloat();

return ;
}
}

print_errno(errno, QString("call sysinfo failed"));
Expand Down
12 changes: 6 additions & 6 deletions deepin-system-monitor-main/system/sys_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ namespace core {
namespace system {

struct load_avg_t {
ulong lavg_1m {0};
ulong lavg_5m {0};
ulong lavg_15m {0};
float lavg_1m {0};
float lavg_5m {0};
float lavg_15m {0};
};
using LoadAvg = std::shared_ptr<struct load_avg_t>;

Expand Down Expand Up @@ -222,9 +222,9 @@ inline void SysInfo::set_btime(timeval &btime)
inline QString &operator<<(QString &buffer, const load_avg_t &rhs)
{
return buffer.append(QString("%1 %2 %3")
.arg(rhs.lavg_1m / 100, 0, 'f', 2, QLatin1Char(' '))
.arg(rhs.lavg_5m / 100, 0, 'f', 2, QLatin1Char(' '))
.arg(rhs.lavg_15m / 100, 0, 'f', 2, QLatin1Char(' ')));
.arg(rhs.lavg_1m , 0, 'f', 2, QLatin1Char(' '))
.arg(rhs.lavg_5m , 0, 'f', 2, QLatin1Char(' '))
.arg(rhs.lavg_15m , 0, 'f', 2, QLatin1Char(' ')));
}

} // namespace system
Expand Down

0 comments on commit c29f67a

Please sign in to comment.