hi.
is possible check how much memory is allocated and how much memory is really used with application in linux?
i want write this info into my application.
i use this:
const static char StatFile[] = "/proc/self/stat";
QScopedPointer<FILE, FileCloser> stat(::fopen(StatFile, "r"));
if ( !stat ) {
qWarning() << __FILE__ << __LINE__ << "Cannot open stat file";
return -1;
}
unsigned long vmsize(0), rss(0);
int r = ::fscanf(stat.data(),
"%*d%*s%*s%*d%*d%*d%*d%*d%*u%*u" "%*u%*u%*u%*u%*u%*d%*d%*d%*d%*d"
"%*d%*u%lu%lu", &vmsize, &rss);
if ( r != 2 ) {
qWarning() << __FILE__ << __LINE__ << "Cannot read vmsize and resident size";
return -1;
}
const static long PageSize = ::sysconf(_SC_PAGESIZE);
return (rss * PageSize) / 1024;
const static char StatFile[] = "/proc/self/stat";
QScopedPointer<FILE, FileCloser> stat(::fopen(StatFile, "r"));
if ( !stat ) {
qWarning() << __FILE__ << __LINE__ << "Cannot open stat file";
return -1;
}
unsigned long vmsize(0), rss(0);
int r = ::fscanf(stat.data(),
"%*d%*s%*s%*d%*d%*d%*d%*d%*u%*u" "%*u%*u%*u%*u%*u%*d%*d%*d%*d%*d"
"%*d%*u%lu%lu", &vmsize, &rss);
if ( r != 2 ) {
qWarning() << __FILE__ << __LINE__ << "Cannot read vmsize and resident size";
return -1;
}
const static long PageSize = ::sysconf(_SC_PAGESIZE);
return (rss * PageSize) / 1024;
To copy to clipboard, switch view to plain text mode
but this is only alocated memory because when i delete some object, this info of memory is not change (maybe after long time)
Bookmarks