From: kgv Date: Fri, 28 Nov 2014 10:22:41 +0000 (+0300) Subject: 0025514: TKernel, OSD_Timer - do not accumulate error in timer within queries in... X-Git-Tag: V6_9_0_beta~265 X-Git-Url: http://git.dev.opencascade.org/gitweb/?p=occt.git;a=commitdiff_plain;h=7e7bbb3a9eacf803db3491e4c4a36075917f2deb 0025514: TKernel, OSD_Timer - do not accumulate error in timer within queries in running state Test-case for issue #25514 Update of test-case --- diff --git a/src/OSD/OSD_Chronometer.cdl b/src/OSD/OSD_Chronometer.cdl index 39f7aff02c..dc18480d70 100644 --- a/src/OSD/OSD_Chronometer.cdl +++ b/src/OSD/OSD_Chronometer.cdl @@ -58,25 +58,25 @@ is -- 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 . -- 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 . -- 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 diff --git a/src/OSD/OSD_Chronometer.cxx b/src/OSD/OSD_Chronometer.cxx index a3333c9dd9..6d95272d16 100644 --- a/src/OSD/OSD_Chronometer.cxx +++ b/src/OSD/OSD_Chronometer.cxx @@ -231,7 +231,7 @@ void OSD_Chronometer::Start () //function : Show //purpose : //======================================================================= -void OSD_Chronometer::Show () +void OSD_Chronometer::Show() const { Show (cout); } @@ -240,39 +240,69 @@ void OSD_Chronometer::Show () //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; +} diff --git a/src/OSD/OSD_Timer.cdl b/src/OSD/OSD_Timer.cdl index 32dc3c5546..65cc6a8372 100644 --- a/src/OSD/OSD_Timer.cdl +++ b/src/OSD/OSD_Timer.cdl @@ -41,22 +41,22 @@ is ---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 .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 . ---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 @@ -70,7 +70,7 @@ is -- the Timer. ---Level: Public - ElapsedTime (me : in out) returns Real; + ElapsedTime (me) returns Real; ---Purpose: Returns elapsed time in seconds. ---Level: Public diff --git a/src/OSD/OSD_Timer.cxx b/src/OSD/OSD_Timer.cxx index ef8773f2ba..c7bae8a581 100644 --- a/src/OSD/OSD_Timer.cxx +++ b/src/OSD/OSD_Timer.cxx @@ -115,7 +115,7 @@ void OSD_Timer::Reset () //purpose : //======================================================================= -void OSD_Timer::Show () +void OSD_Timer::Show() const { Show (cout); } @@ -125,16 +125,14 @@ void OSD_Timer::Show () //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; } //======================================================================= @@ -142,43 +140,39 @@ Standard_Real OSD_Timer::ElapsedTime() //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(); } //======================================================================= diff --git a/tests/bugs/fclasses/bug25514 b/tests/bugs/fclasses/bug25514 new file mode 100644 index 0000000000..480179b90e --- /dev/null +++ b/tests/bugs/fclasses/bug25514 @@ -0,0 +1,48 @@ +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" +}