MCPcopy Create free account
hub / github.com/apple/foundationdb / getResidentMemoryUsage

Function getResidentMemoryUsage

flow/Platform.actor.cpp:281–341  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

279}
280
281uint64_t getResidentMemoryUsage() {
282#if defined(__linux__)
283 uint64_t rssize = 0;
284
285 std::ifstream stat_stream("/proc/self/statm", std::ifstream::in);
286 std::string ignore;
287
288 if (!stat_stream.good()) {
289 TraceEvent(SevError, "GetResidentMemoryUsage").GetLastError();
290 throw platform_error();
291 }
292
293 stat_stream >> ignore;
294 stat_stream >> rssize;
295
296 rssize *= sysconf(_SC_PAGESIZE);
297
298 return rssize;
299#elif defined(__FreeBSD__)
300 uint64_t rssize = 0;
301
302 int status;
303 pid_t ppid = getpid();
304 int pidinfo[4];
305 pidinfo[0] = CTL_KERN;
306 pidinfo[1] = KERN_PROC;
307 pidinfo[2] = KERN_PROC_PID;
308 pidinfo[3] = (int)ppid;
309
310 struct kinfo_proc procstk;
311 size_t len = sizeof(procstk);
312
313 status = sysctl(pidinfo, nitems(pidinfo), &procstk, &len, nullptr, 0);
314 if (status < 0) {
315 TraceEvent(SevError, "GetResidentMemoryUsage").GetLastError();
316 throw platform_error();
317 }
318
319 rssize = (uint64_t)procstk.ki_rssize;
320
321 return rssize;
322#elif defined(_WIN32)
323 PROCESS_MEMORY_COUNTERS_EX pmc;
324 if (!GetProcessMemoryInfo(GetCurrentProcess(), (PPROCESS_MEMORY_COUNTERS)&pmc, sizeof(pmc))) {
325 TraceEvent(SevError, "GetResidentMemoryUsage").GetLastError();
326 throw platform_error();
327 }
328 return pmc.WorkingSetSize;
329#elif defined(__APPLE__)
330 struct task_basic_info info;
331 mach_msg_type_number_t info_count = TASK_BASIC_INFO_COUNT;
332 if (KERN_SUCCESS != task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t)&info, &info_count)) {
333 TraceEvent(SevError, "GetResidentMemoryUsage").GetLastError();
334 throw platform_error();
335 }
336 return info.resident_size;
337#else
338#warning getMemoryUsage unimplemented on this platform

Callers 4

getSystemStatisticsFunction · 0.85
startMemoryUsageMonitorFunction · 0.85
isFullMethod · 0.85

Calls 1

TraceEventClass · 0.85

Tested by

no test coverage detected