#ifndef memtrack_hpp #define memtrack_hpp /* * Author: David Robert Nadeau * Site: http://NadeauSoftware.com/ * License: Creative Commons Attribution 3.0 Unported License * http://creativecommons.org/licenses/by/3.0/deed.en_US */ #include #include #include namespace fv_util { /** * Returns the peak (maximum so far) resident set size (physical * memory use) measured in bytes. */ size_t getPeakRSS() { struct rusage rusage; getrusage(RUSAGE_SELF, &rusage); return (size_t) (rusage.ru_maxrss * 1024L); } /** * Returns the current resident set size (physical memory use) measured * in bytes. */ size_t getCurrentRSS() { long rss = 0L; FILE *fp = NULL; if ((fp = fopen("/proc/self/statm", "r")) == NULL) return (size_t) 0L; /* Can't open? */ if (fscanf(fp, "%*s%ld", &rss) != 1) { fclose(fp); return (size_t) 0L; /* Can't read? */ } fclose(fp); return (size_t) rss * (size_t) sysconf(_SC_PAGESIZE); } } // fv #endif // memtrack_hpp