diff options
author | Ken Moore <ken@pcbsd.org> | 2015-05-21 15:27:33 -0400 |
---|---|---|
committer | Ken Moore <ken@pcbsd.org> | 2015-05-21 15:27:33 -0400 |
commit | 952da97e1338852c8d5eeba380d2244a1f433edf (patch) | |
tree | 00296866beb820d6491abc6f33f1d2b0bba151b9 | |
parent | Remove the extra painting check/update routine for the system tray - send it ... (diff) | |
download | lumina-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.
-rw-r--r-- | libLumina/LuminaOS-Debian.cpp | 12 | ||||
-rw-r--r-- | libLumina/LuminaOS-DragonFly.cpp | 13 | ||||
-rw-r--r-- | libLumina/LuminaOS-FreeBSD.cpp | 32 | ||||
-rw-r--r-- | libLumina/LuminaOS-Linux.cpp | 13 | ||||
-rw-r--r-- | libLumina/LuminaOS-OpenBSD.cpp | 12 | ||||
-rw-r--r-- | libLumina/LuminaOS-kFreeBSD.cpp | 12 | ||||
-rw-r--r-- | libLumina/LuminaOS-template.cpp | 12 | ||||
-rw-r--r-- | libLumina/LuminaOS.h | 5 | ||||
-rw-r--r-- | libLumina/LuminaUtils.cpp | 16 | ||||
-rw-r--r-- | libLumina/LuminaUtils.h | 1 |
10 files changed, 128 insertions, 0 deletions
diff --git a/libLumina/LuminaOS-Debian.cpp b/libLumina/LuminaOS-Debian.cpp index 650a2b5a..e3aabeae 100644 --- a/libLumina/LuminaOS-Debian.cpp +++ b/libLumina/LuminaOS-Debian.cpp @@ -235,4 +235,16 @@ 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) + return QStringList(); //not implemented yet +} + +int LOS::CPUUsagePercent(){ //Returns: Overall percentage of the amount of CPU cycles in use (-1 for errors) + return -1; //not implemented yet +} + +int LOS::MemoryUsagePercent(){ + return -1; //not implemented yet +} + #endif diff --git a/libLumina/LuminaOS-DragonFly.cpp b/libLumina/LuminaOS-DragonFly.cpp index 57ff1b2a..dde24d0c 100644 --- a/libLumina/LuminaOS-DragonFly.cpp +++ b/libLumina/LuminaOS-DragonFly.cpp @@ -194,4 +194,17 @@ QString LOS::FileSystemCapacity(QString dir) { //Return: percentage capacity as QString capacity = mountInfo[1].section(" ",4,4, skipEmpty); return capacity; } + +QStringList LOS::CPUTemperatures(){ //Returns: List containing the temperature of any CPU's ("50C" for example) + return QStringList(); //not implemented yet +} + +int LOS::CPUUsagePercent(){ //Returns: Overall percentage of the amount of CPU cycles in use (-1 for errors) + return -1; //not implemented yet +} + +int LOS::MemoryUsagePercent(){ + return -1; //not implemented yet +} + #endif 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 diff --git a/libLumina/LuminaOS-Linux.cpp b/libLumina/LuminaOS-Linux.cpp index 6929c9c3..e60677d5 100644 --- a/libLumina/LuminaOS-Linux.cpp +++ b/libLumina/LuminaOS-Linux.cpp @@ -222,4 +222,17 @@ QString LOS::FileSystemCapacity(QString dir) { //Return: percentage capacity as QString capacity = mountInfo[1].section(" ",4,4, skipEmpty) + " used"; return capacity; } + +QStringList LOS::CPUTemperatures(){ //Returns: List containing the temperature of any CPU's ("50C" for example) + return QStringList(); //not implemented yet +} + +int LOS::CPUUsagePercent(){ //Returns: Overall percentage of the amount of CPU cycles in use (-1 for errors) + return -1; //not implemented yet +} + +int LOS::MemoryUsagePercent(){ + return -1; //not implemented yet +} + #endif diff --git a/libLumina/LuminaOS-OpenBSD.cpp b/libLumina/LuminaOS-OpenBSD.cpp index 5fda4866..10bb4e15 100644 --- a/libLumina/LuminaOS-OpenBSD.cpp +++ b/libLumina/LuminaOS-OpenBSD.cpp @@ -232,4 +232,16 @@ QString LOS::FileSystemCapacity(QString dir) { return capacity; } +QStringList LOS::CPUTemperatures(){ //Returns: List containing the temperature of any CPU's ("50C" for example) + return QStringList(); //not implemented yet +} + +int LOS::CPUUsagePercent(){ //Returns: Overall percentage of the amount of CPU cycles in use (-1 for errors) + return -1; //not implemented yet +} + +int LOS::MemoryUsagePercent(){ + return -1; //not implemented yet +} + #endif diff --git a/libLumina/LuminaOS-kFreeBSD.cpp b/libLumina/LuminaOS-kFreeBSD.cpp index dee5a6c8..8954d685 100644 --- a/libLumina/LuminaOS-kFreeBSD.cpp +++ b/libLumina/LuminaOS-kFreeBSD.cpp @@ -173,5 +173,17 @@ QString LOS::FileSystemCapacity(QString dir) { //Return: percentage capacity as return QString(); } +QStringList LOS::CPUTemperatures(){ //Returns: List containing the temperature of any CPU's ("50C" for example) + return QStringList(); //not implemented yet +} + +int LOS::CPUUsagePercent(){ //Returns: Overall percentage of the amount of CPU cycles in use (-1 for errors) + return -1; //not implemented yet +} + +int LOS::MemoryUsagePercent(){ + return -1; //not implemented yet +} + #endif #endif diff --git a/libLumina/LuminaOS-template.cpp b/libLumina/LuminaOS-template.cpp index aabd7da3..eb233913 100644 --- a/libLumina/LuminaOS-template.cpp +++ b/libLumina/LuminaOS-template.cpp @@ -121,4 +121,16 @@ QString LOS::FileSystemCapacity(QString dir) { //Return: percentage capacity as return QString(); } +QStringList LOS::CPUTemperatures(){ //Returns: List containing the temperature of any CPU's ("50C" for example) + return QStringList(); //not implemented yet +} + +int LOS::CPUUsagePercent(){ //Returns: Overall percentage of the amount of CPU cycles in use (-1 for errors) + return -1; //not implemented yet +} + +int LOS::MemoryUsagePercent(){ + return -1; //not implemented yet +} + #endif diff --git a/libLumina/LuminaOS.h b/libLumina/LuminaOS.h index eb0e2eb6..738be5e4 100644 --- a/libLumina/LuminaOS.h +++ b/libLumina/LuminaOS.h @@ -91,6 +91,11 @@ public: //Get the filesystem capacity static QString FileSystemCapacity(QString dir) ; //Return: percentage capacity as give by the df command + + //System CPU Information + static QStringList CPUTemperatures(); //Returns: List containing the temperature of any CPU's ("50C" for example) + static int CPUUsagePercent(); //Returns: Overall percentage of the amount of CPU cycles in use (-1 for errors) + static int MemoryUsagePercent(); //Returns: Overall percentage of the amount of available memory in use (-1 for errors) }; #endif diff --git a/libLumina/LuminaUtils.cpp b/libLumina/LuminaUtils.cpp index cbf3b382..f1c007f0 100644 --- a/libLumina/LuminaUtils.cpp +++ b/libLumina/LuminaUtils.cpp @@ -146,6 +146,22 @@ void LUtils::LoadTranslation(QApplication *app, QString appname){ QTextCodec::setCodecForLocale( QTextCodec::codecForName(langEnc.toUtf8()) ); } +double LUtils::DisplaySizeToBytes(QString num){ + num = num.toLower().simplified(); + if(num.endsWith("b")){ num.chop(1); } //remove the "bytes" marker (if there is one) + QString lab = "b"; + if(!num[num.size()-1].isNumber()){ + lab = num.right(1); num.chop(1); + } + double N = num.toDouble(); + QStringList labs; labs <<"b"<<"k"<<"m"<<"g"<<"t"<<"p"; //go up to petabytes for now + for(int i=0; i<labs.length(); i++){ + if(lab==labs[i]){ break; }//already at the right units - break out + N = N*1024.0; //Move to the next unit of measurement + } + return N; +} + QStringList LUtils::listFavorites(){ static QStringList fav; static QDateTime lastRead; diff --git a/libLumina/LuminaUtils.h b/libLumina/LuminaUtils.h index 7af32d21..960e6080 100644 --- a/libLumina/LuminaUtils.h +++ b/libLumina/LuminaUtils.h @@ -44,6 +44,7 @@ public: //Load a translation file for a Lumina Project static void LoadTranslation(QApplication *app, QString appname); + static double DisplaySizeToBytes(QString num); //Turn a display size (like 50M or 50KB) into a double for calculations (bytes) //Various functions for the favorites sub-system // Formatting Note: "<name>::::[dir/app/<mimetype>]::::<path>" |