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.cpp90
1 files changed, 62 insertions, 28 deletions
diff --git a/superkaramba/src/memsensor.cpp b/superkaramba/src/memsensor.cpp
index 98eceea..1aac365 100644
--- a/superkaramba/src/memsensor.cpp
+++ b/superkaramba/src/memsensor.cpp
@@ -33,7 +33,7 @@
#include <uvm/uvm_extern.h>
#endif
-#include <kprocio.h>
+#include <tdeprocio.h>
#if defined Q_OS_FREEBSD || defined(Q_OS_NETBSD)
/* define pagetok in terms of pageshift */
@@ -57,10 +57,10 @@ MemSensor::MemSensor(int msec) : Sensor(msec)
# if defined(Q_OS_FREEBSD) && defined(__FreeBSD_version) && __FreeBSD_version >= 500018
kd = kvm_open("/dev/null", "/dev/null", "/dev/null", O_RDONLY, "kvm_open");
# elif defined Q_OS_FREEBSD
- connect(&ksp, TQT_SIGNAL(receivedStdout(TDEProcess *, char *, int )),
- this,TQT_SLOT(receivedStdout(TDEProcess *, char *, int )));
- connect(&ksp, TQT_SIGNAL(processExited(TDEProcess *)),
- this,TQT_SLOT(processExited( TDEProcess * )));
+ connect(&ksp, TQ_SIGNAL(receivedStdout(TDEProcess *, char *, int )),
+ this,TQ_SLOT(receivedStdout(TDEProcess *, char *, int )));
+ connect(&ksp, TQ_SIGNAL(processExited(TDEProcess *)),
+ this,TQ_SLOT(processExited( TDEProcess * )));
swapTotal = swapUsed = 0;
@@ -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
@@ -273,7 +273,7 @@ void MemSensor::readValues()
# if defined(Q_OS_FREEBSD) && !(defined(__FreeBSD_version) && __FreeBSD_version >= 500018)
ksp.clearArguments();
ksp << "swapinfo";
- ksp.start( TDEProcess::NotifyOnExit,KProcIO::Stdout);
+ ksp.start( TDEProcess::NotifyOnExit,TDEProcIO::Stdout);
# endif
#else
TQFile file("/proc/meminfo");
@@ -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,27 +322,46 @@ void MemSensor::update()
format = "%um";
}
- format.replace( TQRegExp("%fmb", false), TQString::number( (int)(( totalMem - usedMemNoBuffers)/1024.0+0.5)));
- format.replace( TQRegExp("%fm", false), TQString::number( (int)( ( totalMem - usedMem )/1024.0+0.5) ));
-
- format.replace( TQRegExp("%umb", false), TQString::number( (int)((usedMemNoBuffers)/1024.0+0.5)));
- format.replace( TQRegExp("%um", false), TQString::number( (int)((usedMem)/1024.0+0.5 )));
-
- format.replace( TQRegExp("%tm", false), TQString::number( (int)( (totalMem)/1024.0+0.5)));
-
- format.replace( TQRegExp("%fs", false), TQString::number( (int)((totalSwap - usedSwap)/1024.0+0.5)));
- format.replace( TQRegExp("%us", false), TQString::number( (int)(usedSwap/1024.0+0.5)));
- format.replace( TQRegExp("%ts", false), TQString::number( (int)(totalSwap/1024.0+0.5)));
+ SUB_FORMAT_STR(%fmbp, (totalMem - usedMemNoBuffers) * 100.0 / totalMem);
+ SUB_FORMAT_STR(%fmbg, (totalMem - usedMemNoBuffers) / 1024.0 / 1024.0 + 1);
+ SUB_FORMAT_STR(%fmb, (totalMem - usedMemNoBuffers) / 1024.0 + 0.5);
+ SUB_FORMAT_STR(%fmp, (totalMem - usedMem) * 100.0 / totalMem);
+ SUB_FORMAT_STR(%fmg, (totalMem - usedMem) / 1024.0 / 1024.0 + 1);
+ SUB_FORMAT_STR(%fm, (totalMem - usedMem) / 1024.0 + 0.5);
+
+ SUB_FORMAT_STR(%umbp, usedMemNoBuffers * 100.0 / totalMem);
+ SUB_FORMAT_STR(%umbg, usedMemNoBuffers / 1024.0 / 1024.0 + 1);
+ SUB_FORMAT_STR(%umb, usedMemNoBuffers / 1024.0 + 0.5);
+ SUB_FORMAT_STR(%ump, usedMem * 100.0 / totalMem);
+ SUB_FORMAT_STR(%umg, usedMem / 1024.0 / 1024.0 + 1);
+ SUB_FORMAT_STR(%um, usedMem / 1024.0 + 0.5);
+
+ SUB_FORMAT_STR(%tmg, totalMem / 1024.0 / 1024.0 + 1);
+ SUB_FORMAT_STR(%tm, totalMem / 1024.0 + 0.5);
+
+ SUB_FORMAT_STR(%fsp, (totalSwap - usedSwap) * 100.0 / totalSwap);
+ SUB_FORMAT_STR(%fsg, (totalSwap - usedSwap) / 1024.0 / 1024.0 + 1);
+ SUB_FORMAT_STR(%fs, (totalSwap - usedSwap) / 1024.0 + 0.5);
+ SUB_FORMAT_STR(%usp, usedSwap * 100.0 / totalSwap);
+ SUB_FORMAT_STR(%usg, usedSwap / 1024.0 / 1024.0 + 1);
+ SUB_FORMAT_STR(%us, usedSwap / 1024.0 + 0.5);
+
+ SUB_FORMAT_STR(%tsg, totalSwap / 1024.0 / 1024.0 + 1);
+ 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;
@@ -351,10 +373,22 @@ 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 == "%fmg" || f == "%umg" || f == "%fmbg" || f == "%umbg")
+ {
+ meter->setMax(getMemTotal() / 1024 / 1024);
+ }
+ else if (f == "%fs" || f == "%us" || f == "%fsg" || f == "%usg")
+ {
+ meter->setMax(getSwapTotal() / 1024);
+ }
}
#include "memsensor.moc"