diff options
| author | Reid Spencer <rspencer@reidspencer.com> | 2004-12-20 00:59:04 +0000 | 
|---|---|---|
| committer | Reid Spencer <rspencer@reidspencer.com> | 2004-12-20 00:59:04 +0000 | 
| commit | 270888106795447d5238ae40a749f972a2ffd481 (patch) | |
| tree | 9bf3b4eae3172c4fe62e1a2189a43c6b050931b6 /llvm/lib/Support/Timer.cpp | |
| parent | 8b44f87ef942ffbce7b3c90e29f631d8ba74b0f5 (diff) | |
| download | bcm5719-llvm-270888106795447d5238ae40a749f972a2ffd481.tar.gz bcm5719-llvm-270888106795447d5238ae40a749f972a2ffd481.zip  | |
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.
llvm-svn: 19053
Diffstat (limited to 'llvm/lib/Support/Timer.cpp')
| -rw-r--r-- | llvm/lib/Support/Timer.cpp | 72 | 
1 files changed, 13 insertions, 59 deletions
diff --git a/llvm/lib/Support/Timer.cpp b/llvm/lib/Support/Timer.cpp index ff3fd6fefe0..01ab03dd2bf 100644 --- a/llvm/lib/Support/Timer.cpp +++ b/llvm/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)  | 

