1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-10 18:51:21 +03:00

0029349: Foundation Classes, OSD_Timer - add missing theThisThreadOnly constructor option available in OSD_Chronometer

OSD_Timer constructor now has theThisThreadOnly option passed to OSD_Chronometer,
which is FALSE by default.

OSD_Chronometer now provides methods ::UserTimeCPU(), ::SystemTimeCPU() allowing
to fetch CPU times without akward syntax through overloaded ::Show().
This commit is contained in:
kgv 2017-11-28 08:42:40 +03:00 committed by bugmaster
parent 18d8e3e794
commit 2da5126371
4 changed files with 155 additions and 201 deletions

View File

@ -18,33 +18,26 @@
#include <OSD_Chronometer.hxx> #include <OSD_Chronometer.hxx>
#include <Standard_Stream.hxx> #include <Standard_Stream.hxx>
// ====================== PLATFORM-SPECIFIC PART ========================
#ifndef _WIN32 #ifndef _WIN32
//---------- Systemes autres que WNT : ----------------------------------
#include <sys/times.h> #include <sys/times.h>
#include <unistd.h> #include <unistd.h>
#ifdef SOLARIS #ifdef SOLARIS
# include <sys/resource.h> #include <sys/resource.h>
#endif #endif
//=======================================================================
//Selon les plateformes on doit avoir le nombre de clicks par secondes
//qui est l unite de mesure du temps.
//=======================================================================
#ifndef sysconf #ifndef sysconf
# define _sysconf sysconf #define _sysconf sysconf
#endif #endif
#if defined(DECOSF1) #if defined(DECOSF1)
# include <time.h> #include <time.h>
#endif #endif
# ifndef CLK_TCK #ifndef CLK_TCK
# define CLK_TCK CLOCKS_PER_SEC #define CLK_TCK CLOCKS_PER_SEC
# endif #endif
#if (defined(__APPLE__)) #if (defined(__APPLE__))
#include <mach/task.h> #include <mach/task.h>
@ -55,7 +48,8 @@
//function : GetProcessCPU //function : GetProcessCPU
//purpose : //purpose :
//======================================================================= //=======================================================================
void OSD_Chronometer::GetProcessCPU (Standard_Real& UserSeconds, Standard_Real& SystemSeconds) void OSD_Chronometer::GetProcessCPU (Standard_Real& theUserSeconds,
Standard_Real& theSystemSeconds)
{ {
#if defined(__linux__) || defined(__FreeBSD__) || defined(__ANDROID__) || defined(__QNX__) #if defined(__linux__) || defined(__FreeBSD__) || defined(__ANDROID__) || defined(__QNX__)
static const long aCLK_TCK = sysconf(_SC_CLK_TCK); static const long aCLK_TCK = sysconf(_SC_CLK_TCK);
@ -63,11 +57,11 @@ void OSD_Chronometer::GetProcessCPU (Standard_Real& UserSeconds, Standard_Real&
static const long aCLK_TCK = CLK_TCK; static const long aCLK_TCK = CLK_TCK;
#endif #endif
tms CurrentTMS; tms aCurrentTMS;
times (&CurrentTMS); times (&aCurrentTMS);
UserSeconds = (Standard_Real)CurrentTMS.tms_utime / aCLK_TCK; theUserSeconds = (Standard_Real)aCurrentTMS.tms_utime / aCLK_TCK;
SystemSeconds = (Standard_Real)CurrentTMS.tms_stime / aCLK_TCK; theSystemSeconds = (Standard_Real)aCurrentTMS.tms_stime / aCLK_TCK;
} }
//======================================================================= //=======================================================================
@ -109,8 +103,6 @@ void OSD_Chronometer::GetThreadCPU (Standard_Real& theUserSeconds,
#else #else
//---------------------------- Systeme WNT --------------------------------
#include <windows.h> #include <windows.h>
//======================================================================= //=======================================================================
@ -133,16 +125,17 @@ static inline __int64 EncodeFILETIME (PFILETIME pFt)
//function : GetProcessCPU //function : GetProcessCPU
//purpose : //purpose :
//======================================================================= //=======================================================================
void OSD_Chronometer::GetProcessCPU (Standard_Real& UserSeconds, Standard_Real& SystemSeconds) void OSD_Chronometer::GetProcessCPU (Standard_Real& theUserSeconds,
Standard_Real& theSystemSeconds)
{ {
#ifndef OCCT_UWP #ifndef OCCT_UWP
FILETIME ftStart, ftExit, ftKernel, ftUser; FILETIME ftStart, ftExit, ftKernel, ftUser;
::GetProcessTimes (GetCurrentProcess(), &ftStart, &ftExit, &ftKernel, &ftUser); ::GetProcessTimes (GetCurrentProcess(), &ftStart, &ftExit, &ftKernel, &ftUser);
UserSeconds = 0.0000001 * EncodeFILETIME (&ftUser); theUserSeconds = 0.0000001 * EncodeFILETIME (&ftUser);
SystemSeconds = 0.0000001 * EncodeFILETIME (&ftKernel); theSystemSeconds = 0.0000001 * EncodeFILETIME (&ftKernel);
#else #else
UserSeconds = 0.0; theUserSeconds = 0.0;
SystemSeconds = 0.0; theSystemSeconds = 0.0;
#endif #endif
} }
@ -150,33 +143,35 @@ void OSD_Chronometer::GetProcessCPU (Standard_Real& UserSeconds, Standard_Real&
//function : GetThreadCPU //function : GetThreadCPU
//purpose : //purpose :
//======================================================================= //=======================================================================
void OSD_Chronometer::GetThreadCPU (Standard_Real& UserSeconds, Standard_Real& SystemSeconds) void OSD_Chronometer::GetThreadCPU (Standard_Real& theUserSeconds,
Standard_Real& theSystemSeconds)
{ {
#ifndef OCCT_UWP #ifndef OCCT_UWP
FILETIME ftStart, ftExit, ftKernel, ftUser; FILETIME ftStart, ftExit, ftKernel, ftUser;
::GetThreadTimes (GetCurrentThread(), &ftStart, &ftExit, &ftKernel, &ftUser); ::GetThreadTimes (GetCurrentThread(), &ftStart, &ftExit, &ftKernel, &ftUser);
UserSeconds = 0.0000001 * EncodeFILETIME (&ftUser); theUserSeconds = 0.0000001 * EncodeFILETIME (&ftUser);
SystemSeconds = 0.0000001 * EncodeFILETIME (&ftKernel); theSystemSeconds = 0.0000001 * EncodeFILETIME (&ftKernel);
#else #else
UserSeconds = 0.0; theUserSeconds = 0.0;
SystemSeconds = 0.0; theSystemSeconds = 0.0;
#endif #endif
} }
#endif /* _WIN32 */ #endif /* _WIN32 */
// ====================== PLATFORM-INDEPENDENT PART ========================
//======================================================================= //=======================================================================
//function : OSD_Chronometer //function : OSD_Chronometer
//purpose : //purpose :
//======================================================================= //=======================================================================
OSD_Chronometer::OSD_Chronometer(const Standard_Boolean ThisThreadOnly) OSD_Chronometer::OSD_Chronometer (Standard_Boolean theThisThreadOnly)
: myStartCpuUser (0.0),
myStartCpuSys (0.0),
myCumulCpuUser (0.0),
myCumulCpuSys (0.0),
myIsStopped (Standard_True),
myIsThreadOnly (theThisThreadOnly)
{ {
ThreadOnly = ThisThreadOnly; //
Start_user = Start_sys = 0.;
Cumul_user = Cumul_sys = 0.;
Stopped = Standard_True;
} }
//======================================================================= //=======================================================================
@ -193,9 +188,9 @@ OSD_Chronometer::~OSD_Chronometer()
//======================================================================= //=======================================================================
void OSD_Chronometer::Reset () void OSD_Chronometer::Reset ()
{ {
Stopped = Standard_True; myIsStopped = Standard_True;
Start_user = Start_sys = 0.; myStartCpuUser = myStartCpuSys = 0.;
Cumul_user = Cumul_sys = 0.; myCumulCpuUser = myCumulCpuSys = 0.;
} }
@ -213,21 +208,21 @@ void OSD_Chronometer::Restart ()
//function : Stop //function : Stop
//purpose : //purpose :
//======================================================================= //=======================================================================
void OSD_Chronometer::Stop () void OSD_Chronometer::Stop()
{ {
if ( !Stopped ) { if (!myIsStopped)
{
Standard_Real Curr_user, Curr_sys; Standard_Real Curr_user, Curr_sys;
if ( ThreadOnly ) if (myIsThreadOnly)
GetThreadCPU (Curr_user, Curr_sys); GetThreadCPU (Curr_user, Curr_sys);
else else
GetProcessCPU (Curr_user, Curr_sys); GetProcessCPU (Curr_user, Curr_sys);
Cumul_user += Curr_user - Start_user; myCumulCpuUser += Curr_user - myStartCpuUser;
Cumul_sys += Curr_sys - Start_sys; myCumulCpuSys += Curr_sys - myStartCpuSys;
Stopped = Standard_True; myIsStopped = Standard_True;
} }
// else cerr << "WARNING: OSD_Chronometer already stopped !\n" << flush;
} }
//======================================================================= //=======================================================================
@ -236,15 +231,15 @@ void OSD_Chronometer::Stop ()
//======================================================================= //=======================================================================
void OSD_Chronometer::Start () void OSD_Chronometer::Start ()
{ {
if ( Stopped ) { if (myIsStopped)
if ( ThreadOnly ) {
GetThreadCPU (Start_user, Start_sys); if (myIsThreadOnly)
GetThreadCPU (myStartCpuUser, myStartCpuSys);
else else
GetProcessCPU (Start_user, Start_sys); GetProcessCPU (myStartCpuUser, myStartCpuSys);
Stopped = Standard_False; myIsStopped = Standard_False;
} }
// else cerr << "WARNING: OSD_Chronometer already running !\n" << flush;
} }
//======================================================================= //=======================================================================
@ -253,76 +248,42 @@ void OSD_Chronometer::Start ()
//======================================================================= //=======================================================================
void OSD_Chronometer::Show() const void OSD_Chronometer::Show() const
{ {
Show (cout); Show (std::cout);
} }
//======================================================================= //=======================================================================
//function : Show //function : Show
//purpose : //purpose :
//======================================================================= //=======================================================================
void OSD_Chronometer::Show (Standard_OStream& os) const void OSD_Chronometer::Show (Standard_OStream& theOStream) const
{ {
Standard_Real aCumulUserSec = Cumul_user; Standard_Real aCumulUserSec = 0.0, aCumulSysSec = 0.0;
Standard_Real aCumulSysSec = Cumul_sys; Show (aCumulUserSec, aCumulSysSec);
if (!Stopped) std::streamsize prec = theOStream.precision (12);
{ theOStream << "CPU user time: " << aCumulUserSec << " seconds\n";
Standard_Real aCurrUser, aCurrSys; theOStream << "CPU system time: " << aCumulSysSec << " seconds\n";
if (ThreadOnly) theOStream.precision (prec);
GetThreadCPU (aCurrUser, aCurrSys);
else
GetProcessCPU (aCurrUser, aCurrSys);
aCumulUserSec += aCurrUser - Start_user;
aCumulSysSec += aCurrSys - Start_sys;
}
std::streamsize prec = os.precision (12);
os << "CPU user time: " << aCumulUserSec << " seconds " << endl;
os << "CPU system time: " << aCumulSysSec << " seconds " << endl;
os.precision (prec);
} }
//======================================================================= //=======================================================================
//function : Show //function : Show
//purpose : Returns cpu user time //purpose :
//======================================================================= //=======================================================================
void OSD_Chronometer::Show (Standard_Real& theUserSec) const void OSD_Chronometer::Show (Standard_Real& theUserSec, Standard_Real& theSystemSec) const
{ {
theUserSec = Cumul_user; theUserSec = myCumulCpuUser;
if (Stopped) theSystemSec = myCumulCpuSys;
if (myIsStopped)
{ {
return; return;
} }
Standard_Real aCurrUser, aCurrSys; Standard_Real aCurrUser, aCurrSys;
if (ThreadOnly) if (myIsThreadOnly)
GetThreadCPU (aCurrUser, aCurrSys); GetThreadCPU (aCurrUser, aCurrSys);
else else
GetProcessCPU (aCurrUser, aCurrSys); GetProcessCPU (aCurrUser, aCurrSys);
theUserSec += aCurrUser - Start_user; theUserSec += aCurrUser - myStartCpuUser;
} theSystemSec += aCurrSys - myStartCpuSys;
//=======================================================================
//function : Show
//purpose : Returns both user and system cpu times
//=======================================================================
void OSD_Chronometer::Show (Standard_Real& theUserSec,
Standard_Real& theSystemSec) const
{
theUserSec = Cumul_user;
theSystemSec = Cumul_sys;
if (Stopped)
{
return;
}
Standard_Real aCurrUser, aCurrSys;
if (ThreadOnly)
GetThreadCPU (aCurrUser, aCurrSys);
else
GetProcessCPU (aCurrUser, aCurrSys);
theUserSec += aCurrUser - Start_user;
theSystemSec += aCurrSys - Start_sys;
} }

View File

@ -20,12 +20,9 @@
#include <Standard.hxx> #include <Standard.hxx>
#include <Standard_DefineAlloc.hxx> #include <Standard_DefineAlloc.hxx>
#include <Standard_Handle.hxx> #include <Standard_Handle.hxx>
#include <Standard_Boolean.hxx>
#include <Standard_Real.hxx> #include <Standard_Real.hxx>
#include <Standard_OStream.hxx> #include <Standard_OStream.hxx>
//! This class measures CPU time (both user and system) consumed //! This class measures CPU time (both user and system) consumed
//! by current process or thread. The chronometer can be started //! by current process or thread. The chronometer can be started
//! and stopped multiple times, and measures cumulative time. //! and stopped multiple times, and measures cumulative time.
@ -40,17 +37,18 @@ public:
DEFINE_STANDARD_ALLOC DEFINE_STANDARD_ALLOC
//! Initializes a stopped Chronometer. //! Initializes a stopped Chronometer.
//! //!
//! If ThisThreadOnly is True, measured CPU time will account //! If ThisThreadOnly is True, measured CPU time will account
//! time of the current thread only; otherwise CPU of the //! time of the current thread only; otherwise CPU of the
//! process (all threads, and completed children) is measured. //! process (all threads, and completed children) is measured.
Standard_EXPORT OSD_Chronometer(const Standard_Boolean ThisThreadOnly = Standard_False); Standard_EXPORT OSD_Chronometer (Standard_Boolean theThisThreadOnly = Standard_False);
//! Destructor.
Standard_EXPORT virtual ~OSD_Chronometer(); Standard_EXPORT virtual ~OSD_Chronometer();
//! Return true if timer has been started. //! Return true if timer has been started.
Standard_Boolean IsStarted() const { return !Stopped; } Standard_Boolean IsStarted() const { return !myIsStopped; }
//! Stops and Reinitializes the Chronometer. //! Stops and Reinitializes the Chronometer.
Standard_EXPORT virtual void Reset(); Standard_EXPORT virtual void Reset();
@ -73,16 +71,36 @@ public:
//! Shows the current CPU user and system time on the output //! Shows the current CPU user and system time on the output
//! stream <os>. //! stream <os>.
//! The chronometer can be running (laps Time) or stopped. //! The chronometer can be running (laps Time) or stopped.
Standard_EXPORT virtual void Show (Standard_OStream& os) const; Standard_EXPORT virtual void Show (Standard_OStream& theOStream) const;
//! Returns the current CPU user time in seconds.
//! The chronometer can be running (laps Time) or stopped.
Standard_Real UserTimeCPU() const
{
Standard_Real aUserTime = 0.0, aSysTime = 0.0;
Show (aUserTime, aSysTime);
return aUserTime;
}
//! Returns the current CPU system time in seconds.
//! The chronometer can be running (laps Time) or stopped.
Standard_Real SystemTimeCPU() const
{
Standard_Real aUserTime = 0.0, aSysTime = 0.0;
Show (aUserTime, aSysTime);
return aSysTime;
}
//! Returns the current CPU user time in a variable. //! Returns the current CPU user time in a variable.
//! The chronometer can be running (laps Time) or stopped. //! The chronometer can be running (laps Time) or stopped.
Standard_EXPORT void Show (Standard_Real& theUserSeconds) const; void Show (Standard_Real& theUserSeconds) const { theUserSeconds = UserTimeCPU(); }
//! Returns the current CPU user and system time in variables. //! Returns the current CPU user and system time in variables.
//! The chronometer can be running (laps Time) or stopped. //! The chronometer can be running (laps Time) or stopped.
Standard_EXPORT void Show (Standard_Real& theUserSeconds, Standard_Real& theSystemSeconds) const; Standard_EXPORT void Show (Standard_Real& theUserSec, Standard_Real& theSystemSec) const;
public:
//! Returns CPU time (user and system) consumed by the current //! Returns CPU time (user and system) consumed by the current
//! process since its start, in seconds. The actual precision of //! process since its start, in seconds. The actual precision of
//! the measurement depends on granularity provided by the system, //! the measurement depends on granularity provided by the system,
@ -95,33 +113,15 @@ public:
//! differently on different platforms and CPUs. //! differently on different platforms and CPUs.
Standard_EXPORT static void GetThreadCPU (Standard_Real& UserSeconds, Standard_Real& SystemSeconds); Standard_EXPORT static void GetThreadCPU (Standard_Real& UserSeconds, Standard_Real& SystemSeconds);
protected: protected:
Standard_Real myStartCpuUser;
Standard_Real myStartCpuSys;
Standard_Boolean Stopped; Standard_Real myCumulCpuUser;
Standard_Real myCumulCpuSys;
Standard_Boolean myIsStopped;
private: Standard_Boolean myIsThreadOnly;
Standard_Boolean ThreadOnly;
Standard_Real Start_user;
Standard_Real Start_sys;
Standard_Real Cumul_user;
Standard_Real Cumul_sys;
}; };
#endif // _OSD_Chronometer_HeaderFile #endif // _OSD_Chronometer_HeaderFile

View File

@ -14,17 +14,10 @@
// Alternatively, this file may be used under the terms of Open CASCADE // Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement. // commercial license or contractual agreement.
// Update: J.P. TIRAULT Sep,1993
// On heterogeneous platforms we need to use the
// system call gettimeofday. This function is portable and give us
// elapsed time in seconds and microseconds.
#include <OSD_Timer.hxx> #include <OSD_Timer.hxx>
#ifndef _WIN32 #ifndef _WIN32
//---------- No Windows NT Systems ----------------------------------
#include <sys/time.h> #include <sys/time.h>
//======================================================================= //=======================================================================
@ -42,7 +35,6 @@ static inline Standard_Real GetWallClockTime ()
} }
#else #else
//------------------- Windows NT ------------------
#include <windows.h> #include <windows.h>
@ -69,36 +61,36 @@ static inline Standard_Real GetWallClockTime ()
#endif /* _WIN32 */ #endif /* _WIN32 */
// ====================== PLATFORM-INDEPENDENT PART ======================== namespace
{
//! Auxiliary function splits elapsed time in seconds into Hours, Minutes and Seconds.
//! @param theTimeSec [in] elapsed time in seconds
//! @param theHours [out] clamped elapsed hours
//! @param theMinutes [out] clamped elapsed minutes within range [0, 59]
//! @param theSeconds [out] clamped elapsed seconds within range [0, 60)
static void timeToHoursMinutesSeconds (Standard_Real theTimeSec,
Standard_Integer& theHours,
Standard_Integer& theMinutes,
Standard_Real& theSeconds)
{
Standard_Integer aSec = (Standard_Integer)theTimeSec;
theHours = aSec / 3600;
theMinutes = (aSec - theHours * 3600) / 60;
theSeconds = theTimeSec - theHours * 3600 - theMinutes * 60;
}
}
//======================================================================= //=======================================================================
//function : OSD_Timer //function : OSD_Timer
//purpose : //purpose :
//======================================================================= //=======================================================================
OSD_Timer::OSD_Timer() OSD_Timer::OSD_Timer (Standard_Boolean theThisThreadOnly)
: OSD_Chronometer (theThisThreadOnly),
myTimeStart (0.0),
myTimeCumul (0.0)
{ {
TimeStart = TimeCumul = 0.; //
}
//=======================================================================
//function : Compute
//purpose : Calcul les Heures,Minutes,Secondes,Millisecondes a partir
// de deux variables input qui sont:
// TimeCumulInt : Contient un periode de temps exprimee en secondes,
// MicroCumulInt: Contient cette meme periode exprimee en
// microsecondes.
//=======================================================================
static void Compute (Standard_Real Time,
Standard_Integer& heure,
Standard_Integer& minut,
Standard_Real& second)
{
Standard_Integer sec = (Standard_Integer)Time;
heure = sec / 3600;
minut = (sec - heure * 3600) / 60;
second = Time - heure * 3600 - minut * 60;
} }
//======================================================================= //=======================================================================
@ -108,8 +100,8 @@ static void Compute (Standard_Real Time,
void OSD_Timer::Reset (const Standard_Real theTimeElapsedSec) void OSD_Timer::Reset (const Standard_Real theTimeElapsedSec)
{ {
TimeStart = 0.0; myTimeStart = 0.0;
TimeCumul = theTimeElapsedSec; myTimeCumul = theTimeElapsedSec;
OSD_Chronometer::Reset(); OSD_Chronometer::Reset();
} }
@ -120,7 +112,7 @@ void OSD_Timer::Reset (const Standard_Real theTimeElapsedSec)
void OSD_Timer::Reset () void OSD_Timer::Reset ()
{ {
TimeStart = TimeCumul = 0.; myTimeStart = myTimeCumul = 0.0;
OSD_Chronometer::Reset(); OSD_Chronometer::Reset();
} }
@ -131,8 +123,8 @@ void OSD_Timer::Reset ()
void OSD_Timer::Restart () void OSD_Timer::Restart ()
{ {
TimeStart = GetWallClockTime(); myTimeStart = GetWallClockTime();
TimeCumul = 0.; myTimeCumul = 0.0;
OSD_Chronometer::Restart(); OSD_Chronometer::Restart();
} }
@ -153,12 +145,12 @@ void OSD_Timer::Show() const
Standard_Real OSD_Timer::ElapsedTime() const Standard_Real OSD_Timer::ElapsedTime() const
{ {
if (Stopped) if (myIsStopped)
{ {
return TimeCumul; return myTimeCumul;
} }
return TimeCumul + GetWallClockTime() - TimeStart; return myTimeCumul + GetWallClockTime() - myTimeStart;
} }
//======================================================================= //=======================================================================
@ -171,10 +163,10 @@ void OSD_Timer::Show (Standard_Real& theSeconds,
Standard_Integer& theHours, Standard_Integer& theHours,
Standard_Real& theCPUtime) const Standard_Real& theCPUtime) const
{ {
const Standard_Real aTimeCumul = Stopped const Standard_Real aTimeCumul = myIsStopped
? TimeCumul ? myTimeCumul
: TimeCumul + GetWallClockTime() - TimeStart; : myTimeCumul + GetWallClockTime() - myTimeStart;
Compute (aTimeCumul, theHours, theMinutes, theSeconds); timeToHoursMinutesSeconds (aTimeCumul, theHours, theMinutes, theSeconds);
OSD_Chronometer::Show (theCPUtime); OSD_Chronometer::Show (theCPUtime);
} }
@ -183,22 +175,20 @@ void OSD_Timer::Show (Standard_Real& theSeconds,
//purpose : //purpose :
//======================================================================= //=======================================================================
void OSD_Timer::Show (Standard_OStream& os) const void OSD_Timer::Show (Standard_OStream& theOStream) const
{ {
const Standard_Real aTimeCumul = Stopped const Standard_Real aTimeCumul = ElapsedTime();
? TimeCumul
: TimeCumul + GetWallClockTime() - TimeStart;
Standard_Integer anHours, aMinutes; Standard_Integer anHours, aMinutes;
Standard_Real aSeconds; Standard_Real aSeconds;
Compute (aTimeCumul, anHours, aMinutes, aSeconds); timeToHoursMinutesSeconds (aTimeCumul, anHours, aMinutes, aSeconds);
std::streamsize prec = os.precision (12); std::streamsize prec = theOStream.precision (12);
os << "Elapsed time: " << anHours << " Hours " << theOStream << "Elapsed time: " << anHours << " Hours " <<
aMinutes << " Minutes " << aMinutes << " Minutes " <<
aSeconds << " Seconds " << endl; aSeconds << " Seconds\n";
OSD_Chronometer::Show(os); OSD_Chronometer::Show (theOStream);
os.precision (prec); theOStream.precision (prec);
} }
//======================================================================= //=======================================================================
@ -208,11 +198,11 @@ void OSD_Timer::Show (Standard_OStream& os) const
void OSD_Timer::Stop () void OSD_Timer::Stop ()
{ {
if (!Stopped) { if (!myIsStopped)
TimeCumul += GetWallClockTime () - TimeStart; {
myTimeCumul += GetWallClockTime() - myTimeStart;
OSD_Chronometer::Stop(); OSD_Chronometer::Stop();
} }
// else cout << "WARNING: OSD_Timer already Stopped !\n";
} }
//======================================================================= //=======================================================================
@ -222,9 +212,9 @@ void OSD_Timer::Stop ()
void OSD_Timer::Start() void OSD_Timer::Start()
{ {
if (Stopped) { if (myIsStopped)
TimeStart = GetWallClockTime(); {
myTimeStart = GetWallClockTime();
OSD_Chronometer::Start(); OSD_Chronometer::Start();
} }
// else cout << "WARNING: OSD_Timer already Running !\n";
} }

View File

@ -45,7 +45,10 @@ public:
DEFINE_STANDARD_ALLOC DEFINE_STANDARD_ALLOC
//! Builds a Chronometer initialized and stopped. //! Builds a Chronometer initialized and stopped.
Standard_EXPORT OSD_Timer(); //! @param theThisThreadOnly when TRUE, measured CPU time will account time of the current thread only;
//! otherwise CPU of the process (all threads, and completed children) is measured;
//! this flag does NOT affect ElapsedTime() value, only values returned by OSD_Chronometer
Standard_EXPORT OSD_Timer (Standard_Boolean theThisThreadOnly = Standard_False);
//! Stops and reinitializes the timer with specified elapsed time. //! Stops and reinitializes the timer with specified elapsed time.
Standard_EXPORT void Reset (const Standard_Real theTimeElapsedSec); Standard_EXPORT void Reset (const Standard_Real theTimeElapsedSec);
@ -81,8 +84,8 @@ public:
private: private:
Standard_Real TimeStart; Standard_Real myTimeStart;
Standard_Real TimeCumul; Standard_Real myTimeCumul;
}; };