MCPcopy Create free account
hub / github.com/KDE/labplot / getCurrentRSS

Function getCurrentRSS

src/tools/getRSS.h:87–126  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

85 * in bytes, or zero if the value cannot be determined on this OS.
86 */
87size_t getCurrentRSS( )
88{
89#if defined(_WIN32)
90 /* Windows -------------------------------------------------- */
91 PROCESS_MEMORY_COUNTERS info;
92 GetProcessMemoryInfo( GetCurrentProcess( ), &info, sizeof(info) );
93 return (size_t)info.WorkingSetSize;
94
95#elif defined(__APPLE__) && defined(__MACH__)
96 /* OSX ------------------------------------------------------ */
97 struct mach_task_basic_info info;
98 mach_msg_type_number_t infoCount = MACH_TASK_BASIC_INFO_COUNT;
99 if ( task_info( mach_task_self( ), MACH_TASK_BASIC_INFO,
100 (task_info_t)&info, &infoCount ) != KERN_SUCCESS )
101 return (size_t)0L; /* Can't access? */
102 return (size_t)info.resident_size;
103
104#elif defined(__linux__) || defined(__linux) || defined(linux) || defined(__gnu_linux__)
105 /* Linux ---------------------------------------------------- */
106 long rss = 0L;
107 FILE* fp = nullptr;
108 if ( (fp = fopen( "/proc/self/statm", "r" )) == nullptr )
109 return (size_t)0L; /* Can't open? */
110 if ( fscanf( fp, "%*s%ld", &rss ) != 1 )
111 {
112 fclose( fp );
113 return (size_t)0L; /* Can't read? */
114 }
115 fclose( fp );
116
117 if ((size_t)rss > std::numeric_limits<size_t>::max()/(size_t)sysconf( _SC_PAGESIZE))
118 return std::numeric_limits<size_t>::max();
119 else
120 return (size_t)rss * (size_t)sysconf( _SC_PAGESIZE);
121
122#else
123 /* AIX, BSD, Solaris, and Unknown OS ------------------------ */
124 return (size_t)0L; /* Unsupported. */
125#endif
126}

Callers 1

refreshMemoryInfoMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected