23 #if defined(__linux__)
28 using namespace Minisat;
33 static inline int memReadStat(
int field)
39 sprintf(name,
"/proc/%d/statm", pid);
40 FILE* in = fopen(name,
"rb");
41 if (in == NULL)
return 0;
43 for (; field >= 0; field--)
44 if (fscanf(in,
"%d", &value) != 1)
45 printf(
"ERROR! Failed to parse memory statistics from \"/proc\".\n"),
exit(1);
51 static inline int memReadPeak(
void)
56 sprintf(name,
"/proc/%d/status", pid);
57 FILE* in = fopen(name,
"rb");
58 if (in == NULL)
return 0;
62 while (!feof(in) && fscanf(in,
"VmPeak: %d kB", &peak_kb) != 1)
63 while (!feof(in) && fgetc(in) !=
'\n')
70 double Minisat::memUsed() {
return (
double)memReadStat(0) * (double)getpagesize() / (1024*1024); }
72 double peak = memReadPeak() / 1024;
73 return peak == 0 ?
memUsed() : peak; }
75 #elif defined(__FreeBSD__)
79 getrusage(RUSAGE_SELF, &ru);
80 return (
double)ru.ru_maxrss / 1024; }
84 #elif defined(__APPLE__)
85 #include <malloc/malloc.h>
88 malloc_statistics_t t;
89 malloc_zone_statistics(NULL, &t);
90 return (
double)t.max_size_in_use / (1024*1024); }