Use TQt macros for OS detection

Also make a minor adjustment to includes.

Signed-off-by: Alexander Golubev <fatzer2@gmail.com>
master
Alexander Golubev 2 weeks ago
parent 05e4b489d1
commit 4b16c3f8a4

@ -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
}

@ -13,6 +13,8 @@
#ifndef SAMPLE_H
#define SAMPLE_H
#include <tqstring.h>
// -- global constants ---------------------------------------------------
#define MAX_CPU 16 // max number of CPUS in an SMP machine
@ -21,7 +23,7 @@
// -- forward declaration ------------------------------------------------
class KTimeMon;
#ifdef USE_SOLARIS
#ifdef Q_OS_SOLARIS
struct kstat_ctl;
#endif
@ -47,7 +49,7 @@ public:
void fill(unsigned scale); // fill sample with some fake values
};
#ifdef __linux__
#ifdef Q_OS_LINUX
struct MemStats {
const char *name;
unsigned long *stat;
@ -76,22 +78,22 @@ private:
void nonfatal(const TQString& msg);
KTimeMon *timemon;
#ifdef __linux__
#ifdef Q_OS_LINUX
int memFD, statFD;
#elif defined(USE_SOLARIS)
#elif defined(Q_OS_SOLARIS)
struct kstat_ctl *kc;
bool warned;
#endif
#if defined(USE_SOLARIS)
#ifdef Q_OS_SOLARIS
unsigned long pagesPerMB;
#endif
#ifdef __NetBSD__
#ifdef Q_OS_NETBSD
int pg_to_mb_shift;
#endif
Sample sample, oldSample;
unsigned pageScale, swapScale, cxScale;
bool autoscale;
#ifdef __linux__
#ifdef Q_OS_LINUX
struct MemStats memstats[7];
#endif
};

Loading…
Cancel
Save