Implement MaxRSS in terms of mallinfo instead of the system RSS. This gives

us much more accurate numbers and actually WORKS.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4518 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2002-11-04 00:32:44 +00:00
parent 1650015822
commit 9d4ef12b9c
2 changed files with 16 additions and 36 deletions

View File

@@ -9,6 +9,7 @@
#include <sys/time.h> #include <sys/time.h>
#include <sys/unistd.h> #include <sys/unistd.h>
#include <unistd.h> #include <unistd.h>
#include <malloc.h>
#include <stdio.h> #include <stdio.h>
#include <iostream> #include <iostream>
#include <algorithm> #include <algorithm>
@@ -63,20 +64,6 @@ struct TimeRecord {
}; };
static TimeRecord getTimeRecord() { static TimeRecord getTimeRecord() {
static unsigned long PageSize = 0;
if (PageSize == 0) {
#ifdef _SC_PAGE_SIZE
PageSize = sysconf(_SC_PAGE_SIZE);
#else
#ifdef _SC_PAGESIZE
PageSize = sysconf(_SC_PAGESIZE);
#else
PageSize = getpagesize();
#endif
#endif
}
struct rusage RU; struct rusage RU;
struct timeval T; struct timeval T;
gettimeofday(&T, 0); gettimeofday(&T, 0);
@@ -84,15 +71,16 @@ static TimeRecord getTimeRecord() {
perror("getrusage call failed: -time-passes info incorrect!"); perror("getrusage call failed: -time-passes info incorrect!");
} }
struct mallinfo MI = mallinfo();
TimeRecord Result; TimeRecord Result;
Result.Elapsed = T.tv_sec + T.tv_usec/1000000.0; Result.Elapsed = T.tv_sec + T.tv_usec/1000000.0;
Result.UserTime = RU.ru_utime.tv_sec + RU.ru_utime.tv_usec/1000000.0; Result.UserTime = RU.ru_utime.tv_sec + RU.ru_utime.tv_usec/1000000.0;
Result.SystemTime = RU.ru_stime.tv_sec + RU.ru_stime.tv_usec/1000000.0; Result.SystemTime = RU.ru_stime.tv_sec + RU.ru_stime.tv_usec/1000000.0;
Result.MaxRSS = RU.ru_maxrss*PageSize; Result.MaxRSS = MI.uordblks+MI.usmblks;
return Result; return Result;
} }
void Timer::startTimer() { void Timer::startTimer() {
Started = true; Started = true;
TimeRecord TR = getTimeRecord(); TimeRecord TR = getTimeRecord();
@@ -108,6 +96,8 @@ void Timer::stopTimer() {
UserTime += TR.UserTime; UserTime += TR.UserTime;
SystemTime += TR.SystemTime; SystemTime += TR.SystemTime;
MaxRSS += TR.MaxRSS; MaxRSS += TR.MaxRSS;
if ((signed long)MaxRSS < 0)
MaxRSS = 0;
} }
void Timer::sum(const Timer &T) { void Timer::sum(const Timer &T) {
@@ -140,7 +130,7 @@ void Timer::print(const Timer &Total) {
fprintf(stderr, " "); fprintf(stderr, " ");
if (Total.MaxRSS) if (Total.MaxRSS)
std::cerr << MaxRSS << "\t"; fprintf(stderr, " %8ld ", MaxRSS);
std::cerr << Name << "\n"; std::cerr << Name << "\n";
Started = false; // Once printed, don't print again Started = false; // Once printed, don't print again
@@ -182,7 +172,7 @@ void TimerGroup::removeTimer() {
std::cerr << " ---Wall Time---"; std::cerr << " ---Wall Time---";
if (Total.getMaxRSS()) if (Total.getMaxRSS())
std::cerr << " ---Mem---"; std::cerr << " ---Mem---";
std::cerr << " --- Name ---\n"; std::cerr << " --- Name ---\n";
// Loop through all of the timing data, printing it out... // Loop through all of the timing data, printing it out...

View File

@@ -9,6 +9,7 @@
#include <sys/time.h> #include <sys/time.h>
#include <sys/unistd.h> #include <sys/unistd.h>
#include <unistd.h> #include <unistd.h>
#include <malloc.h>
#include <stdio.h> #include <stdio.h>
#include <iostream> #include <iostream>
#include <algorithm> #include <algorithm>
@@ -63,20 +64,6 @@ struct TimeRecord {
}; };
static TimeRecord getTimeRecord() { static TimeRecord getTimeRecord() {
static unsigned long PageSize = 0;
if (PageSize == 0) {
#ifdef _SC_PAGE_SIZE
PageSize = sysconf(_SC_PAGE_SIZE);
#else
#ifdef _SC_PAGESIZE
PageSize = sysconf(_SC_PAGESIZE);
#else
PageSize = getpagesize();
#endif
#endif
}
struct rusage RU; struct rusage RU;
struct timeval T; struct timeval T;
gettimeofday(&T, 0); gettimeofday(&T, 0);
@@ -84,15 +71,16 @@ static TimeRecord getTimeRecord() {
perror("getrusage call failed: -time-passes info incorrect!"); perror("getrusage call failed: -time-passes info incorrect!");
} }
struct mallinfo MI = mallinfo();
TimeRecord Result; TimeRecord Result;
Result.Elapsed = T.tv_sec + T.tv_usec/1000000.0; Result.Elapsed = T.tv_sec + T.tv_usec/1000000.0;
Result.UserTime = RU.ru_utime.tv_sec + RU.ru_utime.tv_usec/1000000.0; Result.UserTime = RU.ru_utime.tv_sec + RU.ru_utime.tv_usec/1000000.0;
Result.SystemTime = RU.ru_stime.tv_sec + RU.ru_stime.tv_usec/1000000.0; Result.SystemTime = RU.ru_stime.tv_sec + RU.ru_stime.tv_usec/1000000.0;
Result.MaxRSS = RU.ru_maxrss*PageSize; Result.MaxRSS = MI.uordblks+MI.usmblks;
return Result; return Result;
} }
void Timer::startTimer() { void Timer::startTimer() {
Started = true; Started = true;
TimeRecord TR = getTimeRecord(); TimeRecord TR = getTimeRecord();
@@ -108,6 +96,8 @@ void Timer::stopTimer() {
UserTime += TR.UserTime; UserTime += TR.UserTime;
SystemTime += TR.SystemTime; SystemTime += TR.SystemTime;
MaxRSS += TR.MaxRSS; MaxRSS += TR.MaxRSS;
if ((signed long)MaxRSS < 0)
MaxRSS = 0;
} }
void Timer::sum(const Timer &T) { void Timer::sum(const Timer &T) {
@@ -140,7 +130,7 @@ void Timer::print(const Timer &Total) {
fprintf(stderr, " "); fprintf(stderr, " ");
if (Total.MaxRSS) if (Total.MaxRSS)
std::cerr << MaxRSS << "\t"; fprintf(stderr, " %8ld ", MaxRSS);
std::cerr << Name << "\n"; std::cerr << Name << "\n";
Started = false; // Once printed, don't print again Started = false; // Once printed, don't print again
@@ -182,7 +172,7 @@ void TimerGroup::removeTimer() {
std::cerr << " ---Wall Time---"; std::cerr << " ---Wall Time---";
if (Total.getMaxRSS()) if (Total.getMaxRSS())
std::cerr << " ---Mem---"; std::cerr << " ---Mem---";
std::cerr << " --- Name ---\n"; std::cerr << " --- Name ---\n";
// Loop through all of the timing data, printing it out... // Loop through all of the timing data, printing it out...