Subject: RE: using times()
From: [email-masked] (Valery Fine)

22 Sep 1997 01:18:40 -0700
Message-ID: <[email-masked]>
References: <01BCC732.3C3AA5E0@sos>
Reply-To: [email-masked]
To: Sergey Okhapkin <[email-masked]>, [email-masked]

On 22 Sep 97 at 8:33, Sergey Okhapkin wrote:

> times() call works on NT only. The underlying syscall
> GetProcessTimes() unimplemented on windows 95. The output of your
> examle looks the following on my box (NT4.0 SP3):

  Probably like this would be better then just ZERO:

//_______________
Duble_t TStopwatch::GetCPUTime(){

  OSVERSIONINFO OsVersionInfo;
  OsVersionInfo.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
  GetVersionEx(&OsVersionInfo);
  if (OsVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) {
    DWORD       ret;
    FILETIME    ftCreate,       // when the process was created
                ftExit;         // when the process exited

    union     {FILETIME ftFileTime;
               __int64  ftInt64;
              } ftKernel; // time the process has spent in kernel mode

    union     {FILETIME ftFileTime;
               __int64  ftInt64;
              } ftUser;   // time the process has spent in user mode

    HANDLE hProcess = GetCurrentProcess();
    ret = GetProcessTimes (hProcess, &ftCreate, &ftExit,
                                     &ftKernel.ftFileTime,
                                     &ftUser.ftFileTime);
    if (ret != TRUE){
      ret = GetLastError ();
      ::Error ("GetCPUTime", " Error on GetProcessTimes 0x%lx",
      (int)ret);
    }
      return (Double_t) (ftKernel.ftInt64 + ftUser.ftInt64) * gTicks;
  }
  else
      return GetRealTime();
//_______________
Double_t TStopwatch::GetRealTime(){
  union     {FILETIME ftFileTime;
             __int64  ftInt64;
            } ftRealTime; // time the process has spent in kernel mode
  SYSTEMTIME st;
  GetSystemTime(&st);
  SystemTimeToFileTime(&st,&ftRealTime.ftFileTime);
  return (Double_t)ftRealTime.ftInt64 * gTicks;
}

Dr. Valeri Faine (Valery Fine)
    ------------ -------------   Phone: +41 22 767 4921
CERN                             FAX  : +41 22 767 7155
CH-1211 Geneva, 23               mailto:[email-masked] 
Switzerland                      http://nicewww.cern.ch/~fine
                                 
-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".