Skip to content

Commit

Permalink
add current cpu clock to main page
Browse files Browse the repository at this point in the history
  • Loading branch information
jgabriel98 committed Jan 11, 2020
1 parent 28c3c29 commit cd75dbd
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
21 changes: 21 additions & 0 deletions stacer-core/Info/cpu_info.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "cpu_info.h"

#include "command_util.h"

quint8 CpuInfo::getCpuCoreCount() const
{
static quint8 count = 0;
Expand Down Expand Up @@ -30,6 +32,25 @@ QList<double> CpuInfo::getLoadAvgs() const
return avgs;
}

double CpuInfo::getAvgClock() const
{
QStringList lines = CommandUtil::exec("bash",{"-c", LSCPU_COMMAND}).split('\n');
QString clockMHz = lines.filter(QRegExp("^CPU MHz")).first().split(":").last();
return clockMHz.toDouble();
}

QList<double> CpuInfo::getClocks() const
{
QStringList lines = FileUtil::readListFromFile(PROC_CPUINFO)
.filter(QRegExp("^cpu MHz"));

QList<double> clocks;
for(auto line: lines){
clocks.push_back(line.split(":").last().toDouble());
}
return clocks;
}

QList<int> CpuInfo::getCpuPercents() const
{
QList<double> cpuTimes;
Expand Down
3 changes: 3 additions & 0 deletions stacer-core/Info/cpu_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "Utils/file_util.h"

#define PROC_CPUINFO "/proc/cpuinfo"
#define LSCPU_COMMAND "LANG=nl_NL.UTF-8 lscpu"
#define PROC_LOADAVG "/proc/loadavg"
#define PROC_STAT "/proc/stat"

Expand All @@ -18,6 +19,8 @@ class STACERCORESHARED_EXPORT CpuInfo
quint8 getCpuCoreCount() const;
QList<int> getCpuPercents() const;
QList<double> getLoadAvgs() const;
double getAvgClock() const;
QList<double> getClocks() const;

private:
int getCpuPercent(const QList<double> &cpuTimes, const int &processor = 0) const;
Expand Down
5 changes: 5 additions & 0 deletions stacer/Managers/info_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ QList<double> InfoManager::getCpuLoadAvgs() const
return ci.getLoadAvgs();
}

double InfoManager::getCpuClock() const
{
return ci.getAvgClock();
}

/*
* Memory Provider
*/
Expand Down
1 change: 1 addition & 0 deletions stacer/Managers/info_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class InfoManager
quint8 getCpuCoreCount() const;
QList<int> getCpuPercents() const;
QList<double> getCpuLoadAvgs() const;
double getCpuClock() const;

quint64 getSwapUsed() const;
quint64 getSwapTotal() const;
Expand Down
3 changes: 2 additions & 1 deletion stacer/Pages/Dashboard/dashboard_page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ void DashboardPage::systemInformationInit()
void DashboardPage::updateCpuBar()
{
int cpuUsedPercent = im->getCpuPercents().at(0);
double cpuCurrentClockGHz = im->getCpuClock()/1000.0;

// alert message
int cpuAlerPercent = mSettingManager->getCpuAlertPercent();
Expand All @@ -142,7 +143,7 @@ void DashboardPage::updateCpuBar()
}
}

mCpuBar->setValue(cpuUsedPercent, QString("%1%").arg(cpuUsedPercent));
mCpuBar->setValue(cpuUsedPercent, QString("%1 GHz\n%2%").arg(cpuCurrentClockGHz, 0, 'f', 2).arg(cpuUsedPercent));
}

void DashboardPage::updateMemoryBar()
Expand Down

0 comments on commit cd75dbd

Please sign in to comment.