Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JSysinfo.hh
Go to the documentation of this file.
1#ifndef __JSYSTEM__JSYSINFO__
2#define __JSYSTEM__JSYSINFO__
3
4#ifndef __APPLE__
5#include <sys/sysinfo.h>
6#else
7#include <sys/sysctl.h>
8#include <iostream>
9/**
10 * A minimal custom version to define just the data we need.
11 *
12 * (because on macOS sys/sysinfo does not exist)
13 */
14struct sysinfo {
15 long uptime; /* Seconds since boot */
16 unsigned long totalram; /* Total usable main memory size */
17 unsigned long freeram; /* Available memory size */
18 unsigned int mem_unit{1}; /* Memory unit size in bytes. 1 means we report memory in bytes */
19};
20#endif
21
22/**
23 * \file
24 * System information.
25 * \author mdejong
26 */
27namespace JSYSTEM {}
28namespace JPP { using namespace JSYSTEM; }
29
30namespace JSYSTEM {
31
32 /**
33 * Auxiliary class for system information.
34 * This class encapsulates the <tt>sysinfo</tt> data structure.
35 */
36 struct JSysinfo :
37 public sysinfo
38 {
39#if !defined(__APPLE__)
40 /**
41 * Default constructor.
42 */
44 {
45 ::sysinfo(static_cast<sysinfo*>(this));
46 }
47#else
48 JSysinfo() {
49 unsigned long totalram;
50 size_t len=sizeof(totalram);
51 sysctlbyname("hw.memsize",&totalram,&len,NULL,0);
52 this->totalram = totalram;
53 this->uptime = 0;
54 this->freeram = 0;
55 }
56#endif
57
58
59 /**
60 * Get total RAM.
61 *
62 * \return total RAM [B]
63 */
64 unsigned long long int getTotalRAM() const
65 {
66 return (unsigned long long int) this->totalram * (unsigned long long int) this->mem_unit;
67 }
68 };
69}
70
71#endif
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for operating system calls.
Auxiliary class for system information.
Definition JSysinfo.hh:38
unsigned long long int getTotalRAM() const
Get total RAM.
Definition JSysinfo.hh:64
JSysinfo()
Default constructor.
Definition JSysinfo.hh:43