-- the chronometer.
---Level: Public
- Show (me : in out) is virtual;
+ Show (me) is virtual;
---Purpose: Shows the current CPU user and system time on the
-- standard output stream <cout>.
-- The chronometer can be running (laps Time) or stopped.
---Level: Public
- Show (me : in out; os : in out OStream from Standard) is virtual;
+ Show (me; os : in out OStream from Standard) is virtual;
---Purpose: Shows the current CPU user and system time on the output
-- stream <os>.
-- The chronometer can be running (laps Time) or stopped.
---Level: Public
- Show (me : in out; UserSeconds : in out Real from Standard) ;
+ Show (me; theUserSeconds : in out Real from Standard);
---Purpose: Returns the current CPU user time in a variable.
-- The chronometer can be running (laps Time) or stopped.
---Level: Public
- Show (me : in out; UserSeconds : in out Real from Standard;
- SystemSeconds : in out Real from Standard) ;
+ Show (me; theUserSeconds : in out Real from Standard;
+ theSystemSeconds : in out Real from Standard);
---Purpose: Returns the current CPU user and system time in variables.
-- The chronometer can be running (laps Time) or stopped.
---Level: Public
//function : Show
//purpose :
//=======================================================================
-void OSD_Chronometer::Show ()
+void OSD_Chronometer::Show() const
{
Show (cout);
}
//function : Show
//purpose :
//=======================================================================
-void OSD_Chronometer::Show (Standard_OStream& os)
+void OSD_Chronometer::Show (Standard_OStream& os) const
{
- Standard_Boolean StopSav = Stopped;
- if (!StopSav) Stop();
+ Standard_Real aCumulUserSec = Cumul_user;
+ Standard_Real aCumulSysSec = Cumul_sys;
+ if (!Stopped)
+ {
+ Standard_Real aCurrUser, aCurrSys;
+ if (ThreadOnly)
+ 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: " << Cumul_user << " seconds " << endl;
- os << "CPU system time: " << Cumul_sys << " seconds " << endl;
+ os << "CPU user time: " << aCumulUserSec << " seconds " << endl;
+ os << "CPU system time: " << aCumulSysSec << " seconds " << endl;
os.precision (prec);
- if (!StopSav) Start();
}
//=======================================================================
//function : Show
//purpose : Returns cpu user time
//=======================================================================
-void OSD_Chronometer::Show (Standard_Real& second)
+void OSD_Chronometer::Show (Standard_Real& theUserSec) const
{
- Standard_Boolean StopSav = Stopped;
- if (!StopSav) Stop();
- second = Cumul_user;
- if (!StopSav) Start();
+ theUserSec = Cumul_user;
+ if (Stopped)
+ {
+ return;
+ }
+
+ Standard_Real aCurrUser, aCurrSys;
+ if (ThreadOnly)
+ GetThreadCPU (aCurrUser, aCurrSys);
+ else
+ GetProcessCPU (aCurrUser, aCurrSys);
+
+ theUserSec += aCurrUser - Start_user;
}
+
//=======================================================================
//function : Show
//purpose : Returns both user and system cpu times
//=======================================================================
-void OSD_Chronometer::Show (Standard_Real& user,
- Standard_Real& system)
+void OSD_Chronometer::Show (Standard_Real& theUserSec,
+ Standard_Real& theSystemSec) const
{
- Standard_Boolean StopSav = Stopped;
- if (!StopSav) Stop();
- user = Cumul_user;
- system = Cumul_sys;
- if (!StopSav) Start();
-}
+ 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;
+}
---Purpose: Stops and reinitializes the timer.
---Level: Public
- Show (me : in out) is redefined;
+ Show (me) is redefined;
---Purpose: Shows both the elapsed time and CPU time on the standard output
-- stream <cout>.The chronometer can be running (Lap Time) or
-- stopped.
---Level: Public
- Show (me : in out; os : in out OStream from Standard) is redefined;
+ Show (me; os : in out OStream from Standard) is redefined;
---Purpose: Shows both the elapsed time and CPU time on the
-- output stream <OS>.
---Level: Public
- Show (me : in out; seconds : in out Real from Standard;
- minutes : in out Integer from Standard;
- hours : in out Integer from Standard;
- CPUtime : in out Real from Standard);
-
+ Show (me; theSeconds : in out Real from Standard;
+ theMinutes : in out Integer from Standard;
+ theHours : in out Integer from Standard;
+ theCPUtime : in out Real from Standard);
+
---Purpose: returns both the elapsed time(seconds,minutes,hours)
-- and CPU time.
---Level: Public
-- the Timer.
---Level: Public
- ElapsedTime (me : in out) returns Real;
+ ElapsedTime (me) returns Real;
---Purpose: Returns elapsed time in seconds.
---Level: Public
//purpose :
//=======================================================================
-void OSD_Timer::Show ()
+void OSD_Timer::Show() const
{
Show (cout);
}
//purpose :
//=======================================================================
-Standard_Real OSD_Timer::ElapsedTime()
+Standard_Real OSD_Timer::ElapsedTime() const
{
- if (!Stopped)
+ if (Stopped)
{
- // update cumulative time
- Stop();
- Start();
+ return TimeCumul;
}
- return TimeCumul;
+ return TimeCumul + GetWallClockTime() - TimeStart;
}
//=======================================================================
//purpose :
//=======================================================================
-void OSD_Timer::Show (Standard_Real& seconds,
- Standard_Integer& minutes,
- Standard_Integer& hours,
- Standard_Real& CPUtime)
+void OSD_Timer::Show (Standard_Real& theSeconds,
+ Standard_Integer& theMinutes,
+ Standard_Integer& theHours,
+ Standard_Real& theCPUtime) const
{
- Standard_Boolean StopSav=Stopped;
- if (!StopSav) Stop();
-
- Compute (TimeCumul, hours, minutes, seconds);
- OSD_Chronometer::Show(CPUtime);
-
- if (!StopSav) Start();
+ const Standard_Real aTimeCumul = Stopped
+ ? TimeCumul
+ : TimeCumul + GetWallClockTime() - TimeStart;
+ Compute (aTimeCumul, theHours, theMinutes, theSeconds);
+ OSD_Chronometer::Show (theCPUtime);
}
-
//=======================================================================
//function : Show
//purpose :
//=======================================================================
-void OSD_Timer::Show (Standard_OStream& os)
+void OSD_Timer::Show (Standard_OStream& os) const
{
- Standard_Boolean StopSav=Stopped;
- if (!StopSav) Stop();
-
- Standard_Integer heure,minut;
- Standard_Real second;
- Compute (TimeCumul, heure, minut, second);
-
- std::streamsize prec = os.precision (12);
- os << "Elapsed time: " << heure << " Hours " <<
- minut << " Minutes " <<
- second << " Seconds " << endl;
+ const Standard_Real aTimeCumul = Stopped
+ ? TimeCumul
+ : TimeCumul + GetWallClockTime() - TimeStart;
+
+ Standard_Integer anHours, aMinutes;
+ Standard_Real aSeconds;
+ Compute (aTimeCumul, anHours, aMinutes, aSeconds);
+
+ std::streamsize prec = os.precision (12);
+ os << "Elapsed time: " << anHours << " Hours " <<
+ aMinutes << " Minutes " <<
+ aSeconds << " Seconds " << endl;
OSD_Chronometer::Show(os);
os.precision (prec);
-
- if (!StopSav) Start();
}
//=======================================================================
--- /dev/null
+puts "========"
+puts "OCC25514"
+puts "========"
+puts ""
+#########################################################################################
+# TKernel, OSD_Timer - do not accumulate error in timer within queries in running state
+#########################################################################################
+
+# Set number of cycle iteration
+set IterationCount 10000
+set iCounter 1
+
+# Set rank of timer's value
+set TimeRank 2
+
+# Start timers
+dchrono bug_info_1 reset
+dchrono bug_info_2 reset
+dchrono bug_info_1 start
+dchrono bug_info_2 start
+
+# Operation cycle (show only one timer state)
+while {$iCounter != $IterationCount} {
+ dchrono bug_info_1 show
+ set iCounter [expr {$iCounter + 1}]
+}
+
+# Stop timers
+dchrono bug_info_1 stop
+dchrono bug_info_2 stop
+
+# Get timers value
+set Timer_1 [dchrono bug_info_1 show]
+set Timer_2 [dchrono bug_info_2 show]
+
+# Modify timers value for comparison
+set TimerValue_1 [lindex $Timer_1 6]
+set TimerValue_1 [string range $TimerValue_1 0 [expr {[string first "." $TimerValue_1] + $TimeRank}]]
+set TimerValue_2 [lindex $Timer_2 6]
+set TimerValue_2 [string range $TimerValue_2 0 [expr {[string first "." $TimerValue_2] + $TimeRank}]]
+
+# Comparison of timer's values
+puts "Compare: [lindex $Timer_1 6] vs [lindex $Timer_2 6]"
+if {$TimerValue_1 != $TimerValue_2} {
+ puts "ERROR: OCC25514 is reproduced."
+} else {
+ puts "OK"
+}