summaryrefslogtreecommitdiffstats
path: root/superkaramba/src/memsensor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'superkaramba/src/memsensor.cpp')
-rw-r--r--superkaramba/src/memsensor.cpp68
1 files changed, 43 insertions, 25 deletions
diff --git a/superkaramba/src/memsensor.cpp b/superkaramba/src/memsensor.cpp
index 8da5d58..3223b0b 100644
--- a/superkaramba/src/memsensor.cpp
+++ b/superkaramba/src/memsensor.cpp
@@ -210,9 +210,9 @@ int MemSensor::getSwapTotal()
mib[1] = VM_UVMEXP;
ssize = sizeof(uvmexp);
- if (sysctl(mib,2,&uvmexp,&ssize,NULL,0) != -1) {
- pagesize = uvmexp.pagesize;
- STotal = (pagesize*uvmexp.swpages) >> 10;
+ if (sysctl(mib, 2, &uvmexp, &ssize, NULL, 0) != -1) {
+ pagesize = uvmexp.pagesize;
+ STotal = (pagesize*uvmexp.swpages) >> 10;
}
return STotal;
#else
@@ -254,10 +254,10 @@ int MemSensor::getSwapFree()
ssize = sizeof(uvmexp);
if (sysctl(mib,2,&uvmexp,&ssize,NULL,0) != -1) {
- pagesize = uvmexp.pagesize;
- STotal = (pagesize*uvmexp.swpages) >> 10;
- SUsed = (pagesize*uvmexp.swpginuse) >> 10;
- SFree = STotal - SUsed;
+ pagesize = uvmexp.pagesize;
+ STotal = (pagesize*uvmexp.swpages) >> 10;
+ SUsed = (pagesize*uvmexp.swpginuse) >> 10;
+ SFree = STotal - SUsed;
}
return SFree;
#else
@@ -287,6 +287,9 @@ void MemSensor::readValues()
#endif
}
+#define SUB_FORMAT_STR(fstring, value) \
+ format.replace(TQRegExp(#fstring, false), TQString::number((int)(value)));
+
void MemSensor::update()
{
readValues();
@@ -319,34 +322,38 @@ void MemSensor::update()
format = "%um";
}
- format.replace( TQRegExp("%fmbp", false), TQString::number( (int)((totalMem - usedMemNoBuffers) * 100.0 / totalMem) ));
- format.replace( TQRegExp("%fmb", false), TQString::number( (int)((totalMem - usedMemNoBuffers) / 1024.0 + 0.5) ));
- format.replace( TQRegExp("%fmp", false), TQString::number( (int)((totalMem - usedMem) * 100.0 / totalMem) ));
- format.replace( TQRegExp("%fm", false), TQString::number( (int)((totalMem - usedMem) / 1024.0 + 0.5) ));
+ SUB_FORMAT_STR(%fmbp, (totalMem - usedMemNoBuffers) * 100.0 / totalMem)
+ SUB_FORMAT_STR(%fmb, (totalMem - usedMemNoBuffers) / 1024.0 + 0.5)
+ SUB_FORMAT_STR(%fmp, (totalMem - usedMem) * 100.0 / totalMem)
+ SUB_FORMAT_STR(%fm, (totalMem - usedMem) / 1024.0 + 0.5)
- format.replace( TQRegExp("%umbp", false), TQString::number( (int)(usedMemNoBuffers * 100.0 / totalMem) ));
- format.replace( TQRegExp("%umb", false), TQString::number( (int)(usedMemNoBuffers / 1024.0 + 0.5) ));
- format.replace( TQRegExp("%ump", false), TQString::number( (int)(usedMem * 100.0 / totalMem) ));
- format.replace( TQRegExp("%um", false), TQString::number( (int)(usedMem / 1024.0 + 0.5) ));
+ SUB_FORMAT_STR(%umbp, usedMemNoBuffers * 100.0 / totalMem)
+ SUB_FORMAT_STR(%umb, usedMemNoBuffers / 1024.0 + 0.5)
+ SUB_FORMAT_STR(%ump, usedMem * 100.0 / totalMem)
+ SUB_FORMAT_STR(%um, usedMem / 1024.0 + 0.5)
- format.replace( TQRegExp("%tm", false), TQString::number( (int)(totalMem / 1024.0 + 0.5) ));
+ SUB_FORMAT_STR(%tm, totalMem / 1024.0 + 0.5)
- format.replace( TQRegExp("%fsp", false), TQString::number( (int)((totalSwap - usedSwap) * 100.0 / totalSwap) ));
- format.replace( TQRegExp("%fs", false), TQString::number( (int)((totalSwap - usedSwap) / 1024.0 + 0.5) ));
- format.replace( TQRegExp("%usp", false), TQString::number( (int)(usedSwap * 100.0 / totalSwap) ));
- format.replace( TQRegExp("%us", false), TQString::number( (int)(usedSwap / 1024.0 + 0.5) ));
+ SUB_FORMAT_STR(%fsp, (totalSwap - usedSwap) * 100.0 / totalSwap)
+ SUB_FORMAT_STR(%fs, (totalSwap - usedSwap) / 1024.0 + 0.5)
+ SUB_FORMAT_STR(%usp, usedSwap * 100.0 / totalSwap)
+ SUB_FORMAT_STR(%us, usedSwap / 1024.0 + 0.5)
- format.replace( TQRegExp("%ts", false), TQString::number( (int)(totalSwap / 1024.0 + 0.5) ));
+ SUB_FORMAT_STR(%ts, totalSwap / 1024.0 + 0.5)
meter->setValue(format);
++it;
}
#if defined(Q_OS_FREEBSD) && !(defined(__FreeBSD_version) && __FreeBSD_version >= 500018)
if (set)
+ {
MaxSet = true;
+ }
#endif
}
+#undef SUB_FORMAT_STR
+
void MemSensor::setMaxValue( SensorParams *sp )
{
Meter *meter;
@@ -358,10 +365,21 @@ void MemSensor::setMaxValue( SensorParams *sp )
{
f = "%um";
}
- if( f=="%fm" || f== "%um" || f=="%fmb" || f=="%umb" )
- meter->setMax( getMemTotal() / 1024 );
- if( f=="%fs" || f== "%us" )
- meter->setMax( getSwapTotal() / 1024 );
+
+ else if (f.endsWith("p"))
+ {
+ meter->setMax(100);
+ }
+
+ else if (f == "%fm" || f == "%um" || f == "%fmb" || f == "%umb")
+ {
+ meter->setMax(getMemTotal() / 1024);
+ }
+
+ else if (f == "%fs" || f == "%us")
+ {
+ meter->setMax(getSwapTotal() / 1024);
+ }
}
#include "memsensor.moc"