문제

I've simple program e.g. in C++

#include <iostream>  
int main()  
{  
    int a = 1000;  
    std::cout << a << std::endl;  
    return 0;  
}  

and i'm trying to calculate memory usage with GNU time. But in "time" output (with my format, it doesn't matter) maximum size of process in memory is calculated with libc.so which has printf function (call to std::cout) and is equal to 3.5 Mb.
Is there a way to calculate process memory without loaded shared libs?

UPD I can't do it while process, which memory i wanna measure, runs, for several reasons. I'm asking if there's a way to do it with outer wrapper tool (like time is)

도움이 되었습니까?

해결책

The pmap utility, or just reading the file /proc/123/maps for process of pid 123, and /proc/self/maps for your own process, gives you the detailed map of the memory. You could then ignore the lines concerning libraries you don't want to measure.

Try cat /proc/self/maps to understand more... (it displays the map of that cat command).

It is Linux specific (probably won't work on Solaris or FreeBSD).

There is also the more standard getrusage system call (which don't differentiate memory used by shared libraries from other memory use).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top