diff options
| author | Chris Lattner <sabre@nondot.org> | 2004-06-07 19:34:51 +0000 | 
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2004-06-07 19:34:51 +0000 | 
| commit | 6068345cc591e8310e7f847aedd619b804674879 (patch) | |
| tree | 6807a93cd4d1a2b35e186da8a248e85d204a802a /llvm/lib/Support/Timer.cpp | |
| parent | bbc373bf8b6376bf6ef0d40de65d1ed43a78fc27 (diff) | |
| download | bcm5719-llvm-6068345cc591e8310e7f847aedd619b804674879.tar.gz bcm5719-llvm-6068345cc591e8310e7f847aedd619b804674879.zip  | |
Implement getTimeRecord natively in Win32, properly conditionalize the
getrusage implementation on HAVE_GETRUSAGE
llvm-svn: 14050
Diffstat (limited to 'llvm/lib/Support/Timer.cpp')
| -rw-r--r-- | llvm/lib/Support/Timer.cpp | 35 | 
1 files changed, 28 insertions, 7 deletions
diff --git a/llvm/lib/Support/Timer.cpp b/llvm/lib/Support/Timer.cpp index 5d493b8a15e..52b616fa2c4 100644 --- a/llvm/lib/Support/Timer.cpp +++ b/llvm/lib/Support/Timer.cpp @@ -13,18 +13,19 @@  #include "Support/Timer.h"  #include "Support/CommandLine.h" -#include "Config/sys/resource.h" -#include "Config/sys/time.h" -#include "Config/unistd.h" -#include "Config/malloc.h" -#include <iostream>  #include <algorithm> +#include <iostream>  #include <functional>  #include <fstream>  #include <map> +#include "Config/sys/resource.h" +#include "Config/sys/time.h" +#include "Config/unistd.h" +#include "Config/malloc.h" +#include "Config/windows.h"  using namespace llvm; -// GetLibSupportInfoOutputFile - Return a file stream to print our output on... +// GetLibSupportInfoOutputFile - Return a file stream to print our output on.  namespace llvm { extern std::ostream *GetLibSupportInfoOutputFile(); }  // getLibSupportInfoOutputFilename - This ugly hack is brought to you courtesy @@ -113,6 +114,23 @@ struct TimeRecord {  };  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); + +  // FILETIME's are # of 100 nanosecond ticks. +  double ScaleFactor = 1.0/(10*1000*1000); + +  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; @@ -134,8 +152,11 @@ static TimeRecord getTimeRecord(bool Start) {    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;  | 

