10#if defined(CompilerHasProcStat)
16#if defined(CompilerHasSysinfo)
17#include <sys/sysinfo.h>
19#include <sys/sysctl.h>
20#include <sys/resource.h>
23static_assert(
sizeof(
void*) == 8,
"Assuming 64-bit build; i.e., 8-byte pointers");
24static_assert(std::numeric_limits<float>::is_iec559,
"std::numeric_limits<float>::is_iec559");
25static_assert(std::numeric_limits<double>::is_iec559,
"std::numeric_limits<double>::is_iec55");
26static_assert(CHAR_BIT == 8,
"CHAR_BIT != 8");
27static_assert(
sizeof(char) == 1,
"sizeof(short) != 1");
28static_assert(
sizeof(short) == 2,
"sizeof(short) != 2");
29static_assert(
sizeof(
int) == 4,
"sizeof(int) != 4");
30static_assert(
sizeof(
long long) == 8,
"sizeof(long long) != 8");
31static_assert(
'A' == 65,
"A != 65");
40 long megaByte = 1024 * 1024;
41 long usageMB ((value + (megaByte/2)) / megaByte );
42 const long maxInteger = std::numeric_limits<int>::max();
43 if (usageMB>maxInteger) {
44 logError(
"convertMemorySize()",
"cannot cast result to return value: " << usageMB );
46 result =
static_cast<int>(usageMB);
53#if defined(CompilerHasSysinfo)
59 return convertMemorySize(info.totalram,format);
67 return convertMemorySize(info.freeram,format);
73 int mib[] = { CTL_HW, HW_MEMSIZE };
74 int64_t physical_memory;
78 length =
sizeof(int64_t);
79 sysctl(mib, 2, &physical_memory, &length, NULL, 0);
80 return convertMemorySize(physical_memory, format);
84 struct rusage usage{};
85 if(0 == getrusage(RUSAGE_SELF, &usage)) {
87 return convertMemorySize(freeMem, format);
98#if defined(CompilerHasProcStat)
103 pid_t pid = getpid();
105 sprintf(work,
"/proc/%d/stat", (
int)pid);
106 f = fopen(work,
"r");
109 logError(
"getMemoryUsage()",
"can't open file " << work );
112 if(fgets(work,
sizeof(work),
f) == NULL) {
113 logError(
"getMemoryUsage",
"Error while reading from file");
118 for (
int i = 1; i < 23; i++) {
119 pCh = strtok(NULL,
" ");
122 std::size_t rawInput = atol(pCh);
124 std::size_t rawInput = 0;
127 return convertMemorySize(rawInput,format);
double f(double p4, double p1, double p5, double rho1, double rho5, double gamma)
#define logError(methodName, logMacroMessageStream)
Wrapper macro around tarch::tarch::logging::Log to improve logging.
tarch::logging::Log _log("exahype2::fv")
int getTotalMemory(MemoryUsageFormat format)
int getMemoryUsage(MemoryUsageFormat format)
Method for getting the application's memory footprint.
int getFreeMemory(MemoryUsageFormat format)