diff options
author | Ken Moore <ken@pcbsd.org> | 2015-06-10 10:26:42 -0400 |
---|---|---|
committer | Ken Moore <ken@pcbsd.org> | 2015-06-10 10:26:42 -0400 |
commit | 5d87db101a4bfb308033a0774c18c291f0f71717 (patch) | |
tree | 373bbe5e9733cb8712411e90c33915f04d350935 /libLumina | |
parent | Merge branch 'master' of github.com:pcbsd/lumina (diff) | |
download | lumina-5d87db101a4bfb308033a0774c18c291f0f71717.tar.gz lumina-5d87db101a4bfb308033a0774c18c291f0f71717.tar.bz2 lumina-5d87db101a4bfb308033a0774c18c291f0f71717.zip |
Update the memory calculation for FreeBSD/PC-BSD to also use the kernel info directly instead of running top (much faster).
Diffstat (limited to 'libLumina')
-rw-r--r-- | libLumina/LuminaOS-FreeBSD.cpp | 23 |
1 files changed, 5 insertions, 18 deletions
diff --git a/libLumina/LuminaOS-FreeBSD.cpp b/libLumina/LuminaOS-FreeBSD.cpp index 96a7d9c2..ae394f38 100644 --- a/libLumina/LuminaOS-FreeBSD.cpp +++ b/libLumina/LuminaOS-FreeBSD.cpp @@ -318,24 +318,11 @@ int LOS::CPUUsagePercent(){ //Returns: Overall percentage of the amount of CPU c int LOS::MemoryUsagePercent(){ //SYSCTL: vm.stats.vm.v_<something>_count - - //qDebug() << "Get Mem Usage"; - QStringList mem = LUtils::getCmdOutput("top -n 0").filter("Mem: ", Qt::CaseInsensitive); - if(mem.isEmpty()){ return -1; } - mem = mem.first().section(":",1,50).split(", "); - //Memory Labels: "Active", "Inact", "Wired", "Cache", "Buf", "Free" (usually in that order) - // Format of each entry: "<number><Unit> <Label>" - double fB = 0; //Free Bytes - double uB = 0; //Used Bytes - for(int i=0; i<mem.length(); i++){ - if(mem[i].contains("Inact") || mem[i].contains("Free")){ fB = fB+LUtils::DisplaySizeToBytes(mem[i].section(" ",0,0)); } - else{ uB = uB+LUtils::DisplaySizeToBytes(mem[i].section(" ",0,0)); } - } - //qDebug() << "Memory Calc:" << mem; - //qDebug() << " - Bytes:" << "U:"<<uB<<"F:"<< fB<<"T:"<< (uB+fB); - double per = (uB/(fB+uB)) * 100.0; - //qDebug() << " - Percentage:" << per; - return qRound(per); + QStringList info = LUtils::getCmdOutput("sysctl -n vm.stats.vm.v_page_count vm.stats.vm.v_wire_count vm.stats.vm.v_active_count"); + if(info.length()<3){ return -1; } //error in fetching information + //List output: [total, wired, active] + double perc = 100.0* (info[1].toLong()+info[2].toLong())/(info[0].toDouble()); + return qRound(perc); } #endif |