#ifndef __JSYSTEM__JSYSINFO__ #define __JSYSTEM__JSYSINFO__ #ifndef __APPLE__ #include #else #include #include /** * A minimal custom version to define just the data we need. * * (because on macOS sys/sysinfo does not exist) */ struct sysinfo { long uptime; /* Seconds since boot */ unsigned long totalram; /* Total usable main memory size */ unsigned long freeram; /* Available memory size */ unsigned int mem_unit{1}; /* Memory unit size in bytes. 1 means we report memory in bytes */ }; #endif /** * \file * System information. * \author mdejong */ namespace JSYSTEM {} namespace JPP { using namespace JSYSTEM; } namespace JSYSTEM { /** * Auxiliary class for system information. * This class encapsulates the sysinfo data structure. */ struct JSysinfo : public sysinfo { #if !defined(__APPLE__) /** * Default constructor. */ JSysinfo() { ::sysinfo(static_cast(this)); } #else JSysinfo() { unsigned long totalram; size_t len=sizeof(totalram); sysctlbyname("hw.memsize",&totalram,&len,NULL,0); this->totalram = totalram; this->uptime = 0; this->freeram = 0; } #endif /** * Get total RAM. * * \return total RAM [B] */ unsigned long long int getTotalRAM() const { return (unsigned long long int) this->totalram * (unsigned long long int) this->mem_unit; } }; } #endif