From 8b50c1c962429dacc54a6961a88fc55b585c51b3 Mon Sep 17 00:00:00 2001 From: Serge Gautherie Date: Mon, 20 Apr 2009 12:23:52 +0200 Subject: [PATCH] Bug 487605 - nsStopwatch.cpp: Fix GetProcessTimes() usage; (Bv1-MC) stopwatch.cpp; r+sr=roc --- modules/libutil/src/stopwatch.cpp | 38 +++++++++++++++---------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/modules/libutil/src/stopwatch.cpp b/modules/libutil/src/stopwatch.cpp index c7529667d61a..929a1101a991 100644 --- a/modules/libutil/src/stopwatch.cpp +++ b/modules/libutil/src/stopwatch.cpp @@ -191,22 +191,20 @@ double Stopwatch::GetRealTime(){ #endif } - -double Stopwatch::GetCPUTime(){ +double Stopwatch::GetCPUTime() { #if defined(R__MAC) -// return(double)clock() / gTicks; - return(double)clock(); +// return(double)clock() / gTicks; + return(double)clock(); #elif defined(R__UNIX) - struct tms cpt; - times(&cpt); - return (double)(cpt.tms_utime+cpt.tms_stime) / gTicks; + struct tms cpt; + times(&cpt); + return (double)(cpt.tms_utime+cpt.tms_stime) / gTicks; #elif defined(R__VMS) - return(double)clock()/gTicks; + return(double)clock()/gTicks; #elif defined(WINCE) - return 0; + return 0; #elif defined(WIN32) - DWORD ret; FILETIME ftCreate, // when the process was created ftExit; // when the process exited @@ -219,15 +217,16 @@ double Stopwatch::GetCPUTime(){ } ftUser; // time the process has spent in user mode HANDLE hProcess = GetCurrentProcess(); - ret = GetProcessTimes (hProcess, &ftCreate, &ftExit, - &ftKernel.ftFileTime, - &ftUser.ftFileTime); - if (ret != PR_TRUE){ - ret = GetLastError (); #ifdef DEBUG - printf("%s 0x%lx\n"," Error on GetProcessTimes", (int)ret); + BOOL ret = +#endif + GetProcessTimes(hProcess, &ftCreate, &ftExit, + &ftKernel.ftFileTime, &ftUser.ftFileTime); +#ifdef DEBUG + if (!ret) + // ToDo: May want to use NS_ERROR(). + printf("Error: GetProcessTimes() failed, 0x%lx\n", (int)GetLastError()); #endif - } /* * Process times are returned in a 64-bit structure, as the number of @@ -237,10 +236,9 @@ double Stopwatch::GetCPUTime(){ * * Convert sum of high 32-bit quantities to 64-bit int */ + return (double) (ftKernel.ftInt64 + ftUser.ftInt64) * gTicks; - return (double) (ftKernel.ftInt64 + ftUser.ftInt64) * gTicks; - -#endif +#endif # elif, WIN32 }