FML
Functions
SystemMemory.h File Reference

Go to the source code of this file.

Functions

size_t getPeakRSS ()
 Returns the peak (maximum so far) resident set size (physical memory use) measured in bytes, or zero if the value cannot be determined on this OS. More...
 
size_t getCurrentRSS ()
 Returns the current resident set size (physical memory use) measured in bytes, or zero if the value cannot be determined on this OS. More...
 

Function Documentation

◆ getCurrentRSS()

size_t getCurrentRSS ( )

Returns the current resident set size (physical memory use) measured in bytes, or zero if the value cannot be determined on this OS.

Definition at line 82 of file SystemMemory.h.

82 {
83#if defined(_WIN32)
84 /* Windows -------------------------------------------------- */
85 PROCESS_MEMORY_COUNTERS info;
86 GetProcessMemoryInfo(GetCurrentProcess(), &info, sizeof(info));
87 return (size_t)info.WorkingSetSize;
88
89#elif defined(__APPLE__) && defined(__MACH__)
90 /* OSX ------------------------------------------------------ */
91 struct mach_task_basic_info info;
92 mach_msg_type_number_t infoCount = MACH_TASK_BASIC_INFO_COUNT;
93 if (task_info(mach_task_self(), MACH_TASK_BASIC_INFO, (task_info_t)&info, &infoCount) != KERN_SUCCESS)
94 return (size_t)0L; /* Can't access? */
95 return (size_t)info.resident_size;
96
97#elif defined(__linux__) || defined(__linux) || defined(linux) || defined(__gnu_linux__)
98 /* Linux ---------------------------------------------------- */
99 long rss = 0L;
100 FILE * fp = NULL;
101 if ((fp = fopen("/proc/self/statm", "r")) == NULL)
102 return (size_t)0L; /* Can't open? */
103 if (fscanf(fp, "%*s%ld", &rss) != 1) {
104 fclose(fp);
105 return (size_t)0L; /* Can't read? */
106 }
107 fclose(fp);
108 return (size_t)rss * (size_t)sysconf(_SC_PAGESIZE);
109
110#else
111 /* AIX, BSD, Solaris, and Unknown OS ------------------------ */
112 return (size_t)0L; /* Unsupported. */
113#endif
114}
void info(HaloModel **hmp)
Definition: Wrapper.cpp:83

◆ getPeakRSS()

size_t getPeakRSS ( )

Returns the peak (maximum so far) resident set size (physical memory use) measured in bytes, or zero if the value cannot be determined on this OS.

Definition at line 41 of file SystemMemory.h.

41 {
42#if defined(_WIN32)
43 /* Windows -------------------------------------------------- */
44 PROCESS_MEMORY_COUNTERS info;
45 GetProcessMemoryInfo(GetCurrentProcess(), &info, sizeof(info));
46 return (size_t)info.PeakWorkingSetSize;
47
48#elif (defined(_AIX) || defined(__TOS__AIX__)) || \
49 (defined(__sun__) || defined(__sun) || defined(sun) && (defined(__SVR4) || defined(__svr4__)))
50 /* AIX and Solaris ------------------------------------------ */
51 struct psinfo psinfo;
52 int fd = -1;
53 if ((fd = open("/proc/self/psinfo", O_RDONLY)) == -1)
54 return (size_t)0L; /* Can't open? */
55 if (read(fd, &psinfo, sizeof(psinfo)) != sizeof(psinfo)) {
56 close(fd);
57 return (size_t)0L; /* Can't read? */
58 }
59 close(fd);
60 return (size_t)(psinfo.pr_rssize * 1024L);
61
62#elif defined(__unix__) || defined(__unix) || defined(unix) || (defined(__APPLE__) && defined(__MACH__))
63 /* BSD, Linux, and OSX -------------------------------------- */
64 struct rusage rusage;
65 getrusage(RUSAGE_SELF, &rusage);
66#if defined(__APPLE__) && defined(__MACH__)
67 return (size_t)rusage.ru_maxrss;
68#else
69 return (size_t)(rusage.ru_maxrss * 1024L);
70#endif
71
72#else
73 /* Unknown OS ----------------------------------------------- */
74 return (size_t)0L; /* Unsupported. */
75#endif
76}