summaryrefslogtreecommitdiff
path: root/lib/Support/Timer.cpp
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2004-12-20 00:59:04 +0000
committerReid Spencer <rspencer@reidspencer.com>2004-12-20 00:59:04 +0000
commitdf52c9aaf2ec6fbd0562e849cdba36e620537989 (patch)
treec163902993a542166ef47f44336c1481de081d00 /lib/Support/Timer.cpp
parentab5eaea72ec80b2639ce3fd6de709f713796175d (diff)
downloadllvm-df52c9aaf2ec6fbd0562e849cdba36e620537989.tar.gz
llvm-df52c9aaf2ec6fbd0562e849cdba36e620537989.tar.bz2
llvm-df52c9aaf2ec6fbd0562e849cdba36e620537989.tar.xz
For PR351:
* Move system dependent implementation out of this file. * Make implementation use sys::Process::GetMallocUsage where necessary. * Make implementation use sys::Process::GetTimeUsage where necessary. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19053 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/Timer.cpp')
-rw-r--r--lib/Support/Timer.cpp72
1 files changed, 13 insertions, 59 deletions
diff --git a/lib/Support/Timer.cpp b/lib/Support/Timer.cpp
index ff3fd6fefe..01ab03dd2b 100644
--- a/lib/Support/Timer.cpp
+++ b/lib/Support/Timer.cpp
@@ -13,16 +13,11 @@
#include "llvm/Support/Timer.h"
#include "llvm/Support/CommandLine.h"
-#include <algorithm>
-#include <iostream>
-#include <functional>
+#include "llvm/System/Process.h"
#include <fstream>
+#include <iostream>
#include <map>
-#include "llvm/Config/sys/resource.h"
-#include "llvm/Config/sys/time.h"
-#include "llvm/Config/unistd.h"
-#include "llvm/Config/malloc.h"
-#include "llvm/Config/windows.h"
+
using namespace llvm;
// GetLibSupportInfoOutputFile - Return a file stream to print our output on.
@@ -42,12 +37,10 @@ static std::string &getLibSupportInfoOutputFilename() {
}
namespace {
-#ifdef HAVE_MALLINFO
cl::opt<bool>
TrackSpace("track-memory", cl::desc("Enable -time-passes memory "
"tracking (this may be slow)"),
cl::Hidden);
-#endif
cl::opt<std::string, true>
InfoOutputFilename("info-output-file", cl::value_desc("filename"),
@@ -98,65 +91,26 @@ Timer::~Timer() {
}
}
-static long getMemUsage() {
-#ifdef HAVE_MALLINFO
- if (TrackSpace) {
- struct mallinfo MI = mallinfo();
- return MI.uordblks/*+MI.hblkhd*/;
- }
-#endif
- return 0;
-}
-
struct TimeRecord {
double Elapsed, UserTime, SystemTime;
long MemUsed;
};
static TimeRecord getTimeRecord(bool Start) {
-#if defined(HAVE_WINDOWS_H)
- unsigned __int64 ProcCreate, ProcExit, KernelTime, UserTime, CurTime;
-
- GetProcessTimes(GetCurrentProcess(), (FILETIME*)&ProcCreate,
- (FILETIME*)&ProcExit, (FILETIME*)&KernelTime,
- (FILETIME*)&UserTime);
- GetSystemTimeAsFileTime((FILETIME*)&CurTime);
+ TimeRecord Result;
- // FILETIME's are # of 100 nanosecond ticks.
- double ScaleFactor = 1.0/(10*1000*1000);
+ sys::TimeValue now(0,0);
+ sys::TimeValue user(0,0);
+ sys::TimeValue sys(0,0);
- TimeRecord Result;
- Result.Elapsed = (CurTime-ProcCreate)*ScaleFactor; // Wall time
- Result.UserTime = UserTime*ScaleFactor;
- Result.SystemTime = KernelTime*ScaleFactor;
- return Result;
-#elif defined(HAVE_GETRUSAGE)
- struct rusage RU;
- struct timeval T;
- long MemUsed = 0;
- if (Start) {
- MemUsed = getMemUsage();
- if (getrusage(RUSAGE_SELF, &RU))
- perror("getrusage call failed: -time-passes info incorrect!");
- }
- gettimeofday(&T, 0);
+ sys::Process::GetTimeUsage(now,user,sys);
- if (!Start) {
- if (getrusage(RUSAGE_SELF, &RU))
- perror("getrusage call failed: -time-passes info incorrect!");
- MemUsed = getMemUsage();
- }
+ Result.Elapsed = now.seconds() + now.microseconds() / 1000000.0;
+ Result.UserTime = user.seconds() + user.microseconds() / 1000000.0;
+ Result.UserTime = sys.seconds() + sys.microseconds() / 1000000.0;
+ Result.MemUsed = sys::Process::GetMallocUsage();
- TimeRecord Result;
- 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.SystemTime = RU.ru_stime.tv_sec + RU.ru_stime.tv_usec/1000000.0;
- Result.MemUsed = MemUsed;
return Result;
-#else
- // Can't get resource usage.
- return TimeRecord();
-#endif
}
static std::vector<Timer*> ActiveTimers;
@@ -202,7 +156,7 @@ void Timer::sum(const Timer &T) {
/// currently active timers, which will be printed when the timer group prints
///
void Timer::addPeakMemoryMeasurement() {
- long MemUsed = getMemUsage();
+ long MemUsed = sys::Process::GetMallocUsage();
for (std::vector<Timer*>::iterator I = ActiveTimers.begin(),
E = ActiveTimers.end(); I != E; ++I)