aboutsummaryrefslogtreecommitdiff
path: root/libLumina/LuminaOS-FreeBSD.cpp
diff options
context:
space:
mode:
authorKen Moore <ken@pcbsd.org>2015-05-21 15:27:33 -0400
committerKen Moore <ken@pcbsd.org>2015-05-21 15:27:33 -0400
commit952da97e1338852c8d5eeba380d2244a1f433edf (patch)
tree00296866beb820d6491abc6f33f1d2b0bba151b9 /libLumina/LuminaOS-FreeBSD.cpp
parentRemove the extra painting check/update routine for the system tray - send it ... (diff)
downloadlumina-952da97e1338852c8d5eeba380d2244a1f433edf.tar.gz
lumina-952da97e1338852c8d5eeba380d2244a1f433edf.tar.bz2
lumina-952da97e1338852c8d5eeba380d2244a1f433edf.zip
Add a few new functions to LuminaOS:
1) CPUTemperatures() 2) CPUUsagePercent() 3) MemoryUsagePercent() These functions have been filled out for the LuminaOS-FreeBSD implementation, but not for any of the others yet. The FreeBSD implementation has also not been tested yet. Also add a new "DisplayNumberToBytes()" function into LuminaUtils for converting sizes in a string format (50M or 50MB for example) into a double with the number of bytes for calculations.
Diffstat (limited to 'libLumina/LuminaOS-FreeBSD.cpp')
-rw-r--r--libLumina/LuminaOS-FreeBSD.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/libLumina/LuminaOS-FreeBSD.cpp b/libLumina/LuminaOS-FreeBSD.cpp
index 7ef782d9..0843b1ce 100644
--- a/libLumina/LuminaOS-FreeBSD.cpp
+++ b/libLumina/LuminaOS-FreeBSD.cpp
@@ -255,4 +255,36 @@ QString LOS::FileSystemCapacity(QString dir) { //Return: percentage capacity as
return capacity;
}
+QStringList LOS::CPUTemperatures(){ //Returns: List containing the temperature of any CPU's ("50C" for example)
+ QStringList temps = LUtils::getCmdOutput("sysctl -ai").filter(".temperature:");
+ for(int i=0; i<temps.length(); i++){
+ temps[i] = temps[i].section(":",1,5).simplified(); //only pull out the value, not the variable
+ }
+ return temps;
+}
+
+int LOS::CPUUsagePercent(){ //Returns: Overall percentage of the amount of CPU cycles in use (-1 for errors)
+ QStringList info = LUtils::getCmdOutput("iostat -t proc -Cd");
+ //Output: [cpu header, column headers, values(us ni sy in id)]
+ if(info.length()==3){
+ //idle value is the last one, use 100% minus that (don't worry about usage breakdown)
+ return (100 - info[2].section(" ",4,4,QString::SectionSkipEmpty).toInt());
+ }else{
+ return -1; //error
+ }
+}
+
+int LOS::MemoryUsagePercent(){
+ QStringList mem = LUtils::getCmdOutput("top -n 0").filter("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)); }
+ }
+ return qRound( (uB/(fB+uB)) * 100.0);
+}
+
#endif
bgstack15