|
|
|
|
@ -21,17 +21,16 @@
|
|
|
|
|
#ifdef HAVE_FCNTL_H
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#endif
|
|
|
|
|
#include <fstream>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
#if defined(USE_SOLARIS)
|
|
|
|
|
#ifdef Q_OS_SOLARIS
|
|
|
|
|
#include <kstat.h>
|
|
|
|
|
#include <sys/sysinfo.h>
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#include <sys/swap.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef __NetBSD__
|
|
|
|
|
#ifdef Q_OS_NETBSD
|
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
|
#include <sys/sched.h>
|
|
|
|
|
#include <uvm/uvm_extern.h>
|
|
|
|
|
@ -46,11 +45,11 @@
|
|
|
|
|
|
|
|
|
|
// -- global definitions -------------------------------------------------
|
|
|
|
|
|
|
|
|
|
#if defined(USE_SOLARIS)
|
|
|
|
|
#ifdef Q_OS_SOLARIS
|
|
|
|
|
extern "C" int getpagesize(); // argh, have to define prototype!
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef __linux__
|
|
|
|
|
#ifdef Q_OS_LINUX
|
|
|
|
|
// -- global constants ---------------------------------------------------
|
|
|
|
|
#define STAT_NAME "/proc/stat"
|
|
|
|
|
#define MEMINFO_NAME "/proc/meminfo"
|
|
|
|
|
@ -79,14 +78,14 @@ void KSample::Sample::fill(unsigned scale)
|
|
|
|
|
// the proc filesystem; for other platforms perform equivalent initialisation
|
|
|
|
|
KSample::KSample(KTimeMon *t, bool a, unsigned p, unsigned s, unsigned c) :
|
|
|
|
|
timemon(t),
|
|
|
|
|
#ifdef __linux__
|
|
|
|
|
#ifdef Q_OS_LINUX
|
|
|
|
|
memFD(-1), statFD(-1),
|
|
|
|
|
#elif defined (USE_SOLARIS)
|
|
|
|
|
#elif defined (Q_OS_SOLARIS)
|
|
|
|
|
kc(0), warned(false),
|
|
|
|
|
#endif
|
|
|
|
|
pageScale(p), swapScale(s), cxScale(c), autoscale(a)
|
|
|
|
|
{
|
|
|
|
|
#ifdef __linux__
|
|
|
|
|
#ifdef Q_OS_LINUX
|
|
|
|
|
memstats[0].name = "SwapTotal:";
|
|
|
|
|
memstats[0].stat = &sample.stotal;
|
|
|
|
|
memstats[1].name = "MemTotal:";
|
|
|
|
|
@ -122,7 +121,7 @@ KSample::KSample(KTimeMon *t, bool a, unsigned p, unsigned s, unsigned c) :
|
|
|
|
|
|
|
|
|
|
fcntl( statFD,F_SETFD, FD_CLOEXEC );
|
|
|
|
|
|
|
|
|
|
#elif defined (USE_SOLARIS)
|
|
|
|
|
#elif defined (Q_OS_SOLARIS)
|
|
|
|
|
if ((kc = kstat_open()) == 0) {
|
|
|
|
|
KMessageBox::error(timemon, i18n("Unable to initialize the 'kstat' library. "
|
|
|
|
|
"This library is used for accessing kernel information. "
|
|
|
|
|
@ -134,7 +133,7 @@ KSample::KSample(KTimeMon *t, bool a, unsigned p, unsigned s, unsigned c) :
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if defined(USE_SOLARIS)
|
|
|
|
|
#if defined(Q_OS_SOLARIS)
|
|
|
|
|
pagesPerMB = (1024*1024) / getpagesize();
|
|
|
|
|
if (pagesPerMB == 0) pagesPerMB = 1; // paranoia sanity check
|
|
|
|
|
#endif
|
|
|
|
|
@ -146,10 +145,10 @@ KSample::KSample(KTimeMon *t, bool a, unsigned p, unsigned s, unsigned c) :
|
|
|
|
|
// Get rid of the resources we acquired in the constructor.
|
|
|
|
|
KSample::~KSample()
|
|
|
|
|
{
|
|
|
|
|
#ifdef __linux__
|
|
|
|
|
#ifdef Q_OS_LINUX
|
|
|
|
|
close(memFD);
|
|
|
|
|
close(statFD);
|
|
|
|
|
#elif defined (USE_SOLARIS)
|
|
|
|
|
#elif defined (Q_OS_SOLARIS)
|
|
|
|
|
if (kc != 0) kstat_close(kc);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
@ -206,7 +205,7 @@ void KSample::readSample()
|
|
|
|
|
{
|
|
|
|
|
sample.cpus = 0; // just to make sure...
|
|
|
|
|
|
|
|
|
|
#ifdef __linux__ // linux makes it simple: use the /proc if
|
|
|
|
|
#ifdef Q_OS_LINUX // linux makes it simple: use the /proc if
|
|
|
|
|
int l;
|
|
|
|
|
char buffer[4096];
|
|
|
|
|
|
|
|
|
|
@ -265,7 +264,7 @@ void KSample::readSample()
|
|
|
|
|
}
|
|
|
|
|
sample.cpus = l;
|
|
|
|
|
|
|
|
|
|
#elif defined(USE_SOLARIS)
|
|
|
|
|
#elif defined(Q_OS_SOLARIS)
|
|
|
|
|
kstat_t *ksp;
|
|
|
|
|
|
|
|
|
|
sample.cpus = 0;
|
|
|
|
|
@ -387,7 +386,7 @@ void KSample::readSample()
|
|
|
|
|
free(stbl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#elif defined(__NetBSD__)
|
|
|
|
|
#elif defined(Q_OS_NETBSD)
|
|
|
|
|
int mib[2];
|
|
|
|
|
int ncpu;
|
|
|
|
|
size_t len;
|
|
|
|
|
@ -462,11 +461,11 @@ void KSample::updateSample()
|
|
|
|
|
// Convert v to a value representing megabytes.
|
|
|
|
|
inline void KSample::makeMBytes(unsigned long &v)
|
|
|
|
|
{
|
|
|
|
|
#ifdef __linux__
|
|
|
|
|
#ifdef Q_OS_LINUX
|
|
|
|
|
v /= 1024; // can it be simpler ;-)
|
|
|
|
|
#elif defined(USE_SOLARIS)
|
|
|
|
|
#elif defined(Q_OS_SOLARIS)
|
|
|
|
|
v /= pagesPerMB;
|
|
|
|
|
#elif defined(__NetBSD__)
|
|
|
|
|
#elif defined(Q_OS_NETBSD)
|
|
|
|
|
v >>= pg_to_mb_shift;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|