Certain operations in my app are using more memory than I think they should, and I would like to log the current memory usage to help identify which they are.
Is there a system call that will return the amount of memory currently in use?
Certain operations in my app are using more memory than I think they should, and I would like to log the current memory usage to help identify which they are.
Is there a system call that will return the amount of memory currently in use?
You can give a try to
mallocDebug
function : http://developer.apple.com/mac/library/DOCUMENTATION/Performance/Conceptual/ManagingMemory/Articles/FindingPatterns.html.The following C function returns the CPU time and resident memory of process pid. To get the resources of other processes, you need root permission. You may also try getrusage(), but I never get it work properly for memory usage. Getting CPU time with getrusage() always works to me.
The function is adapted from the source codes of the ps and top commands. It is part of my program that monitors the memory of other processes.
Following @user172818 advice, I tried
getrusage
and it worked for me:I am using
Mac OS X 10.9.4
, with compilerApple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
.launch your application with Instruments. put it through the paces, and evaluate the results...